ASU CSE 240 MIDTERM REVIEW
QUESTION SET WITH ACCURATE
ANSWERS
◉ A critical step in writing a recursive function is to assume that
the
Answer: size-m problem has been solved by the underlying
recursive mechanism, where m < n.
◉ Given this snippet of code, identify what is the stopping
condition and return value?
void deleteList(struct contact* node) {
if (node == NULL) return;
else {
deleteList(node->next);
free(node);
}
,}
Answer: deleteList(node->next);
◉ merge-short is typically implemented using
Answer: a function with two recursive calls.
◉ In the hanoi towers function, what part of the code represent
step 4: Constructiopn of size-n problem from size-(n-1) problems?
Answer: hanoitowers(n-1, S, D, M);
hanoitowers(1, S, M, D);
hanoitowers(n-1, M, S, D);
◉ If you want to change the insertion sort function with a size-(n-
1) problem, as discussed in the lecture, to a merge sort function,
where do you need to make changes?
Answer: CorrectC.
In the definition of size-m problem
CorrectD.
, In the code code that constructs the solution of size-n problem
from the size-m problem.
◉ When inserting a data into a binary search tree, the data should
be inserted
Answer: at the position to keep the entire tree as a binary search
tree.
◉ The complexity of searching an arbitrary binary search tree is
the order of
Answer: O(n)
◉ Consider an array, a linked list, and a binary search tree. Which
data structure requires fewest comparisons in average to search
an element stored in the data structure?
Answer: binary search tree
◉ How do we include a user-defined library, say myMathLib.h,
into a program that uses this library?
Answer: #include "myMathLib.h"
◉ What is the key difference between a static variable and a
global variable?
Answer: They have different visibility.
QUESTION SET WITH ACCURATE
ANSWERS
◉ A critical step in writing a recursive function is to assume that
the
Answer: size-m problem has been solved by the underlying
recursive mechanism, where m < n.
◉ Given this snippet of code, identify what is the stopping
condition and return value?
void deleteList(struct contact* node) {
if (node == NULL) return;
else {
deleteList(node->next);
free(node);
}
,}
Answer: deleteList(node->next);
◉ merge-short is typically implemented using
Answer: a function with two recursive calls.
◉ In the hanoi towers function, what part of the code represent
step 4: Constructiopn of size-n problem from size-(n-1) problems?
Answer: hanoitowers(n-1, S, D, M);
hanoitowers(1, S, M, D);
hanoitowers(n-1, M, S, D);
◉ If you want to change the insertion sort function with a size-(n-
1) problem, as discussed in the lecture, to a merge sort function,
where do you need to make changes?
Answer: CorrectC.
In the definition of size-m problem
CorrectD.
, In the code code that constructs the solution of size-n problem
from the size-m problem.
◉ When inserting a data into a binary search tree, the data should
be inserted
Answer: at the position to keep the entire tree as a binary search
tree.
◉ The complexity of searching an arbitrary binary search tree is
the order of
Answer: O(n)
◉ Consider an array, a linked list, and a binary search tree. Which
data structure requires fewest comparisons in average to search
an element stored in the data structure?
Answer: binary search tree
◉ How do we include a user-defined library, say myMathLib.h,
into a program that uses this library?
Answer: #include "myMathLib.h"
◉ What is the key difference between a static variable and a
global variable?
Answer: They have different visibility.