Linear & Binary Search Flashcards

1
Q

Runtime of linear search on an unsorted array/arraylist

A

O(n)

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

Runtime of binary search on a sorted array/arraylist

A

O(logn)

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

Most effective search to perform on an unsorted array/arraylist?

A

Linear Search O(n)

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

Most effective search to perform on a sorted array/arraylist?

A

Binary Search O(logn)

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

How do you perform linear search?

A

By checking EVERY spot in an array/arraylist

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

How do you perform binary search?

A

Guessing game! We check the halfway points and say “lower or higher”. MUST BE SORTED!

low -> lowest index
high -> length - 1 (last index)
mid -> low + high / 2 (if this results in a decimal value- we ONLY focus on the whole number value [ei: 6.5 = mid -> 6])

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

Runtime of comparing two unsorted lists to one another

A

n^2

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

Runtime of comparing one sorted list to one unsorted list

A

n*logn
or
nlogn

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

Runtime of comparing two sorted lists to one another

A

2n

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

How do you find the low when performing binary search?

A

index 0

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

How do you find the high when performing binary search?

A

length of list - 1

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

How do you find the mid when performing binary search?

A

high + low / 2

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