You are on page 1of 23
Data Structures Questions Latest Data Structures MCQ Objective Questions - Ee ane Bar lela) Re eect See Ce Clu Ney lel) eos ey aes Des Creer cag & Quizzes B Download App MCQ Question 1: Stack A has the entries a, b, and c (with a on top). Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of stack B can only be printed. In this arrangement, Which of the following permutations of a, b, and c are not possible? 1. bac 2 cha 3. cab 4. abe Certo ay] India's Super Teachers for all govt. exams: Under One Roof Answer (Detailed Solution Below) Option 8:cab Data Structures MCQ Question 1 Detailed Solution The correct answer is option 3. Concept: The given two stacks are, StackA Stack B Top=0| a Empty Top=1|b Top =2| c Option 1: bac Stack A has a top element is “a” but the first expected element is b so element “a’ is inserted into stack B. Then prints the element "b” Pop the element from the “a' from stack B. Pop the element from the "c” from stack A. Hence itis possible. { Option 2:¢ ba G e Stack A has a top element ‘a’ but the first expected element is 'c’ so element “a” and " into stack B. Then pop the element ‘c’ from stack A(i.e top element) Noe Then pop the element from "b’ from stack B (i.e top element) Gy Then pop the element from ‘a" from stack B (12 tgp elemer S Henca itis possible Option 3:c ab Stack A has.a top element ’a’ but the first expected elements 'c’ so element “a” and "b" is inserted into stack B. Then pop the element "c’ from stack A(.c top element) Then pop the element from *b” from stack B (i.e top element) but the next expected element is "a’. Itis not possible because An entry that popped out of stack B can only be printed. So the given sequence is not possible. Option 4:a be Stack A has a top element “a’ but the first expected element is ‘a’ so element a’ is printed immediately. Then pop the element from stack A and print the top element i.e "b’. Then pop the element from stack A and print the top element ie Hence itis possible. Hence the correct answer is c ab. India's #1 Learning Platform BS Ta Otel) Ce Le) as pa Sees las VE Cresta & Quizzes Download App MCQ Question 2: ? View this Question Online > The method provided by Python to insert elements into a stack is: 1. >. " append() 3. push() 4. addi) Answer (Detailed Solution Below) Option 1: append() Data Structures MCQ Question 2 Detailed Solution Correct answer: Option 1 4 Explanation: & + Python provides the appenci() method to add elements to the top of a stack, until an overflow condition is encounter: + The operation of erin hes into a stack is called @ Push operation, but Python does not have any in-built function e same name. + The insert() and add() ere not valid Python functions. Important points: + The operation of removing elements from a stack is called a pop operation and the in-built python method to perform this is pop(). + However, the function for pushing elements into a stack is not the same as the name of the operation, push. Pr India’s #1 Learning Platform Ree ARR es Start Complete Exam Preparation pees Pa epee Dis oed Cree ars Download App puoi? MCQ Question 3: View this Question Online > 793+4/* The evaluation of the above postfix expression Is: Answer (Detailed Solution Below) Option 4:21 Data Structures MCQ Question 3 Detailed Solution Correct answer: Option 4 Explanation: The evaluation of the expression is as follows: input string|Stack| Operation 7 7 | Push? 9 |79| Puss 3 |793] Pusha Rs Pop 9and 3 ~~ + 1772 bush a+ a 4 (7124 Pusha Pop 12 and 4. 1 | 73 Ipush 12/4=3 «| oy | Pop7ands. Push 7*3=21 India’s #1 Learning Platform Start Complete Exam Preparation ca Pears Pea ey ey MasterClass Oeics pina Download App MCQ Question 4: CG View this Question Online > NA . When a * b is written as *ab, it is called oe , ) Post earenh 2 lish notation 3. Polish notation 4, Infix expression Answer (Detailed Solution Below) Option 3: Polish notation Data Structures MCQ Question 4 Detailed Solution Explanation: cnt ewe ea? + When the operands \wed by the operator, we call such an expression a postfix, expression, A post) ion is also called a Reverse Polish Notation (RPN). + When the operands are preceded by the operator, we call such an expression a prefix expression. A prefix expression is a/so called a Polish notation. + When the operator is placed in between the operators, it is called an infix expression. Important points: Here, a *b is the infix expression and *ab is the prefix expression or the Polish notation & A ee ea ec SSE Ta eri ele LiCl) Oras fara Py CO cree Coreen D> Download App MCQ Question 5: View this Question Online > exons) Convert the following infix expression to postfix expression using stack: (A+B¥(C-D)*E+(F/G)*H1) ABCD-E"*+FG/H"+1- 2. ABCD-E'*+FG/H*H+ ‘ 3. ABHCD-EMFG/H*+1- 4. ABECD-EMEG/HNH oe f “Answer (Detailed Solution Below) Option 1: ABCD-E*+FG/H*+/- Data Structures MCQ Question 5 Detailed Solution Correct answer: Option 1 Explanation: The conversion using stack is as follows: [ Input string ‘Stack Output string ( I ( A A a AB (we AB (( AB ( ABC (we ABC (we ABCD (4 ABCD- we ABCD- (ee ABCD-E (+ ABCD-E'™*+ (+( ABCD-E**+ (+ ABCD-EM+F (+ ABCD-E+F ay ABCD-E"+FG ABCD-E"+FG/ (+* ABCD-E**+FG/ ABCD-EM+FG/H s ( |ABCD-E“+FG/H"+) I | ABCD-E"*+FG/H"41 ) \ABCD-E"*+FG/H'+! Important points: The order of precedence of operators that are followed are — brackets, exponentiation, division & multiplication, addition & subtraction. fop Data Structures MCQ Objective Questions India’s #1 Learning Platform PS ETa merely l(c eT ey Te LiCl) Sea Download App MCQ Question 6: View this Question Online > Which type of data structure stack is it? 1. Linear 2. NomLinear 3. Nonconsecutive 4. None of these Answer (Detailed Solution Below) Option 1: Linear x“ MCQ Question 6 Detailed Solution The correct answer is option 1. Concept: Linear data structure: The elements are accessed in sequential order but it is not compulsory to store all the elements sequentially. Example: Queue, Stack, and Linked List. Stack: Astack is a linear data structure In which operations are carried out in a specific order. The sequence might be LIFO (Last In First Out) or FILO (First In Last Out). Example: Consider the canteen, where plates are heaped on top of one another. The plate at the top is the first to be removed, but the plate at the bottom is the one that stays in the stack the longest. Nyy yy GQ} |e empty push push push pop ¢O stack e The first insert 1 is poped at last so 1 Is there in the stack for the longest period Cy Explanation: O Adata structure stack is a linear data structure because the el ie stack are accessed in sequential order but itis not compulsory to store all the entially. In the above example, element 1 is accessed only after elements 2 and 3. s the linear fashion Hence the correct answer is Linear, © Additional Information Basic Operations of Stack: There are a few fundamental operations that we may use to conduct various tasks on a stack. + Push: Add an element to the top of a stack. + Pop: Remove an element from the top of a stack. + IsEmpty: Check if the stack is empty. + IsFull: Check if the stack is full + Peek: Get the value of the top element without removing it. Non-linear data structure: Elements of the data structures are stored or accessed in a nonlinear order. Example: Trees and Graphs. India’s #1 Learning Platform Seam eels) Cle ely) Faleauc Phe Kl robes Crea rad Download App MCQ Question 7: View this Question Online > A notation is used for writing an expression in which binary operators are written in between the operands. , 1. Infix Ps 2. Prefix ¥ Ss 4. Non of the above Answer (Detailed Solution Below) Option 1 : Infix Data Structures MCQ Question 7 Detailed Solution Correct option is Infix CONCEPT: An expression mainly consists of operands, operators, and symbols. These must be arranged according to a set of rules so that expressions can be evaluated using the set of rules. : There are mainly three notations used for writing expression: x+y +xy xy+ cee. \ Infix Prefix Postfix Infix notation: When the operator is written in between the operands itis known as infix notation. Example 2+5 Prefix notation: When the operator is written before the operands it is known as Prefix notation. Example +25 Postfix notation: When the operator is written after the operands it is known as Postfix notation. Example 25+ ee ae Start Complete Exam Preparation Cea ceca Or euTS abe ie reaerey sterClasses (ores Download App Exo MCQ Question 8: View this Question Online > Which of the following operation will be performed by pops function on stack “stackname” in the following code? def pops(stackname): return len(stackname) 1. Read top most element of the stack. 2. _—" from the stack. 3. Push element on to the top of stack. 4. Returns the size of stack. Answer (Detailed Solution Below) Option 4: Retums the size of stack. Data Structures MCQ Question 8 Detailed Solution Correct option is Returns the size of stack. CONCEPT: In python def keyword is used to define a function, itis placed before a function name. ‘syntax: def function_name: ~ definition statements... In the above question pops is a user-defined function that tekes a stack named “stackname” as argument and retums the length of stack using len() function. Example: Let stackname-[1,2,3] is a stack which contains 3 elements On calling the pops(stackname) function, it will return 3 as length of stack. x ee ee anny parca) Start Complete Exam Preparation (&) caivie oor Elite PCy Cresta Byori Download App MCQ Question 9: = View this Question Online > Elements “5”, "9", “2" and “4” are placed in.a queue and are deleted one at a time. In what order will they be removed? ; 1. 2495 3. 5942 4. 9924 Answer (Detailed Solution Below) Option 4: 5924 Data Structures MCQ Question 9 Detailed Solution The correct option is 5924 CONCEPT: Aqueueis en ordered linear date structure, following the FIFO strategy. We will add the elements veigeeued method and the queue looks like: On deleting elements one by one from the front using the dequeue() method we get 5924 asa sequence. & India's #1 Learning Platform PS la merlin (ee Cee-Lo) Ce Dan ue ost Pru fers ea Perera Creer pao si Download App MCQ Question 10: View this Question Online > Two fundamental operations performed on the stack are 1. BACK & FRONT ch 2. TOP & HEAD e 3. ENQUEUE & DEQUEUE O 4. PUSH & POP NO r XE Solution Below) tion 4: PUSH & POP Data Structures MCQ Question 10 Detailed Solution The correct answer is option 4. Concept: ‘Stack: A stack is a linear data structure in which operations are carried out in a specific order. The sequence might be LIFO (Last In First Out) or FILO (First In Last Out). A stack is an abstract data type that acts as a collection of components and has two primary operations: Pop and Push Cc India’s #1 Learning Platform Start Complete Exam Preparation cal goatee raed (ex) a PO Serern Cree ear pao si Download App MCQ Question 11: View this Question Online> Reena ea! Trying to add an element to 4 full stack results in an exception called 1. overflow 2. inflow 3. outflow 4, underflow Answer (Detailed Solution Below) Option 1 : overflow & ro " India’s #1 Learning Platform Ue BS Ta a eLey yao) Co ad TLC) aie eed Ei aca resect Creer Exons Download App MCQ Question 12: View this Question Online > Which method is used to check whether the queue has any element or not? 1. IS FULL 2. ISEMPTY 3. PEEK 4. IF EMPTY Answer (Detailed Solution Below) Option 2: |S EMPTY ee eee acy Roe) SS Ea ery ele LiCl) Etter Question Bank raid Marc ma a alii eon Download App MCQ Question 13: View this Question Online > Whats the value after evaluation of the following expression? 78+52-* 1,12 2. 85 3. 25 4.45 Answer (Detailed Solution Below) Option 4: 45 Cera cece India’s #1 Learning Platform Sy eae SS Elam Orel) Cle ele) ees rab ts MasterClasses Cresson Download App MCQ Question 14: View this Question Online > What will be the value printed by the following python code: #consider stack is already implemented for you and has predefined pop and push method. sestack() sum=0 s.push(15) s.push(5) s.pop() s.push(7) s.push(11) while( len(stack) > 0): sum=sum + s.pop() print(sum) 1,31 2.37 3. 33 4. 26 Answer (Detailed Solution Below) Option 3: 33 ee eR estas Start Complete Exam Preparation Prue eaicd erga) pire) eee et Download App MCQ Question 15: View this Question Online > Any arithmetic expression cannot be represented in which of the following notations? 1. Infix 2. Midfix 3. Postfix A. Prefix Answer (Detailed Solution Below) Option 2: Midfix

You might also like