Now test yourself Flashcards

1
Q

Explain what data structure should be used in a breadth first search: (2)

A

A queue as each newly discovered node is added to the rear of the queue and queues are discovered in the order they are found.

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

State one potential use for a breadth first search: (1)

A

shorted path through an unweighted graph

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

Explain what data structure should be used in a depth first search: (2)

A

A stack as each newly discovered node is inspected immediately and the route can be stepped through in reverse (popped) to find a new path.

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

State one potentially use for a Depth first search (1)

A

Navigating a maze

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

Which tree traversal algorithm will print the value of the root node as the last line? (1)

A

Post order traversal

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

which tree traversal algorithm would be most suitable for copying a tree? (1)

A

Pre order traversal

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

Describe two possible uses for post order traversal: (2)

A

Emptying a tree
Converting from infix to post fix notation (RPN)

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

Which tree traversal algorithm can be used to output a list in ascending order? (1)

A

In order traversal

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

What type of algorithm is a binary search algorithm? (1)

A

an example of a divide and conquer algorithm

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

Give one disadvantage of using linear search (1)

A

inefficient for large lists

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

Give two situations where linear search would be an appropriate choice (2)

A

If a list is unordered or if the list is small

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

Suggest one advantage of using binary search over linear search (1)

A

Binary search is much quicker than linear search for large sorted lists

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

State one Disadvantage of using a instead of Linear search (1)

A

List must be sorted for a binary search

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

Why is a binary search more efficient than a linear search? (2)

A

The list of possible values is halved each time.

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

State the number of comparisons needed to run through one pass of the bubble sort for a lost of 10 items:

A

10

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

Suggest to methods for improving the efficiency of the standard Bubble sort: (2)

A

after each pass check if a swap has been made - if no swap has been made then the list can be assumed to be sorted.

reduce the number of comparisons after each pass by one because the highest value is guaranteed to have bubbled to the end each time.

17
Q

Give two situations in which merge sort would be more suitable than bubble sort (2)

A

Large lists

18
Q

Give one situation in which bubble sort is more suitable than merge sort? (1)

A

Some lists that are nearly in order since merge sort has a fixed number of steps.