sTaCk – important questions for Boards 2027
CBSE Class 12 Computer Science
How do the elements of a string differ from the elements of a list?
Answer
A string contains a sequence of characters; a list is a sequence whose elements may be of different types.
What is a data structure, and what kinds of operations does it enable to be performed efficiently on stored data?
Answer
A data structure is a mechanism to store, organise and access data, together with operations that can be efficiently performed on the data. It organises multiple elements for easy processing.
Explain how strings, lists, sets and tuples can represent collections of elements, including whether the elements may be of the same type or different types.
Answer
1. Strings, lists, sets and tuples can represent collections of elements of the same type or of different types. 2. A string stores a sequence of characters, while a list can contain elements of different types; grouping elements supports faster accessibility and efficient processing of the stored collection as a collective data unit.
Describe the stack procedure for evaluating a postfix expression: state what is done when an operand is read and when a binary operator is read, including the order in which the two popped values are used. (4 marks)
Answer
A postfix expression is evaluated by scanning its symbols from left to right and using a stack to hold operands and intermediate results. 1. When the next character is an operand, PUSH it onto the stack. The operand remains available for an operator that appears later in the expression. 2. When a binary operator is read, POP the top two values from the stack. The first value popped is the right operand, and the second value popped is the left operand. 3. Apply the operator to the left operand followed by the right operand, then PUSH the computed result onto the stack. For example, if the popped values are 8 and then 7 for subtraction, calculate 7 − 8. 4. Continue until every character has been processed. A valid complete expression leaves its net result as the single element of the stack. Thus, the stack stores operands and partial results during postfix evaluation.
What is a stack, and at which end are its insertion and deletion operations performed? Explain the LIFO principle and describe the purpose of the PUSH and POP operations.
Answer
A stack is a linear data structure in which insertion and deletion are performed at one end, usually called TOP. 1. The TOP is the end from which elements are added and removed. The two basic stack operations are PUSH and POP. 2. PUSH inserts an element onto the stack at TOP. The newly inserted element becomes the top element. 3. POP removes an element from TOP. The element at the top is the first one available for deletion. 4. Stack follows the LIFO principle: an element inserted last is the first one to be out. Therefore, elements are removed in the reverse order in which they were inserted. The TOP-based operations and LIFO principle make a stack suitable for processing data in last-in, first-out order.
Which set contains only operations mentioned in the excerpt as applicable to sequence data? (A) Reversal, slicing and counting elements (B) Sorting, hashing and compilation (C) Encryption, deletion and file opening (D) Multiplication, networking and printing
Answer locked. Unlock all answers on SmartKalike
State two benefits of grouping data elements in a data structure, as described in the excerpt.
Answer locked. Unlock all answers on SmartKalike
Explain when a stack implemented using a Python list can encounter an overflow condition. Why does the implementation not otherwise impose a fixed stack capacity? (3 marks)
Answer locked. Unlock all answers on SmartKalike
What assumption does the described postfix-evaluation procedure make about the operators? Explain how this assumption determines how many stack elements are popped when an operator is encountered. (4 marks)
Answer locked. Unlock all answers on SmartKalike
Explain why strings and lists are described as sequence data structures. Compare the kinds of elements found in a string and in a list.
Answer locked. Unlock all answers on SmartKalike
28 more probable questions in this chapter, every one with a full answer.
Unlock all answers on SmartKalike