Advanced Algorithms and Data Structures - Final Exam With
100% Correct Solutions
You are using a language that does not support recursion. What data structure would
you use to traverse a binary search tree in order?
1. Set Next(newNode) to location
2. Set Back(location) to newNode
3. Set Next(Back(location)) to newNode 4. Set Back(newNode) to Back(location) -
ANSWER stack
int z(int k, int n)
{
if (n == k)
return k
else
{
if (n > k)
return z(k, n-k);
else return z(k-n, n);
}
}
Given the above function, what is z(6,8)? - ANSWER 2
A recursive version of an insert operation that takes an external pointer to a list as a
parameter will work only if - ANSWER the list is passed by reference
The three-question testing method has its foundation in what computing technique? -
, ANSWER induction
recursive algorithm - What is the first step when writing a recursive algorithm? ANSWER
getting an exact problem definition
When you have an exact definition of a recursive problem, what is the next step?
ANSWER determining the size
It is good to use recursion when ANSWER a, b, and c are true.
A ____________________ structure is the main control structure in a recursive routine, and
a ____________________ structure is the main control structure in an iterative routine. -
ANSWER branching, looping
Which of the following statements could describe the base case of a recursive
algorithm? - ANSWER If the parameter value is 100, the function is equal to zero.
Which of the following statements could describe the base case of a recursive
algorithm? - ANSWER b and d above
Consider the following binary search tree and answer the question. The numbers on the
nodes are labels so that we can talk about the nodes; they are not values in the key
members of the items in the tree.
If a node is to be inserted into the tree whose key data member is less than the key data
member in node 1 but greater than the key data member in node 5, where would it be
inserted? - ANSWER node 5's right child
Look at the following binary search tree and answer the question. The numbers on the
nodes are labels so that we can talk about the nodes; they are not values in the key
members of the items in the tree.
If node 1 is to be deleted, the value in which nodes could be used to replace it? -
100% Correct Solutions
You are using a language that does not support recursion. What data structure would
you use to traverse a binary search tree in order?
1. Set Next(newNode) to location
2. Set Back(location) to newNode
3. Set Next(Back(location)) to newNode 4. Set Back(newNode) to Back(location) -
ANSWER stack
int z(int k, int n)
{
if (n == k)
return k
else
{
if (n > k)
return z(k, n-k);
else return z(k-n, n);
}
}
Given the above function, what is z(6,8)? - ANSWER 2
A recursive version of an insert operation that takes an external pointer to a list as a
parameter will work only if - ANSWER the list is passed by reference
The three-question testing method has its foundation in what computing technique? -
, ANSWER induction
recursive algorithm - What is the first step when writing a recursive algorithm? ANSWER
getting an exact problem definition
When you have an exact definition of a recursive problem, what is the next step?
ANSWER determining the size
It is good to use recursion when ANSWER a, b, and c are true.
A ____________________ structure is the main control structure in a recursive routine, and
a ____________________ structure is the main control structure in an iterative routine. -
ANSWER branching, looping
Which of the following statements could describe the base case of a recursive
algorithm? - ANSWER If the parameter value is 100, the function is equal to zero.
Which of the following statements could describe the base case of a recursive
algorithm? - ANSWER b and d above
Consider the following binary search tree and answer the question. The numbers on the
nodes are labels so that we can talk about the nodes; they are not values in the key
members of the items in the tree.
If a node is to be inserted into the tree whose key data member is less than the key data
member in node 1 but greater than the key data member in node 5, where would it be
inserted? - ANSWER node 5's right child
Look at the following binary search tree and answer the question. The numbers on the
nodes are labels so that we can talk about the nodes; they are not values in the key
members of the items in the tree.
If node 1 is to be deleted, the value in which nodes could be used to replace it? -