Deck 7: Stacks
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/44
Play
Full screen (f)
Deck 7: Stacks
1
You can use stacks to convert recursive algorithms into nonrecursive algorithms, especially recursive algorithms that are not tail recursive.
True
2
A stack is a list of homogenous elements in which the addition and deletion of elements occurs only at one end.
True
3
The computer uses a stack to implement function calls.
True
4
The item added to the stack last will be the item removed last.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
5
The operation push removes the bottom element from the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
The operation pop returns the top element of the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
7
The operation top removes the top element of the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
8
An element can be removed from the stack only if there is something in the stack, and an element can be added to the stack only if there is room.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
To successfully implement a stack, we need at least seven operations.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
10
Functions such as push and pop that are required to implement a stack are not inherently available to C++ programmers.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
11
An array is a random access data structure; a stack is not.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
12
Adding, or pushing, an element onto the stack is a two-step process.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
13
The function copyStack makes a copy of a stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
14
The time-complexity of the copyStack function is O(1).
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
15
In a linked list implementation of a stack, only a fixed number of elements can be pushed onto the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
16
If we compare the push function of the stack with the insertFirst function for general lists, we see that the algorithms to implement these operations are similar.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
17
The equivalent postfix expression for the infix expression a + b is + a b.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
18
The postfix expression 6 3 + 2 * = evaluates to 18.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
19
The postfix expression 2 3 + 1 * = evaluates to 8.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
20
In the function evaluateOpr, two operands are needed to evaluate an operation and operands are saved in the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
Stacks can be used to print a list backwards without using recursion.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
The stack container class provides the operation size to return the actual number of elements in the stack.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
A data structure in which the elements are added and removed from one end only is known as a ____.
A) queue
B) deque
C) hash table
D) stack
A) queue
B) deque
C) hash table
D) stack
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
24
We can perform the operation ____ to retrieve the top element of the stack.
A) head
B) first
C) top
D) peek
A) head
B) first
C) top
D) peek
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
25
The operation ____ is used to remove the top element from the stack.
A) pop
B) push
C) peek
D) isEmpty
A) pop
B) push
C) peek
D) isEmpty
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
The ____ operation checks whether the stack is full.
A) isEmpty
B) peek
C) pop
D) isFullStack
A) isEmpty
B) peek
C) pop
D) isFullStack
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
27
The ____ operation checks whether the stack is empty.
A) isFullStack
B) isEmptyStack
C) peek
D) pop
A) isFullStack
B) isEmptyStack
C) peek
D) pop
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
28
Because all the elements of a stack are of the same type, you can use a(n) ____ to implement a stack.
A) struct
B) array
C) record
D) class
A) struct
B) array
C) record
D) class
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
To remove, or pop, an element from the stack ____.
A) decrement stackTop by 1
B) increment stackTop by 1
C) invert stackTop
D) do nothing
A) decrement stackTop by 1
B) increment stackTop by 1
C) invert stackTop
D) do nothing
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
The stack is empty if stackTop is ____.
A) 0
B) NULL
C) 1
D) MAX
A) 0
B) NULL
C) 1
D) MAX
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
The operation ____ reinitializes the stack to an empty state.
A) alloc
B) init
C) initializeStack
D) new
A) alloc
B) init
C) initializeStack
D) new
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
The function ____ makes an identical copy of a stack.
A) readStack
B) buildStack
C) clearStack
D) copyStack
A) readStack
B) buildStack
C) clearStack
D) copyStack
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
A client's program can include a header file via the ____ statement.
A) pragma
B) include
C) using
D) matching
A) pragma
B) include
C) using
D) matching
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
The class linkedListType is a(n) ____ class and therefore does not implement all the operations.
A) derived
B) partial
C) abstract
D) generic
A) derived
B) partial
C) abstract
D) generic
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
35
In ____ notation, the operator is written between the operands.
A) infix
B) postfix
C) prefix
D) nofix
A) infix
B) postfix
C) prefix
D) nofix
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
36
In the late 1950s, the Australian philosopher and early computer scientist Charles L. Hamblin proposed a scheme in which the operators follow the operands (postfix operators), resulting in the ____ notation.
A) Inverse Polish
B) Inverted Roman
C) Reverse Polish
D) Reverse Arabic
A) Inverse Polish
B) Inverted Roman
C) Reverse Polish
D) Reverse Arabic
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
37
If the postfix expression is error free, the function ____ outputs the result.
A) printResult
B) pop
C) push
D) readResult
A) printResult
B) pop
C) push
D) readResult
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
38
The function ____, if possible, evaluates the expression and leaves the result in the stack.
A) printResult
B) clearStack
C) readExpression
D) evaluateExpression
A) printResult
B) clearStack
C) readExpression
D) evaluateExpression
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
The function evaluateExpression evaluates each ____ expression.
A) prefix
B) postfix
C) previsit
D) inverted
A) prefix
B) postfix
C) previsit
D) inverted
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
40
The function ____ (if possible) evaluates an expression.
A) evaluateOpr
B) evaluateOperand
C) evaluateExpression
D) evaluateAll
A) evaluateOpr
B) evaluateOperand
C) evaluateExpression
D) evaluateAll
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
41
The function ____ is called whenever an error is discovered in the expression.
A) clearExp
B) discardExp
C) newExp
D) evaluateExp
A) clearExp
B) discardExp
C) newExp
D) evaluateExp
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
42
The function discardExp reads and writes the input data only until the input is '____'.
A) ;
B) *
C) +
D) =
A) ;
B) *
C) +
D) =
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
43
If the postfix expression contains no errors, the function ____ prints the result.
A) printResult
B) evaluateExpression
C) clearExp
D) evaluateOpr
A) printResult
B) evaluateExpression
C) clearExp
D) evaluateOpr
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
The ____ can be used to determine whether two stacks are identical.
A) rational operator
B) logical operator
C) relational operator
D) arithmetic operator
A) rational operator
B) logical operator
C) relational operator
D) arithmetic operator
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck