Chapter 4 Search Flashcards

(20 cards)

1
Q

What is the assumption required for Binary Search to work?

A

The array must be sorted in non-decreasing order.

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

What is the time complexity of Binary Search?

A

O(log n)

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

Why can Binary Search sometimes be less practical than sequential search?

A

Because sorting the array first takes O(n log n), which can outweigh the benefit if only one or few queries are needed.

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

What data structure embeds the power of binary search?

A

Binary Search Trees (BSTs)

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

What is the worst-case time complexity of searching in a Binary Search Tree?

A

O(n) in case of a completely unbalanced tree.

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

What kind of tree ensures efficient BST operations in expectation?

A

Balanced Binary Search Tree

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

What is the difference between BFS and DFS in graph search?

A

BFS explores all neighbors at the current depth before going deeper; DFS explores as deep as possible along one path before backtracking.

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

What is the time complexity of BFS and DFS?

A

O(|V| + |E|) where V is vertices and E is edges.

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

What is the purpose of colours in BFS/DFS?

A

To mark the state of each vertex: unvisited (white), discovered (grey), and fully explored (black).

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

What problem does the Apriori algorithm solve?

A

Efficiently finding frequent itemsets in transaction data.

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

What is the key principle behind the Apriori algorithm?

A

If a set is infrequent, all its supersets are also infrequent.

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

What data structure is used in kd-Trees?

A

A binary tree where splits alternate between dimensions.

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

What is the time complexity of nearest neighbor search using brute force?

A

O(n)

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

What advantage do kd-Trees offer for nearest neighbor search?

A

They can reduce search time to O(log n) in ideal conditions.

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

Why might kd-Trees perform poorly?

A

In high dimensions or with skewed distributions.

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

How does a kd-Tree decide on the splitting dimension?

A

By cycling through dimensions using depth modulo number of dimensions.

17
Q

What is pruning in kd-Tree search?

A

Skipping branches of the tree that cannot contain a closer point than the current best.

18
Q

What is a use-case of nearest neighbor search in data science?

A

Classification, e.g. k-nearest neighbors for labeling.

19
Q

How does BFS guarantee shortest path in terms of hops?

A

It explores nodes layer by layer from the source.

20
Q

What is a practical limitation of DFS in search?

A

It may go deep down a path that doesn’t lead to the destination, missing closer solutions.