BEGINNER⭐ Must Know 4 min read 3 views
Stacks, Queues, Linked Lists & Binary Tree Properties
Infix/Postfix evaluation, Circular Queue full/empty modular arithmetic, Linked List pointer complexities, Binary Tree degree handshaking lemma, and unique tree reconstruction rules.
1. Stacks & Queues Complexity Nuances
- Stack Applications: Function activation records, Infix-to-Postfix conversion (), Postfix evaluation, Stock Span / Next Greater Element ( monotonic stack), and DFS.
- Queue Using Two Stacks ():
Enqueuepushes to in ;Dequeuepops from (transferring only when is empty) Amortized per operation, worst-case single dequeue . - Circular Array Queue (size , wasting 1 slot):
- Empty:
front == rear - Full:
(rear + 1) % N == front(holds elements max unless an explicitcountis maintained).
- Empty:
2. Singly vs Doubly Linked List Complexities
| Operation | Singly LL (Head only) | Singly LL (Head + Tail) | Doubly Linked List |
|---|---|---|---|
| Insert at Front / Delete at Front | |||
| Insert at End | (with tail) | ||
| Delete Last Node | (still needs predecessor!) | (with tail) |
3. Binary Tree Traversals & Unique Reconstruction
Given two traversals of a binary tree with distinct keys, when is the tree uniquely determined?
- Inorder + Preorder YES (Unique)
- Inorder + Postorder YES (Unique)
- Inorder + Level-Order YES (Unique)
- Preorder + Postorder NO in general — YES ONLY IF the binary tree is Full/Strict (every node has or children)!
- BST Only: A single Preorder (or single Postorder) suffices to reconstruct a BST uniquely because sorting the keys automatically yields the Inorder traversal!
📐 Quick Revision Formula Sheet
Binary Tree Leaf-to-Degree-2 Theorem
💡 Number of leaf nodes (degree 0) equals number of degree-2 internal nodes + 1
Strict (Full) k-ary Tree Leaves
💡 Where L = leaves and I = internal nodes
#Data Structures#Stacks#Queues#Linked Lists#Binary Trees#Traversals
🎯 Practice PYQs on This Topic (2)
Q1.GATE CS DSAMCQEASY
+1 Marks • -0.33 NegA binary tree has nodes with degree (two children) and nodes with degree . How many leaf nodes (degree ) does the binary tree contain?
Q2.GATE CS DSAMCQEASY
+2 Marks • -0.67 NegEvaluate the postfix (Reverse Polish) expression: 8 2 3 ^ / 2 3 * + 5 1 * - where ^ denotes exponentiation.