Recursion and Binary Trees Flashcards

1
Q

means “defining a problem in terms of itself”.

A

RECURSION

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

It is commonly used in mathematics, where there are many examples of expressions written in terms of themselves.

A

RECURSION

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

what is Recursive Algorithm

A

A recursive algorithm calls itself with smaller input values and obtains the results by simply performing the operations on these smaller values. If a problem can be solved using smaller versions of the problem, and the smaller versions reduce to solve another problem, then one can utilized a recursive algorithm to solve that problem.

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

Designing Recursive Algorithms

A

Initialize the algorithm.

Check to see whether the current value(s) being processed match the base case. If so, process and return the value.

Redefine the answer in terms of a smaller or simpler sub-problem or sub-problems.

Run the algorithm on the sub-problem.

Combine the results in the formulation of the answer.

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

Limitations of Recursive Approach:

A

Recursive solutions may involve extensive overhead because they use function calls.

Each time you call a function you use up some of your memory allocation may be in stack or heap. If there are large number of recursive calls – then you may run out of memory.

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

A binary tree is a a collection of ___ that consists of the _______ and other subsets to the __________, which are called the ___ and ___________

A

A binary tree is a a collection of nodes that consists of the root and other subsets to the root points, which are called the left and right subtrees.

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

Every _______ node on a binary tree can have up to ______ (roots of the two subtrees); any more children and it becomes a general tree.

A

Every parent node on a binary tree can have up to two child nodes (roots of the two subtrees); any more children and it becomes a general tree.

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

A node that has no children is called a

A

leaf node.

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

Visit the root, traverse the left subtree and then traverse the right subtree

A

Preorder

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

Traverse the left subtree (), traverse the right subtree () and then visit the root.

A

Postorder

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

Traverse the left subtree, visit the root and the traverse the right subtree ().

A

in order

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

We can construct a simple search tree if we add new nodes with value x on the tree using this strategy:

A

Every time x is less than the value in the node we move down to the left.
Every time x is greater than the value in the node we move down to the right.

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