Professional Documents
Culture Documents
Ebook Data Abstraction and Problem Solving With C Walls and Mirrors 7Th Edition Carrano Test Bank Full Chapter PDF
Ebook Data Abstraction and Problem Solving With C Walls and Mirrors 7Th Edition Carrano Test Bank Full Chapter PDF
Ebook Data Abstraction and Problem Solving With C Walls and Mirrors 7Th Edition Carrano Test Bank Full Chapter PDF
2. If the array
6, 2, 7, 13, 5, 4
is added to a stack, in the order given, which number will be the first number to be removed from the stack?
a. 6
b. 2
c. 5
d. 4
Answer: d.
3. The item that is removed first from a stack is called the ______ of the stack.
a. front
b. top
c. base
d. prime
Answer: b.
4. If the array
6, 21, 35, 3, 6, 2, 13
is added to a stack, in the order given, which of the following is the top of the stack?
a. 2
b. 6
c. 3
d. 13
e. 35
Answer: d.
6. The ______ operation of the ADT stack adds an item to the top of the stack.
a. isEmpty
b. push
c. pop
d. peek
Answer: b.
7. The ______ operation of the ADT stack retrieves and then removes the top of the stack.
a. isEmpty
b. push
c. pop
d. peek
Answer: c.
8. The ______ operation of the ADT stack retrieves the top of the stack, but does not change the stack.
a. isEmpty
b. push
c. pop
d. peek
Answer: d.
11. If a stack is used by an algorithm to check for balanced braces, which of the following is true of a balanced
braces string once the end of the string is reached?
a. the stack is empty
b. the stack has one “{”
c. the stack has one “}”
d. the stack has one “{” and one “}”
Answer: a.
13. Which of the following is NOT true about converting infix expressions to postfix expressions?
a. the operands always stay in the same order with respect to one another
b. the operators always stay in the same order with respect to one another
c. an operator will move only “to the right” with respect to the operands
d. all parentheses are removed
Answer: b.
14. Which of the following is the postfix form of the infix expression: (a + b) * c / d
a. a b + c * d /
b. a b * c / d +
c. a + b * c / d
d. a b + c d * /
Answer: a.
16. In a graph that represents the flight map for the HPAir problem, if a flight exists from city C1 to city C2, C2 is
said to be ______ C1.
a. adjacent to
b. similar to
c. related to
d. bordering
Answer: a.
17. In a graph that represents the flight map for the HPAir problem, if a flight exists from city C1 to city C2, the
path from C1 to C2 is called a _______.
a. relation
b. neighborhood
c. directed path
d. connecting path
Answer: c.
18. ______ are considered when choosing the next city to visit in a stack-based nonrecursive solution to the HPAir
problem.
a. All cities
b. All unvisited cities adjacent to the destination city
c. All cities adjacent to the city on the top of the stack
d. All unvisited cities adjacent to the city on the top of the stack
Answer: d.
19. An algorithm that uses a stack to implement a nonrecursive solution to the HPAir problem reaches the
conclusion that there is no path from an origin city to a destination city only after ______.
a. the algorithm has backtracked to the origin
b. the algorithm has backtracked to the origin and there remain no unvisited cities to fly to from the origin
c. the algorithm has reached a city and there remain no unvisited cities to fly to from that city
d. the algorithm has reached the destination and there remain no unvisited cities to fly to from the
destination
Answer: b.
21. When a recursive call to a function occurs, the compiler’s implementation must remember all of the following
information EXCEPT ______.
a. values of parameters
b. values of local variables
22. The ______ operation of the ADT stack retrieves and then removes the top of the stack.
a. isEmpty
b. push
c. pop
d. peek
Answer: C
23. A stack is initially empty, then the following commands are performed:
push 5, push 7, pop, push 10, push 5, pop
which of the following is the correct stack after those commands (assume the top of the stack is on the
left)?
a. 5 10 7 5
b. 5 10
c. 7 5
d. 10 5
Answer: D
26. Consider the peek() operation for the ADT Stack as described by the author. What is its output?
a. true or false
a. there is no output
b. the object that is at the top of the stack
c. the number of items left on the stack
Answer: C.
29. Consider the push(newEntry) operation of the ADT Stack. What is the output of the operation?
a. true or false
b. there is no output
c. the object that is at the top of the stack
d. the number of items left on the stack
Answer: A.
31. Which of the following is not a listed outcome of the exhaustive search strategy described in the text?
a. You go around in circles forever
b. It is impossible to reach a city because no flights go there
c. You eventually reach the destination city
True/False Questions
1. If 5 items are added to a stack, the first item to be removed from the stack is the first item that was added to the
stack.
Answer: False.
4. A program can use the operations of the ADT stack without knowing how the operations are implemented.
Answer: True.
5. If the characters in a string are added to a stack one at a time, characters removed from the stack will occur in
the order in which they appear in the original string.
Answer: False.
6. When infix expressions are converted to postfix expressions, the operands always stay in the same order with
respect to one another.
Answer: True.
7. According to the author, the LIFO property of stacks seems inherently unfair.
Answer: True
2. What is the difference between the stack pop and peek operations?
Answer: The pop operation removes the top of the stack. The peek operation retrieves the top of the stack, but
does not remove it.
3. In a program that uses a stack to check for balanced braces in an string, what condition indicates that the braces
are balanced when the end of the string is reached?
Answer: The braces in a string are balanced if the stack is empty when the end of the string is reached.
4. What restriction does the array-based implementation of a stack place on the push operation?
Answer: The array-based implementation of a stack prevents the push operation from adding an item to the stack
when the array is full.
5. What are the three facts about converting from infix expressions to postfix expressions?
Answer: The three facts are:
• The operands always stay in the same order with respect to one another.
• An operator will move only “to the right” with respect to the operands.
• All parentheses are removed.
6. What factors determine the placement of operators when an infix expression is converted to a postfix
expression?
Answer: The factors that determine the placement of operators are parentheses, operator precedence, and left-to-
right association.
9. If a stack is used in a nonrecursive solution to the HPAir problem, when is it necessary to backtrack from a city?
Answer: It is necessary to backtrack from a city whenever there are no more unvisited cities to fly to from that city.
16. Following are the steps in the process to convert from infix to postfix form. Put them in the correct order by
writing the number of the step in the blank to the left.
_____ When you encounter a “)”, pop operators off the stack and append them to the end of postfixExp until you
encounter the matching “(“
_____ When you reach the end of the string, pop the remaining contents off the stack and append them to the end of
postfixExp.
_____ When you encounter an operator, if the stack is empty, push the operator onto the stack. However, if the
stack is not empty, pop operators of greator or equal precedence from the stack and append them to postfixExp,
stopping when you encounter a “(“ or an operator of lower precedence or when the stack becomes empty. You then
push the current operator in the expression onto the stack.
Answer: 4, 2, 5, 1, 3