4.4 - Fundamentals of Algorithms Flashcards

(11 cards)

1
Q

What is a tree?

A

A tree is a connected, undirected graph with no cycles.

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

What are the 3 types of tree-traversal algorithms?

A

In-order
Pre-order
Post-order

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

What is a recursively-defined procedure?
What must it have to be recursive?
What can it be used for?

A

Recursion (or a recursive procedure) is one that calls itself. It is used when a problem can be broken down, and the same algorithm is repeatedly used on each sub-problem.

It MUST have an end condition, and any recursive algorithm can be written using iteration instead (and vice versa).
It can be used for:
- Sorting agorithms
- Parsing XML/HTML
- Working with files
- In directory structure

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

What is pre-order tree traversal used for?

A
  • Copying a tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is in-order tree traversal used for?

A
  • Binary earch trees
  • Outputing tree nodes in order (print method)
  • Polish notation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is post-order tree traversal used for?

A
  • Reverse polish notation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the issue with infix notation

A
  • There can be ambiguity over the order of operations e.g.
    6 + 4 x 2
    1. (6 + 4) x 2
    OR
    2. 6 + (4 x 2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is pre-fix notation?

A

Mathematical notation where the operator is at the start of the operands

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

What is post-fix notation?

A

Mathematical notation where the operator is at the end of the operands

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

How do we implement post-fx notation using a stack?

A
  1. Read the numbers onto the stack
  2. When you reach an operator, pop that last 2 numbers off, apply the operator to them
  3. Push the result back onto the stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is advantage of using post-fix (reverse polish) over pre-fix (polish) notation?

A

In reverse polish, the operators appear in the order required for completion, therefore are easier to implement using a stack.

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