💡 Summary: Turning Data Structure Theory into Working Lab Case Studies
In a Data Structures lab or mini-project viva, examiners usually ask: "Why did you pick this data structure for this problem, and how does it behave when inputs grow?" A strong case study starts with the real-world requirement, maps each operation to a clean structure, tests edge cases (empty inputs, duplicates, missing keys, or cycles), and states the time and space trade-offs clearly.
Below are 10 complete student case studies—grouped into two parts with runnable Python lab examples—showing how core data structures work together in practical applications.
- Identify Operations: List what happens most often—fast lookup by key, LIFO undo, FIFO waiting, ordered traversal, or priority dispatch.
- Pick Matching Structures: Match each operation to a structure (hash map for O(1) average lookup, stack for undo/brackets, queue/deque for scheduling, min-heap for next-smallest/urgent item, graph for routes/dependencies).
- Test Edge Cases: Always test empty collections, single elements, duplicate keys, invalid lookups, and large counts.
- Document Complexity: State time and space complexity for key operations so your lab report and viva answers are crisp.
| Requirement | Recommended Structure | Typical Operation |
|---|---|---|
| Fast key-to-record lookup & counts | Hash Table / Dictionary | Insert / lookup in O(1) average |
| Undo history & nested tag/bracket checks | Stack (LIFO) | Push / pop in O(1) |
| Fair arrival order & level-by-level scan | Queue / Deque (FIFO) | Enqueue / dequeue in O(1) |
| Always pick highest/lowest priority next | Binary Heap (Priority Queue) | Push / pop min or max in O(log n) |
| Routes, prerequisites & network links | Graph (Adjacency List) | BFS / DFS / Shortest Path |
case_studies = [
(1, "Browser Back/Forward History", "Two Stacks (Undo / Redo)"),
(2, "Hospital / Print Spooler Queue", "FIFO Queue + Priority Heap"),
(3, "Grocery / Library SKU & Book Lookup", "Hash Map + Sorted Search"),
(4, "Course Prerequisite & Build Planner", "Directed Graph + Topological Sort"),
(5, "Campus Delivery / Map Shortest Route", "Weighted Graph + Dijkstra"),
(6, "Student Leaderboard & Top-K Scores", "Min-Heap / Sorting"),
(7, "Expression & Code Bracket Validator", "Stack"),
(8, "Recent Cache (LRU Concept) Tracker", "Doubly Linked List + Hash Map"),
(9, "Organization / File Directory Explorer", "Tree Traversal (DFS / BFS)"),
(10, "Exam Marks & Batch Report Sorter", "Sorting + Counting/Buckets"),
]
for num, title, ds in case_studies:
print(f"Case {num:02d}: {title:38s} -> {ds}")
- Case Study 1 — Browser Back & Forward Navigation (Two Stacks): Visiting a new page pushes the current page onto
back_stackand clearsforward_stack; clicking Back pops fromback_stackand pushes ontoforward_stack. - Case Study 2 — Lab Printer & Helpdesk Ticket Queue (FIFO + Priority): Normal print jobs follow arrival order (FIFO queue), while urgent lab/exam jobs can be prioritized with a heap.
- Case Study 3 — Library Book / Store Inventory Lookup (Hash Map): Looking up a book ID or product SKU in O(1) average time and updating available copies cleanly without scanning the whole catalog.
- Case Study 4 — Semester Course Prerequisite Planner (Topological Sort): Checking whether a student's chosen subjects have a valid order or a circular prerequisite loop before registering.
- Case Study 5 — Campus Shortest Path Finder (Dijkstra's Algorithm): Finding the shortest walking or cycling route between campus buildings when path distances vary.
# Case Study 1: Browser Back / Forward Using Two Stacks
class BrowserHistory:
def __init__(self, homepage):
self.current = homepage
self.back_stack = []
self.forward_stack = []
def visit(self, url):
self.back_stack.append(self.current)
self.current = url
self.forward_stack.clear()
def back(self):
if not self.back_stack:
return self.current
self.forward_stack.append(self.current)
self.current = self.back_stack.pop()
return self.current
def forward(self):
if not self.forward_stack:
return self.current
self.back_stack.append(self.current)
self.current = self.forward_stack.pop()
return self.current
# Case Study 3: Library Catalog Lookup via Hash Map
library_db = {
"BK-101": {"title": "Data Structures", "copies": 4},
"BK-102": {"title": "Operating Systems", "copies": 2},
"BK-103": {"title": "Computer Networks", "copies": 5},
}
def borrow_book(book_id):
rec = library_db.get(book_id)
if not rec or rec["copies"] <= 0:
return f"{book_id}: Unavailable"
rec["copies"] -= 1
return f"{book_id}: Issued '{rec['title']}' (remaining={rec['copies']})"
bh = BrowserHistory("portal.edu/home")
bh.visit("portal.edu/ds-lab")
bh.visit("portal.edu/quiz-1")
print("Case 1 After Back :", bh.back())
print("Case 1 After Forward:", bh.forward())
print("Case 3 Borrow Book :", borrow_book("BK-101"))
- Case Study 6 — Top-K Coding Contest Leaderboard (Min-Heap): Maintaining the top
Kscores across a stream of submissions using a min-heap of sizeKso the lowest of the top scores is always at the root. - Case Study 7 — Code / Math Parentheses & Bracket Checker (Stack): Verifying that every
(,[, and{closes in the right order before compiling or evaluating an expression. - Case Study 8 — Recent Items / LRU Cache Simulator (Hash Map + Doubly Linked List): Keeping recently accessed items near the front in O(1) time and evicting the least recently used item when capacity is full.
- Case Study 9 — Folder & Category Tree Explorer (Tree Traversal): Traversing nested folders or topic trees using DFS (pre-order/post-order) or BFS (level-order).
- Case Study 10 — Exam Marks & Batch Report Sorter (Sorting): Sorting student marks (0–100) or records cleanly and generating rank summaries.
import heapq
# Case Study 6: Top-K Scores Using a Min-Heap of Size K
def top_k_scores(scores, k):
heap = []
for s in scores:
if len(heap) < k:
heapq.heappush(heap, s)
elif s > heap[0]:
heapq.heapreplace(heap, s)
return sorted(heap, reverse=True)
# Case Study 7: Balanced Brackets Checker Using a Stack
def is_balanced(expr):
pairs = {")": "(", "]": "[", "}": "{"}
stack = []
for ch in expr:
if ch in "([{":
stack.append(ch)
elif ch in pairs:
if not stack or stack.pop() != pairs[ch]:
return False
return len(stack) == 0
print("Case 6 Top 3 Scores :", top_k_scores([54, 91, 78, 88, 96, 67, 85], 3))
print("Case 7 Balanced Expr :", is_balanced("{a + [b * (c - d)]}"), is_balanced("{a + [b)}"))
- Explain why, not just what: State why your chosen data structure fits the workload better than a plain list or linear scan.
- Walk through a concrete trace: Be ready to trace insert, search, pop, or traversal step by step on a 4–6 item sample input.
- Mention edge cases & limits: Note empty inputs, duplicates, missing items, or cycle/capacity limits in your output.
viva_points = [
"State the main operations (lookup, push/pop, enqueue/dequeue, min/max, traverse).",
"Give time and space complexity for those key operations.",
"Show edge-case handling (empty input, missing key, duplicates)."
]
for p in viva_points:
print("*", p)