Fundamentals of Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the two ways of traversing a graph and describe them

A

Depth first - Starts at chosen node and explores as far as possible (deep) along each branch away from the starting node before backtracking.

Breadth first - Starts at chosen node and visits the closest ones first. (a queue can be used to keep track of nodes to visit)

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

What is a binary tree?

A

A structure where each node can only have up to 2 child nodes attached to it.

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

What are the three ways of traversing a binary tree and describe how to do them?

A

Top Tip: Draw a line below the tree, going all the way around and into every crevasse .

Pre-order - goes to the LEFT of the line (before)

In-order - goes below the line (inline)

Post-order - goes to the RIGHT of the line (after)

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

What’s the difference between an adjacency matrix and an adjacency array?

A

They both display the same information, except one uses either a 0 or a 1 to show if is connected to a node whereas lists just display the ones they are connected to. For example:
List - A | B, C
| A | B | C | D |
Array - A | 0 | 1 | 1 | 0 |

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

Define the term single source in Dijkstra’s algorithm.

A

It means that the shortest path is calculated from a singular starting point.

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

Explain the steps involved in following Dijkstra’s algorithm

A

1) Start from the first vertex
2) Work out the weight/cost for each edge between that vertex and other connected vertices
3) Move on to the next nearest vertex and repeat the process, except taking into account the previous weightings/costs.
4) Repeat this process, storing information about the shortest route (smallest weighting) until you reach the destination vertex.

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

What is a Linear Search?

A

A simple search technique that compares items one by one

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

What is Binary Search?

A

A technique for searching data that works by splitting datasets in half repeatedly until the search item is found.

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

What tree traversal would you use to perform a binary tree search?

A

In-order

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

What is reverse polish notation/postfix notation

A

A way of writing mathematical operations where the operators come after the operands (numbers)

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

What is infix notation?

A

NORMAL - where expressions are written with the operators within the operands.

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

What is the easiest method of creating Reverse polish notations?

A

Use a stack:

1) Push digits onto the stack one by one until you push an operand.
2) Pop all operators and operands out of the stack

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

What tree traversals would create infix, postfix and prefix mathematical operations?

A

In-order would produce infix, or normal

Post-order would produce postfix, or Reverse Polish Notation

Pre-order would produce prefix, or Polish Notation

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

What is prefix notation?

A

Expressions that are written with their operators before the operands.

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

Define bubble sort.

A

A technique for putting data in order by repeatedly stepping through an array, comparing adjacent elements and swapping them if necessary until the array is done.

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

Define Merge Sort

A

A technique for putting data in order by splitting lists into single elements and then merging them back together again.

17
Q

What is meant by a base case in Backus Naur Form.

A

A non-recursive case.