Topic: Problem-solving techniques using algorithms, pseudocode, and flowcharts
Course: C Programming Fundamentals
Prepared by: Dr. Mohsin F. Dar
Designation: Assistant Professor, School of Computer Science
Institution: UPES, Dehradun
Target Audience: B.Tech-CSE-I-B47 and B.Tech-CSE-I-B48
By the end of this lecture, students will be able to:
Definition: An algorithm is a step-by-step procedure or set of rules designed to solve a specific problem or perform a particular task.
Each step must be clear and unambiguous
Takes zero or more inputs
Produces at least one output
Must terminate after finite steps
Each step must be feasible and executable
Same input produces same output
Definition: Pseudocode is a high-level description of a computer program's logic that uses natural language mixed with programming constructs.
BEGIN / START - Start of algorithm END / STOP - End of algorithm INPUT / READ - Input operation OUTPUT / PRINT - Output operation SET / ASSIGN - Assignment operation IF...THEN...ELSE - Conditional statements WHILE...DO - Loop statements FOR...TO...DO - Loop statements REPEAT...UNTIL - Loop statements
BEGIN FindMaximum
INPUT A, B, C
SET MAX = A
IF B > MAX THEN
SET MAX = B
END IF
IF C > MAX THEN
SET MAX = C
END IF
OUTPUT "The maximum number is: ", MAX
END FindMaximum
This pseudocode can be easily translated to C, Python, Java, or any other programming language.
Definition: A flowchart is a graphical representation of an algorithm that uses standard symbols to represent different types of operations and the flow of control.
Oval: Start and End points
Rectangle: Process / Action steps
Diamond: Decision / Condition
Parallelogram: Input / Output operations
Circle: Connector (jumps to another part of flow)
Curved Rectangle: Document / Report
Double-Rectangle: Predefined process / Subroutine
Arrows indicate the direction of flow. Example: START → PROCESS → DECISION? → YES/NO paths
YES: MAX = B NO: Skip
YES: MAX = C NO: Skip
BEGIN SumNaturalNumbers
INPUT N
SET SUM = 0
SET I = 1
WHILE I <= N DO
SET SUM = SUM + I
SET I = I + 1
END WHILE
OUTPUT "Sum is: ", SUM
END SumNaturalNumbers
Iteration 1: I=1, SUM=0+1=1
Iteration 2: I=2, SUM=1+2=3
Iteration 3: I=3, SUM=3+3=6
Iteration 4: I=4, SUM=6+4=10
Iteration 5: I=5, SUM=10+5=15
Final: I=6 > N=5, so OUTPUT SUM = 15
| Aspect | Algorithm | Pseudocode | Flowchart |
|---|---|---|---|
| Format | Step-by-step text | Structured text with keywords | Graphical symbols |
| Ease of Understanding | Good for logical thinkers | Easy for programmers | Visual, easy for everyone |
| Detail Level | High-level overview | Medium detail | Visual flow representation |
| Modification | Easy to modify | Very easy to modify | Requires redrawing |
| Space Required | Compact | Compact | More space needed |
| Best For | Problem analysis | Code planning | Visual communication |
Best Practice: Use all three methods complementarily! Start with an algorithm for problem understanding, create pseudocode for implementation planning, and draw flowcharts for visual verification and communication.
Calculate the factorial of a number
Input: A positive integer N
Output: N! (N factorial)
Check if a number is prime
Input: A positive integer N
Output: "Prime" or "Not Prime"
Sort an array using bubble sort
Input: Array of integers
Output: Sorted array in ascending order
Assignment: For each problem, create: