Full Test Bank Chapter 5 - Stacks - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.

Full Test Bank Chapter 5 - Stacks

Chapter 5 - Stacks

True/False (10)

  1. The first item added to a stack is the first one removed.
  2. A stack restricts access to its entries.
  3. All entries in the stack ADT must have the same data type.
  4. Infix expressions are easier to evaluate than postfix expressions.
  5. Parentheses override the rule of operator precedence.
  6. You can only pop from the top of the stack but you can peek at any entry on the stack.
  7. The bottom item in a stack was the last item added.
  8. You cannot reach the bottom item in a stack without popping all of the other items off first.
  9. Pull is an alias for the pop method.
  10. In the program stack, the second record on the stack belongs to the method that called the current method.

Short Answer (5)

  1. Draw the resultant stack after the following operations. Label the top entry of your stack.
    push(X), push(Q), push (Y), peek(), pop(), push(T), peek()
  2. Draw the resultant stack after the following operations. Label the top entry of your stack.
    push(F), pop(), push(G), push(K), push(E), pop().
  3. Convert the following infix expression to a postfix expression.
    w (x + y) / z
  4. Convert the following infix expression to a postfix expression.
    (a + b) (c – d) / ((e – f) (g + h))
  5. Using the evaluatePostfix algorithm, evaluate the following postfix expression.
    a b c + d -
    Assume that a = 10 , b = 2, c = 5, d = 3 .

Multiple Choice (30) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.

  1. When you add an item to a stack, you place it
    1. on the top
    2. on the bottom
    3. in the middle
    4. it doesn’t matter where
  2. When you remove an item from a stack, you remove it from
    1. the top
    2. the bottom
    3. the middle
    4. wherever the client specifies
  3. Stacks exhibit which type of behavior?
    1. last-in, first out
    2. first-in, last out
    3. first-in, first out
    4. last-in, last out
  4. The operation to add an entry to a stack is called a(n)
    1. push
    2. add
    3. put
    4. peek
  5. The operation to retrieve the top entry of a stack without removing it is called a(n)
    1. peek
    2. pop
    3. look
    4. top
  6. The operation to return a stack’s top entry is called a(n)
    1. pop
    2. get
    3. top
    4. peek
  7. The operation to remove all entries from a stack is called a(n)
    1. clear
    2. remove
    3. removeAll
    4. empty
  8. A reasonable action when attempting to remove an item from an empty stack is
    1. assume a precondition that the stack is not empty has been met
    2. throw an exception
    3. return null
    4. all of the above
  9. The pop and peek methods throw a(n) ________ exception when the stack is empty.
    1. runtime
    2. checked
    3. compile time
    4. stackEmpty
  10. The precedence of an operator in a postfix expression
    1. is implied by the order in which the operators and operands occur
    2. is always left to right
    3. is always right to left
    4. depends on the compiler implementation
  11. Polish notation is another term for a(n)
    1. prefix expression
    2. postfix expression
    3. infix expression
    4. algebraic expression
  12. Reverse polish notation is another term for a(n)
    1. postfix expression
    2. prefix expression
    3. infix expression
    4. algebraic expression
  13. An expression that has correctly paired delimiters is called a(n)
    1. balanced expression
    2. Reverse Polish expression
    3. infix expression
    4. algebraic expression
  14. Given the following infix expression, which one of the following is the corresponding postfix expression? a + r ^ 2 – 5
    1. a r 2 ^ + 5 -
    2. a r + ^ 5 –
    3. a r 2 5 + ^ -
    4. none of the above
  15. Given the following infix expression, which one of the following is the corresponding postfix expression? w + x y / z
    1. w x y z / +
    2. w x + y z /
    3. w x y q + /
    4. none of the above
  16. Given the following infix expression, which one of the following is the corresponding postfix expression? (a + b) (c – d) / (e + f)
    1. a b + c d - e f + /
    2. a b c d e f + - / +
    3. a b + c d – e f + /
    4. none of the above
  17. Using the evaluatePostfix algorithm, evaluate the following postfix expression.
    7 2 + 4
    1. 36
    2. 13
    3. 15
    4. 18
  18. Using the evaluatePostfix algorithm, evaluate the following postfix expression.
    a b + c d - 
    Assume that a = 5, b = 7, c = 6, and d = 2.
    1. 48
    2. 39
    3. 55
    4. none of the above
  19. Using the evaluatePostfix algorithm, evaluate the following postfix expression.
    w x + y  z /
    Assume that w = 3 , x = 4, y = 2, z = 7.
    1. 2
    2. 28
    3. 18
    4. 21
  20. During program execution, the _____ references the current instruction.
    1. program counter
    2. stack
    3. frame
    4. activation record
  21. The _____ shows a method’s state during execution.
    1. activation record
    2. stack
    3. program counter
    4. program stack
  22. At the time a method is called during program execution, the activation record is pushed onto the
    1. program stack
    2. execution stack
    3. frame
    4. none of the above
  23. Ordinary algebraic expressions are also known as
    1. infix expressions
    2. postfix expressions
    3. prefix expressions
    4. all of the above
  24. _____ is an alias for the name of the pop method.
    1. pull
    2. remove
    3. delete
    4. all of the above
  25. _____ is an alias for the push method.
    1. insert
    2. pull
    3. delete
    4. all of the above
  26. _____ is an alias for the peek method.
    1. getTop
    2. pull
    3. look
    4. all of the above
  27. The activation record contains
    1. the method’s arguments
    2. local variables
    3. a copy of the program counter
    4. all of the above
  28. In the program stack, the record at the top of the stack belongs to the method
    1. that is currently executing
    2. that is scheduled to execute next
    3. that called the method that is currently executing
    4. none of the above
  29. To convert an infix expression to a postfix expression
    1. scan the infix expression left to right
    2. scan the infix expression right to left
    3. search for all of the operators first
    4. search for all of the operands first
  30. What is the entry returned by the peek method after the following stack operations?
    push(A), push(R), pop(), push(D), pop(), push(L), pop(), push(J), push(S), pop(), pop()
    1. A
    2. S
    3. L
    4. D

Document Information

Document Type:
DOCX
Chapter Number:
5
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 5 - Stacks
Author:
Frank M. Carrano

Connected Book

Data Structures with Java 5e Complete Test Bank

By Frank M. Carrano

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party