Algorithms: Binary Search Flashcards

1
Q

Which is more efficient: linear search or binary search?

A

binary search is more efficient as we are able to leverage a divide and conquer strategy. We compare the target element to the middle element of the array. If the target element is less than the middle element, then we are able to ignore the right of the array. Repeating this same strategy until we find out target element or determine that the element is not present.

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

What is the bisect module?

A

Bisect is a built-in binary search module in Python that takes in a sorted array of integers and a key, and returns the index of the first occurrence of that key from the array

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

What does bisect_left do?

A

bisect_left is a method of the bisect module which returns the index of the left-most occurrence of the key

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

What does bisect_right do?

A

bisect_right is a method of the bisect module which returns the index to the right of the key element. This is used to serve as an insertion point.

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

What does the bisect function do?

A

bisect is equivalent in functionality to bisect_right

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

What is the purpose of insort_left and insort_right?

A

the purpose is to maintain the sorting of a list when inserting a new element. These both operate similarly to bisect_left and bisect_right, respectively. The difference in functionality is that insort INSERTS an element into the list whereas bisect returns the index of a target element

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

What is a cyclically shifted array?

A

an array that is able to become sorted by shifting its elements cyclically

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