Chapter 4: Quicksort Flashcards
Write out the code for the earlier sum function.
Write a recursive function to count the number of items in a list.
Find the maximum number in a list.
Remember binary search from chapter 1? It’s a divide-and-conquer algorithm, too. Can you come up with the base case and recursive case for binary search?
The base case for binary search is an array with one item. If the item you’re looking for matches the item in the array, you found it! Otherwise, it isn’t in the array. In the recursive case for binary search, you split the array in half, throw away one half, and call binary search on the other half.
Printing the value of each element in an array. What’s the big O
O(n)
Doubling the value of each element in an array. Big O?
O(n)
Doubling the value of just the first element in an array. Big O?
O(1)
Creating a multiplication table with all the elements in the array. So if your array is [2, 3, 7, 8, 10], you first multiply every element by 2, then multiply every element by 3, then by 7, and so on.
O(n^2)