0% found this document useful (0 votes)
3 views7 pages

Unit 1 Notes

An algorithm is a step-by-step set of instructions for solving a specific problem, characterized by being finite, clear, and effective. Learning algorithms is crucial for understanding computer problem-solving, programming foundations, and logical thinking. Key concepts include flowcharts and pseudocode for representation, with examples like Bubble Sort and Binary Search illustrating different sorting and searching techniques.

Uploaded by

Mehdi Boujrada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Unit 1 Notes

An algorithm is a step-by-step set of instructions for solving a specific problem, characterized by being finite, clear, and effective. Learning algorithms is crucial for understanding computer problem-solving, programming foundations, and logical thinking. Key concepts include flowcharts and pseudocode for representation, with examples like Bubble Sort and Binary Search illustrating different sorting and searching techniques.

Uploaded by

Mehdi Boujrada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

What is an Algorithm?

• Definition: An algorithm is a step-by-step set of instructions designed to solve a specific


problem or perform a task.
• Key Features:
1. Finite: It must have a clear start and end.
2. Clear and Precise: Each step must be easy to understand and follow.
3. Effective: It should achieve the desired outcome.

Why Learn Algorithms?

• Algorithms are essential for:


o Understanding how computers solve problems.
o Learning the foundation of programming and problem-solving.
o Applying logical thinking to break problems into smaller, manageable steps.

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

Key Concepts in Algorithms

• Input: Data the algorithm needs to process.


• Process: The steps or operations performed on the data.
• Output: The result of the algorithm.
• Decisions: Points where the algorithm chooses between two or more paths (e.g.,
conditions like "IF this THEN that").
• Iteration: Repeating a step or set of steps (e.g., loops).
Algorithm Example: Finding the Largest Number

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?

• A flowchart is a visual representation of an algorithm using shapes and arrows to show


the flow of steps in solving a problem.
• It helps in understanding and designing algorithms in a simple, visual way.

Flowchart Symbols

Symbol Shape Purpose


Start/End Oval Indicates the start or end of the process.
Process Rectangle Represents an action or operation. Example: "Add 2
numbers".
Decision Diamond Represents a decision point with yes/no or true/false
answers. Example: "Is X greater than Y?"
Input/Output Parallelogram Represents input (e.g., "Enter a number") or output (e.g.,
"Display result").
Arrow Line with Shows the flow of control from one step to another.
arrowhead
Bubble Sort

• 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

Feature Bubble Sort Merge Sort


Method Compares and swaps adjacent Splits the list, sorts smaller parts, and
elements repeatedly merges them
Ease of Use Simple to understand More complex to understand
Best for Small datasets Large datasets
How it Repeated passes over the list Recursively splits and merges
Works
Linear Search

• 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.

Efficiency of Searching Algorithms

• Linear Search Efficiency:


o For a list of nnn elements:
§ In the best case, the target is the first element (1 comparison).
§ In the worst case, the target is the last element or not in the list (n
comparisons).
o Linear Search is slower because it may need to check every element.
• Binary Search Efficiency:
o For a list of nnn elements:
§ Each step eliminates half the list, so it requires fewer comparisons.
§ Works much faster for large datasets because it reduces the problem size
exponentially.

Comparison Table

Feature Linear Search Binary Search


Works on Unsorted and sorted lists Sorted lists only
Speed Slower for large lists Faster for large lists
Implementation Simple to understand Requires sorting and more steps
Best Use Small datasets or unsorted lists Large, sorted datasets
Decomposition

• 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

• Decomposition breaks a problem into smaller parts.


• Abstraction simplifies each part by focusing only on the important details.
• Together, they make solving problems easier by organizing and simplifying tasks.

Examples in Everyday Life

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.

You might also like