U401 SAC Notes Time Complexity Flashcards
Describe binary search and its one limitation
Repeatedly divides the array in half until the target element is found or if the array is empty,by comparing the middle element with the target element.
One limitation is that the array must be sorted to begin with.
Recurrence relation for Binary Search
T(n) = T(n/2) +O(1) where d = 0
What is the master theorem
A tool that is used to solve recurrence relations in divide and conquer algorithms
Time complexity for binary search
O(logn) - worst case
O(1) - best case (if the target value is the middle value)
Time complexity for merge sort
O(nlogn)
Time complexity for quick sort
Best case- O(nlogn)
Worst case- O(n^2)
Recurrence relation for Merge sort
T(n) = 2T(n/2) + O(n^1)
Recurrence relation for quick sort
best case-
T(n) = 2T(n/2) + O(n^1)
worst case
T(n) = T(n-1) + O(n)
explain the correct structure of a recurrence relation that permits the use of the Master Theorem
Only recurrence relations of the form T(n) = aT(n/b) + f(n)
where a >=1
b>1
f(n)>0
What is merge sort?
Merge sort is a divide and conquer algorithm as it recursively divides the array into smaller subarrays to sort then merging them back together to obtain the resultant sorted array.
What is quick sort?
What is recursion?
a method where a problem is divided into smaller, simpler problems until a condition is met. This technique involves a function calling itself to solve the sequential smaller problems.
If the algorithm was modified to include the reading of a file of sorted data. What would be the overall big-oh
time complexity of the algorithm
O(N)