Data Structures in Python Class 12
A data structure is a way of organising data so it can be used efficiently. In Class 12 the main data structure studied in depth is the stack, implemented ...
Data Structures in the Syllabus
A data structure is a way of organising data so it can be used efficiently. In Class 12 the main data structure studied in depth is the stack, implemented using a Python list. Students also revisit lists, tuples and dictionaries from Class 11 as supporting structures. Understanding data structures helps you choose the right tool for a problem - for example, a stack is perfect when the most recently added item must be removed first.
The Stack and Its Operations
A stack follows the LIFO rule - Last In, First Out - like a pile of plates where you take the top plate first. Its main operations are push (add an item to the top), pop (remove the top item), and peek or top (look at the top item without removing it). In Python a list works as a stack: mylist.append(x) pushes and mylist.pop() removes the last item. You must also check for an empty stack (underflow) before popping. Stacks are used in undo features, expression evaluation and function calls.
Example and Exam Tip
Example: starting with an empty list, push 10, push 20, then pop returns 20 because it was added last. Exam tip: a very common board question asks you to write push and pop functions for a stack using a list, including the underflow check that prints "Stack Empty" when popping from an empty stack. Practise tracing a sequence of push and pop operations and writing the stack contents after each step - examiners award marks for the intermediate states, not just the final answer.