Programming: algorithms Flashcards

1
Q

describe the process of graph traversal

A

visiting each vertex in a graph

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

what are the two algorithms used for graph traversal?

A

depth first and breadth first

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

describe the concept of a depth first traversal

A

a branch is fully explored before back tracking

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

describe the concept of a breadth first algorithm

A

each adjacent node is fully explored before moving to the next node

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

describe the process of depth first traversal

A

a stack is used

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

what is the root node in graph traversal

A

the node from which the traversal starts

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

if the root node were F, with two child nodes being B and G, which child node would be discovered first?

A

B

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

what is a breadth first algorithm used for?

A

finding the shortest path on an unweighted graph

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

for depth and breadth graph traversal, which uses a stack and which uses a queue?

A

depth first traversal uses a stack and a breadth first traversal uses a queue.

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

describe the use of a pre order tree traversal algorithm

A

can be used to copy a tree

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

describe the use of an in order tree traversal algorithm

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
12
Q

describe a purpose of a post order tree traversal algorithm

A

converting from Infix to reverse polish notation or emptying a tree

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

describe a tree traversal

A

the process of visiting/updating/outputting each node in a tree.

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

what is the difference between graph and tree traversals?

A

-tree traversals are unique to trees
-tree traversals must start at the root node

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

where can an in order traversal be used?

A

only with binary trees

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

what is a binary tree

A

a rooted, ordered tree in which each parent node has no more than 2 child nodes

17
Q

what is the purpose of reverse polish notation

A

-it removes the need for brackets
-eliminates confusion over the order of execution

18
Q

describe reverse polish notation

A

the opcode is written after the operand

19
Q

what is infix and postfix?

A

infix is a sum written as a human would write it, postfix is a sum written in reverse polish notation form

20
Q

how is a stack used to evaluate postfix equations?

A

an algorithms goes along an array (containing the postfix expression) and operands are pushed onto a stack. Once an opcode is identified, two items of the stack are popped and the operation is performed.

21
Q

describe a linear search

A

the list is iterated through and each value in the list is checked until the desired item is found

22
Q

what is the time complexity of a linear search?

A

O(N)

23
Q

when can a binary search be used?

A

when the list is sorted. If it is not, it must be sorted before a binary search can be carried out

24
Q

how does a binary search work?

A

the midpoint of the list is compared to the desired value and depending on if it is higher or lower than it, a half of the list is discounted as it will not contain the desired value. The midpoint of what’s left of the list is then found, and so on.

25
Q

define a binary tree search

A

functions the same as a binary search, only with the values in a list represented in a binary tree

26
Q

describe the purpose of a sorting algorithm

A

to put the elements of an array into a specific order

27
Q

what is the advantage of having a sorted list?

A

a binary search can be performed on a sorted list, which has a time complexity of O(logN), compared o O(N) of a linear search

28
Q

describe the process of a merge sort

A

a list of items is broken down into individual elements (individual sorted lists) and then combined into groups of two, then groups of four and ordered as they are combined

29
Q

what is an optimisation algorithm?

A

an algorithm that finds the best possible solution to a problem

30
Q

describe dijkstra’s algorithm

A

A pathfinding algorithm designed to find the shortest path between two points

31
Q

summarise the functioning of dijkstra’s algorithm

A

functions similarly to a breadth first searching algorithm, keeping track of visited nodes in a queue. The difference between the two is that a priority queue is used with dijkstra’s algorithm to give weighting to certain paths.

32
Q

where is dijkstra’s algorithm commonly used?

A

-satellite navigation systems
-routers, shortest network route during packet transmission

33
Q

describe the steps of dijkstra’s algorithm

A

1.select start and end nodes
2.determine the distance of each adjacent node to the start node
3.the start node is fully explored. Choose the node closest to A and mark it as the shortest distance
4. the shortest path from this node to one of its adjacent nodes is then recorded etc.

34
Q
A