Programming Logic and Algorithms Study Guide
Fundamentals of Programming Logic and Reasoning
Etymology and Definition of Logic:
- Logic originates from the Greek term logiké, which is intrinsically related to logos, meaning reason, word, or discourse.
- Logic represents the structured manner of thinking and reasoning, encompassing intellectual operations and cognitive processing.
Application in Computer Science:
- Programming relies heavily on logical reasoning to structure computer programs with coherence, clarity, and practicality.
- Logical application occurs when thoughts and ideas are coherent and sequentially chained together.
Relevance for Computing Professionals:
- Proficiency in logical reasoning is essential for software developers, database administrators (DBAs), network analysts, and systems architects.
Programming Logic Definition:
- According to Moraes (2000, p. 4), programming logic is defined as the technique of chaining thoughts to achieve a specific goal.
- In computer programming, thoughts are translated into a sequence of ordered instructions executed as tasks to solve a given problem.
Concept of Instructions:
- In general language, instructions are rules or standards established for performing or using something.
- In computing, an instruction consists of one or more pieces of information directing the computer to perform a specific action or task.
Logic and Correctness of Thought:
- According to Oliveira et al. (2012, p. 23), logic treats the correctness of thought. As philosophy, it examines why thoughts occur in specific ways; as an art or technique, it teaches the proper application of the laws of thought.
- Logic establishes order in human reasoning, preventing chaotic or disorganized thoughts, and uses premises (prior knowledge) to determine whether conclusions are true or false.
- According to Forbellone and Eberspacher (2005, p. 12), logic is the "art of thinking well" and the "science of the forms of thought." It focuses on the correctness of reasoning to bring order to reason.
Characteristic Actions of Technical Logic:
- According to Raulino (2013), logical proficiency enables six characteristic actions:
- Organizing knowledge across any domain of activity.
- Reasoning correctly without conscious strain.
- Observing and interpreting information rapidly.
- Expanding linguistic competence in oral and written expression.
- Developing aptitude for quantitative reasoning.
- Recognizing structural patterns within premises, presuppositions, and scenarios.
Logical Arguments and Structure
Structure of Logical Arguments:
- Sequentially chained thoughts form arguments.
- According to Raulino (2013), logical arguments follow specific structural principles:
- Propositions are the explicit affirmations comprising an argument.
- An argument is a collection of propositions arranged such that one proposition derives directly from the others.
- The derived proposition is designated as the conclusion (), while the supporting propositions are termed premises ().
- In a valid argument, premises serve as evident proof establishing the truth of the conclusion.
- The terms hypothesis and thesis are frequently used as technical synonyms for premises and conclusion, respectively.
Syllogisms:
- A syllogism is a formal logical argument consisting of exactly two premises and one conclusion.
- Example of a valid syllogism:
- Premises:
- : Todo cearense é humorista.
- : Todo humorista gosta de forró.
- Conclusion:
- : Todo cearense gosta de forró.
Validity versus Truth:
- According to Lima (2012), the study of arguments in formal logic evaluates exclusively the validity of the structural connection between premises and conclusion, irrespective of whether individual premises are empirically true or false.

Logic Notation and Formal Representations
Definition of Notation:
- Notation represents concepts, elements, or operations through standardized graphic symbols or characters within a specific field of knowledge.
Propositional Symbolic Notation:
- According to Bianchi (2012), logical values of propositions use standardized notation:
- Simple Propositions: Represented by lowercase letters (e.g., , , ).
- Compound Propositions: Represented by uppercase letters (e.g., , , ).
- Logical Value Functions:
- indicates that the logical value of proposition is True ().
- indicates that the logical value of proposition is False ().
Notation Examples:
- Simple Propositions:
- : "Um triângulo tem três lados."
- : "São Paulo é um país."
- Compound Propositions:
- Let : "O sol é uma estrela" and : "A terra é uma estrela."
- (where symbol represents the logical disjunction connective "ou").
Formulas:
- According to Alencar Filho (2002), compound propositions constructed from combinations of simple propositions are also designated as propositional formulas or simply formulas.
Propositional Logic, Grammar, and Principles
Definition of Proposition:
- According to Bianchi (2012), a proposition is a set of words or symbols expressing a thought with complete sense, allowing the assignment of exactly one of two possible logical values: True () or False ().
- According to Andrade and Carmelo (1999), a proposition is a declarative sentence expressed via words or numbers.
Fundamental Axiomatic Principles:
- Principle of Non-Contradiction: A proposition cannot be simultaneously true and false under the same context.
- Principle of the Excluded Middle (Terceiro Excluído): A proposition is strictly either true or false; no third truth value exists.
Concrete Proposition Examples:
- "Fortaleza é a capital do estado do Ceará." True ()
- True ()
- False ()
- "O número 4 é primo, e o número 3 é par." False ()
- Declarative statements whose exact empirical values are unknown remain valid propositions (e.g., "Existe vida pós-morte.").
Formal Language versus Natural Language:
- According to Neto (2017, p. 2), natural human language is inadequate for formal logical analysis due to ambiguities and unrigorous syntax.
- Formal mathematical languages precisely specify grammar rules to evaluate logical relationships without ambiguity.
Composition of Propositional Logic Language:
- Alphabet: A countable set of admissible symbols:
- Propositional variables ()
- Logical connectives ()
- Natural language text combined with connectives
- Delimiters
() - Grammar: Formulates well-formed expressions via strict rules:
- Propositional variables are atomic formulas.
- If is a formula, is a formula.
- If and are formulas, , , , and are formulas.
- No other formulas exist beyond those generated by rules 1 through 3.
- Semantics: Assigns definitive truth values ( or ) to every expression derived from propositional formulas.
Types of Propositions:
- Simple Propositions (atomic statements):
- "Maria é muito bonita."
- "Antônio é estudioso."
- Compound Propositions (statements joined by connectives):
- "Carlos é enfermeiro, e Cecília é médica."
- "Comprei um carro novo; então, vamos viajar."
Logical Connectives and Truth Tables
Function of Connectives:
- According to Andrade and Carmelo (1999), logical operators or connectives (, , , , ) perform operations upon propositions analogous to arithmetic operators on numbers or intersection operators in set theory.
- The resulting truth value of a compound proposition depends strictly on the operator applied and the individual truth values of the constituent propositions.
Connective Symbols:
- Negation: or
- Conjunction:
- Disjunction:
- Conditional:
- Biconditional:
Truth Table Row Calculation:
- For simple propositions, the required number of rows in a truth table is computed as (where represents the binary logical values and ):
- For simple propositions (): rows.
- For simple propositions (): rows.
Truth Table Summary for Standard Connectives:
- Operational Rules for Connectives:
- Conjunction (): Expression (read as " e "). True exclusively when both and are True.
- Example: : "O sol é quente" (), : "" () is
- Negation (): Expression (read as "não ", "não é verdade que ", or "é falso que "). Inverts the truth value of
- Example: : "O canário é amarelo" : "O canário não é amarelo"
- Conditional (): Expression (read as "se então "). Represents logical implication. False strictly when premise is True and conclusion is False; True in all other cases.
- Example: : "O alfabeto tem vinte símbolos" (), : "O Brasil tem trinta estados" () is
- Biconditional (): Expression (read as " se e somente se "). True strictly when both propositions carry identical truth values (both True or both False).
- Example: : "O cachorro mia" (), : " é um número par" () is
Equivalence Properties in Propositional Logic
Logical properties permit algebraic transformation of compound propositions using identical connectives without altering truth table results.
Associative Property:
- Conjunction:
- Disjunction:
- Truth Table for Associative Conjunction:
- Commutative Property:
- Conjunction:
- Disjunction:
- Truth Table for Commutative Disjunction:
- Distributive Property:
- Conjunction over Disjunction:
- Disjunction over Conjunction:
- Truth Table for Distributive Conjunction over Disjunction:
Algorithms: Concept, Characteristics, and Execution Flow
Definition of Algorithm:
- According to Forbellone and Eberspacher (2005, p. 3), an algorithm is a sequence of steps designed to achieve a well-defined goal.
- According to the Instituto Federal Fluminense (2019, p. 6), an algorithm is the specification of an ordered sequence of instructions—finite and non-ambiguous—that must be followed to solve a specific problem, guaranteeing repeatability.
Purpose and Utility of Algorithms:
- Serves as the base conceptual framework for learning all programming languages.
- Enables problem solutions to be conceptualized independently before being translated (codified) into specific programming languages.
- Multiple distinct algorithms can be created to solve the exact same problem.
Essential Technical Characteristics:
- Complete: All instructions must be entirely clear and unique.
- Non-redundant: Instructions must admit only one single interpretation.
- Deterministic: Execution under identical conditions must consistently yield the expected result.
- Finite: Execution must begin and terminate after a specific, limited number of steps.
Examples of Linear Step-by-Step Flow:
- Changing a lightbulb:
- Identify burned-out lightbulb.
- Get a ladder.
- Position ladder under light fixture.
- Fetch new lightbulb.
- Climb ladder.
- Remove old lightbulb.
- Install new lightbulb.
- Switch on light.
- Changing a flat tire:
- Get jack and spare tire from trunk.
- Position jack under car near flat tire without raising it.
- Loosen lug nuts using proper wrench.
- Raise car with jack and remove flat tire.
- Mount spare tire.
- Attach lug nuts and tighten partially.
- Lower car and remove jack.
- Fully tighten lug nuts.
- Store flat tire and tools in trunk.
- Close trunk.
- Both procedures demonstrate linear flow (executed top-to-bottom, left-to-right). Complete algorithms must also handle contingency states (e.g., a defective new lightbulb or a deflated spare tire).
Algorithm Representation Methods and Pseudocode
Three Main Methods of Representation:
- Natural Language: Algorithm described in common native prose (e.g., Portuguese).
- Advantage: Highly accessible.
- Disadvantage: High ambiguity and multiple potential interpretations, making translation to programming code difficult.
- Flowchart (Fluxograma): Graphical representation using standardized geometric symbols.
- Geometric Elements in Flowcharts:
- Terminal: Represents start or end of flow.
- Manual Input: Represents manual data entry (typically keyboard).
- Process: Identifies computational operations or calculations.
- Display: Shows information output (screen output).
- Decision: Evaluates conditional tests for branching or loop control.
- Line: Connects symbols indicating flow direction.
- Connector: Connects separated algorithm segments or splits diagrams.
- Disadvantage: Conceals low-level implementation details needed for programming.
- Pseudocode (Portugol / Structured Portuguese):
- Also referred to as Portugol, Pseudocódigo, or Pseudolinguagem (Carvalho, 2007).
- A highly restricted form of natural language with defined syntax rules bridging natural language and formal programming languages.
- Structure of a Pseudocode Program:
ALGORITMO <nome do algoritmo> <definição de variáveis> INÍCIO <comandos> FIM
Pseudocode Control Structures:
- Conditional Branching (
SE-ENTÃO-SENÃO):
SE <condição> ENTÃO <comandos> SENÃO <comandos> FIMSE ```  * **Selection Structure (`ESCOLHA-CASO`)**:ESCOLHA
- Pre-Test Repetition (
ENQUANTO-FAÇA): - Evaluates condition at the beginning. Executes commands while condition is True; terminates when condition becomes False. Commands may execute 0 times.
- Counted Loop Repetition (
PARA-FAÇA): - Utilizes an explicit control variable iterating from an initial value to a final value for a predetermined number of executions.
- Post-Test Repetition (
REPITA-ATÉ): - Evaluates condition at the end. Commands execute at least once, repeating until condition evaluates to True.
- Input/Output Commands:
leia(variável): Reads data input into memory.escreva("argumento"): Displays text or output to the user interface.
- Conditional Branching (
Practice Review Questions
- Question 1: In your own words, explain the composition of an argument.
- Question 2: Define a proposition.
- Question 3: In computer programming, what are sequential instructions?
- Question 4: According to the presented concepts, what is logic?
- Question 5: What is an algorithm?
- Question 6: How are clear objectives achieved in computer programming?
- Question 7: What are the essential technical characteristics of an algorithm?
- Question 8: In your own words, explain execution flow.
- Question 9: What are the main forms of algorithm representation?
- Question 10: Among the forms of algorithm representation, why is pseudocode considered most effective? Explain.
Bibliographic References
- Alencar Filho, E. de (2002). Iniciação à Lógica Matemática. São Paulo: Nobel.
- Andrade, D., & Carmelo, E. L. do M. (1999). Elementos de Lógica.
- Bessa, A. (2021). Algoritmos e Lógica de Programação: O que é isso e porque é importante. Alura.
- Bianchi, L. (2012). Lógica Matemática. Website Lumadi.
- Bravo, R. de S. F. (2016). Lógica Proposicional. UFF.
- Carvalho, F. P. de (2007). Apostila de Lógica de Programação: Algoritmos. Faculdades Integradas de Taquara (FACCAT).
- Dicionário Informal (2022). Notação.
- Forbellone, A. L. V., & Eberspacher, H. F. (2005). Lógica de Programação: a Construção de Algoritmos e Estruturas de Dados (3rd ed.). São Paulo: Pearson Prentice Hall.
- Franck, N. S. (2017). Raciocínio Lógico e Matemático. São Paulo: Maxi Educa.
- Instituto Federal Fluminense (2019). Apostila de Lógica de Programação.
- Lima, C. S. (2012). Apostila de Lógica: Fundamentos de Lógica e Algoritmos. IFRN.
- Moraes, P. S. de (2000). Lógica de Programação. In Curso Básico de Lógica de Programação. Unicamp.
- Neto, F. C. (2017). Caderno de Lógica Proposicional. Cadernos CiComp.
- Oliveira, C. R. de et al. (2012). Lógica de Programação: Manual do Professor. Ceará: SEDUC.
- Prus, É. M. (2001). Um Modelo de Sistema Tutor Inteligente Aplicado ao Ensino da Programação Estruturada (Master's thesis). Universidade Federal de Santa Catarina, Florianópolis.
- Raulino, F. (2013). Fundamentos de Lógica e Algoritmos: Introdução. Natal: IFRN.
- Significados (2022). Significado de Lógica.