Solo JavaScript Project
+
Course-Wide Contest
Next Monday Evening
7:30pm - 9:00pm
(Conflict signups end this Wednesday!)
We call this strategy a Linear Search
Hint: The data is sorted!
We call this strategy a Binary Search
Data | Linear Search | Binary Search |
---|---|---|
7 | _______ |
_______ |
15 | _______ |
_______ |
31 | _______ |
_______ |
n | _______ |
_______ |
1 2 3 4 5 6 7 *
1 2 3 *
3 *
What is the worst case running time for a binary search with 15 values?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
What is the worst case running time for a linear search with 31 values?
What is the worst case running time for a binary search with 31 values?
Data | Linear Search | Binary Search |
---|---|---|
7 | 7 | 3 |
15 | _______ |
_______ |
31 | _______ |
_______ |
n | _______ |
_______ |
var games = [ { score: [4, 1], opponent: "Oakland" }, { score: [1, 0], opponent: "Illinois State" }, { score: [5, 2], opponent: "TCU" }, ... ];Program a Linear Search on JSFiddle
var data = [ 50, 34, 87, 13, 11, 58, 17, 29, 58 ];
We call this strategy a Selection Sort
// 1: Find the lowest value [ 50, 34, 87, 13, 11, 58, 17, 29, 58 ] // 2: Swap with the first [ 11, 34, 87, 13, 50, 58, 17, 29, 58 ] // 3: Repeat, ignoring the sorted part [ 11, 34, 87, 13, 50, 58, 17, 29, 58 ]
[ 50, 34, 87, 13, (11), 58, 17, 29, 58 ] [ 11, 34, 87, 13, 50 , 58, 17, 29, 58 ]
Data | Linear Search | Binary Search | Selection Sort |
---|---|---|---|
9 | _______ |
_______ |
_______ |
100 | _______ |
_______ |
_______ |
n | _______ |
_______ |
_______ |
var games = [ { score: [4, 1], opponent: "Oakland" }, { score: [1, 0], opponent: "Illinois State" }, { score: [5, 2], opponent: "TCU" }, ... ];Program a Binary Search on JSFiddle