Algorithms Flashcards

(47 cards)

1
Q

What is an algorithm?

A

A set of instructions which completes a task in a finite time and always terminates

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

What is graph traversal?

A

The process of visiting each vertex in a graph

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

Name the two types of graph traversal

A

Depth-first search and breadth-first search

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

Which traversal is best for navigating a maze?

A

Depth-first search

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

What is breadth-first traversal useful for?

A

Shortest path on an unweighted graph

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

What abstract data type is used for a breadth-first traversal?

A

Queue

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

What abstract data type is used in a depth-first traversal?

A

Stack

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

What type of graphs can be traversed?

A

Connected graphs

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

Can a tree undergo depth-first traversal?

A

Yes- although it might be more appropriate to use a tree-traversal

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

Can a graph traversal start from any node?

A

Yes

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

What is tree-traversal?

A

The process of visiting updating or outputting each node in a tree- it is an algorithm

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

Name the three types of tree-traversal

A

Preorder- inorder and postorder

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

Name a use of postorder traversal

A

Emptying a tree, Infix to RPN (reverse polish notation) conversions, Producing a postfix expression from an expression tree

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

Which traversal would be used for copying a tree?

A

Preorder traversal

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

Name a use of inorder traversal

A

Outputting the contents of a binary search tree in ascending order

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

Can inorder traversal be performed on any tree?

A

No- only binary trees (including binary search trees)

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

Can preorder traversal be performed on any tree?

A

Yes

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

Can postorder traversal be performed on any tree?

A

Yes

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

Where does tree traversal start?

20
Q

How do traversals work their way around the tree?

A

Anticlockwise

21
Q

How would In-Order traversal work

A

Left, Root, Right. Start from furthest left and go to right

22
Q

How would Post-Order traversal work

A

Left, Right, Root. Start from furthest left and check each leaf node, go up the last one until one before root, switch to other leaf node on other side and repeat.

23
Q

How would Pre-Order traversal work

A

Root, Left sub-tree, Right sub-tree. Start from top and work down each sub-node

24
Q

What is the benefit of reverse Polish notation?

A

It eliminates the need for brackets

25
Convert the infix expression 14 + 6 to reverse Polish
14 6 +
26
Convert the infix expression (12 - 4) × (3 + 5) to reverse Polish
12 4 - 3 5 + ×
27
Convert the reverse Polish expression 13 6 + 4 - to infix
(13 + 6) - 4
28
Convert the infix expression 3(4 - 2) + 9 to reverse Polish
4 2 - 3 × 9 +
29
Convert the reverse Polish expression 4 6 7 + - to infix
4 - (6 + 7)
30
Which is not an example of where reverse Polish is used?
PreScript
31
What is the result of the reverse Polish expression 2 8 × 2 4 - × ?
-32
32
What is the result of the reverse Polish expression 4 6 8 - - ?
6
33
What is a searching algorithm used for?
A searching algorithm is used to find a specified data item within a set of data
34
Time complexity of linear search
O(N)
35
What must be true about a set of data if it is to be searched using the binary search algorithm?
The set of data must be sorted
36
Which is most efficient- binary search or linear search?
Binary search
37
Time complexity of binary search
O(LogN)
38
Calculation used to find the midpoint of a set of data
Add the first and last positions of the data and divide by two
39
Time complexity of binary tree search
O(LogN)
40
What is a binary tree?
A rooted- ordered tree in which each node has no more than 2 children
41
Which sorting algorithm is most time efficient: bubble sort or merge sort?
Merge sort
42
Which sorting algorithm is an example of a divide and conquer algorithm?
Merge sort
43
What is the time complexity of the bubble sort algorithm?
O(n^2)
44
What is the time complexity of the merge sort algorithm?
O(nlogn)
45
What is the purpose of an optimisation algorithm?
To find the best possible solution to the problem posed
46
What is the purpose of Dijkstra’s algorithm?
To find the shortest path between two nodes in a network
47
Which is not an example of where Dijkstra’s algorithm is used?
Binary tree search