BCA SCHOOL
Programming Tutorials • Notes • Practical • Books
LATEST TUTORIALS

Introduction to Logic & Basics of Algorithms | BCA School BKNMU

by BCA School •



BCA Sem 1  |  Unit 1  |  Computer Concepts & C Programming

Introduction of Logic & Basics of Algorithms — BKNMU Junagadh

Boolean Logic, Logic Gates, Truth Tables, Algorithms, Flowcharts, and Pseudo-code

BKNMU Junagadh NEP 2020 Boolean Logic Logic Gates Algorithms Flowcharts
In simple words: Before writing code in C programming, we must learn how to think logically like a computer. Computer logic is based on Boolean Algebra (evaluating True or False conditions), while an Algorithm is a step-by-step procedure designed to solve a specific problem logically and efficiently.
📖 Part 1: Fundamental Logic Gates

Computers make decisions using hardware switches called Logic Gates. The three primary building block gates are:

Y = A . B

1. AND Gate

Outputs True (1) ONLY if ALL inputs are True. Acts like logical multiplication (1 × 0 = 0).

Y = A + B

2. OR Gate

Outputs True (1) if AT LEAST ONE input is True. Acts like logical addition (1 + 0 = 1).

Y = A'

3. NOT Gate (Inverter)

Inverts the input value. Converts True (1) to False (0) and False (0) to True (1).

1️⃣ Master Table of Fundamental Logic Gates & Truth Tables

Here is a summary table of fundamental logic gates, their symbols, logical equations, and output rules:

Logic GateBoolean ExpressionCondition RuleTruth Table Summary
AND GateY = A . BOutput is 1 only when input A is 1 AND input B is 1. Otherwise, output is 0.0&0=0, 0&1=0, 1&0=0, 1&1=1
OR GateY = A + BOutput is 1 when input A is 1 OR input B is 1 (or both). Output is 0 only when both are 0.0|0=0, 0|1=1, 1|0=1, 1|1=1
NOT GateY = A'Single-input gate that reverses the binary input signal.Input 0 ➔ Output 1
Input 1 ➔ Output 0
ℹ️ What is a Truth Table? A Truth Table is a mathematical chart listing every possible combination of inputs (0s and 1s) alongside the corresponding output generated by a logic circuit.
🎨 Part 2: Basics of Algorithms & Decision Pipeline

The 4-Step Decision Flow of an Algorithm:

1. Input (Get Data) ➔ 2. Decision (Evaluate Logic) ➔ 3. Process (Execute Steps) ➔ 4. Output (Show Result)

An algorithm receives input, tests logical conditions, carries out instructions based on those decisions, and terminates after producing the output.

🔍 Flowchart vs. Pseudo-code
1. Flowchart (Visual Representation)
  • Uses standard geometric shapes connected by arrows.
  • Oval: Start / Stop terminal.
  • Parallelogram: Input / Output operation.
  • Rectangle: Processing / Calculation step.
  • Diamond: Decision / Condition branching.
2. Pseudo-code (Textual Representation)
  • Written in structured, plain English-like sentences.
  • Not bound by strict compiler syntax like C.
  • Focuses on algorithm logic rather than language syntax.
  • Uses keywords like START, INPUT, IF-ELSE, PRINT, END.
💻 Example — Algorithm & Pseudo-code for Finding Largest of Two Numbers

Here is how a problem is represented as a structured algorithm and pseudo-code before writing actual C code:

// Pseudo-code Example: Find Largest Number START INPUT NumberA, NumberB IF NumberA > NumberB THEN PRINT "NumberA is Largest" ELSE PRINT "NumberB is Largest" ENDIF END
💡 Exam Tip: When writing algorithms in theory exams, ensure that your steps are Finite (must terminate after a set number of steps), Unambiguous (each step must be clear), and have defined **Inputs** and **Outputs**.
🔄 Essential Characteristics of an Algorithm (FITE U)
1

1. Input & Output Defined

Must accept zero or more well-defined inputs and produce at least one output result.

2

2. Definiteness (Unambiguous)

Every step must be completely clear, direct, and have only one interpretation.

3

3. Finiteness

The algorithm must terminate after a finite number of steps. It must never run endlessly.

4

4. Effectiveness

Every step must be simple enough that it can be carried out basic processing manually or in finite time.

⚠️ Infinite Loop Warning: An algorithm without a termination condition will cause an **Infinite Loop**, wasting system CPU resources and failing to output a final result!
📝 Quick Revision — Key Exam Points
  • Boolean Logic: Logic system using binary values 1 (True) and 0 (False).
  • Primary Logic Gates: AND (both true), OR (any true), NOT (inverts value).
  • Truth Table: Chart displaying outputs for all possible binary input combinations.
  • Algorithm: A finite, step-by-step logical process for solving a problem.
  • Flowchart: Visual diagram of an algorithm using standard geometric symbols.
  • Pseudo-code: Informal, structured plain-English description of code logic.
  • Algorithm Rules: Must be finite, unambiguous, effective, and produce output.