Recursive algorithms Flashcards

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

What does 0! zero factorial equal

A

It equals 1

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

What do recursive algorithms use?

A

They use stack data structures

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

What must a recursive routine have?

A
  • It must have a stopping condition or base case (which means it will stop calling itself and start to unwind)
  • For input values (excluding the stopping condition) it must call itself
  • The stop condition must be reached after a finite number of calls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why must there be a finite point before the stopping point?

A

if there isn’t the stack will overflow (as there is no more space in the stack)

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

What is a recursive subroutine?

A

A subroutine that is defined in terms of itself

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

What three things are held in a stack frame?

A
  • The return address,
  • The parameters
  • The local variables
    used in the subroutine are held in the stack frame in the call stack
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What sort of algorithm is used for tree traversals?

A

Recursive algorithms

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

What is the algorithm for an in order tree traversal?

A
  • Traverse the left subtree
  • Visit the root node
  • Traverse the right subtree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the algorithm for an post order tree traversal?

A
  • Traverse the left subtree
  • Traverse the right subtree
  • Visit the root node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the algorithm for an pre order tree traversal?

A
  • Visit the root node
  • Traverse the left subtree
  • Traverse the right subtree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can a binary tree be represented in memory?

A

A binary tree can be represented in memory by three 1 dimensional arrays

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

What position in an array/list is the value of the root node stored in?

A

It is stored as the first element of the list

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

What three columns are required for storing a binary tree as three arrays/lists in memory?

A

1 column to identify the data in each node, 1 column holding the left pointers to the left subtrees and 1 column holding the right pointers to the right subtrees.

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

What can in order traversal algorithms be used for?

A

Can be used to output the values held in the nodes in alphabetic or numerical sequence.

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

What can post order traversal algorithms be used for?

A

Can be used for writing algebraic expressions in Reverse Polish Notation

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

What can pre order traversal algorithms be used for?

A

Can be used for

  • copying a tree
  • producing a prefix expression from an expression tree
17
Q

What is a divide-and-conquer algorithm?

A

An algorithm that uses recursion to break down a problem into two or more sub-problems so the problem is simpler to solve