Topic 4
Programming
IB Computer Science
Part 3
The British International School, Istanbul
Intro
The British International School, Istanbul
What do you need to know for the IB exam?
The British International School, Istanbul
Linear Search
nums = [31, 54, 67, 29, 51, 61, 23, 35]
The British International School, Istanbul
Binary Search (Example 1)
nums = [23, 29, 31, 35, 51, 54, 61, 67]
The British International School, Istanbul
Binary Search (Example 2)
nums = [23, 29, 31, 35, 54, 61, 67]
The British International School, Istanbul
Binary Search (Example 3)
nums = [23, 29, 31, 35, 54, 61, 67, 73, 77, 81, 99]
The British International School, Istanbul
Binary Search (Approaching the Code)
nums = [23, 29, 31, 35, 54, 61, 67]
The British International School, Istanbul
The British International School, Istanbul
Linear Search vs. Binary Search
Feature | Linear Search | Binary Search |
Search Direction | Sequential | Divides arrays into halves |
Prerequisites | None | Array must be sorted |
Practical Usage | Small arrays or unsorted data | Large and sorted |
# of Comparisons (Best Case) | 1 time | 1 time |
# of Comparisons (Worst Case) | N, where N is the length of the array | log2(N) where N is the length of the array |
The British International School, Istanbul
Bubble Sort
nums = [31, 54, 67, 29, 51, 61, 23, 35]
The British International School, Istanbul
Bubble Sort (Approaching the Code)
nums = [31, 54, 67, 29, 51, 61, 23, 35]
The British International School, Istanbul
Bubble Sort Basic Tasks
The British International School, Istanbul
Selection Sort
nums = [31, 54, 67, 29, 51, 61, 23, 35]
The British International School, Istanbul
Selection Sort (Approaching the Code)
nums = [31, 54, 67, 29, 51, 61, 23, 35]
The British International School, Istanbul
Selection Sort Basic Tasks
The British International School, Istanbul
Bubble Sort vs. Selection Sort
Feature | Bubble Sort | Selection Sort |
Methodology | Compare adjacent values and swap the bigger with the small or vice-versa; Repeat N times | Divide array into sorted and unsorted portions; find the maximum (or minimum) in unsorted, add to sorted portion and remove from unsorted portion. |
# of Swaps | Each pass through an array leads to many swaps (less efficient) | Each pass through an array leads to one swap |
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul
The British International School, Istanbul