ASU CSE 240 MIDTERM
COMPLETE QUESTION SET WITH VERIFIED
SOLUTIONS GRADED A+
Question 1.
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.
Question 2.
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);
Question 3.
In the following query language statement, which function acts as the filter function?
var myQuery = from b in Books where b.price < 80 orderby b.title select b;
ANSWER
C.
where
Question 4.
The reason that we need to call fflush() or cin.ignore() is because the previous
ANSWER
input leaves a character in the file buffer.
,Question 5.
What is the best of deleting all the nodes in a binary tree pointed to by the root pointer?
ANSWER
Traverse the tree and delete each node individually.
Question 6.
Given the information below, which of the following snippet of codes will insert a new node in the
second place in the linked-list. Assume the linked-list contains already at least one node.
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} *head, *p, *q;
ANSWER
p = (struct contact *) malloc(sizeof(struct contact));
...
p->next = head->next;
head->next = p;
Question 7.
Given the Scheme code below, answer the following questions related the Fantastic Four abstract
approach.
(define dtob(lambda(N) ; line 1
(if (= 0)(list0) ; line 2
(append (dtob (quotient N 2)) ; line 3
(list (remainder N 2)))))) ; line 4
(1) What line of code defines the stopping condition and the return value? Choose [Size1]
(2) What line of code contains the size-M problem, where M < N? Choose [SizeM]
(3) What lines of code define the step that construct the solution to size-N problem? Choose [SizeM_N
ANSWER
(1) What line of code defines the stopping condition and the return value? Choose Correct Line
2
(2) What line of code contains the size-M problem, where M < N? Choose Correct Line 3
(3) What lines of code define the step that construct the solution to size-N problem? Choose
Correct Lines 3 & 4
, Question 8.
What is the return value of the code below?
(define lst '(3 5 2 9))
(min (min (car lst) (cadr lst)) (min (caddr lst) (cadddr lst)))
ANSWER
2
Question 9.
Given the Scheme code as follows. What is the output?
(define not-gate (lambda(x) (if (= x 0) 1 0)))
(define onescomplement (lambda (a-list) (map not-gate a-list))) (onescomplement '(0 1 0 2 0 3))
ANSWER
CorrectA.
(1 0 1 0 1 0)
Question 10.
If a function calls another function, the local variables in these two functions use the memory from
ANSWER
different stack frames.
Question 11.
We use "Pass by Constant Reference" when:
ANSWER
Function does not want to modify the value, the value is expensive to copy and NULL is not
valid
Question 12.
A fact starts with a relationship followed by a list of arguments. The arguments of a fact
ANSWER
can have a structure similar to that of a fact.
COMPLETE QUESTION SET WITH VERIFIED
SOLUTIONS GRADED A+
Question 1.
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.
Question 2.
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);
Question 3.
In the following query language statement, which function acts as the filter function?
var myQuery = from b in Books where b.price < 80 orderby b.title select b;
ANSWER
C.
where
Question 4.
The reason that we need to call fflush() or cin.ignore() is because the previous
ANSWER
input leaves a character in the file buffer.
,Question 5.
What is the best of deleting all the nodes in a binary tree pointed to by the root pointer?
ANSWER
Traverse the tree and delete each node individually.
Question 6.
Given the information below, which of the following snippet of codes will insert a new node in the
second place in the linked-list. Assume the linked-list contains already at least one node.
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} *head, *p, *q;
ANSWER
p = (struct contact *) malloc(sizeof(struct contact));
...
p->next = head->next;
head->next = p;
Question 7.
Given the Scheme code below, answer the following questions related the Fantastic Four abstract
approach.
(define dtob(lambda(N) ; line 1
(if (= 0)(list0) ; line 2
(append (dtob (quotient N 2)) ; line 3
(list (remainder N 2)))))) ; line 4
(1) What line of code defines the stopping condition and the return value? Choose [Size1]
(2) What line of code contains the size-M problem, where M < N? Choose [SizeM]
(3) What lines of code define the step that construct the solution to size-N problem? Choose [SizeM_N
ANSWER
(1) What line of code defines the stopping condition and the return value? Choose Correct Line
2
(2) What line of code contains the size-M problem, where M < N? Choose Correct Line 3
(3) What lines of code define the step that construct the solution to size-N problem? Choose
Correct Lines 3 & 4
, Question 8.
What is the return value of the code below?
(define lst '(3 5 2 9))
(min (min (car lst) (cadr lst)) (min (caddr lst) (cadddr lst)))
ANSWER
2
Question 9.
Given the Scheme code as follows. What is the output?
(define not-gate (lambda(x) (if (= x 0) 1 0)))
(define onescomplement (lambda (a-list) (map not-gate a-list))) (onescomplement '(0 1 0 2 0 3))
ANSWER
CorrectA.
(1 0 1 0 1 0)
Question 10.
If a function calls another function, the local variables in these two functions use the memory from
ANSWER
different stack frames.
Question 11.
We use "Pass by Constant Reference" when:
ANSWER
Function does not want to modify the value, the value is expensive to copy and NULL is not
valid
Question 12.
A fact starts with a relationship followed by a list of arguments. The arguments of a fact
ANSWER
can have a structure similar to that of a fact.