You are on page 1of 16
Data Structures Questions | India’s #1 Learning Platform Sneek ects Start Complete Exam Preparation roleanrs occ) ems Reged Crestor rte a Pi MCQ Question 1: Which type of data structure stack is it? 1. Linear 2, Non-Linear 3. Nonconsecutive 4, None of these coaching India's Super Teachers for all govt. exams Under One Roof Cee Solution Below) \ Answer (Deta Option 1 : Linear Data Structures MCQ Question 1 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. Vy i 2) || 2 || @ BG) a G empty push. push push = pop 8 i oO The first insert 1 is poped at last so 1 is there in the stack for ‘od of time. Explanation: ents of the stack are A data structure stack is a linear data structure be accessed in sequential order but it is not Mh re all the elements sequentially. In the above example, elerne! ccessed only after elements 2 and 3. Hence it follows 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 non-linear order. Example: Trees and Graphs. ee aC Rae oliul eee SS la melee Ll) Pears famed eae) ie adress Excise Download App MCQ Question 2: View this Question Online > A_____ notation is used for writing an expression in which binary operators are written in between the operands. S&S 1. Infix : » 2. Prefix ‘ 4, Non of the above Answer (Detailed Solution Below) Option 1 : Infix Data Structures MCQ Question 2 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 eppreesphe can be evaluated using the set of rules. There are mainly three notations used for writing. ES x+y xy xy+ ont Infix Prefix Postfix a Infix notation: When the operator is written in between the operands it is 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+ 2 ieee ann pera) Re ee Start Complete Exam Preparation Pena aera De aed Ds creer) (eres ene pues Download App MCQ Question 3: View this Question Online > Elements “5”, “9”, “2” and “4” are placed in a quetié and are deleted one ata time. In what order will they be removed? — ) 1, 2495 xX > 3, 5942 4, 5924 Answer (Detailed Solution Below) Option 4: 5924 , Data Structures MCQ Question 3 Detailed Solution = The correct option is 5924 CONCEPT: ’ Aqueue is an ordered linear data structure, following the FIFO strategy. We will add the elements mao method and the queue looks like: On deleting elements one by one from the front using the dequeue() method we get 592 4 asa sequence. eae ori Start Complete Exam Preparation ier aed f mac hose ere Question Bank Download App Pyotr MCQ Question 4: . View this Question Online > ‘ Which of the following operation will be perforgrespwPops function on stack "stackname" in the following code? def pops(stackname): oO return late © 1, Read to os tn /ement from the stack. je stack. 3. Push element on to the top of stack. 4. Returns the size of stack. Answer (Detailed Solution Below) Option 4: Returns the size of stack. Data Structures MCQ Question 4 Detailed Solution cs Correct option is Retums the size of stack. WV CONCEPT: oO In python def keyword is used to define a fun: d before a function name. Syntax: & definition statements... In the above question pops is a user-defined function that takes a stack named "stackname’ as argument and returns 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. ean Bae ttia en Start Complete Exam CARR ota Pega fared eae ree oer by Dorcas Download App = MCQ Question 5: View this Question Online > Two fundamental operations performed on the stack are 1. BACK & FRONT 2, TOP & HEAD oO» 3. ENQUEUE & DEQUEUE “a. 4, PUSH&POP Barrer cetaice Solution Below) Option 4: PUSH & POP Data Structures MCQ Question 5 Detailed Solution The correct answer is option 4. Concept: ‘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). A stack Is an abstract data type that acts as a collection of components and has two primary operations: Pop and Push 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 ( ‘ al. ie) Gu” 2) 2 || 2 empty push push push pop b stack : ; The first insert 1 is poped at last so “" in the stack for the longest period of time. Explanation: Stack has some basic operations which are push and pops without these operations we can not perform the insert and delete the elements Hence the push and pop are the basic operations. 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. Hence the correct answer Is PUSH & POP. Cc ieee ae ur partie) Start Complete Exam Preparation Cee Dan ecg Paes faeces sae ereeeand Download App MCQ Question 6: View this Question Online > Which method is used to check whether the qi Gen element or not? 1. IS FULL oo sw ge Answer (Detailed Solution Below) Option 2: IS EMPTY Data Structures MCQ Question 6 Detailed Solution Acorrect answer Is an option (2) IS EMPTY Trying to add an element to a full stack results in an exception called 1. overflow 2. inflow ‘ ad 3. outflow > 4. underflow — ,o” BAS ces Solution Below) Option 1 : overflow Data Structures MCQ Question 7 Detailed Solution The correct option is overflow CONCEPT: The basic operations of the stack may hit a special condition or raise an error like: Underflow happens when we try to pop (remove) an item from the stack when the stack is already empty. Overflow happens when we try to push an item onto a stack, when the stack is full or out of memory. ©; Additional Information Stack is a linear data structure that follows a lastin first out order. In python, we can implement a stack using a list data structure by using ; ahpeg0! and pop() methods Basic Operations of Stack: ms. % + Push: Adding an item to the top of the stack is done using the push operation. * Pop: Removing an item ma N of the stack is done using the pop operation. In python, we can perform Push item using the append() method Pop top item using the pop() method empty push push a push (cy @us’ Ge Top=-1 Top=0 Top=1 ss Top=2 Stack [0] =a Stack [1]=b Stack [2}=c ann Stack [2] . Teter nae nly Reet PSE Ta merlin) (ec ae ye L Cod) Pru Dc MCQ Question 8: View this Question Online > What is the value after evaluation of the following expression? 78+52-* 112 aad Answer (Detailed Solution Below) Option 4:45 Data Structures MCQ Question 8 Detailed Solution The correct answer is option 4. Concept: Stack: A Stack is a data structure that is linear. It uses the Last In, First Out (LIFO) storage mechanism. A new element is always added to the top of a stack when it is addet the top element is always removed first from a stack. Explanation: G Postfix Expression Evaluation using Stack: NA 1. In the provided Postiix Expression, read eac 2. If the reading symbol is an operand, it shoul 3. Perform TWO pop operations and store t variables if the reading symbol i Then, using operand’ and oper: ei result to the Stack. a ne from left to right. (o the Stack. ed operands in two distinct ..*, /, etc). (operand and operand2). ading symbol operation and return the rs . Finally! pop the value a tas the final result. edie evRI Es roa oe Itprints as output 45, Hence the correct answer Is 45. & eal ea ac Caner eco PSE la merle (Ce hl) Peau arsed (= hee Die researc > Download App MCQ Question 9: 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. s=stack() sum=0 s.push(15) s.push(5) s.pop() s.push(7) s.push(11) G while( len(stack) > 0 ): sum=sum + s.pop() print(sum) 1 ae y 2.37 Answer (Detailed Solution Below) Option 3:33 Data Structures MCO Question 9 Detailed Solution: The correct option is 33 CONCEPT: Stack is a data structure that follows last in first out order for insertion and deletion of items. The insertion and deletion of items take place from one end only using the top pointer. ¥ EXPLANATION: In the above program, the following operations are performed on the aa executing the for loop push(75), push(5), pop(), push(7), push(11) noo” Push (15) Push (5) Push() Push (7) L |_| Ged Lael 45 Tor] 15 | 4 Ss Ss s s Ss Now items of the stack are popped one by one in the while loop and added to the sum variable #iteration 1: sum = sum + s.pop()=0+11 #iteration 2; sum = sum + s.pop()=11+7 #iteration 3: sum = sum + s.pop() = 18 + 15 after popping 3 items from the stack, the stack becomes empty and the while loop stops/ends, The final value of sum = 33 that will be printed in the end. oa eal ac en PS ela merle le ee hol) Peau arsed a) Mosk Tets Doce Question Bank & Quizzes AR ee Ta Download App MCQ Question 10: tt ¢ View this Question Online >)” Any arithmetic expression cannot be represented in which of the following “o V. infix 2. Midfix 3. Postfix 4. Prefix Answer (Detailed Solution Below) Option 2 : Midfix

You might also like