Fundamentals of Algorithms Flashcards

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

What is Breadth-first traversal?

A

Start at root

Enqueue node onto the queue

Mark as visited

Repeat steps 2,3 for all nodes connected to head node

Dequeue the front of the queue

Repeat steps 4,5 until queue is empty

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

What is Depth-first traversal?

A

A method of searching a graph by navigating to the smallest undiscovered node adjacent to the current node.
Backtracks on itself up and down branches
Uses a stack

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

Where do you put the dot for pre-order?

A

left

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

Where do you put the dot for post-order?

A

right

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

Where do you put the dot for in-order?

A

bottom

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

What is infix form?

A

A form of mathematical notation which places the operators between the operands

e.g., 4 + 5 = 9

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

How do you convert infix to Reverse Polish (postfix)?

A

Display it like a tree and then do post order traversal

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

How do you do Reverse Polish Notation with a single stack?

A

When you encounter an operand, push it onto the stack.

When you encounter an operator, pop two values from the stack and push the result into the stack.

When you have finished i.e. have been through the whole expression, pop the final answer from the stack

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

What is a Linear Search?

A

Look through each element in turn until a match is found

Doesn’t work well on long lists as it can take a long time especially if list is not ordered.

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

What is a Binary Search?

A

Only works if values in structure are ordered

It works by repeatedly dividing in half the portion of the list that could contain the item, until you’ve narrowed down the possible location to just one.

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

What is a bubble sort?

A

A sorting algorithm that works by examining each adjacent elements in the list from left to right, switching their positions if they are out of order.

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

How does a merge sort work?

A

The list is divided into the smallest unit (one element)

It continuously cuts down a list into multiple sub lists until each has only one item, then merges those sub lists into a sorted list.

Until finally all the elements are sorted and combined into one list.

( RECURSIVE algorithm split in half on left each element until all separated then move to the right and do the same )

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

What is an Optimisation Algorithm?

A

Finds the best possible solution to a problem e.g., Dijksta’s Algorithm

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

What does Dijksta’s Algorithm do?

A

It finds the shortest path from the starting node to every other node in a network

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

How does Dijksta’s keep track of visited nodes?

A

With a Priority queue

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

How does Dijksta’s Algorithm work?

A

Makes note of distances from nodes to start position, at this point only the nodes connected to start will have a value, the others will have a distance of infinity.

Creates list called ‘Unvisited’

Take note the start node is fully explored and choose node closest to the start node, update the table to reflect the shortest distance from A to each node. Mark that node as fully explored.

Repeat step 2, always selecting the node the shortest distance from A which hasn’t been fully explored, continue until every node has been fully explored.
USES PRIORITY QUEUE

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

Why might Backus-Naur form be used to represent a language instead of Regular Expressions?

A

Regular expressions cannot support recursion like Backus-Naur can

18
Q

Regular Expression: what does * mean?

A

0 or more repetitions

19
Q

Regular Expression: what does + mean?

A

1 or more repetitions

20
Q

Regular Expression: what does ? mean?

A

Previous character optional

21
Q

Regular Expression: what does ┃ mean?

A

Alternative/ or

22
Q

Regular Expression: what does () mean?

A

Used to group regular expressions

23
Q

What is Reverse Polish Notation?

A

A postfix way of writing expressions. Rather than the opcode being between the operand it is written after the operand.

Can be executed on a stack

24
Q

What are the advantages of using RPN over infix notation?

A

Simpler for computer to evaluate

Simpler to code algorithm

Don’t need brackets

25
Q

In Finite State Machine what is the double circle?

A

Valid stop state

When it is valid to stop

26
Q

How does a finite state machine differ from a Turing machine?

A

Don’t have to worry about tape

Or header

27
Q

What is meant by the term reject state?

A

No escape from that state -no way out

Rule won’t be valid if you stop there

28
Q

What are finite state machines used for?

A

Used to validate an input

Represent regular expressions in a computer

A less powerful Turing machine

29
Q

Definition of a Finite State Machine

A

A FSM is a computing machine that has a fixed set of possible states, a set of inputs that change the state, and a set of possible outputs.

30
Q

What is the use of a call stack?

A

Each time a subroutine is called, the return address, parameters, and local variables used int the subroutine are held in a stack frame in the call stack.
These are then all popped from the stack each time the end of a subroutine is reached.

31
Q

What does recursion look like in Backus-Naur Form?

A

where a statement is defined in terms of itself e.g.,

<variable> ::= <variable>│<variable>, <variable>
</variable></variable></variable></variable>

32
Q

What is a Syntax Diagram?

A

graphical method of representing the syntax of a language, and maps directly to Backus-Naur Form

33
Q

What is the Travelling Salesman Problem?

A

Finding the quickest route to traverse all nodes

it will become intractable when you add enough nodes

34
Q

Which complexity dictates the growth rate?

A

Factorial

35
Q

Explain what is meant by the time complexity of an algorithm?

A

How long it will take an algorithm to complete in relation to the size of the input.

36
Q

Explain why recursion isn’t suitable for a large array?

A

Recursion may not be suitable for searching large arrays because each call requires a new stack frame, which can consume a lot of memory.

37
Q

Define Cardinality

A

the number of elements in a set.

38
Q

What is an algorithm?

A

A (step-by-step) description of how to complete a task

Independent of any programming language;

39
Q

What is meant by the divide and conquer approach?

A

Divide and Conquer is an algorithm design paradigm that involves breaking a problem down into smaller, more manageable sub-problems, solving each sub-problem independently, and then combining their solutions to solve the original problem.

40
Q

What is the format of a transition function?

A

δ (Current state, Input symbols) = (Next state, Output symbol, Movement)