Tribhuvan University
Faculty of Management
Office of the Dean
Official Model Question Paper / Dean's Office Blueprint
Candidates are required to give their answers in their own words as far as practicable. The figures in the margin indicate full marks.
Group A
Brief Answer Questions. Attempt ALL questions.
[5 × 2 = 10]- [2]
Define Big-O (
), Big-Omega ( ), and Big-Theta ( ) asymptotic notations with their mathematical definitions. View model solution
Answer:
- Big-O (
- Asymptotic Upper Bound): if there exist positive constants and such that: Represents the worst-case ceiling on algorithm running time. - Big-Omega (
- Asymptotic Lower Bound): if there exist positive constants and such that: Represents the best-case floor on algorithm running time. - Big-Theta (
- Asymptotically Tight Bound): if there exist positive constants and such that:
- Big-O (
- [2]
What is a Circular Queue? State why it is preferred over a linear array queue and write the condition for queue full.
View model solution
Answer:
- Circular Queue: A linear FIFO data structure where the last position of the underlying array connects back to the first position, forming a circular ring.
- Advantage: Overcomes the false overflow problem of linear array queues, where vacated slots at the front after dequeuing cannot be reused even if free memory exists.
- Queue Full Condition: Using modular arithmetic with array capacity
MAX: Queue empty condition:.
- [2]
Differentiate between a Singly Linked List (SLL) and a Doubly Linked List (DLL) in terms of memory overhead and operations.
View model solution
Answer:
Parameter Singly Linked List (SLL) Doubly Linked List (DLL) Node Structure Contains data field and a single pointer ( next).Contains data field and two pointers ( prevandnext).Memory Overhead Lower memory overhead (1 pointer per node). Higher memory overhead (2 pointers per node). Traversal Strictly unidirectional (forward traversal only). Bidirectional (can traverse both forward and backward). Node Deletion Requires traversal from head to locate previous node ( ). Can delete a given node in time without needing predecessor pointer. - [2]
Define the Balance Factor of an AVL Tree and state the permitted values for a node to remain balanced.
View model solution
Answer:
- Balance Factor (
): In an AVL self-balancing binary search tree, the Balance Factor of any node is defined as the height difference between its left subtree and right subtree: - Permitted Values: An AVL tree strictly enforces that for every node in the tree:
If an insertion or deletion causesto become , tree rotations (LL, RR, LR, or RL) are performed immediately to restore balance.
- Balance Factor (
- [2]
Compare Breadth-First Search (BFS) and Depth-First Search (DFS) graph traversals in terms of underlying data structures and use cases.
View model solution
Answer:
Parameter Breadth-First Search (BFS) Depth-First Search (DFS) Data Structure Used Queue (FIFO) Stack (LIFO) or Function Call Recursion Search Strategy Explores all neighboring vertices at current depth before moving deeper. Explores as deep as possible along each branch before backtracking. Shortest Path Guarantees finding the shortest path on unweighted graphs. Does not guarantee finding the shortest path. Primary Use Cases Shortest path on unweighted graphs, peer-to-peer networking, crawler level-order. Topological sorting, detecting cycles in directed graphs, maze solving.
Group B
Descriptive Answer Questions. Attempt any THREE questions.
[3 × 10 = 30]- [10]
Analyze the application of stacks in expression conversion: a) Convert the following Infix Expression into Postfix Notation using a stack:
wheredenotes exponentiation. Provide a complete step-by-step tabular trace showing Token, Operator Stack, and Output String. (6 Marks) b) Write a complete algorithm in pseudocode/C to evaluate a postfix expression containing multi-digit integers. (4 Marks) View model solution
Stack-Based Infix to Postfix Conversion and Evaluation
a) Tabular Trace of Infix to Postfix Conversion
- Expression:
- Precedence Hierarchy:
(Exponentiation, Right-to-Left, highest) (Left-to-Right) (Left-to-Right) (lowest inside stack).
Step Current Token Action Taken Operator Stack Postfix Output Expression 1 (Push to stack (2 AAppend to output (A3 +Push to stack ( +A4 BAppend to output ( +A B5 )Pop until (A B +6 *Push to stack *A B +7 (Push to stack * (A B +8 CAppend to output * (A B + C9 -Push to stack * ( -A B + C10 DAppend to output * ( -A B + C D11 )Pop until (*A B + C D -12 /Same precedence as *, pop*, push//A B + C D - *13 (Push to stack / (A B + C D - *14 EAppend to output / (A B + C D - * E15 +Push to stack / ( +A B + C D - * E16 FAppend to output / ( +A B + C D - * E F17 ^Higher precedence than +, push/ ( + ^A B + C D - * E F18 GAppend to output / ( + ^A B + C D - * E F G19 )Pop until ((pop^, then+)/A B + C D - * E F G ^ +20 End Pop remaining operators (pop /)[Empty]A B + C D - * E F G ^ + /- Final Postfix String:
b) Postfix Evaluation Algorithm in C
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> #define STACK_SIZE 100 typedef struct { int data[STACK_SIZE]; int top; } OperandStack; void push(OperandStack *s, int val) { s->data[++(s->top)] = val; } int pop(OperandStack *s) { return s->data[(s->top)--]; } int evaluate_postfix(const char *exp) { OperandStack stack; stack.top = -1; for (int i = 0; exp[i] != '\0'; i++) { if (isspace(exp[i])) continue; // Multi-digit operand parsing if (isdigit(exp[i])) { int val = 0; while (isdigit(exp[i])) { val = (val * 10) + (exp[i] - '0'); i++; } i--; // adjust loop increment push(&stack, val); } else { // Operator: pop two operands int op2 = pop(&stack); int op1 = pop(&stack); switch (exp[i]) { case '+': push(&stack, op1 + op2); break; case '-': push(&stack, op1 - op2); break; case '*': push(&stack, op1 * op2); break; case '/': push(&stack, op1 / op2); break; case '^': push(&stack, (int)pow(op1, op2)); break; } } } return pop(&stack); } - Expression:
- [10]
Examine Binary Search Trees (BST) and AVL Trees: a) Detail the three cases of node deletion in a standard BST (leaf node, single child, and two children replaced by in-order successor). (4 Marks) b) Construct an AVL Tree by inserting the following key sequence into an initially empty tree:
[50, 20, 60, 10, 8, 15, 30, 25]Illustrate every intermediate unbalance, identify the rotation type (LL, RR, LR, RL), and draw the resulting balanced tree after each rotation. (6 Marks)View model solution
BST Deletion and AVL Tree Construction Step-by-Step
a) Three Cases of BST Node Deletion
- Case 1 (Node is a Leaf): The node has no children. Deletion is trivial: the parent pointer to this node is set to
NULL, and the node’s memory is deallocated (pointer update). - Case 2 (Node has Exactly One Child): The node has either a left child or a right child. The parent’s pointer is updated to point directly to the node’s single child, bypassing the deleted node.
- Case 3 (Node has Two Children):
- Find the node’s In-order Successor (the smallest node in its right subtree) OR In-order Predecessor (largest node in its left subtree).
- Copy the value of the in-order successor into the target node.
- Recursively delete the in-order successor from the right subtree (which falls into Case 1 or Case 2, since the successor can have at most one child).
b) AVL Tree Construction: Sequence
[50, 20, 60, 10, 8, 15, 30, 25]- Insert 50, 20, 60:
- Balanced. Root 50 (
), left child 20 ( ), right child 60 ( ).
- Balanced. Root 50 (
- Insert 10:
- Inserted at
. . Balanced.
- Inserted at
- Insert 8 (Triggers LL Rotation):
- Inserted at
. - Tree path:
. (unbalanced at node 20, Left-Left violation). - Perform LL Rotation at Node 20:
- Node 10 becomes parent of 20 and 8.
- Subtree at 50 left becomes: 10 (root), 8 (left), 20 (right).
- Tree is balanced.
- Inserted at
- Insert 15 (Triggers LR Rotation):
- Inserted at
. (Node 50 is unbalanced). - Path from 50: Left child is 10, right child of 10 is 20
LR Violation. - Perform LR Rotation at Node 50:
- First, rotate Left on 10: 20 becomes left child of 50, 10 becomes left child of 20, 15 becomes right child of 10.
- Second, rotate Right on 50: 20 becomes new root of entire tree!
- Left child of 20 is 10 (with children 8, 15); Right child of 20 is 50 (with child 60).
- Tree is balanced!
- Inserted at
- Insert 30:
- Inserted at
. Balanced.
- Inserted at
- Insert 25 (Triggers RL Rotation):
- Inserted at
. - Path from 50: Left child is 30, left child of 30 is 25.
- Node 30 has
. Node 50 has left height 2, right height 1 . - Let’s check Root 20: Left subtree height is 2 (nodes 10, 8, 15). Right subtree height is 3 (nodes 50, 30, 25).
. Balanced! - Node 50 has
. - Complete balanced tree!
- Inserted at
Final Balanced AVL Structure
20 (BF = -1) / \ 10 (BF=0) 50 (BF = +1) / \ / \ 8 15 30 60 / 25Every node satisfies
. Search complexity guaranteed . - Case 1 (Node is a Leaf): The node has no children. Deletion is trivial: the parent pointer to this node is set to
- [10]
Compare MergeSort and HeapSort: a) Formulate the MergeSort divide-and-conquer recurrence relation and prove its time complexity
using the Master Theorem. (5 Marks) b) Define the Max-Heap Property. Detail the max_heapify()procedure, explain how a heap is built inlinear time, and trace HeapSort sorting an array in-place. (5 Marks) View model solution
MergeSort vs. HeapSort: Recurrences and Heap Mechanics
a) MergeSort Divide-and-Conquer Recurrence and Master Theorem Proof
1. Recurrence Formulation
MergeSort divides an array of size
into two equal subproblems of size , recursively sorts each half, and merges the two sorted lists in linear time : 2. Proof via Master Theorem
The generalized Master Theorem recurrence has the form:
where(number of subproblems), (subproblem reduction factor), and . - Evaluate the critical ratio:
- Compare
with : - This satisfies Case 2 of the Master Theorem (
): MergeSort runs intime across all cases (best, average, and worst).
b) HeapSort and Max-Heap Mechanics
1. Max-Heap Property
A complete binary tree where for every non-root node
with parent : The maximum element in the dataset is always stored at the root (Arr[0]).2.
max_heapify(Arr, n, i)Procedure- Identify left child
and right child . - Find the largest among
Arr[i],Arr[l], andArr[r]. - If largest
, swap Arr[i]withArr[largest]and recursively callmax_heapify(Arr, n, largest)down the tree (height).
3. Why
build_max_heapruns inLinear Time Calling
max_heapifyon all internal nodes fromdown to 0: 4. In-Place HeapSort Routine
- Build Max-Heap from unsorted input (
). - For
down to 1: - Swap root
Arr[0](maximum) with last leafArr[i]. - Reduce heap size by 1 (
). - Run
max_heapify(Arr, i, 0)on the new root to restore max-heap property ().
- Swap root
- Resulting array is sorted in ascending order in
time and auxiliary space.
- Evaluate the critical ratio:
- [10]
Examine Shortest Path and Minimum Spanning Tree (MST) Graph Algorithms: a) Detail Dijkstra’s Single-Source Shortest Path Algorithm. Trace the algorithm step-by-step to find the shortest path from source vertex
to all vertices in a directed weighted graph with vertices and edges: . Show the distance array after each vertex extraction. (6 Marks) b) Compare Prim’s Algorithm and Kruskal’s Algorithm for constructing a Minimum Spanning Tree. (4 Marks) View model solution
Dijkstra Shortest Path Algorithm and MST Comparison
a) Dijkstra Single-Source Shortest Path Trace
1. Graph Specification
- Vertices:
, Source = . - Directed Weighted Edges:
- From
: - From
: - From
: - From
:
- From
2. Step-by-Step Algorithm Execution Trace
Step Visited Vertex Relaxed Outgoing Edges Tentative Distances Predecessors 0 (Init) None Initialize source distance , others 1 (dist 0) Relax <br>Relax 2 (dist 2) Relax <br>Relax <br>Relax 3 (dist 3) Relax 4 (dist 8) Relax 5 (dist 10) No unvisited outgoing edges Finalized 3. Final Shortest Paths from Source
- To
: Distance = 0 | Path: - To
: Distance = 3 | Path: - To
: Distance = 2 | Path: - To
: Distance = 8 | Path: - To
: Distance = 10 | Path:
b) Prim’s vs. Kruskal’s Minimum Spanning Tree Algorithms
Parameter Prim’s Algorithm Kruskal’s Algorithm Growth Strategy Vertex-based: Grows a single continuous tree outward from an arbitrary start vertex. Edge-based: Adds lowest-weight edge across the entire graph that does not form a cycle. Data Structures Priority Queue / Min-Heap for vertex distance keys. Disjoint Set Union (DSU / Union-Find) with path compression. Graph Density Preference Preferred for Dense Graphs ( ), running in or . Preferred for Sparse Graphs ( ), running in . Intermediate State Always forms a valid single connected tree at every step. May form a disconnected forest of trees that merges at the final steps. - Vertices:
Group C
Comprehensive Answer / Case Analysis Question. Attempt ALL questions.
[1 × 20 = 20]- [20]
Systems Engineering Case Study: Tribhuvan International Airport (TIA) Real-Time Baggage Routing, Flight Scheduling, and Passenger Dispatch Engine
Civil Aviation Authority of Nepal (CAAN) is replacing the automated flight operations and baggage logistics management systems at TIA Kathmandu:
- Operational Requirements:
- VIP & Emergency Boarding Dispatch: Emergency humanitarian flights and VIP diplomatic aircraft must be dispatched dynamically based on priority score, where highest-priority flights preempt lower-priority departures.
- Passenger Boarding Pass Verification: High-throughput security gates scan passport numbers to verify passenger identity, check flight status, and assign gates in sub-millisecond time.
- Automated Inter-Terminal Baggage Conveyor System: Luggage containers must be routed across a network of 25 conveyor junctions and transfer chutes to find the least transit-time path from check-in counters to aircraft cargo holds.
- Performance Criteria: During festive peak seasons (Dashain/Tihar), system load spikes to 120,000 passenger lookups and 45,000 routed bags daily without database stalls.
Questions: a) Formulate the Abstract Data Type (ADT) and data structure design: Select and justify the optimal data structures for: (i) Emergency Flight Dispatch, (ii) Passenger Verification by Passport, and (iii) Conveyor Baggage Routing. Analyze the time and space complexity of each. (6 Marks) b) Implement the real-time luggage pathfinding routing engine in Java or C using Dijkstra’s algorithm. Write complete, robust code implementing the graph node structure, adjacency list representation, priority queue edge relaxations, and destination route reconstruction. (7 Marks) c) Analyze Hash Table engineering and collision resolution for passenger lookups: Contrast Separate Chaining versus Open Addressing with Double Hashing. Formulate the load factor threshold (
), detail dynamic rehashing overhead, and explain how to prevent worst-case hash degradation. (7 Marks) View model solution
Systems Engineering Solution: TIA Airport Logistics and Flight Dispatch Engine
a) Data Structure Selection and Complexity Justification
1. VIP & Emergency Flight Dispatch: Max-Heap Priority Queue
- Justification: Aircraft departures require dynamic priority management where emergency relief and VIP aircraft can arrive at arbitrary times with higher priority scores than scheduled flights. A binary Max-Heap allows extracting the highest priority flight in
time and inserting newly scheduled flights in time ( amortized). - Complexity: Time: Insert
, Extract-Max , Peek . Space: contiguous array.
2. Passenger Boarding Pass Verification: Hash Table with Separate Chaining
- Justification: Security turnstiles require instantaneous, near-constant-time passport lookups (
average time) to prevent passenger bottlenecks. Keys are hashed 9-character passport numbers. - Complexity: Time: Search/Insert
average, worst-case. Space: where is bucket capacity.
3. Inter-Terminal Baggage Conveyor Routing: Directed Weighted Graph with Adjacency List
- Justification: Conveyor junctions and chutes form a network with unidirectional belt segments and variable transit times (weights). An adjacency list representation is space-optimal for sparse transportation graphs (
). - Complexity: Space:
. Pathfinding (Dijkstra): Time with Min-Heap.
b) Real-Time Conveyor Routing Implementation in Java (Dijkstra)
import java.util.*; class Edge { int target; int weightSeconds; public Edge(int target, int weightSeconds) { this.target = target; this.weightSeconds = weightSeconds; } } class NodeEntry implements Comparable<NodeEntry> { int node; int cost; public NodeEntry(int node, int cost) { this.node = node; this.cost = cost; } @Override public int compareTo(NodeEntry other) { return Integer.compare(this.cost, other.cost); } } public class BaggageRoutingEngine { private int numJunctions; private List<List<Edge>> adjList; public BaggageRoutingEngine(int numJunctions) { this.numJunctions = numJunctions; adjList = new ArrayList<>(numJunctions); for (int i = 0; i < numJunctions; i++) { adjList.add(new ArrayList<>()); } } public void addConveyorSegment(int u, int v, int transitSeconds) { adjList.get(u).add(new Edge(v, transitSeconds)); } public List<Integer> findFastestBaggageRoute(int startJunction, int destinationHold) { int[] dist = new int[numJunctions]; int[] parent = new int[numJunctions]; Arrays.fill(dist, Integer.MAX_VALUE); Arrays.fill(parent, -1); PriorityQueue<NodeEntry> pq = new PriorityQueue<>(); dist[startJunction] = 0; pq.offer(new NodeEntry(startJunction, 0)); while (!pq.isEmpty()) { NodeEntry current = pq.poll(); int u = current.node; if (current.cost > dist[u]) continue; // Stale queue entry if (u == destinationHold) break; // Reached destination for (Edge edge : adjList.get(u)) { int v = edge.target; int weight = edge.weightSeconds; if (dist[u] + weight < dist[v]) { dist[v] = dist[u] + weight; parent[v] = u; pq.offer(new NodeEntry(v, dist[v])); } } } // Reconstruct Optimal Conveyor Path List<Integer> path = new ArrayList<>(); if (dist[destinationHold] == Integer.MAX_VALUE) { return path; // Unreachable } for (int curr = destinationHold; curr != -1; curr = parent[curr]) { path.add(curr); } Collections.reverse(path); return path; } }
c) Hash Table Engineering, Collision Resolution, and Load Factors
1. Separate Chaining vs. Open Addressing with Double Hashing
- Separate Chaining: Each hash table slot contains a linked list or balanced red-black tree (as in Java 8+
HashMap). If collision occurs, the element is appended to the bucket chain.- Advantage for Airport: Never runs out of slots; performance degrades gracefully even if load factor momentarily exceeds 1.0.
- Open Addressing (Double Hashing): All elements reside directly within the array. On collision, probe sequence uses a secondary hash function:
. - Disadvantage: Sensitive to clustering; table cannot exceed 100% capacity; deletion requires tombstone markers.
2. Load Factor Threshold (
) and Dynamic Rehashing - Load Factor:
- When
, probability of hash collisions increases exponentially, causing lookup times to degrade from toward . - Dynamic Rehashing: When
reaches 0.75, the engine allocates a new bucket array of size , recalculates hash indices, and migrates all existing records into the new table. The resizing cost is amortized across thousands of subsequent fast insertions ( amortized).
3. Preventing Worst-Case
Hash Flooding Attacks If malicious actors submit forged passport numbers that collide on the exact same hash bucket (algorithmic complexity attack):
- Implement Universal Hashing (choosing random hash multipliers at startup).
- Convert buckets with
elements from linked lists into Red-Black balanced trees, guaranteeing worst-case lookup latency of rather than .
- Operational Requirements: