Hi Chegg experts, i am currently am stuck on 11-34 and would like some help if p
ID: 3579434 • Letter: H
Question
Hi Chegg experts, i am currently am stuck on 11-34 and would like some help if possible.
Question 11
The std::binary_search function will test if a value exists in sorted sequence. It returns true if any element in the range [first,last] is equivalent to that value, and false otherwise.
True
False
Question 12
I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer.
which of these pointers will change during a deletion operation?
Only front_ptr changes.
Neither changes
Both change.
Only rear_ptr changes.
Question 13
Consider this binary search tree:
Suppose we remove the root, replacing it with something from the left subtree. What will be the new root?
1
2
4
5
Question 14
In an open-address hash table there is a difference between those spots which have never been used and those spots which have previously been used but no longer contain an item. Which function has a better implementation because of this difference?
size
insert
is_present
remove
Two or more of the above functions
Question 15
The _______________ may be selected in the quicksort algorithm for comparison purposes.
last element
middle element
random element
Any of the above
Question 16
You have a stack of 10 items and you wish to do a pop operation. Which element would be removed from the stack if it were implemented with an array?
index 0
index 10
index 9
index 1
Question 17
Which of the following statements regarding binary trees are true?
Every node has at most two children.
Every non-empty tree has exactly one root node.
Every non-root node has exactly one parent.
Every binary tree has at least one node.
Question 18
Which of the following statements is true?
A graph can drawn on paper in only one way.
A graph must have at least one vertex.
A graph must have at least one edge.
Graph vertices may be linked in any manner.
Question 19
Consider the following function. The line numbers are indicated on the left side for reference only and are not part of the code.
1 float p( float x, int n )
2 {
3 if ( n == 0 )
4 return 1;
5 else
6 return x * p( x, n – 1 );
7 }
The base case is shown on:
lines 5-6
lines 3-4
lines 3-6
line 1
Question 20
Which of the following problems would be best solved with a breadth-first search?
You need to find a valid path from one node to the next through a maze graph.
You need to find the closest node to node x that stores a value greater than 10.
You need to discover if there is a cycle in a graph.
Question 21
When an element is retrieved in a chained hash table:
an element is hashed to a position in the array, then a sequential search of the linked list at that position is performed.
each linked list in the table is searched, one by one, until the element is found
a sequential search is made from the hashed position through the array until the element is found
an element is hashed to a position in the array and if the element is not found in that location, the
search returns NULL.
Question 22
Consider the following function:
void test_a(int n)
{
cout << n << " ";
if (n>0)
test_a(n-2);
}
Which function call will result in the output: 4 2 0
test_a(0);
test_a(2);
test_a(4);
Question 23
Consider the following graph:
0, 1, 4, 2, 3, 5, 6
0, 1, 4, 3, 6, 5
0, 1, 2, 3, 4, 5, 6
0, 1, 3, 5, 6, 4
Question 24
What is this an example of?
priority matrix
linked list
adjacency list
adjacency matrix
Question 25
int mysteryFunction(vector vec, int low, int high, int key)
{
if ( low > high )
{
return -1;
}
int mid = (low + high)/2;
if ( vec[mid] == key )
return mid;
else if ( vec[mid] > key )
return mysteryFunction(vec, low, mid-1, key);
else
return mysteryFunction(vec, mid+1, high, key);
}
What is this an example of?
in-order traversal of a binary search tree
circular array pop function
binary search function
binary search tree insert function
Question 26
Consider the following function. The line numbers are indicated on the left side for reference only and are not part of the code.
1 float p( float x, int n )
2 {
3 if ( n == 0 )
4 return 1;
5 else
6 return x * p( x, n – 1 );
7 }
The recursive case is shown on:
lines 3-4
lines 5-6
line 1
lines 3-6
Question 27
The _______ case is the case that stops recursion.
condition
blocking
base
recursive
Question 28
A(n) _____________ is a node in a graph.
pointer
vertical
vertex
edge
Question 29
Consider the following recursive function:
void quiz(int i)
{
if (i > 1)
{
quiz(i / 2);
quiz(i / 2);
}
cout << "*";
}
How many asterisks will print with this call:
quiz(0);
0
1
Question 30
Here is a small binary tree:
What is the order of nodes visited using a pre-order traversal?
1 2 3 14 7 10 11 40 30
1 3 2 7 10 40 30 11 14
14 2 1 3 11 10 7 30 40
1 2 3 7 10 11 14 30 40
Question 31
A queue should not be built with an array. A circular array would be a better implementation choice for this data structure.
True
False
Question 32
Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step?
The array elements form a tree.
Elements in each half of the array are sorted among themselves.
Elements in the first half of the array are less than or equal to elements in the second half of the array.
Question 33
Consider the following graph:
In what order are the vertices visited for a depth-first search that starts at v0?
0, 4, 1, 6
0, 1, 3, 5, 6, 4, 2
0, 1, 3, 6, 5, 4
0, 2, 1, 3, 5, 6
Question 34
What additional requirement is placed on an array, so that binary search may be used to locate an entry?
The array's size must be a power of two.
The array elements must form a tree.
The array must have at least 2 entries.
The array must be sorted.
Only front_ptr changes.
Neither changes
Both change.
Only rear_ptr changes.
14 216 4Explanation / Answer
Ans 11: True.
Ans 12: Only front_ptr changes : as only we have to point to a null after deletion of a node.
Ans 13: 5. To make a binary tree all the node should be greater than left child and smaller than right child. Tree will look like:
5
/
2 16
/
1 4
Ans 14:
Ans 15: random element. : If you choose the first last, it may be the largest item in a sorted list and give worst-case behavior. You can choose a random item, or median-of-three (front, middle, end)
Ans 16: index 9: In the pop operation last element is removed from the stack and as array follow indexes starting from 0, then the 10th element would be the element at index 9.
Ans 17: Every node has at most two children.
Ans 18: A graph must have at least one vertex.
Ans 19: lines 3-4: Base case is something which prevents the recursion from going into infinite recursive calls. here line 3-4 signifies the same.
Ans 20:
Ans 21: an element is hashed to a position in the array and if the element is not found in that location, the search returns NULL.
Ans 22: test_a(4);
Ans 23: (Incomplete Ques)
Ans 24: adjacency matrix
Ans 25: binary search function: it seraches for the element in the middle and than in left or right sub part.
Ans 26: lines 5-6. Recursive case is something which recursively calls the same function. here line 5-6 signifies the same
Ans 27: The base case is the case that stops recursion
Ans 28: A(n) vertex is a node in a graph
Ans 29: 1 as the cout is out side of the condition
Ans 30: 14 2 1 3 11 10 7 30 40 . As pre order traversal is node->left child ->right child
Ans 31: True. After deletion of the element the unused memory can be used.
Ans 32: Elements in each half of the array are sorted among themselves.
Ans 33: 0, 1, 3, 6, 5, 4
Ans 34: The array must be sorted.