Unit 1 Notes
Unit 1 Notes
Representing Algorithms
1. Flowcharts:
o Visual diagrams that represent the steps of an algorithm.
o Shapes:
§ Oval: Start/End.
§ Rectangle: Process or action.
§ Diamond: Decision or condition.
o Arrows indicate the flow of control.
2. Pseudocode:
o A structured way to write algorithms in plain English.
o Not actual code but follows a logical, programming-like structure.
o Example:
Start
Input number1, number2
Sum = number1 + number2
Output Sum
End
1. Flowchart Representation:
o Start → Input numbers → Compare numbers → Output the largest → End.
2. Pseudocode Representation:
Start
Input number1, number2
IF number1 > number2 THEN
Output number1
ELSE
Output number2
End
What is a Flowchart?
Flowchart Symbols
• Definition: A simple sorting algorithm that repeatedly compares adjacent elements and
swaps them if they are in the wrong order.
• Steps:
1. Start at the beginning of the list.
2. Compare the first two elements.
3. If the first element is greater than the second, swap them.
4. Move to the next pair and repeat the process until the end of the list.
5. Repeat these steps for the entire list until no swaps are needed.
• Key Points:
o It sorts the largest unsorted element in each pass and places it at the correct
position at the end.
o The algorithm stops when the list is sorted and no swaps are made during a pass.
o Simple to understand but slow for large lists.
• Practical Use:
o Best for small datasets or when learning about sorting algorithms.
Merge Sort
• Definition: A sorting algorithm that splits the list into smaller parts, sorts them, and
merges them back together in order.
• Steps:
1. Split the list into two halves.
2. Keep splitting each half until each part contains only one element (these are
already sorted).
3. Compare the elements in each part and merge them back together in the correct
order.
4. Continue merging until the entire list is sorted.
• Key Points:
o Uses a divide and conquer method: it breaks the problem into smaller parts and
solves each part.
o Faster and more efficient for large lists compared to Bubble Sort.
o Slightly more complex to implement because it uses splitting and merging.
Comparison
• Definition: A simple searching algorithm that checks each element in a list one by one
until the target element is found or the end of the list is reached.
• How It Works:
1. Start at the first element of the list.
2. Compare the current element with the target value.
3. If they match, stop and return the position of the element.
4. If they don't match, move to the next element.
5. Repeat until the target is found or the end of the list is reached.
• Key Features:
o Can be used on unsorted or sorted lists.
o Simple to implement.
o Slower for large lists because it may require checking every element.
• Example:
o List: [5, 8, 12, 20, 25]
o Target: 20
o Steps: Compare 5, 8, 12, and 20. Match found at position 4.
• Advantages:
o Easy to understand and implement.
o Works on any type of list.
• Disadvantages:
o Inefficient for large datasets.
Binary Search
• Definition: A more efficient searching algorithm that works only on sorted lists. It
repeatedly divides the list into halves to narrow down the search.
• How It Works:
1. Start with the entire sorted list.
2. Find the middle element of the list.
3. Compare the middle element with the target value:
§ If they match, the search is complete.
§ If the target is smaller, search in the left half.
§ If the target is larger, search in the right half.
4. Repeat the process until the target is found or the list is fully divided.
• Key Features:
o Requires the list to be sorted.
o Faster than Linear Search for large datasets.
• Example:
o List: [5, 8, 12, 20, 25]
o Target: 20
o Steps:
§ Middle element is 12. Compare 20 with 12.
§ 20 > 12, so search the right half [20, 25].
§ Middle element is 20. Match found.
• Advantages:
o Much faster for large datasets.
o Efficient for sorted lists.
• Disadvantages:
o Does not work on unsorted lists.
o Slightly more complex to implement.
Comparison Table
• Definition: Breaking down a complex problem into smaller, more manageable parts that
are easier to understand, solve, and work on independently.
• Key Features:
o Helps to focus on individual parts of the problem.
o Each smaller part can be solved independently or by different team members.
o Once solved, the smaller parts can be combined to solve the overall problem.
• Why It's Important:
o Simplifies complex problems.
o Makes large tasks easier to manage and debug.
o Encourages reusability of solutions (e.g., creating reusable modules in
programming).
• Example:
o Problem: Design a program to book tickets for a cinema.
o Decomposed tasks:
1. Create a user interface to select a movie.
2. Implement a system to choose seats.
3. Write code to calculate the total cost.
4. Add functionality for payment processing.
5. Generate and display the ticket.
• Practical Use in IGCSE:
o When writing pseudocode or designing flowcharts, you should often break down
problems into smaller steps.
Abstraction
• Definition: The process of removing unnecessary details and focusing only on the
important information needed to solve a problem.
• Key Features:
o Simplifies problems by ignoring irrelevant details.
o Makes it easier to understand and solve problems.
o Helps create general solutions that work for many specific cases.
• Why It's Important:
o Avoids being overwhelmed by unnecessary details.
o Encourages efficiency by focusing on what really matters.
o Helps in creating models or simulations of real-world scenarios.
• Example:
o Problem: Plan a route for a delivery truck.
o Abstracted details:
§ Keep: Location of delivery points, distances, and time taken.
§ Ignore: Road conditions, color of the truck, or weather.
• Practical Use in IGCSE:
o You should use abstraction when drawing flowcharts or writing pseudocode to
focus only on essential parts of the algorithm.
Relationship Between Decomposition and Abstraction
1. Decomposition:
o Planning a meal:
§ Decide on a menu.
§ Buy ingredients.
§ Cook each dish separately.
§ Serve the meal.
2. Abstraction:
o Reading a train timetable:
§ Focus on the train numbers, departure times, and destinations.
§ Ignore the color of the timetable or the font used.