Algorithms, Flowcharts, Pseudocode & Dry Run
Programming Fundamentals
October 15, 2025
Course: Algorithms, Flowcharts, Pseudocode & Dry Run
1. Algorithm
- Definition: An algorithm is a step-by-step method to solve a problem or perform a specific task.
- Key Points:
- Each step must be clear and ordered properly.
- It must produce the correct result.
- It should finish after a limited number of steps.
Example: Find Greater Number
- Start
- Input A, B
- If A > B β Print "A is greater"
- Else β Print "B is greater"
- Stop
2. Flowchart
- Definition: A flowchart is a visual diagram that shows the steps of an algorithm using symbols.
- Common Symbols:
- Oval β Start / End
- Parallelogram β Input / Output
- Rectangle β Process
- Diamond β Decision (Yes/No)
- Arrow β Flow of control
Example: Check Even or Odd Number
- Start
- Input Number
- Is Number % 2 == 0?
- If Yes β Print "Even"
- If No β Print "Odd"
- End
3. Pseudocode
- Definition: Pseudocode is writing an algorithm in simple English-like steps before coding.
- Advantages:
- Easy to understand
- No syntax errors
- Helps in planning logic
Example: Check Even or Odd
START Input num IF num % 2 == 0 THEN PRINT "Even" ELSE PRINT "Odd" END
4. Dry Run
- Definition: Dry run means checking your algorithm or code manually, step by step, using sample data.
- Purpose:
- Find logic mistakes.
- Understand program flow.
Example: Check Positive or Negative
x = -5 IF x > 0 THEN PRINT "Positive" ELSE PRINT "Negative"
Dry Run Table:
Step | Statement | x | Output |
---|---|---|---|
1 | x = -5 | -5 | - |
2 | x > 0 ? | -5 | False |
3 | Else β Print "Negative" | -5 | Negative |
Final Output: Negative
5. Example Algorithms, Flowcharts, and Pseudocodes
Example 1: Check Greater Number
Algorithm: 1. Start 2. Input A, B 3. If A > B β Print "A is greater" 4. Else β Print "B is greater" 5. Stop Pseudocode: START Input A, B IF A > B THEN PRINT "A is greater" ELSE PRINT "B is greater" END
Example 2: Nested Loops
Algorithm: 1. Start 2. For i = 1 to 3 For j = 1 to 2 Print i, j 3. Stop Pseudocode: START FOR i = 1 TO 3 FOR j = 1 TO 2 PRINT i, j END FOR END
Example 3: Nested Conditions
Algorithm: 1. Start 2. Input x 3. If x > 0 If x % 2 == 0 β Print "Positive Even" Else β Print "Positive Odd" Else β Print "Negative or Zero" 4. Stop
Example 4: Series 5,10,15,20,25,30
Algorithm: 1. Start 2. For i = 5 to 30 step 5 Print i 3. Stop Output: 5 10 15 20 25 30
Example 5: Series 1,4,9,16,25,36,49,64
Algorithm: 1. Start 2. For i = 1 to 8 Print i * i 3. Stop Output: 1 4 9 16 25 36 49 64
Example 6: Fibonacci Series (0,1,1,2,3,5,8,13,21)
Algorithm: 1. Start 2. Set a = 0, b = 1 3. Print a, b 4. For i = 3 to n c = a + b Print c a = b b = c 5. Stop Output: 0 1 1 2 3 5 8 13 21
Example 7: Finding Factorial
Algorithm: 1. Start 2. Input n 3. Set fact = 1 4. For i = 1 to n fact = fact * i 5. Print fact 6. Stop Output: For n = 5 β 120
Example 8: Bubble Sort
Algorithm: 1. Start 2. Input list of numbers 3. Repeat (n-1) times 4. For i = 0 to n-2 If list[i] > list[i+1], swap them 5. Print sorted list 6. Stop Example Input: [5, 2, 4, 1] Output: [1, 2, 4, 5]
Example 9: ATM Withdraw Machine
Algorithm: 1. Start 2. Input PIN 3. If PIN is correct Display Menu: Withdraw, Balance, Exit If Withdraw β Input amount If amount <= balance β Dispense cash & update balance Else β Print "Insufficient Balance" Else β Print "Wrong PIN" 4. Stop Pseudocode: START Input PIN IF PIN == 1234 THEN PRINT "1.Withdraw 2.Balance 3.Exit" Input choice IF choice == 1 THEN Input amount IF amount <= balance THEN PRINT "Cash Dispensed" ELSE PRINT "Insufficient Balance" ENDIF ELSE PRINT "Invalid PIN" END