CS 235 Midterm 2
The reallocate function for class Queue
Typically does not copy elements to identical index positions
The sequential representation of ADT deque ______.
Is not practical (too many O(n) operations)
If you need to provide a stack, a queue, a deque, an input-restricted deque, and an output restricted deque, _____.
Each of the others should "have" a deque as a data member
With the recursive linear search algorithm given in the book, how many items in the list need to be checked if the item is not in the list?
Every item in the list
True or false: The maze solving algorithm will not function properly if there is more than one possible path through the maze.
False
Which of the following most accurately describes the behavior of a queue?
First in, first out (FIFO).
Suppose you have a binary search tree. Which kind of traversal would print the contents in increasing order?
Inorder.
Which of the following is true about Binary Trees?
None of the above.
The inorder traversal sequence of a binary tree is A B C. The root is _______.
Not a unique binary tree.
To convert from infix (without parentheses) to postfix, use a stack of
Operators and operands
Infix-to-postfix uses a stack of ____, postfix evaluation a stack of _____, and postfix-to-infix a stack of _____.
Operators, operands, operators
__________ traversal doesn't exist.
Outorder
When a queue is represented using a single-linked list, the links should
Point from the front towards the rear.
In tail recursion, ____________.
The recursive call is the last executable statement in the function
When comparing recursion and iteration, all of the following are true EXCEPT
There is always a recursive solution to a problem that is solvable by iteration.
What is the matching infix expression to the following postfix expression: 8 9 + 4 * -
There is none, it is an invalid expression
Traversal algorithms are fairly simple. What attribute of trees makes that so?
Trees are recursive data structures.
Unlink a vector, a set does not support the subscript operator (e.g. mySet[0]). If someone still wanted to iterate through each item in a set, they should __________.
Use an iterator
Writing "towers of Hanoi" code for 64 disks is
Virtually the same as for 3 disks.
For the contiguous representation fo ADT deque, when an end of the deque is reached, __.
Wrap around to the other end
Should a new Huffman tree be built for each file you create? Why or why not?
Yes, because different files may contain symbols with different frequencies.
Searching for an item in a linked list is O(___). Searching in a binary search tree is O(___).
n, log(n)
What is recursion?
problem-solving approach that causes functions to call themselves with different arguments
A heap
requires every subtree to be a heap.
The performance of a self-balancing binary search tree
is of order of log(number of elements in the tree).
With the recursive binary search algorithm given in the book, how many items in the list need to be checked if the item is not in the list?
log(n), where n is the number of items in the list
What kind of mapping is used in a map from keys to values?
many-to-one
What makes backtracking different from random trial and error?
Backtracking is a systematic approach that will not try the same path more than once
Compared with a linked list, a binary tree ________.
has nodes with two child nodes instead of one next node
Which of the following stack configurations are correct in terms of precedence? Let the far left be the bottom of the stack, and the right be the top.
+ %
A Huffman tree for an alphabet of 15 distinct characters has _____ leaf nodes.
15
Set A has 10 members and set B has 14 members. The intersection of the two sets has 5 members. How many members are in the union of the two sets?
19
How many base cases are in the maze solving algorithm?
3
Suppose set A contains the strings "apples", "oranges", and "pineapples". Then the strings "apples" and "grapes" are inserted. How many items are in A after these two insertions?
4
If the number 5 is deleted from the above tree, what would be the level-order traversal order? 5 / \ 1 10 / \ / 0 4 7 \ 9
4 1 10 0 7 9
If the number 3 is inserted into the following binary tree, what would be the pre-order traversal order? 5 / \ 1 10 / \ / 0 4 7 \ 9
5 1 0 4 3 10 7 9
What is the matching postfix expression to the following infix expression: 7 + (2 * 3) / 9?
7 2 3 * 9 / +
What is the result of the postfix expression: 4 7 * 20 - ?
8
If a particular binary tree is full and has 100 leaf nodes, how many internal nodes does it have?
99
In a binary search tree, all of the following are synonyms except _______.
a node's parent
The contiguous implementation of ADT deque is ____.
More like the contiguous implementation of ADT queue
What things are necessary in a recursive function?
A base case and a recursive call
Pick the correct statement.
A binary tree is a tree.
Which of the following would not be a good application for a binary tree?
A family tree.
Pick the best statement
A full binary tree need not be complete and a complete binary tree need not be full.
Suppose you want to make a priority queue where smaller numbers have the highest priority. Which of the following would be the best underlying data structure?
A min-heap
What happens when a recursive function calls itself?
A new instance of the function is called
Pick the best statement:
A queue differs from a stack in only one operation.
Pick the best relationship for queues and deques
A queue has-a deque
A Priority Queue is an extension of a queue with the following properties:
An element with high priority is dequeued before an element with low priority.
Suppose the following operations are performed on an empty queue: Push A, push B, push C, push E, pop, and push D. What would be the next value to be accessed from this queue?
B
Which of the following functions is the least efficient when implemented recursively?
Calculating the nth Fibonacci number.
When the array representation of ADT queue becomes full, ____.
Call a reallocate function specialized for the array-based queue
The contiguous Implementation on an ADT queue______.
Calls for a circular array
Which representation of a queue has the most favorable Big Ohs for the (as discussed in class)?
Circular array
Generally speaking, an ADT can be represented using a(n)_______.
Contiguous structure or a linked structure
Recursion typically is justified when it reduces ________.
Design and coding time
What is the downside of recursion?
The function may result in a run-time error when there is no more memory available.
A map consists of a set of keys, each with one or more values. Which typically is/are unique?
The keys
When a recursive function returns after three iterations because it hits a base case, where does it return to?
The previous iteration, right after it called the next iteration
A Priority Queue
is a container adapter that uses a specific underlying container, e.g. vector or deque.
A binary tree's conceptual counterpart of a double-linked list ______.
consists of links to children and parents: three links per node
A Huffman tree, like the one depicted on page 450 of the course text, is a _________.
full binary tree
With a heap,
insertion traces a path from a leaf to the root.
If the size of a heap is n, the performance
is O(log n) for insertion.