Module quiz: Introduction to algorithms
12. Given an array of 6 numbers [6,8,19,48,9,90]and applying insertion sort, how many swaps must occur before the array is sorted?
- 6
- 2
- 4
14. Why do we need Big-O notation to evaluate our programs?
- Because sorting is complicated, and we need a complicated metric.
- Because measuring time is relative to a person’s computer, so a relative metric is required.
- Because sorting requires that things are moved around to save space.
15. What is parallelization?
- It is about running code at the same time in threads or on separate computers.
- It is about writing your code in one go.
- It is about calling functions repetitively until they have achieved a base case.
16. Why would you decide to use recursion?
- It lends itself well to a divide and conquer approach.
- Recursion reduces the pressure on the compiler by making less stack calls.
- It looks cool and makes your code seem more intelligent.
17. Why does Memoization work well with dynamic programming?
- Because it takes a lot of memory to run some programs and memoization allows you to store data in smaller sizes.
- It takes up less space in the hard drive.
- It requires less compiling because it stores previous results, reducing the load on the CPU.
18. How are the principles of dynamic programming and greedy algorithms at odds with one another?
- The principle of dynamic programming is to exhaustively compute the best solution, while a greedy approach will favor take the immediate best option.
- The greedy algorithm will use up CPU by monopolizing resources.
- Because dynamic programming will react with more agility to a program, while the greedy approach will be slower and more self-centered.
19. Why is a binary search conducted in O(log n) time?
- It is not, it is conducted in O(n).
- Regardless of the size of the input, at every step the number of calculations is halved.
- Because as it searches it sorts the elements.