U401 SAC Notes Time Complexity Flashcards

1
Q

Describe binary search and its one limitation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Recurrence relation for Binary Search

A

T(n) = T(n/2) +O(1) where d = 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the master theorem

A

A tool that is used to solve recurrence relations in divide and conquer algorithms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Time complexity for binary search

A

O(logn) - worst case
O(1) - best case (if the target value is the middle value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Time complexity for merge sort

A

O(nlogn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Time complexity for quick sort

A

Best case- O(nlogn)
Worst case- O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Recurrence relation for Merge sort

A

T(n) = 2T(n/2) + O(n^1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Recurrence relation for quick sort

A

best case-
T(n) = 2T(n/2) + O(n^1)
worst case
T(n) = T(n-1) + O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

explain the correct structure of a recurrence relation that permits the use of the Master Theorem

A

Only recurrence relations of the form T(n) = aT(n/b) + f(n)

where a >=1
b>1
f(n)>0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is merge sort?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is quick sort?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is recursion?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

O(N)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly