0% found this document useful (0 votes)
53 views4 pages

Stacks

The document contains a series of questions and answers related to stacks, a data structure used in computer science. It covers concepts such as stack operations (push, pop), conditions (overflow, underflow), and applications of stacks. Additionally, it includes assertions and reasons, case study-based questions, and true/false questions to assess understanding of stack implementation and behavior.

Uploaded by

aim_aim11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Stacks

The document contains a series of questions and answers related to stacks, a data structure used in computer science. It covers concepts such as stack operations (push, pop), conditions (overflow, underflow), and applications of stacks. Additionally, it includes assertions and reasons, case study-based questions, and true/false questions to assess understanding of stack implementation and behavior.

Uploaded by

aim_aim11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Class XII # Stacks

1 What is the process of inserting data into a stack called?


A. Create B. Insert C. Push D. Evaluate
2 What is the process of deleting data from a stack called?
A. Drop B. Delete C. Erase D. Pop
3 Which pointer is associated with a stack?
A. First B. Front C. Rear D. Top
4 Assume a stack has size 4. If a user tries to push a fifth element to a stack, which of the mentioned
condition will arise?
A. Underflow B. Overflow C. Crash D. Successful Insertion
5 If a user tries to pop an empty stack, which of the mentioned condition will arise?
A. Empty data B. Overflow C. Underflow D. No error
6 Assume a stack Stk implemented as a list. Predict the output of the following code.
def push_char(ch):
Stk.append(ch)
def display_stk():
strdata=""
if len(Stk)==0:
print("Empty Stack")
else:
for i in Stk:
strdata+=i
print(strdata[::-1])
push_char('c')
push_char('b')
push_char('s')
push_char('e')
push_char('2')
push_char('0')
push_char('2')
push_char('1')
A. 1202esbc B. cbse2021 C. 1 D. s
7 Which of these is not an application of stack?
A. Parenthesis Balancing program B. Evaluating Arithmetic Expressions
C. Reversing Data D. Data Transfer between Process
8 Predict the output of the following code:
def insert_data(stk,num):
stk.append(num)
stk=[2,3,4]
insert_data(stk,10)
print(stk)
A. [2,3,4,10] B. [10,2,3,4] C. Overflow D. Underflow
9 Predict the output of the following code:
def push(stk,num):
stk.append(num)
def pop():
if len(stk)==0:
print(“Underflow”)
else:
stk.pop()
stk=[10,100,-1,2,4]
push(stk,200)
pop()
pop()
pop()
push(stk,4)
print(stk[-1])
A. 200 B. 100 C. -1 D. 4 Application
10 Stack data structure works on the following principle.
(A) LILO (B) DIFO (C) FIFO (D) LIFO
11 Which of the following is not an application of stack in real-life.
(A) Pile of clothes in an almirah (B) Multiple chairs in a vertical pile
(C) Persons buying movie tickets from a counter (D) Bangles worn on wrist
12 What will the output of the following Python code?
result=0
numberList=[10,20,30]
numberList.append(40)
result=result+numberList.pop()
result=result+numberList.pop()
print(result)
(A) 40 (B) 70 (C) 30 (D) 10
Analysis Evaluation
13 Predict the output of the following Python code.
answer=[ ]
answer.append('T')
answer.append('A')
answer.append('M')
ch=answer.pop()
print(answer)
(A) ['T', 'A'] (B) ['T', 'A', 'M'] (C) ['A'] (D) IndexError: pop from empty list
14 In Python, list is used for implementing a stack and its built-in-functions___________ and __________ are
used for insertion and deletion, respectively.
(A) Insert, delete (B) append, pop (C) append, remove (D) append, delete
15 In which data type stack is implemented in Python.
A. List B. Tuple C. Int D. Dictionary

ASSERTIONS AND REASONS (16-20)


16 Assertion : The start index of a stack is -1
Reason : Stack Data structure can be implemented through list in Python
A. Both Assertion and reason are true and reason is correct explanation of assertion
B. Assertion and reason both are true but reason is not the correct explanation of assertion
C. Assertion is true, reason is false. D. Assertion is false, reason is true.
17 Assertion: If the size of a stack is 5 and a sixth element is inserted, then Underflow happens
Reason: Overflow is a condition which occurs in bounded stack
A. Both Assertion and reason are true and reason is correct explanation of assertion
B. Assertion and reason both are true but reason is not the correct explanation of assertion
C. Assertion is true, reason is false. D. Assertion is false, reason is true.
18 Assertion: A stack has 2 elements in it. If the stack undergoes 3 pop operations one after another then
Underflow occurs.
Reason: Underflow is a condition which occurs when deletion happens on an empty stack.
A. Both Assertion and reason are true and reason is correct explanation of assertion
B. Assertion and reason both are true but reason is not the correct explanation of assertion
C. Assertion is true, reason is false. D. Assertion is false, reason is true.
19 Assertion: if a stack has the following data, then peek function will return 4
Reason: Arithmetic expression can be evaluated using stack
A. Both Assertion and reason are true and reason is correct explanation of assertion
B. Assertion and reason both are true but reason is not the correct explanation of assertion
C. Assertion is true, reason is false. D. Assertion is false, reason is true.
20 Assertion: Stack is a linear data structure.
Reason: A data structure in which elements are organized in a sequence is called linear data structure.
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
(C) Assertion is true, reason is false. (D) Assertion is false, reason is true.

CASE STUDY BASED QUESTIONS (21-25)


Venkat loves to play cricket. His teacher has given him an assignment on his favourite sport. He has to
write 2 functions AddPlayer(player,runs) and DeletePlayer() to add and remove a player from a stack
which is implemented using a list. Adding a player to a stack is only possible if the player has secured
more than 50 runs. Venkat needs your help in completing the code.
Incomplete code:
#Creating stack
Cricket_Stack=[]
def AddPlayer(player,runs):
if runs>50:
Cricket_Stack ____ # statement 2
print(Cricket_Stack)
def DeletePlayer():
if len(Cricket_Stack) ==0:
print("Empty Stack,Cant pop")
return -1
else:
pop_item=Cricket_Stack[-1]
Cricket_Stack ______________ #statement3
return pop_item
getPlayer= _ ("Enter the player name:") # stat. 1
getruns=int(input("Enter the runs scored by player:"))
AddPlayer(getPlayer,getruns)
print(DeletePlayer())
(Based on the data given above, answer Question No. 21 to 25)
21 Which function will be used in statement 1 to get the player name from the user?
A. read() B. input() C. get() D. pop()
22 Identify the missing code to complete the statement 2:
A. insert(player) B. push(player) C. append(player) D. player(append)
23 Identify the missing code to complete the statement 3:
A. delete() B. pop() C. pop(0) D. append(-1)
24 Assume the current stack position as ['Azhar','Sachin']. If the function AddPlayer() is called with the
arguments ('Karan',30) what will be the stack data after the function call?
A. ['Azhar','Sachin','Karan'] B. ('Azhar','Sachin','Karan')
C. ['Azhar','Sachin'] D. ('Azhar','Sachin')
25 Assume the current stack position as ['Don','Virat','Jeff']. If the function DeletePlayer() is invoked ,What
will be the data in the stack after the function call?
A. ['Don','Virat'] B. ['Virat','Jeff'] C. ['Virat','Jeff'] D. ['Don', 'Virat','Jeff']
TRUE / FALSE QUESTIONS (26-30)
26 The peek operation refers to accessing/inspecting the top element in the stack
A. True B. False
27 The insert operation in stack is known as pop
A. True B. False
28 The top operation does not modify the contents of a stack.
A. True B. False
29 Stack implementation can be performed using a list in Python
A. True B. False
30 For loop can be used for traversing a stack
A. True B. False
: ANSWERS : Question No Answer Question No Answer Question No Answer
1 C 11 C 21 B
2 D 12 B 22 C
3 D 13 A 23 B
4 B 14 B 24 C
5 C 15 A 25 A
6 A 16 D 26 A
7 D 17 D 27 B
8 A 18 A 28 A
9 D 19 B 29 A
10 D 20 A 30 A

You might also like