- Write pseudocode for linear search
- Write pseudocode for binary search
- Translate algorithm pseudocode to working code
- Describe the Big O complexity of linear and binary search
-
Take a minute to look over these examples of pseudocode for a
selectEvenNumbers
function. Which one do you prefer? Why?function selectEvenNumbers takes 1 parameter, numbers (array of integers) create evenNumbers variable and set to an empty array for each num in numbers array check if num is even add num to evenNumers array return evenNumbers
Function selectEvenNumbers Input: numbers -> array integers Output: array of integers set evenNumbers -> [] for i = 0 to i = numbers.length if (numbers[i] % 2 === 0) push numbers[i] onto evenNumbers return evenNumbers
Given an array of integers,
numbers
, and a valueval
, alinearSearch()
function should return the index ofval
innumbers
. Ifval
does not exist innumbers
, return -1.Your answer...
-
What is the Big O complexity of Linear Search?
Your answer...
-
How does binary search work in your own words. What condition needs to be met to use binary search on an array?
Your answer...
-
Write pseudocode for Binary Search. Start by forking this: https://repl.it/@galvanize/BinarySearch
Your answer...
-
Translate your pseudocode from above to working code.
Your answer...
-
What is the Big O complexity of Binary Search?
Your answer...