sorting + searching Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

bubble sort: what is the best runtime?

A

O(n)

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

bubble sort: what is the worst runtime?

A

O(n^2)

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

bubble sort: what is the average runtime?

A

O(n^2)

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

what sort method has the same runtime for all cases (average, best, worst) and what is the runtime?

A

O(n^2) for selection sort

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

insertion sort: what is the best runtime?

A

O(n)

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

insertion sort: what is the average runtime?

A

O(n^2)

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

insertion sort: what is the worst runtime?

A

O(n^2)

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

disadvantages of the selection sort?

A

it will not exit the sort if it sorts the array at an earlier point than O(n^2)

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

structure of a bubble sort?

A

for loop

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

structure of a selection sort?

A

for loop within a for loop

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

structure of an insertion sort?

A

for loop with nested while loop

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

quick sort: best runtime

A

O(n log (n))

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

quick sort: average runtime

A

O(nlog(n))

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

quick sort: worst runtime

A

O(n^2)

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

structure of quicksort

A

a while loop with two nested while loops and one nested if statement

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

what array type is used for quick sort?

A

primitive types

17
Q

what is the runtime for all cases of Merge sort?

A

O(nlog(n))

18
Q

structure of merge sort

A

three unnested while loops, the first while loop has an if/else nested

19
Q

best runtime for binary search

A

O(1)

20
Q

worst and average runtime for binary search

A

O(log(n))

21
Q

best runtime for linear/sequential search

A

O(1)

22
Q

worst and average runtime for linear and sequential search

A

O(n)

23
Q

prerequisite for binary search

A

the array must be in order

24
Q

what does binary search do?

A

outputs the index of the item your are searching for in the array. If it is not in the array, it outputs -1.