Big O Flashcards

1
Q

Insert in ordered array

A

O(n)

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

Removal from ordered array

A

O(n)

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

Linear Search # of comparisons Best Case

A

found as first element

1 comparison

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

Linear Search # of comparisons worst case

A

n comparisons

when element is last element or not in the array

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

Linear Search number of comparisons in average case

A

(3n+1)/4 comparisons

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

Binary Search # of comparisons best case

A

1 comparison

element wanted is in the middle of the array

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

Binary search # of comparisons worst case

A

log(n) + 1 comparisons

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

Binary Search # of comparisons average case

A

closer to worst case then best case

more likely to find the element as the search space gets smaller

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

Selection Sort Barometer Operation

A

n*(n-1)/2

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

Selection Sort # of swaps

A

n-1

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

Insertion sort # of comparisons Worst case

A

n*(n-1)/2

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

Insertion sort # of comparisons best case

A

n comparisons (no moves)

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

Insertion sort # of comparisons average case

A

n*(n-1)/4

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

Quick sort best case run time

A

O(n log n)

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

Quick sort average case run time

A

O( n log n)

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

Quick sort worst case run time

A

O(n^2)

17
Q

Selection sort best case run time

A

O(n^2)

18
Q

Selection sort average case run time

A

O(n^2)

19
Q

Selection sort worst case run time

A

O(n^2)

20
Q

Insertion sort best case run time

A

O(n)

21
Q

Insertion sort average case run time

A

O(n^2)

22
Q

Insertion sort worst case run time

A

O(n^2)

23
Q

Mergesort best case run time

A

O(n log n)

24
Q

Merge sort average case run time

A

O(nlogn)

25
Q

Merge sort worst case run time

A

O(nlogn)

26
Q

HeapSort best case run time

A

O(nlogn)

27
Q

HeapSort average case run time

A

O(nlogn)

28
Q

HeapSort worst case run time

A

O(nlogn)

29
Q

Data structure- insertion, delete, look up - run time

A

O(log n)

30
Q

BST insertion, removal, search cost

A

O(height)

31
Q

sorting an array with BST run time

A

O(n * h)

if balanced than O(nlogn)

32
Q

Run time of Priority Queues insert and remove

A

O(log n)

33
Q

Heap # of swaps for insertion

A

height swaps

34
Q

Heap number of comparisons for removal

A

height * 2 compariosns

35
Q

Run time for insertions and removal from a heap

A

O(log n)

36
Q

Heap removal of a node run time

A

O(logn)

37
Q

Heap removal of a node run time

A

O(nlogn)

38
Q

cost to heapify an array

A

O(n)

39
Q

Time complexity of Radix Sort

A

O(n*k)

where n values of at most k digits