10 - Algorithms 3 (Search) Flashcards

1
Q

What is searching?

A

Searching for an item in a collection

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

Why may you want to search?

A

Want to know if an item is there at all

Want to know an item’s position

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

Name 3 applications of searching

A

Parsing strings

Database queries

Finding files on a disk

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

What is linear searching?

A

Going through all items and checking if any equal the key

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

What’s the worse case of linear searching?

A

Going through all elements

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

What is the work and step complexity of linear search?

A

O(n)

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

What does the performance of linear search depend on?

A

The data distribution

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

What do databases and other applications use to accelerate searching?

A

Sorted lists or B-trees

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

What is binary search?

A

A divide and conquer searching technique

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

What is the process of binary searching?

A

Recursively/iteratively check if the middle location contains the key, if not then discard one half which cannot contain the value, check the middle location of the remaining half and so on

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

What is the parallel search input split?

A

Divide input into p parts (number of processing elements) and run a serial search for each part

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

What are the effects of the input split?

A

A potential speed up of p times

But need to wait for all threads to finish

Some threads might need to perform the worst case scenario

Latency corresponding to the slowest search

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

What is the parallel search multiple keys?

A

Perform multiple searches at the same time

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

What are the effects of multiple keys searching?

A

A potential speed up of p times

Underutilisation if a number of searches is smaller than p - lots of idle threads

Early exit

Larger p makes it more likely that the worst case execution time will happen

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

How does a parallel binary search benefit from parallelism?

A

Parallel implementation using p PEs can perform p searches simultaneously

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

Discuss memory access in parallel search?

A

Binary parallel search cannot benefit from coalesced memory access

Linear parallel search might be faster for small arrays

In general, binary parallel search is preferable

17
Q

What is the P-ary search?

A

A divide and conquer strategy on sorted arrays

18
Q

What is the process of P-ary search?

A

Divide input into p parts, all p threads searching for the same key in a different part, each thread checks if the key can be in their part, the selected part is again assigned in equal shares to all threads, and the process is repeated until the search key is found

19
Q

How does the p-ary search check for the key?

A

Assuming sorted arrays, each thread needs to look only at first and last elements of part of its subset to determine which part contains the search key

This part is again assigned in equal shares to all threads, and process is repeated until search key is found

20
Q

What is the complexity of the p-ary search?

A

O(logpn)

21
Q

What are search trees?

A

Another way of representing data in pre-ordered format

22
Q

What are binary search trees?

A

Where each node can have two children

23
Q

How do you traverse a binary search tree?

A

Compare out key with a node and select left child if its value is lower or right child if it is highter

24
Q

What is the complexity of binary search tree?

A

O(log n)

25
Q

What is a B-tree?

A

A generalisation of binary search trees where each node can have multiple children

When searching, more than two paths diverge from a single node

Very efficient when combined with p-ary parallel search

26
Q

The binary search requires the input data to be sorted. What applications might justify that additional step?

A

Multiple searches, such as database queries. Searching performance depends on data distribution so its better if the key is more likely to be near the start of the collection.

27
Q

What’s the totally rad thing about the step complexity of p-ary?

A

It scales with the increasing number of threads