Entries in a stack are \"ordered\". What is the meaning of this statement? A. A
ID: 3685497 • Letter: E
Question
Entries in a stack are "ordered". What is the meaning of this statement?
A. A collection of stacks can be sorted.
B. Stack entries may be compared with the '<' operation.
C. The entries must be stored in a linked list.
D. There is a first entry, a second entry, and so on.
The operation for adding an entry to a stack is traditionally called:
A. add
B. append
C. insert
D. push
The operation for removing an entry from a stack is traditionally called:
A. delete
B. peek
C. pop
D. remove
Which of the following stack operations could result in stack underflow?
A. is_empty
B. pop
C. push
D. Two or more of the above answers
Which of the following applications may use a stack?
A. A parentheses balancing program.
B. Keeping track of local variables at run time.
C. Syntax analyzer for a compiler.
D. All of the above.
Consider the following pseudocode:
declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
write the stack's top character to the screen
pop a character off the stack
}
What is written to the screen for the input "carpets"?
A. serc
B. carpets
C. steprac
D. ccaarrppeettss
Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced:
declare a character stack
while ( more input is available)
{
read a character
if ( the character is a '(' )
push it on the stack
else if ( the character is a ')' and the stack is not empty )
pop a character off the stack
else
print "unbalanced" and exit
}
print "balanced"
Which of these unbalanced sequences does the above code think is balanced?
A. ((())
B. ())(()
C. (()()))
D. (()))()
Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
A. 1
B. 2
C. 3
D. 4
E. 5 or more
Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). What is the maximum number of parentheses that will ever appear on the stack AT ONE TIME during the computation?
A. 1
B. 2
C. 3
D. 4
E. 5 or more
Suppose we have an array implementation of the stack class, with ten items in the stack stored at data[0] through data[9]. The CAPACITY is 42. Where does the push member function place the new entry in the array?
A. data[0]
B. data[1]
C. data[9]
D. data[10]
Consider the implementation of the stack using a partially-filled array. What goes wrong if we try to store the top of the stack at location [0] and the bottom of the stack at the last used position of the array?
A. Both peek and pop would require linear time.
B. Both push and pop would require linear time.
C. The stack could not be used to check balanced parentheses.
D. The stack could not be used to evaluate postfix expressions.
In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list?
A. At the head
B. At the tail
C. After all other entries that are greater than the new entry.
D. After all other entries that are smaller than the new entry.
In the array version of the stack class (with a fixed-sized array), which operations require linear time for their worst-case behavior?
A. is_empty
B. peek
C. pop
D. push
E. None of these operations require linear time.
In the linked-list version of the stack class, which operations require linear time for their worst-case behavior?
A. is_empty
B. peek
C. pop
D. push
E. None of these operations require linear time.
What is the value of the postfix expression 6 3 2 4 + - *:
A. Something between -15 and -100
B. Something between -5 and -15
C. Something between 5 and -5
D. Something between 5 and 15
E. Something between 15 and 100
Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?
A. 1
B. 2
C. 3
D. 4
E. 5
Explanation / Answer
(1) D
There is a first entry, a second entry, and so on.
(2) D
push
(3) C
pop
(4) B
pop
(5) D
All of the above.
(6) C
steprac
(7) A
((())
(8) C
3
(9) C
3
(10) D
data[10]
(11) B
Both push and pop would require linear time.
(12) A
At the head
(13) E
None of these operations require linear time.
(14) E
None of these operations require linear time.
(15) A
Something between -15 and -100
(16) C
3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.