What algorithm should you use if you are looking for an element in an unsorted array?
Linear Search, iterate through every element in the array and see if it is the target.
What does it mean for a data structure to be heterogeneous?
It can hold any/all types.
Example: ["a", 1, 4.0]
List all the data structures, covered in the class, that utilize hashing.
Sets and Dictionaries.
What makes Binary Search a more efficient algorithm compared to Linear Search?
The time complexity of Binary Search is O(logn).
The time complexity of Linear Search is O(n).
In binary search, we are cutting the number of elements being searched by half. In linear search, we are simply iterating through every element in the array.
What is this algorithm?
Linear Search Algorith
Provide a difference between a Tuple and a List.
A tuple is an immutable data structure and a list is dynamic, in which its size can grow or shrink.
Explain how Dictionaries are different from Sets.
Dictionaries map a key to a particular value while Sets simply holds elements.
Provide a difference between a List and a Set.
Sets guarantee all elements are unique, while Lists cannot guarantee this.
What characteristic should an array have if Binary Search is being used to search for an element in the array? In other words, what must be true about the array if Binary Search is being performed against it?
The array must be sorted. If it is not sorted, Binary Search would not work.
If you were to sort a list or an array, what time complexity should you aim to achieve?
The most optimal sorting algorithm is O(nlogn). What algorithm could this be?
What are the characteristics of a good hash function?
- Fast, Consistent and Minimize Collisions
What algorithm performs better in a worst-case scenario, Quick Sort or Merge Sort?
Merge Sort because the time complexity remains O(nlogn) throughout all cases. Quick Sort becomes O(n^2) if the array is sorted or in reverse order.
What algorithm does the following code belong to?
Merge function in Merge Sort Algorithm
What is the difference between Deep and Shallow Equality?
Deep Equality (==) looks to see if two things are the same internally. Shallow Equality (is) looks to see if two things are the exact same.
Examples:
5 == 5.0 # True
5 is 5.0 # False
What powers hashing data structures and allow operations on them to be constant time?
Example: .add(), .pop()
Hash Functions
Explain the merge sort algorithm.
- Recursively split the array (even v. odd indices) in half until all sections are of size 1
- Merge the arrays back together in the correct order (comparing values in both arrays and adding the smallest one into the new array)
Explain the quick sort algorithm.
Recursively obtain the pivot (index zero) and create three distinct arrays (less_than, equal, more_than).
Once everything is a pivot, it is sorted. Simply concatenate/add to an array.