Unit 1 –
Problem
Solving
ENG. SAMAA AWAD
IGCSE
Computer
Science
Unit 1 Topics
1. Understanding algorithms
2. Creating algorithms
3. Sorting & searching algorithms
4. Decomposition & abstraction
Sorting & Searching
Algorithms
Sorting & Searching
Algorithms
• Two common tasks in computer programs are sorting data in a particular
order, and searching for a particular item.
• Some common sorting algorithms are:
• Bubble Sort
• Merge Sort
• Some common searching algorithms are:
• Linear Search
• Binary Search
Sorting Algorithms
Bubble Sort
• Data can be sorted in ascending order or in descending order.
• In bubble sort, pairs of data items are compared.
• If they are in the wrong order, they are swapped.
• The pairs comparison continues till the end of the list.
• This process is repeated until there are no swaps made.
• This means that all the items in the list are in the correct order.
Bubble Sort
• Here’s an example:
Note that each round is called a pass
Bubble Sort Note that when coding,
in order to swap items,
you will need to create
• Here’s the bubble sort
a temp variable to hold
algorithm as a flowchart:
one of the values that
need to be swapped.
e.g. if x & y need to
be swapped:
temp = x
x=y
y = temp
Merge Sort
• Data can be sorted in ascending order or in descending order.
• In merge sort, the list is divided into two smaller lists.
• The smaller lists are then divided into smaller lists, until each list has one
element.
• This is called recursion, which means repeatedly applying a process.
• The small lists are then merged through recursion, placing the items in the
correct order.
Merge Sort
Merge Sort
Efficiency of Sorting
Algorithms
Efficiency of Sorting
Algorithms
• The bubble sort uses brute force method. It starts at the beginning, and
repeats the same task over and over until it reaches a solution.
• The merge sort uses divide and conquer method. It breaks down the
problem into smaller sub-problems, solves those, and them combines the
solution.
• The previous graph shows that bubble sort is far slower at sorting lists of
more than 1000 items, but for smaller lists the time difference is small.
THANK
YOU