3: Fundamentals of Algorithms Flashcards

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

Breadth-First Search Algorithm

A

Add start node to discovered list
Enqueue start node
While queue is not empty
Dequeue item to become current node
For each neighbour of current node
If neighbour is not in discovered list
Add neighbour to discovered list
Enqueue neighbour

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

Depth-First Search Algorithm

A

Add start node to discovered list
Push start node onto stack
While stack is not empty
Pop item from stack to become current node
For each neighbour of current node
If neighbour is not in discovered list
Add neighbour to discovered list
Push neighbour onto stack

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

Applications of Breadth-First Search Algorithm

A

Shortest path for an unweighted graph

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

Applications of Depth-First Search Algorithm

A

Navigating a maze

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

Uses of Pre-Order Tree Traversal

A

Copying a tree

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

Uses of In-Order Tree Traversal (2)

A
  • Binary search tree
  • Outputting contents of a binary search tree in ascending order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Uses of Post-Order Tree Traversal (3)

A
  • Infix to RPN conversions
  • Producing a postfix expression from an expression tree
  • Emptying a tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Infix Form to RPN (3)

A
  1. Add brackets to the whole expression so the inner set of brackets denotes the first part to be evaluated
  2. Move each infix operator to the end of their corresponding set of brackets
  3. Remove the brackets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Convert 7 + 8 x 6 to RPN

A

(7 + (8 x 6))
(7 + (8 6 x))
(7 (8 6 x) +)
7 8 6 x +

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

RPN to Infix Form (3)

A
  1. Work from left to right to find the first operator, move it one place to the left, and put brackets around the resulting infix expression
  2. Repeat step 1, treating brackets as one operand, until you’re at the end of the expression
  3. Remove redundant brackets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Convert 7 8 6 x + to Infix Form

A

7 (8 x 6) +
(7 + (8 x 6))
7 + 8 x 6

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

Why is RPN Used (6)

A
  • Simpler for a computer to evaluate
  • Simpler to code algorithm
  • Do not need brackets to show correct order of evaluation
  • Operators appear in the order required for computation
  • No need for order of precedence of operators
  • No need to backtrack when evaluating
How well did you know this?
1
Not at all
2
3
4
5
Perfectly