Questions on Stack
1. A Stack is a _______ DS
a. LIFO
b. FIFO
c. LILO
d. FILO
Ans. : a, d : A Stack is a Data Structure behaving Last in And First out or First In and Last Out.. They are one and the Same...
2. In a Stack the elements are entered from ________.
a. End
b. Top
c. Random
d. Bottom
Ans. : b. , The elements are entered and deleted from the stack from the top only.
3. The basic Operations on the Stack are
a. Push & Pop
b. Insert & Delete
c. Enter & Remove
d. Add & Subtract
Ans. : a, Push and Pop are the terminologies used in use of the stack.
4. Condition Checked before Pushing
a. Stack Overflow
b. Stack Underflow
c. No Condition to be checked
d. Both the conditions
Ans . : a. : Check Stack Overflow before pushing.
5. Condition Checked before Poping
a. Stack Overflow
b. Stack Underflow
c. No Condition to be checked
d. Both the conditions
Ans . : b. : Check Stack Underflow before poping.
6. The total nos of pair of brackets in an expression is called _______
a. Open Scopes
b. To be closed Scopes
c. Nesting Depth
d. Depth Sequence
Ans. : c Nesting Depth is the total nos. of open brackets in an expression at any time to be closed.
7. Stacks are implemented using _________.
a. Arrays
b. Linked Lists
c. Static Variables
d. Register Variables
Ans. : a, b, Stack are implemented using arrays as well as linked list.
8. Recursive function call uses _________ Data Structure.
a. Stacks
b. Queues
c. Linked Lists
d. Trees
Ans. : a, Recursive Function Calls uses Stacks.
9. Entries in a stack are "ordered". What is the meaning of this statement?
- A collection of stacks can be sorted.
- Stack entries may be compared with the '<' operation.
- The entries must be stored in a linked list.
- There is a first entry, a second entry, and so on.
Ans. : b, That is the reason it is used by infix and prefix expressions.
10. The operation for adding an entry to a stack is traditionally called:
a. add
b. append
c. insert
d. push
Ans. : d, Push is the operation traditionally used.
- The operation for removing an entry from a stack is traditionally called:
- delete
- peek
- pop
- remove
Ans. : c, pop is the operation used for removing an entry.
- Which of the following stack operations could result in stack underflow?
- is empty
- Continuously poping
- Continuously pushing
- This can never happen
Ans. : b, Continuously poping can result in stack underflow.
- Which of the following applications may use a stack?
- A parentheses balancing program.
- Keeping track of local variables at run time.
- Syntax analyzer for a compiler.
- All of the above.
Ans. : d, All of the above use a stack because they need kinda ordering.
- Consider the following pseudo code:
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"?
- serc
- carpets
- steprac
- ccaarrppeettss
Ans. : c, After working out it comes out to be “steprac” since stack is a last in first out system.
- Here is an INCORRECT pseudo code 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?
((( ))
( ))(( )
(( )( )))
(( )))( )
Ans. : a, ( -> push => top = 0
( -> push => top = 1
( -> push => top = 2
) -> pop => top = 1
) -> pop => top = 0
While loop ends, and balanced is printed, but exp is unbalanced.
- 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:
(()(())(()))
? - 1
- 2
- 3
- 4
- 5 or more
Ans. : c, Max number of parentheses at a time will not be more than 3.
- Suppose we have an array implementation of the stack, 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?
- data[0]
- data[1]
- data[9]
- data[10]
Ans. : d, the next data is stored in 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?
- Both peek and pop would require linear time.
- Both push and pop would require linear time.
- The stack could not be used to check balanced parentheses.
- The stack could not be used to evaluate postfix expressions.
Ans. : b, because both push and pop will be required to be done on the top of the stack.
- In the linked list implementation of the stack , where does the push member function place the new entry on the linked list?
- At the head
- At the tail
- After all other entries those are greater than the new entry.
- After all other entries those are smaller than the new entry.
Ans. a, The head acts as the top.
- In the array version of the stack (with a fixed-sized array), which operations require linear time for their worst-case behavior?
- is_empty
- peek
- pop
- push
Ans. : c, Pop uses linear time.
- In the linked-list version of the stack class, which operations require linear time for their worst-case behavior?
- is_empty
- peek
- pop
- push
Ans. : c, Pop would require linear time.
- What is the value of the postfix expression 6 3 2 4 + - *:
- Something between -15 and -100
- Something between -5 and -15
- Something between 5 and -5
- Something between 5 and 15
Ans. : a, ans works out to be -18 and the infix expr. being 6*(3-(2+4))
- 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?
- 1
- 2
- 3
- 4
- 5
Ans . c, works out to be 3 at the max.
24. The operation on stack that increments the top is called
- Overflow
- Push
- Pop
- Underflow
Ans)B
25. The situation of deleting an element from a stack which doesn’t have elements is called
- Overflow
- Push
- Pop
- Underflow
Ans)D
26. The time complexity of adding an element to a stack of n elements is?
- O(1)
- O(n)
- O(n*n)
- None
Ans)A
27. The time complexity of deleting an element from a stack of n elements is?
- O(n+1)
- O(n)
- O(1)
- None
Ans)C
28. A stack is said to be Full when it is _________
- Unsorted
- Underflow
- Over flow
- Sorted
Ans)C
29. B(i) represents the bottom of I the stack and T(i) represents the
top of I the stack. When a Stack I will becomes full?
top of I the stack. When a Stack I will becomes full?
- B(i)=T(i)
- B(i+1) = T(i)+1
- B(i-1) = T(i+1)
- B(i-1) = T(i-1)
Ans)B
30. what type of storage is used to represent stacks and queues
- Random
- Sequential
- Dynamic
- Logical
Ans : b , page 186 Tenenbaum 2nd edition(2002)
31. Drawbacks of sequential storage in stacks
a. Fixed amount of storage remains allocated to the stack
b.No more than fixed amount of storage can be allocated to the stack
c. Both a) and b)
d. None
Ans : c, page 187 Tenenbaum 2nd edition(2002)
32. what is the infix expression of the given prefix expression : +A*BC
- A*B+C
- A+B*C
- (A+B)*C
- A*(B+C)
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given prefix expression : *+ABC
- A*B+C
- A+B*C
- (A+B)*C
- A*(B+C)
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given prefix expression :
+A*-BC$D*EF
- ((A+B-C)*D)$(E*F)
- A+B-C*D$E*F
- A+(B-C)*D$(E*F)
- ((A+B)-C*D)$E*F
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given prefix expression :
$+A*BC*+ABC
- (A*B+C)$(A+B)*C
- (A+B*C)$((A+B)*C)
- A+(B*C)$A+(B*C)
- (A+B)*C$A+(B*C)
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given prefix expression : +A*BC
- ABC*+
- AB+C*
- AB*C+
- ABC+*
Ans : a, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given prefix expression : *+ABC
- ABC*+
- AB+C*
- AB*C+
- ABC+*
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given prefix expression :
+A*-BC$D*EF
- ABCDEF-*$*+
- ABC-DE*F$*+
- AB-CDEF$**+
- ABC-DEF*$*+
Ans : d, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given prefix expression :
$+A*BC*+ABC
- ABCABC*++*$
- ABC+*AB+C*$
- ABC*+AB+C*$
- AB+C*AB+C*$
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given postfix expression : ABC*+
- A*B+C
- A+B*C
- (A+B)*C
- A*(B+C)
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given Postfix expression : AB+C*
- A*B+C
- A+B*C
- (A+B)*C
- A*(B+C)
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given Postfix expression :
ABC-DEF*$*+
- ((A+B-C)*D)$(E*F)
- A+B-C*D$E*F
- A+(B-C)*D$(E*F)
- ((A+B)-C*D)$E*F
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the infix expression of the given Postfix expression :
ABC*+AB+C*$
- (A*B+C)$(A+B)*C
- (A+B*C)$((A+B)*C)
- A+(B*C)$A+(B*C)
- (A+B)*C$A+(B*C)
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given Infix expression : A+B*C
- ABC*+
- AB+C*
- AB*C+
- ABC+*
Ans : a, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given Infix expression : (A+B)*C
- ABC*+
- AB+C*
- AB*C+
- ABC+*
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given Infix expression :
A+(B-C)*D$(E*F)
- ABCDEF-*$*+
- ABC-DE*F$*+
- AB-CDEF$**+
- ABC-DEF*$*+
Ans : d, Page no 242.Tenenbaum 1994 edition
- what is the postfix expression of the given Infix expression :
(A+B*C)$((A+B)*C)
- ABCABC*++*$
- ABC+*AB+C*$
- ABC*+AB+C*$
- AB+C*AB+C*$
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given postfix expression : ABC*+
- +A*BC
- +AB*C
- +*ABC
- *+ABC
Ans : a, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Postfix expression : AB+C*
- +A*BC
- +AB*C
- +*ABC
- *+ABC
Ans : d, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Postfix expression :
ABC-DEF*$*+
- +*-$*ABCDEF
- A+*-BCD$*EF
- +A*-BC$D*EF
- +*-ABC$*DEF
Ans : c, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Postfix expression :
ABC*+AB+C*$
- $+**+ABCABC
- $+A*BC*+ABC
- $+*ABC*+ABC
- +*ABC$*+ABC
Ans : b, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Infix expression : A+B*C
- +AB*C
- +*ABC
- *+ABC
- +A*BC
Ans : d, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Infix expression : (A+B)*C
- *+ABC
- +A*BC
- +AB*C
- +*ABC
Ans : a, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Infix expression :
A+(B-C)*D$(E*F)
- +*-$*ABCDEF
- A+*-BCD$*EF
- +*-ABC$*DEF
- +A*-BC$D*EF
Ans : d, Page no 242.Tenenbaum 1994 edition
- what is the Prefix expression of the given Infix expression :
(A+B*C)$((A+B)*C)
- $+**+ABCABC
- $+*ABC*+ABC
- $+A*BC*+ABC
- +*ABC$*+ABC
Ans : c, Page no 242.Tenenbaum 1994 edition
56) Consider the following statements.
(i) A stack is a list with the restriction that items are inserted or removed/deleted only at one position, namely the end of the list.
(ii) The general model is that one where there is some element that is at the top of the stack, and it is the only element that is visible.
(iii) A pop or top on an empty stack is generally considered an error in the stack ADT.
(iv) The fundamental operations on stacks are push and pop, where push is relevant to the removal of the most recently inserted element and pop is equivalent to an insertion.
(v) A stack is a list; insertion and deletion can be performed from both ends.
Which of the above statements is/are valid for stacks?
- (i), & (ii) only
- (i), (ii) & (iv) only
- (i), (ii), (iii) & (iv) only
- (i), (ii) & (iii) only
- (i), (ii) & (v) only
Ans) D
57) Consider the following algorithm.
(i) Make an empty stack.
(ii) Read characters until end of the file.
(iii) If the character is an opening symbol, push it into the stack.
(iv)If it is a closing symbol, then if the stack is empty, report an error.
(v)Otherwise, pop the stack. If the symbol popped is not the corresponding opening symbol, then, report an error.
(vi)At end of the file, if the stack is not empty, report an error.
Identify, what the above algorithm intends to do.
- Evaluating a mathematical expression
- Check for balancing of parentheses, brackets and braces and ignore any other character that appears
- Eliminating un-matched parentheses, brackets and braces and ignoring any other character that appears
- Checking compiler errors
- Determination of syntax errors
Ans) B
58)The following shows a series of stack operations.
- Push(5)
- Push(8)
- Isempty( )
- Pop( )
- Push(3)
- Pop( )
- Pop( )
- Pop( )
- Isfull( )
- Push(3)
If the above series of operations is performed, what would be the set returned values?
- {false, 8, 3, 5, error, false, 3}
- {5, 8, false, 8, 3, 5, error, false, 3}
- {false, 8, 3, 5, error, false}
- {false, 8,3, 5, false}
- {false, 8, 3, 5, error, true}
Ans) C
59) Consider the following operations and their definitions.
(i) Clear( ) :– Clear the stack.
(ii) Is_Empty( ) :– Remove all items from the stack.
(iii) Insert( x) :- Insert element x in to any location of the stack.
(iv) Delete(p) :- Delete the element from the position p.
(v) Top( ) :- Return and remove the topmost element from the stack.
Which of the above operations is/are valid in stacks according to the basic definitions?
- (i), (ii) and (v) only
- (i)and (v) only
- (i)only
- (i)and (ii) only
- (i), (ii), (iii), (iv) and (v)
Ans) C
60) Consider the following infix expression.
((A+B)*C-(D-E))^(F+G)
Note: ^ denotes the power.
Equivalent postfix and prefix expressions are respectively
- AB+C*DE--FG+^, ^-*ABC-DE+FG
- AB+C*DE-FG+^, ^-*+ABC-DE+FG
- AB+C*DE--FG+^, ^-*+ABC-DE+FG
- AB+C*DE-FG+^, ^-*+ACB-DE+FG
- AB+C*DE--FG+^, ^-*+CBA-DE+FG
Ans) C
0 comments:
Post a Comment