210 likes | 285 Views
Searching & Sorting. Linear Search. I'm thinking of a number between 1 and 100 You try to guess it I'll give too low/too high hints. Linear Search. I'm thinking of a number between 1 and 100 You try to guess it I'll give too low/too high hints Method #1 – Linear Search 1, 2, 3….
E N D
Linear Search • I'm thinking of a number between 1 and 100 • You try to guess it • I'll give too low/too high hints
Linear Search • I'm thinking of a number between 1 and 100 • You try to guess it • I'll give too low/too high hints • Method #1 – Linear Search • 1, 2, 3….
Binary Search • Method #2 – Binary Search • Pick middle of remaining search space • Too high? Eliminate middle and above • Too low? Eliminate middle and below
Binary Search Searching for 5:
Binary Search Searching for 5:
Binary Search Searching for 5:
Binary Search Searching for 5:
Binary Search Searching for 5:
Binary Search Searching for 5:
Binary Search Searching for 6:
Binary Search Searching for 6:
Binary Search Searching for 6:
Binary Search Searching for 6:
Binary Search Searching for 6:
Binary Search Searching for 6:
Simple Sort • Get a list of unsorted numbers • Make a new empty list • Repeat steps these steps until the unsorted list is empty • Select the smallest unsorted number • Move this number to the sorted list
Insertion Sort • Get a list of unsorted numbers • Set a marker for the sorted section after the first number in the list • Repeat steps until the unsorted section is empty • Select the first unsorted number • Swap this number to the left until it arrives at the correct sorted position • Advance the sorted marker to the right one position
Selection Sort • Get a list of unsorted numbers • Set a marker for the sorted section at the front of the list • Repeat steps until one number remains in the unsorted section • Find smallest number in the unsorted section • Swap this number with the first number in the unsorted section • Advance the marker to the right one position