Data Structures and Algorithms

Data Structures & Algorithms โ€“ Complete Exam Guide 2025 | GATE, IBPS, SSC, UPSC
๐Ÿ’ป Computer Science ยท Competitive Exam 2025

Data Structures &
Algorithms Master Guide

Array ยท Linked List ยท Stack ยท Queue ยท Tree ยท Graph ยท Hashing ยท Sorting ยท Searching ยท Big-O Notation ยท 50 MCQs with Explanations โ€” for GATE, IBPS, SSC, UPSC, NDA & Campus Placements

GATE CSIBPS PO/ClerkSSC CGLUPSC GS-III NDA/CDSRBI Grade BCampus PlacementsBank Internal
๐Ÿ“š

FoundationWhat is a Data Structure?

A Data Structure is a method of organising and storing data in a computer so it can be accessed and modified efficiently. Choosing the right data structure directly impacts the speed and memory usage of programs.

TermMeaningExample
DataRaw facts (numbers, text, values)Account number: 12345678
StructureOrganised format for storageRows and columns
Data StructureWay to store and manage data efficientlyArray of account numbers
AlgorithmStep-by-step solution procedureSorting customer names Aโ€“Z
ADTAbstract Data Type โ€” defines behaviour without implementationStack, Queue are ADTs
โšก Core Exam Facts
  • Data Structures are classified as Linear (sequential) and Non-Linear (hierarchical/networked)
  • Stack and Queue are ADTs (Abstract Data Types) โ€” keyboards and integers are NOT
  • Data structures are stored in RAM (main memory) during execution
  • Wrong data structure = slower programs + excess memory usage
  • Used in: banking software, OS, databases, networking, AI โ€” essentially all software
โžก๏ธ

Data Arranged SequentiallyLinear Data Structures

๐Ÿ“ฆ

Array

Linear ยท Fixed Size

Collection of same-type elements stored in continuous memory. Access any element instantly using its index. Size fixed at declaration.

Access
O(1) by index
Insert/Delete Middle
O(n) โ€” shifting needed
Memory
Continuous/contiguous
Size
Fixed at compile time
๐Ÿ”—

Linked List

Linear ยท Dynamic Size

Nodes connected via pointers. 10 โ†’ 20 โ†’ 30 โ†’ NULL. Types: Singly, Doubly, Circular. No continuous memory needed.

Insert at Head
O(1)
Search
O(n) โ€” traverse
Memory
Non-contiguous
Size
Dynamic
๐Ÿ“š

Stack

LIFO โ€” Last In, First Out

Like a stack of plates โ€” last placed, first removed. Operations: Push (add) and Pop (remove). Peek to see top without removing.

Push/Pop
O(1)
Search
O(n)
Overflow
top = maxSizeโˆ’1
Underflow
top = โˆ’1 or NULL
๐Ÿšถ

Queue

FIFO โ€” First In, First Out

Like a bank counter line โ€” first to arrive, first to be served. Enqueue (insert at rear), Dequeue (remove from front). Variants: Circular, Priority, Deque.

Enqueue/Dequeue
O(1)
Insert at
Rear
Delete at
Front
Uses
BFS, scheduling, printing
๐ŸŽฏ Linear DS โ€” Exam Key Points
  • LIFO โ†’ Stack | FIFO โ†’ Queue โ€” most tested one-liner
  • Stack uses: Undo/Redo, recursion, DFS, expression evaluation, parentheses matching
  • Queue uses: BFS, printer scheduling, bank token system, OS scheduling
  • Last node of singly linked list has next pointer = NULL
  • Circular linked list: last node’s next points to Head
  • Doubly linked list: each node has prev + next pointers (traversal both ways)
  • Array first index = 0 in most programming languages
๐ŸŒณ

Data Arranged Hierarchically / NetworkedNon-Linear Data Structures

๐ŸŒณ

Tree

Hierarchical ยท Non-Linear

Nodes connected in parent-child hierarchy. Root (top), Leaf (no children). Binary Tree: max 2 children per node. BST: left < root < right.

Root
Topmost node
Leaf
Node with no children
BST Search
O(log n) balanced
Tree with n nodes
nโˆ’1 edges
๐ŸŒ

Graph

Network of Nodes & Edges

Nodes (vertices) connected by edges. Can be directed/undirected, weighted/unweighted. A Tree is a special case of Graph (connected, acyclic).

BFS uses
Queue
DFS uses
Stack/Recursion
Adj. Matrix
O(nยฒ) space
Adj. List
O(n+e) space
๐Ÿ”‘

Hash Table

Key-Value ยท Fast Search

Stores data as key-value pairs. A hash function maps key โ†’ index. Average O(1) for search, insert, delete. Collision = two keys map to same index.

Search avg
O(1)
Search worst
O(n) โ€” many collisions
Collision fix
Chaining, Linear probing
Used in
Databases, passwords
โ›ฐ๏ธ

Heap

Complete Binary Tree ยท Priority

Max Heap: largest element at root. Min Heap: smallest at root. Used to implement Priority Queue. Insert + Delete = O(log n).

Max Heap root
Largest element
Min Heap root
Smallest element
Insert/Delete
O(log n)
Priority Queue
Implemented via Heap
TermMeaningExam Trigger
RootTopmost node of tree“Top of tree” = Root
LeafNode with no children“No children” = Leaf
HeightLongest path from root to leafSingle node height = 0 (most conventions)
BST propertyLeft < Root < RightInorder BST = sorted ascending order
Directed GraphEdges have direction (โ†’)Also called Digraph
Undirected GraphEdges have no direction (โ€”)Social network friendships
Weighted GraphEdges have values (cost/distance)Railway route map
AVL TreeSelf-balancing BST (balance factor โˆ’1, 0, 1)Always balanced, O(log n) operations
B-Tree / B+ TreeMulti-way balanced treeUsed in databases and file systems
โš–๏ธ

Most Tested TableData Structures Comparison

FeatureArrayLinked ListStackQueue
TypeLinearLinearLinear (restricted)Linear (restricted)
SizeFixedDynamicDynamicDynamic
AccessO(1) by indexO(n) traverseOnly topOnly front/rear
MemoryContinuousNon-continuousEitherEither
LogicIndexPointerLIFOFIFO
Insert middleO(n) โ€” shiftO(1) after nodeNot applicableNot applicable
Real-lifeBook rackTrain coachesStack of platesBank queue
๐Ÿ“Š

Big-O Notation โ€” Most TestedAlgorithm Complexity

Time Complexity = how long an algorithm takes as input size (n) grows. Space Complexity = how much memory it uses. Big-O notation describes the worst-case upper bound.

Complexity Order โ€” Best to Worst
O(1)
Constant
<
O(log n)
Logarithmic
<
O(n)
Linear
<
O(n log n)
Linearithmic
<
O(nยฒ)
Quadratic
<
O(2โฟ)
Exponential
<
O(n!)
Factorial
NotationNameMeaningExam Focus
O (Big-O)Upper boundWorst case โ€” maximum time takenโญโญโญโญโญ Most asked
ฮ˜ (Theta)Tight boundAverage / exact growth rateโญโญโญ
ฮฉ (Omega)Lower boundBest case โ€” minimum timeโญโญ
ComplexityExample Algorithm/OperationExam Example
O(1)Array access by index, Stack push/pop, Hash table accessarr[5] = value
O(log n)Binary Search, BST balanced searchSearch in sorted 1000 items = ~10 steps
O(n)Linear Search, Linked List traversalFind element in unsorted array
O(n log n)Merge Sort, Quick Sort (average), Heap SortBest efficient sorting for large data
O(nยฒ)Bubble Sort, Selection Sort, Insertion SortBasic/naive sorting algorithms
O(2โฟ)Recursive Fibonacci, subset enumerationExponential โ€” avoid for large n
๐Ÿ”ข

Know Complexities โ€” Very Frequently TestedSorting Algorithms

AlgorithmBest CaseAverage CaseWorst CaseSpaceStable?Type
Bubble SortO(n)O(nยฒ)O(nยฒ)O(1)โœ… YesComparison
Selection SortO(nยฒ)O(nยฒ)O(nยฒ)O(1)โŒ NoComparison
Insertion SortO(n)O(nยฒ)O(nยฒ)O(1)โœ… YesComparison
Merge SortO(n log n)O(n log n)O(n log n)O(n)โœ… YesDivide & Conquer
Quick SortO(n log n)O(n log n)O(nยฒ)O(log n)โŒ NoDivide & Conquer
Heap SortO(n log n)O(n log n)O(n log n)O(1)โŒ NoHeap-based
๐ŸŽฏ Sorting โ€” Exam Key Points
  • Bubble/Selection/Insertion = O(nยฒ) โ€” basic, slow for large data
  • Merge/Quick/Heap = O(n log n) average โ€” efficient for large data
  • Quick Sort worst case = O(nยฒ) (when pivot is always min/max)
  • Merge Sort = Divide and Conquer | Always O(n log n) โ€” most stable and reliable
  • Stable sort = maintains relative order of equal keys (Bubble, Insertion, Merge)
  • Heap Sort = uses heap data structure | Space O(1) in-place
๐ŸŒณ

All 4 Methods โ€” Exam FavouriteTree Traversal Methods

Preorder
Root โ†’ Left โ†’ Right
Memory: Root comes PRE (before children). Used for: prefix expression, copying tree
Inorder
Left โ†’ Root โ†’ Right
Gives sorted order for BST. Most tested. Used for: sorted output of BST
Postorder
Left โ†’ Right โ†’ Root
Root comes POST (after children). Used for: postfix expression, deleting tree
Level Order
Level by level (top to bottom)
Uses a Queue (BFS). Visits all nodes at each depth before going deeper
๐ŸŽฏ Traversal โ€” Exam Memory Tricks
  • Inorder BST = sorted ascending โ€” most asked single fact about BST traversal
  • Preorder = Root FIRST | Inorder = Root MIDDLE | Postorder = Root LAST
  • Level order traversal uses Queue (BFS); DFS uses Stack/recursion
  • Preorder โ†’ prefix expression | Inorder โ†’ infix | Postorder โ†’ postfix
  • BST with keys [5, 10, 15]: Inorder = 5, 10, 15 (sorted!) โ€” always verify this
๐Ÿ”‘

Fast O(1) LookupHashing & Hash Tables

Hashing = technique to map a key to an array index using a hash function, enabling O(1) average search. A Hash Table stores data as key-value pairs. Banking example: customer roll no. โ†’ customer name.

TermMeaningExample
Hash FunctionMaps key โ†’ index in hash tablehash(101) = 101 % 10 = 1
CollisionTwo different keys get the same hash indexhash(101) = hash(201) = 1
ChainingEach index stores a linked list of colliding entriesIndex 1 โ†’ [101: Ravi, 201: Priya]
Linear ProbingOn collision, try next available slotIndex 1 taken โ†’ try index 2, 3โ€ฆ
Load FactorNo. of entries / table size โ€” ideally < 0.7Too high = many collisions
โšก

All Operations โ€” Must MemoriseDS Operations Complexity Summary

Data StructureAccessSearchInsertDeleteNotes
ArrayO(1)O(n)O(n) middleO(n) middleFast access, slow middle ops
Linked ListO(n)O(n)O(1) headO(1) given nodeFast insert/delete at head
StackO(n)O(n)O(1) pushO(1) popLIFO โ€” only top accessible
QueueO(n)O(n)O(1) enqueueO(1) dequeueFIFO โ€” front/rear only
BST (balanced)O(log n)O(log n)O(log n)O(log n)Skewed BST = O(n)
Hash TableO(1) avgO(1) avgO(1) avgO(1) avgWorst case O(n) with many collisions
Heap (Max/Min)O(n)O(n)O(log n)O(log n) rootRoot access = O(1)
๐Ÿฆ

Real-World & Banking ApplicationsDS & Algorithms in Real Life

๐Ÿ“ฆ

Array

Monthly balance for 12 months, IFSC codes list, marks table (2D), interest rate slabs

๐Ÿ”—

Linked List

Bank transaction logs (frequent add/remove), browser forward/backward history, adjacency list for graphs

๐Ÿ“š

Stack

Undo/Redo in banking software, recursion, DFS traversal, expression evaluation, parentheses matching

๐Ÿšถ

Queue

Bank token/counter system, printer job scheduling, BFS, OS round-robin scheduling, call centre

๐ŸŒณ

Tree

Bank branch hierarchy (HOโ†’Zoneโ†’Regionโ†’Branch), menu structures, BST for sorted account numbers

๐ŸŒ

Graph

ATM/branch network routing, fraud detection patterns, shortest path algorithms, social networks

๐Ÿ”‘

Hash Table

Customer record indexing, password storage, database indexing, cache systems

โ›ฐ๏ธ

Priority Queue/Heap

VIP customer service first, ATM cash denomination selection, CPU job scheduling

๐Ÿ—๏ธ

B-Tree / B+ Tree

Core banking database indexing on disk, file system organisation (used in Oracle, MySQL)

๐Ÿ”„

Circular Queue

Round-robin CPU scheduling, circular token systems, ring buffer for real-time data

โ†”๏ธ

Deque

Browser history (back/forward), sliding window algorithms, input-restricted queue systems

๐Ÿ”

Binary Search

Find customer by account number in sorted file, lookup in sorted price tables

Scenario / QuestionBest Data Structure / Algorithm
Undo/Redo in bank transaction entryStack (two stacks)
Bank counter customer token systemQueue
Hierarchical branch network (HOโ†’Branch)Tree
ATM/branch route optimisationGraph + Dijkstra
Customer indexing for fast lookupHash Table
Serving VIP customers firstPriority Queue (Max Heap)
Searching sorted account recordsBinary Search
Database indexing on diskB-Tree / B+ Tree
Fraud pattern detection in accountsGraph analytics
Fixed list of 12 months’ balancesArray
BFS in graph / Level order in treeQueue
DFS in graphStack / Recursion
๐Ÿ“

Tap Any Option to Reveal AnswerMCQ Practice โ€” 50 Questions (5 Chapters)

Score: 0 / 0
CH.1Basics, Arrays & ComplexityQ.01โ€“Q.12
Q.01Basics๐Ÿ”ฅ Most Asked
A data structure is primarily used to:
โœ” Correct: B
A Data Structure is a method of organising and storing data so it can be accessed and used efficiently. Choosing the right one improves program speed and reduces memory usage.
Q.02Classification๐Ÿ”ฅ Most Asked
Which of the following is a NON-LINEAR data structure?
โœ” Correct: D โ€” Tree
Linear DS: Array, Linked List, Stack, Queue (sequential). Non-Linear DS: Tree and Graph (hierarchical/networked). Tree has parent-child hierarchy โ€” not a straight sequence.
Q.03Complexity๐Ÿ”ฅ Most Asked
In Big-O notation, O(1) means:
โœ” Correct: A โ€” Constant time
O(1) = constant time. The operation takes the same time regardless of n. Examples: array access by index, stack push/pop, hash table lookup (average). Best possible complexity.
Q.04Complexity๐Ÿ”ฅ Most Asked
Which time complexity is BEST (most efficient)?
โœ” Correct: B โ€” O(1) is best
Complexity order from best to worst: O(1) < O(log n) < O(n) < O(n log n) < O(nยฒ) < O(2โฟ) < O(n!). O(1) is constant โ€” always the fastest regardless of data size.
Q.05Array๐Ÿ”ฅ Most Asked
Accessing any element in an array by its index takes:
โœ” Correct: A โ€” O(1) constant time
Arrays store elements in contiguous memory. Since each element’s address = base_address + (index ร— size), any element can be accessed in constant time O(1) โ€” this is the biggest advantage of arrays.
Q.06Array๐Ÿ”ฅ Most Asked
Inserting an element in the MIDDLE of an array is slow because:
โœ” Correct: B โ€” Elements must be shifted
To insert in the middle of an array, all elements from the insertion point to the end must be shifted one position right โ€” O(n) time. Similarly, deletion in the middle requires shifting left.
Q.07Array
Index of the first element in an array in most programming languages is:
โœ” Correct: B โ€” Index 0
Most programming languages (C, Java, Python, JavaScript) use 0-based indexing. The first element is at index 0, last element at index nโˆ’1 for an array of n elements.
Q.08Complexity๐Ÿ”ฅ Most Asked
Big-O notation (O) represents which case of an algorithm?
โœ” Correct: C โ€” Worst case (upper bound)
Big-O (O) = worst case / upper bound. This is the most asked notation in exams. ฮ˜ (Theta) = average. ฮฉ (Omega) = best case (lower bound). O is used most because it guarantees the worst outcome.
Q.09ADT๐Ÿ”ฅ Most Asked
Which of the following is an example of an Abstract Data Type (ADT)?
โœ” Correct: C โ€” Stack
An ADT (Abstract Data Type) defines operations and behaviour without specifying implementation. Stack (push/pop), Queue (enqueue/dequeue), Tree are ADTs. Integer, Float are primitive types. Keyboard is hardware.
Q.10Complexity๐Ÿ”ฅ Most Asked
Which of the following is the correct ordering from BEST to WORST complexity?
โœ” Correct: A
The correct order is: O(1) < O(log n) < O(n) < O(n log n) < O(nยฒ) < O(2โฟ) < O(n!). Constant is best; factorial is worst. This chain is one of the most tested facts in CS exams.
Q.11Array
What is stored in a 2D array?
โœ” Correct: B โ€” Table/matrix (rows and columns)
A 2D array stores data in rows and columns โ€” like a matrix or table. Example: marks of 5 students in 3 subjects โ†’ 5ร—3 = 2D array. Used widely in banking for multi-dimensional data.
Q.12Array
A fixed-size list of 12 months for storing monthly account balances is best stored in:
โœ” Correct: A โ€” Array
When the size is fixed and known (12 months), an array is ideal. Access balance[5] = June balance in O(1). Arrays are best for fixed-size, index-based access.
CH.2Linked List, Stack & QueueQ.13โ€“Q.26
Q.13Linked List๐Ÿ”ฅ Most Asked
In a singly linked list, each node contains:
โœ” Correct: C โ€” Data + pointer to next node
Singly linked list: each node = data + next pointer. Doubly linked list: each node = data + prev + next. Last node’s next = NULL. Head pointer stores address of first node.
Q.14Linked List๐Ÿ”ฅ Most Asked
Which is NOT an advantage of linked list over array?
โœ” Correct: C โ€” Random access is NOT possible in O(1)
Linked lists do NOT support O(1) random access. To reach the k-th element, you must traverse k nodes = O(k). Arrays support O(1) access. This is the biggest disadvantage of linked lists.
Q.15Linked List๐Ÿ”ฅ Most Asked
In a circular linked list, the last node’s next pointer points to:
โœ” Correct: C โ€” Head node
In a circular linked list, the last node’s next points back to the head, forming a circle. Used for: round-robin scheduling, circular token systems.
Q.16Linked List
Which linked list is BEST for browser forward/backward history navigation?
โœ” Correct: B โ€” Doubly linked list
Doubly linked list allows traversal in BOTH directions (prev and next pointers). Perfect for browser history โ€” go back (prev pointer) or forward (next pointer) easily.
Q.17Stack๐Ÿ”ฅ Most Asked
A stack works on which principle?
โœ” Correct: B โ€” LIFO (Last In, First Out)
Stack = LIFO. The last element pushed is the first popped. Like a stack of plates โ€” the plate you put on top last is the first one you take. Memory trick: Stack of plates = LIFO.
Q.18Stack๐Ÿ”ฅ Most Asked
If elements 1, 2, 3, 4 are pushed in this order, which element is removed first by pop?
โœ” Correct: D โ€” 4 is popped first
LIFO principle: push 1, 2, 3, 4 โ†’ stack (bottom to top): [1, 2, 3, 4]. Pop removes 4 first (top element). Next pop removes 3, then 2, then 1.
Q.19Stack๐Ÿ”ฅ Most Asked
Which data structure is used for function call management and recursion?
โœ” Correct: B โ€” Stack
Function calls use a call stack. When function A calls function B, B is pushed on the stack. When B completes, it’s popped. Recursion also uses the stack โ€” each recursive call is pushed and popped in LIFO order.
Q.20Stack๐Ÿ”ฅ Most Asked
Undo operation in a text editor or banking software is best implemented using:
โœ” Correct: B โ€” Stack
Each action is pushed onto the stack. When Undo is pressed, the last action is popped and reversed (LIFO). For Undo+Redo, two stacks are used.
Q.21Queue๐Ÿ”ฅ Most Asked
A queue works on which principle?
โœ” Correct: A โ€” FIFO (First In, First Out)
Queue = FIFO. First customer to join the bank queue is first to be served. Operations: Enqueue (insert at rear), Dequeue (remove from front).
Q.22Queue๐Ÿ”ฅ Most Asked
In a queue, insertion happens at which end?
โœ” Correct: A โ€” Rear end
Queue: Insert at Rear (Enqueue) | Delete from Front (Dequeue). Remember: Join a queue at the back, served from the front โ€” FIFO.
Q.23Queue๐Ÿ”ฅ Most Asked
Which data structure is used to implement BFS (Breadth First Search)?
โœ” Correct: B โ€” Queue
BFS = Queue | DFS = Stack/Recursion. BFS visits all nodes at current depth before going deeper โ€” Queue ensures this level-by-level order. Also used for Level Order tree traversal.
Q.24Queue
A circular queue is also known as:
โœ” Correct: B โ€” Ring buffer
A circular queue is also called a Ring Buffer. The rear index wraps around: rear = (rear + 1) % size. Solves the “false overflow” problem of simple linear queues.
Q.25Queue๐Ÿ”ฅ Most Asked
A deque (Double-Ended Queue) allows:
โœ” Correct: C โ€” Both ends
A Deque (Double-Ended Queue) = insert/delete from BOTH front AND rear. More flexible than simple queue. Best implemented using a doubly linked list.
Q.26Bank App๐Ÿ”ฅ Most Asked
In a bank’s token-based customer service system, customers join and are served using:
โœ” Correct: B โ€” Queue (FIFO)
Bank token systems use a Queue. Customer joins โ†’ Enqueue (add to rear). Customer served โ†’ Dequeue (remove from front). First come, first served = FIFO principle.
CH.3Trees, BST & HeapsQ.27โ€“Q.38
Q.27Tree๐Ÿ”ฅ Most Asked
The topmost node in a tree is called:
โœ” Correct: B โ€” Root
Tree terminology: Root = topmost node. Leaf = node with no children. Internal node = has at least one child. Degree = number of children of a node.
Q.28BST๐Ÿ”ฅ Most Asked
In a Binary Search Tree (BST), the left child key is:
โœ” Correct: B โ€” Less than the parent
BST property: Left child < Parent < Right child. This property enables efficient O(log n) search in a balanced BST โ€” compare key with root, go left or right accordingly.
Q.29BST Traversal๐Ÿ”ฅ Most Asked
Inorder traversal of a BST produces elements in:
โœ” Correct: B โ€” Sorted ascending order
Inorder traversal (Left โ†’ Root โ†’ Right) of a BST always produces elements in sorted ascending order. This is the most tested property of BST. BST [5,10,15]: Inorder = 5, 10, 15.
Q.30Traversal๐Ÿ”ฅ Most Asked
Preorder traversal visits nodes in which sequence?
โœ” Correct: C โ€” Root โ†’ Left โ†’ Right
Traversal sequences: Preorder = Root-Left-Right (Root FIRST) | Inorder = Left-Root-Right | Postorder = Left-Right-Root (Root LAST).
Q.31Traversal๐Ÿ”ฅ Most Asked
Level Order traversal (BFS on tree) uses which data structure?
โœ” Correct: B โ€” Queue
Level order traversal visits all nodes at each depth before going deeper โ€” this is BFS on a tree. Uses a Queue: enqueue root, then dequeue and enqueue its children, level by level.
Q.32Tree
A tree with n nodes has how many edges?
โœ” Correct: B โ€” n โˆ’ 1 edges
A tree with n nodes always has exactly n โˆ’ 1 edges. This is a fundamental property of trees (connected acyclic graphs). Example: 5 nodes โ†’ 4 edges.
Q.33BST๐Ÿ”ฅ Most Asked
Average time complexity for search in a BALANCED BST is:
โœ” Correct: B โ€” O(log n)
Balanced BST search = O(log n). Each comparison eliminates half the remaining nodes (similar to binary search). Unbalanced/skewed BST degrades to O(n) โ€” like a linked list.
Q.34Tree Types๐Ÿ”ฅ Most Asked
Which tree is widely used in DATABASE INDEXING and FILE SYSTEMS?
โœ” Correct: C โ€” B-Tree / B+ Tree
B-Tree and B+ Tree are multi-way balanced trees specifically designed for disk storage. Oracle, MySQL, file systems all use B+ Trees for indexing โ€” they minimise disk reads by keeping more data per node.
Q.35Heap๐Ÿ”ฅ Most Asked
In a MAX Heap, the largest element is at:
โœ” Correct: B โ€” The root
Max Heap: largest element is always at the root. Min Heap: smallest element at root. Heaps are complete binary trees. Used to implement Priority Queues.
Q.36Heap๐Ÿ”ฅ Most Asked
Priority Queue is most commonly implemented using:
โœ” Correct: B โ€” Heap
Heap is the standard implementation of Priority Queue. Max Heap โ†’ dequeue always gives highest priority. Banking use: serving VIP customers first, ATM cash denomination selection.
Q.37AVL๐Ÿ”ฅ Most Asked
An AVL tree is a:
โœ” Correct: B โ€” Self-balancing BST
AVL Tree = self-balancing BST where balance factor (left height โˆ’ right height) = {โˆ’1, 0, 1} for every node. Guarantees O(log n) operations always (unlike plain BST which can degrade to O(n)).
Q.38Bank App๐Ÿ”ฅ Most Asked
In banking, to represent the hierarchical structure HO โ†’ Zones โ†’ Regions โ†’ Branches, which DS is used?
โœ” Correct: C โ€” Tree
A hierarchical parent-child relationship (HO is parent, Zones are children, Regions are grandchildren, Branches are leaves) is naturally represented by a Tree. HO = Root node.
CH.4Graphs, Hashing & SortingQ.39โ€“Q.46
Q.39Graph๐Ÿ”ฅ Most Asked
BFS (Breadth First Search) traversal of a graph uses which data structure?
โœ” Correct: B โ€” Queue
BFS = Queue. Explores all neighbours at current depth before going deeper. DFS = Stack/Recursion. Memory trick: BFS = Broad first (level by level) = Queue. DFS = Deep first = Stack.
Q.40Graph๐Ÿ”ฅ Most Asked
A Tree is a special case of a Graph that is:
โœ” Correct: B โ€” Connected and acyclic
A Tree is a special graph that is: connected (every node is reachable) and acyclic (no cycles). n nodes โ†’ nโˆ’1 edges. If you add one more edge to a tree, it creates a cycle and becomes a general graph.
Q.41Graph๐Ÿ”ฅ Most Asked
For a SPARSE graph (few edges), which representation is more memory-efficient?
โœ” Correct: B โ€” Adjacency List for sparse graphs
Adjacency Matrix = O(nยฒ) space (wastes space when few edges). Adjacency List = O(n+e) โ€” only stores existing edges. For sparse graphs (few edges), adjacency list is much more efficient.
Q.42Hashing๐Ÿ”ฅ Most Asked
Collision in a hash table means:
โœ” Correct: A โ€” Two keys get same index
Collision = two different keys map to the same index in the hash table. Solved by: Chaining (linked list at each index) or Open Addressing (linear probing, quadratic probing).
Q.43Hashing๐Ÿ”ฅ Most Asked
Average time complexity for search in a well-designed hash table is:
โœ” Correct: A โ€” O(1) average
Hash table average search = O(1). The hash function directly maps key to index โ€” no traversal needed. Worst case = O(n) when many collisions. Good hash function + proper table size keeps average at O(1).
Q.44Sorting๐Ÿ”ฅ Most Asked
Which sorting algorithms have worst-case O(nยฒ) complexity?
โœ” Correct: A โ€” Bubble, Selection, Insertion
Basic/naive sorts = O(nยฒ) worst case: Bubble, Selection, Insertion. Efficient sorts = O(n log n): Merge, Heap (always), Quick (average). Quick Sort worst case = O(nยฒ) when pivot is always min/max.
Q.45Sorting๐Ÿ”ฅ Most Asked
Merge Sort uses which algorithm design technique?
โœ” Correct: B โ€” Divide and Conquer
Merge Sort = Divide and Conquer. Divides array into halves, sorts each half, then merges. Always O(n log n). Stable sort. Requires O(n) extra space. Quick Sort also uses Divide and Conquer.
Q.46Sorting
A “stable sort” means:
โœ” Correct: A โ€” Maintains relative order of equal keys
Stable sort = preserves the relative order of elements with equal keys. Stable: Bubble, Insertion, Merge. Unstable: Selection, Quick, Heap. Important when sorting records on multiple keys.
CH.5Applied & Banking ApplicationsQ.47โ€“Q.50
Q.47Applied๐Ÿ”ฅ Most Asked
Which mapping is CORRECT?
โœ” Correct: A
Essential mappings: LIFO โ†’ Stack (plates) | FIFO โ†’ Queue (bank line) | Priority โ†’ Heap (VIP service). These three are the most tested data structure classification facts.
Q.48Applied๐Ÿ”ฅ Most Asked
For real-time fraud detection in banking using suspicious transaction PATTERNS between accounts, the best data structure is:
โœ” Correct: C โ€” Graph
Fraud detection involving relationships between accounts (A sends money to B who sends to Cโ€ฆ) = Graph problem. Graph algorithms detect suspicious cycles, clusters, and patterns in financial networks.
Q.49Applied๐Ÿ”ฅ Most Asked
For core banking DATABASE INDEXING on disk (like MySQL, Oracle), which tree is preferred?
โœ” Correct: C โ€” B-Tree / B+ Tree
B-Tree and B+ Tree are the standard for database and filesystem indexing. They store more keys per node (minimising disk reads), handle large datasets efficiently, and stay balanced automatically.
Q.50Applied๐Ÿ”ฅ Most Asked
Which statement is MOST accurate about data structures in banking technology?
โœ” Correct: C
Data Structures are everywhere in banking: Array (monthly data), Queue (token system), Stack (undo/redo), Tree (org hierarchy, DB indexes), Graph (fraud detection, routing), Hash (customer lookup), Heap (priority). All DS are relevant!
โšก

Last-Minute PrepQuick Revision Flash Cards

๐Ÿ“ฆ Array

  • Fixed size, continuous memory
  • Access by index = O(1)
  • Insert/delete middle = O(n) (shifting)
  • First index = 0
  • Best for: fixed-size indexed data

๐Ÿ”— Linked List

  • Nodes + pointers, dynamic size
  • Insert at head = O(1)
  • Search/access = O(n)
  • Singly: next only | Doubly: prev+next | Circular: last โ†’ head
  • Best for: frequent inserts/deletes

๐Ÿ“š Stack

  • LIFO = Last In, First Out
  • Push/Pop = O(1)
  • Overflow: top = maxSizeโˆ’1 | Underflow: top = โˆ’1
  • Uses: Undo, recursion, DFS, expression eval

๐Ÿšถ Queue

  • FIFO = First In, First Out
  • Enqueue (rear), Dequeue (front) = O(1)
  • Uses: BFS, bank tokens, scheduling
  • Circular Queue = Ring Buffer

๐ŸŒณ Tree / BST

  • Root = top, Leaf = no children
  • n nodes โ†’ nโˆ’1 edges
  • BST: Left < Root < Right
  • Inorder BST = sorted output
  • Balanced BST = O(log n) all ops

๐ŸŒณ Tree Traversal

  • Preorder = Root โ†’ L โ†’ R
  • Inorder = L โ†’ Root โ†’ R (sorted for BST)
  • Postorder = L โ†’ R โ†’ Root
  • Level order = uses Queue (BFS)

๐ŸŒ Graph

  • Vertices + Edges (directed/undirected)
  • BFS โ†’ Queue | DFS โ†’ Stack
  • Sparse graph โ†’ Adjacency List
  • Dense graph โ†’ Adjacency Matrix
  • Tree = connected + acyclic graph

๐Ÿ”‘ Hashing

  • Hash function โ†’ key to index
  • Search avg = O(1)
  • Collision = same index for 2 keys
  • Fix: Chaining or Linear Probing

๐Ÿ“Š Big-O Order

  • O(1) < O(log n) < O(n)
  • < O(n log n) < O(nยฒ)
  • < O(2โฟ) < O(n!)
  • Big-O = worst case

๐Ÿ” Searching

  • Linear Search = O(n) โ€” any data
  • Binary Search = O(log n) โ€” sorted only
  • Binary on 1000 items โ‰ˆ 10 steps

๐Ÿ”ข Sorting

  • Bubble/Selection/Insertion = O(nยฒ)
  • Merge/Quick avg/Heap = O(n log n)
  • Quick Sort worst = O(nยฒ)
  • Merge Sort = Divide & Conquer, stable

๐Ÿฆ Banking DS Map

  • Queue โ†’ bank token system
  • Stack โ†’ Undo/Redo operations
  • Tree โ†’ HO โ†’ Branch hierarchy
  • Graph โ†’ fraud detection, routing
  • B+ Tree โ†’ database indexing
  • Hash โ†’ customer lookup
๐Ÿ“Œ Must-Know Keywords
LIFO = StackFIFO = Queue Inorder BST = SortedBFS = Queue DFS = StackO(1) = Best Binary Search = O(log n)Merge Sort = O(n log n) B+ Tree = Database IndexHash Table = O(1) avg AVL = Self-Balancing BSTHeap = Priority Queue