int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else
ID: 3694286 • Letter: I
Question
int foo(int n) //Line 1
{ //Line 2
if (n == 0) //Line 3
return 0; //Line 4
else //Line 5
return n + foo(n - 1); //Line 6
} //Line 7
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?
Flag this Question
Question 41
void printNum(int num) //Line 1
{ //Line 2
if (n < 0) //Line 3
cout << "Num is negative" << endl; //Line 4
else if (num == 0) //Line 5
cout << "Num is zero" << endl; //Line 6
else //Line 7
{ //Line 8
cout << num << " "; //Line 9
printNum(num – 1); //Line 10
} //Line 11
} //Line 12
Consider the accompanying definition of a recursive function. Which of the statements represent the base case?
Question 42
void printNum(int num) //Line 1
{ //Line 2
if (n < 0) //Line 3
cout << "Num is negative" << endl; //Line 4
else if (num == 0) //Line 5
cout << "Num is zero" << endl; //Line 6
else //Line 7
{ //Line 8
cout << num << " "; //Line 9
printNum(num – 1); //Line 10
} //Line 11
} //Line 12
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?
Question 43
int recFunc(int num)
{
if (num >= 10)
return 10;
else
return num * recFunc(num + 1);
}
Consider the accompanying definition of a recursive function. What is the output of the following statement?
cout << recFunc(8) << endl;
Question 44
int recFunc(int num)
{
if (num >= 10)
return 10;
else
return num * recFunc(num + 1);
}
Consider the accompanying definition of a recursive function. What is the output of the following statement?
cout << recFunc(10) << endl;
Question 45
Consider the following definition of the recursive function print.
void print(int num)
{
if (num > 0)
{
cout << num << " ";
print(num - 1);
}
}
What is the output of the following statement?
print(4);
Question 46
Consider the following definition of the recursive function mystery.
int mystery(int first, int last)
{
if (first > last)
return 0;
else if (first == last)
return first;
else
return first + mystery(first + 1, last - 1);
}
What is the output of the following statement?
cout << mystery(6, 10) << endl;
47
What is the purpose of the following code?
current = head;
while (current != NULL)
{
//Process current
current = current->link;
}
Question 48
struct nodeType
{
int info;
nodeType *link;
};
nodeType *head, *p, *q, *newNode;
newNode = new nodeType;
Consider the accompanying code. What is the effect of the following statement?
newNode->info = 50;
Question 49
When building a linked list in the ____ manner, a new node is always inserted at the end of the linked list.
Question 50
Which of the following is a basic operation on singly linked lists?
Question 51
What is the output of the following program segment? (The class unorderedLinkedList is as defined in the book.)
unorderedLinkedList<int> list;
list.insertFirst(6);
list.insertLast(5);
list.insertFirst(4);
list.insertFirst(8);
list.insertLast(10);
list.deleteNode(4);
list.insertFirst(1);
list.print();
Question 52
The ____ deallocates the memory occupied by the nodes of a list when the class object goes out of scope.
Question 53
Consider the following code, which deletes all the nodes in a linked list.
void doublyLinkedList<Type>::destroy()
{
nodeType<Type> *temp; //pointer to delete the node
while (first != NULL)
{
temp = first;
first = first->next;
____
}
last = NULL;
count = 0;
}
Which of the following is the missing statement?
Question 54
Consider the following code:
template <class Type>
int doublyLinkedList<Type>::length() const
{
____
}
The statement that provides the length of the linked list is ____.
Question 55
Which of the following statements appears in the insert function of a doubly linked list?
Question 56
The deleteNode operation (if the item to be deleted is in a doubly linked list) requires the adjustment of ____ pointer(s) in certain nodes.
Flag this Question
Question 572 pts
A(n) ____ is a list of homogenous elements in which the addition and deletion of elements occurs only at one end.
Flag this Question
Question 582 pts
The addition and deletion of elements of the stack occurs only at the ____ of the stack.
Flag this Question
Question 592 pts
The ____ element of the stack is the last element added to the stack.
Flag this Question
Question 602 pts
A stack is a(n) ____ data structure.
Flag this Question
Question 612 pts
You can perform the add operation, called ____, to add an element onto the stack.
Flag this Question
Question 622 pts
A stack can be implemented as either an array or a(n) ____ structure.
Flag this Question
Question 632 pts
If you try to add a new item to a full stack, the resulting condition is called a(n) ____.
Flag this Question
Question 642 pts
Popping an element from an empty stack is called ____.
Flag this Question
Question 652 pts
What is the output of the following code?
stackType<int> stack;
int x, y;
x = 4;
y = 2;
stack.push(6);
stack.push(x);
stack.push(x + 1);
y = stack.top();
stack.pop();
stack.push(x + y);
x = stack.top();
stack.pop();
cout << "x = " << x << endl;
Flag this Question
Question 662 pts
What is the output of the following code?
stackType<int> stack;
int x, y;
x = 5;
y = 3;
stack.push(4);
stack.push(x);
stack.push(x + 1);
y = stack.top();
stack.pop();
stack.push(x + y);
x = stack.top();
stack.pop();
cout << "x = " << x << endl;
cout << "y = " << y << endl;
Flag this Question
Question 672 pts
The expression (a - b) * (c + d) is equivalent to which of the following postfix expressions?
Flag this Question
Question 682 pts
A queue is a data structure in which the elements are ____.
Flag this Question
Question 692 pts
Which of the following is a basic operation performed on a queue?
Flag this Question
Question 702 pts
What is the output of the following code?
queueType<int> queue;
int x, y;
x = 2;
y = 3;
queue.addQueue(x);
queue.addQueue(y);
x = queue.front();
queue.deleteQueue();
queue.addQueue(x + 2);
queue.addQueue(x);
queue.addQueue(y - 3);
y = queue.front();
queue.deleteQueue();
cout << "x = " << x << endl;
cout << "y = " << y << endl;
Flag this Question
Question 712 pts
What is the output of the following code?
queueType<int> queue;
int x, y;
x = 2;
y = 6;
queue.addQueue(x);
queue.addQueue(y);
x = queue.front();
queue.deleteQueue();
queue.addQueue(x + 2);
queue.addQueue(x);
queue.addQueue(y - 3);
while (!queue.isEmptyQueue())
{
cout << queue.front() << " ";
queue.deleteQueue();
}
cout << endl;
Flag this Question
Question 722 pts
The sequential search algorithm uses a(n) ____ variable to track whether the item is found.
Flag this Question
Question 732 pts
A sequential search of an n-element list takes ____ key comparisons if the item is not in the list.
Flag this Question
Question 742 pts
A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list.
Flag this Question
Question 752 pts
Consider the following list:
int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}
When performing a binary search, the target is first compared with ____.
Flag this Question
Question 762 pts
Consider the following list:
int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}
When performing a binary search for 75, after the first comparison, the search is restricted to ____.
Flag this Question
Question 772 pts
The formula to find the index of the middle element of a list is ____.
Flag this Question
Question 782 pts
With the binary search algorithm, ____ key comparison(s) is/are made in the successful case—the last time through the loop.
Flag this Question
Question 792 pts
In a bubble sort for list of length n, the first step is to compare elements ____.
Flag this Question
Question 802 pts
After the second iteration of bubble sort for a list of length n, the last ____ elements are sorted.
Flag this Question
Question 812 pts
In the bubble sort algorithm, the following code accomplishes swapping values in elements at positions index and index + 1.
Flag this Question
Question 822 pts
If n = 1000, to sort the list, bubble sort makes about ____ item assignments.
Flag this Question
Question 832 pts
For a list of length n, insertion sort makes ____ key comparisons, in the worst case.
Flag this Question
Question 842 pts
Which of the following correctly states the quick sort algorithm?
Flag this Question
Question 852 pts
The behavior of quick sort is ____ in the worst case and ____ in the average case.
Flag this Question
Question 862 pts
____ sort requires knowing where the middle element of the list is.
Flag this Question
Question 872 pts
In the diagram of a binary tree, an arrow is called a(n) ____.
Flag this Question
Question 882 pts
A binary tree has a special node called the ____ node.
Flag this Question
Question 892 pts
In a diagram of a binary tree, each node is represented as a(n) ____.
Flag this Question
Question 902 pts
Three lines at the end of an arrow in the diagram of a binary tree indicate that the subtree ____.
Flag this Question
Question 912 pts
Consider that A is a binary tree, C and D are the subtrees of A. Which of the following statements is always true?
Flag this Question
Question 922 pts
Each link in a binary tree node points to a(n) ____ of that node.
Flag this Question
Question 932 pts
Every node in a binary tree has at most ____ children.
Flag this Question
Question 942 pts
A node in a binary tree is called a(n) ____ if it has no left and right children.
Flag this Question
Question 952 pts
In a binary tree, the level of the children of the root node is ____.
Flag this Question
Question 962 pts
The ____ of a node in a binary tree is the number of branches on the path from the root to the node.
Flag this Question
Question 972 pts
The most common operation performed on a binary tree is a(n) ____.
Flag this Question
Question 982 pts
The three traversal algorithms discussed for binary trees are ____, ____, and ____.
Flag this Question
Question 992 pts
The listing of the nodes produced by the postorder traversal of a binary tree is called the ____.
Question 100
The sequence of operations in a postorder traversal is ____.
Statements in Lines 1-6Explanation / Answer
Hello there ,
Please find anwers below.
Let me know if you want any explaination.
Thanks.
Q-40:Statements in Lines 5 and 6
Q-41:Statements in Lines 3-6
Q-42:Statements in Lines 7-11
Q-43:720
Q-44:10
Q-45:4 3 2 1
Q-46:21
Q-47:Traversal of a linked list
Q-48:Stores 50 in the info field of the newNode
Q-49:forward
Q-50:Retrieve the data of an arbitrary node.
Q-51:1 8 6 5 10
Q-52:destructor
Q-53:delete temp;
Q-54:return count;
Q-55:count++;
Q-56:two
Q-57:stack
Q-58:top
Q-59:tail
Q-60:LIFO
Q-61:push
Q-62:linked
Q-63:overflow
Q-64:underflow
Q-65:x = 9
Q-66:x = 11
y = 6
Q-67:a b - c d + *
Q-68:added to the rear and deleted from the front
Q-69:isEmptyQueue
Q-70: x = 2
y = 3
Q-71:6 4 2 3
Q-72:bool
Q-73:n
Q-74:n/2
Q-75:39
Q-76:list[6]...list[11]
Q-77:(first + last) / 2
Q-78:one
Q-79:list[0] and list[1]
Q-80:two
Q-81:
temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
Q-82:250,000
Q-83:n(n - 1)/2
Q-84:
if (the list size is greater than 1)
{
a. Partition the list into two sublists, say lowerSublist and
upperSublist.
b. Quick sort lowerSublist.
c. Quick sort upperSublist.
d. Combine the sorted lowerSublist and sorted upperSublist.
}
Q-85:O(n2), O(nlog2n)
Q-86:Merge
Q-87:directed branch
Q-88:root /superparent not sure. mostly root.
Q-89:circle
Q-90:is empty
Q-91:C and D are binary trees.
Q-92:child
Q-93:two
Q-94:leaf
Q-95:1
Q-96:level
Q-97:traversal
Q-98:inorder, preorder, postorder
Q-99:postorder table
Q-100:traverse left; traverse right; visit --> Means Visit the root not at last.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.