Algorithm Design Notes Word Format
Algorithm Design Notes Word Format
Abstraction
Definition: Abstraction is simplifying a problem by focusing on essential details and
ignoring the irrelevant ones.
Real-World Example: Google Maps ignores buildings and trees; it focuses only on roads and
intersections.
Benefits of Abstraction:
Reduces complexity.
Focuses on key ideas.
Promotes reusability.
Decomposition
Definition: Decomposition involves breaking down a complex problem into smaller,
manageable sub-problems.
Real-World Example: Building a website involves designing UI, coding backend, and
creating a database.
Stepwise Refinement
Definition: A top-down design approach, refining a broad problem into detailed steps.
High-Level: Get numbers → Sum numbers → Count them → Divide → Display result
Refined: Initialize sum, loop through list, add values, divide, and return average
Logic Statements
These statements use conditions (like IF) to determine the flow of logic.
Example:
IF number > 0 THEN
OUTPUT 'Positive'
ELSE
OUTPUT 'Not Positive'
Pseudocode
Pseudocode Example: Find the maximum value in a list
FUNCTION findMax(list):
max = list[0]
FOR each element IN list:
IF element > max:
max = element
RETURN max
Searching Algorithms
Comparison of Linear and Binary Search:
Algorithm Efficiency
Algorithm Time Complexity Space Complexity
Linear Search O(n) O(1)
Binary Search O(log n) O(1)
Bubble Sort O(n²) O(1)
Insertion Sort O(n²) O(1)
Exercises to Practice
1. 1. Explain how a weather app uses abstraction.
2. 2. Break 'cooking dinner' into decomposable steps.
3. 3. Write pseudocode to find the smallest number in a list.
4. 4. Draw a flowchart for linear search.
5. 5. Why is binary search more efficient than linear search for large sorted data?