Chapter 5
Data Structure and Algorithms
TU BIM past exam questions
Past questions and answers
22 questions set from this chapter. Most repeated first.
- 2023 AD Model · 1 mark
Define abstract data type.
Answer
An abstract data type (ADT) is a mathematical model of a data structure that specifies the data it stores and the operations that can be performed on it, without saying how they are implemented. The user sees only the interface (e.g. push, pop for a stack), while the implementation (array or linked list) stays hidden.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
What are the advantages of doubly linked list over single linked list?
Answer
- It can be traversed in both directions (forward using
next, backward usingprev). - A node can be deleted given only a pointer to that node, since its predecessor is reachable through
prev(no need to search for the previous node). - Insertion before a given node is easy and takes time.
- Operations at the tail (insert or delete last node) are efficient when a tail pointer is kept.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
Define skip list.
Answer
A skip list is a probabilistic data structure made of several layers of sorted linked lists. The bottom layer holds all the elements, and each higher layer is a sparser "express lane" that skips over many elements of the layer below. Search, insertion and deletion take expected time, similar to a balanced tree.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
List the applications of stack?
Answer
- Function call management and recursion (call stack)
- Expression evaluation and conversion (infix to postfix/prefix, postfix evaluation)
- Checking balanced parentheses
- Undo/redo operations in editors
- Backtracking (e.g. maze solving) and depth-first search
- Browser back-button history
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
Which is more efficient a binary search or a linear search? Justify your answer on the basis of time complexity.
Answer
Binary search is more efficient (for sorted data).
- Linear search checks elements one by one, so its worst and average time complexity is .
- Binary search halves the search range at each step, so its worst-case time complexity is .
For , linear search needs up to comparisons while binary search needs about . The only requirement is that the list must be sorted.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
What is tail recursion?
Answer
A recursion is tail recursion when the recursive call is the very last operation performed by the function, so nothing remains to be done after the call returns. Such calls can be converted into a loop (tail-call optimisation), saving stack space. Example:
int fact(int n, int acc) {
if (n <= 1) return acc;
return fact(n - 1, n * acc); /* last statement is the call */
}
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
List out the practical applications of tree data structure?
Answer
- File system directory structure
- HTML/XML DOM representation
- Binary search trees for fast searching and sorting
- Heaps for priority queues and heap sort
- Expression trees in compilers
- Decision trees and game trees in AI
- Routing tables and tries (autocomplete, dictionaries)
- B-trees and B+ trees for database indexing
- Huffman trees for data compression
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
Define max heap with example.
Answer
A max heap is a complete binary tree in which the value of every node is greater than or equal to the values of its children, so the largest element is at the root.
Example: the array represents
50
/ \
30 40
/ \ /
10 20 35
Each parent (; ; ) is at least as large as its children.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
What do you mean by adjacency matrix?
Answer
An adjacency matrix is a way of representing a graph with vertices as an matrix , where (or the edge weight) if there is an edge from vertex to vertex , and (or ) otherwise. For an undirected graph the matrix is symmetric. It needs space and allows checking for an edge in time.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 1 mark
What is shortest path problem?
Answer
The shortest path problem is the problem of finding a path between two vertices (or from one source to all other vertices) in a weighted graph such that the sum of the edge weights along the path is minimum. It is solved with algorithms such as Dijkstra's (non-negative weights), Bellman-Ford and Floyd-Warshall.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
Write an algorithm or function for pop operation in stack.
Answer
Algorithm POP (array implementation, top initially )
- If
top == -1, print "Stack underflow" and stop. - Set
item = stack[top]. - Set
top = top - 1. - Return
item.
#define MAX 100
int stack[MAX];
int top = -1;
int pop() {
int item;
if (top == -1) {
printf("Stack underflow\n");
return -1;
}
item = stack[top];
top--;
return item;
}
Time complexity is .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
Write a function or an algorithm for enqueue operation in circular queue.
Answer
Algorithm ENQUEUE (circular queue of size MAX, front = rear = -1 initially)
- If
(rear + 1) % MAX == front, print "Queue overflow" and stop. - If
front == -1, setfront = 0(first element). - Set
rear = (rear + 1) % MAX. - Set
queue[rear] = item.
#define MAX 5
int queue[MAX];
int front = -1, rear = -1;
void enqueue(int item) {
if ((rear + 1) % MAX == front) {
printf("Queue overflow\n");
return;
}
if (front == -1)
front = 0;
rear = (rear + 1) % MAX;
queue[rear] = item;
}
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
How linked list can be considered as an abstract data type?
Answer
An ADT defines a set of data and the operations on it, hiding the implementation. A linked list fits this definition:
- Data: an ordered collection of elements (nodes holding data and a link).
- Operations: insert (at beginning, end, or position), delete, search, traverse, and check whether it is empty.
- Hidden implementation: the user calls
insert()ordelete()without needing to know how pointers are rearranged. The same list interface could be implemented with arrays or pointers.
Hence a linked list is an ADT (the "list ADT") whose pointer-based implementation is separate from its interface.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
Write an algorithm or function for selection sort.
Answer
Algorithm. For to : find the index min of the smallest element in a[i..n-1], then swap a[i] with a[min].
void selectionSort(int a[], int n) {
int i, j, min, temp;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++) {
if (a[j] < a[min])
min = j;
}
if (min != i) {
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
Time complexity is in all cases.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
Write a recursive algorithm or function to compute gcd of any two positive integers.
Answer
Using Euclid's algorithm: if , otherwise .
Algorithm GCD(a, b)
- If
b == 0, returna. - Else return
GCD(b, a % b).
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
For example, .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 3 marks
Convert the following infix expression to equivalent postfix expression: .
Answer
Expression:
| Symbol | Stack | Postfix output |
|---|---|---|
| ( | ( | |
| A | ( | A |
| * | ( * | A |
| B | ( * | AB |
| ) | AB* | |
| + | + | AB* |
| ( | + ( | AB* |
| C | + ( | AB*C |
| * | + ( * | AB*C |
| D | + ( * | AB*CD |
| ) | + | ABCD |
| end | ABCD+ |
Postfix expression:
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 5 marks
Why computational complexity is performed? Illustrate the concept of big Oh notation with pictorial representation.
Answer
Why complexity analysis is performed.
- To measure how the running time (time complexity) and memory use (space complexity) of an algorithm grow with input size .
- To compare algorithms independently of hardware, language and compiler.
- To choose the most efficient algorithm for large inputs and predict its scalability.
Big Oh notation. if there exist positive constants and such that
It gives an asymptotic upper bound on the growth rate (worst case).
Pictorial representation.
time
| c*g(n)
| /
| / . f(n)
| / .
| / .
| /.
| /.
| .
| /
|_____/_____|______________ n
n0
For the curve always stays below .
Example: for , so with , .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 5 marks
Define doubly linked list. Write an algorithm or function to delete a last node of doubly linked list.
Answer
Definition. A doubly linked list is a linear data structure in which each node has three fields: prev (pointer to the previous node), data, and next (pointer to the next node). It can be traversed in both directions.
NULL <- [prev|10|next] <-> [prev|20|next] <-> [prev|30|next] -> NULL
Algorithm: delete the last node
- If
head == NULL, print "List empty" and stop. - If
head->next == NULL(only one node), freehead, sethead = NULL, and stop. - Set
temp = head. - While
temp->next != NULL, settemp = temp->next. (tempis now the last node.) - Set
temp->prev->next = NULL. - Free
temp.
struct node {
int data;
struct node *prev, *next;
};
void deleteLast(struct node **head) {
struct node *temp = *head;
if (temp == NULL) {
printf("List empty\n");
return;
}
if (temp->next == NULL) { /* single node */
free(temp);
*head = NULL;
return;
}
while (temp->next != NULL)
temp = temp->next;
temp->prev->next = NULL;
free(temp);
}
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 5 marks
Sort the following data values using the concept of quick sort: 11,13,8,15,20,22,4,3,26,2.
Answer
Quick sort with the first element as pivot. Data: .
Pass 1 (pivot 11). Move i right to the first element greater than the pivot and j left to the first element not greater than it, and swap them until they cross:
- swap and :
- swap and :
- swap and :
- pointers cross; swap the pivot with :
Left part , pivot 4: . Then with pivot 3 gives . So the left part sorts to .
Right part , pivot 22: .
- , pivot 13: , and sorts to .
So the right part sorts to .
Sorted output:
Average time complexity is ; the worst case is .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 5 marks
List out the collision resolution technique and explain how linear probing is used to resolve the hash collision.
Answer
A collision occurs when two keys hash to the same index of the hash table.
Collision resolution techniques
- Open addressing (closed hashing): linear probing, quadratic probing, double hashing.
- Separate chaining (open hashing): each table slot holds a linked list of all keys that hash to it.
- Rehashing (resizing the table and re-inserting keys).
Linear probing. If the slot is occupied, the following slots are tried one by one, wrapping around the table, until an empty slot is found:
Searching follows the same probe sequence until the key or an empty slot is found.
Example. Table size , , insert :
- , so it goes to slot 1.
- , so it goes to slot 0.
- , so it goes to slot 6.
- , but slot 1 is occupied, so try slot 2, which is free, and place it there.
Linear probing is simple and cache-friendly, but it suffers from primary clustering (long runs of filled slots).
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 10 marks
Why it is necessary to balance the binary search tree? Differentiate between binary search tree and multiway search tree? Construct B-tree of order 5 for following data values: 20,40,80,30,120,90,50,140,110,60,100,200,190,250,60,130,220,170.
Answer
Why balance a binary search tree. In a BST, search, insertion and deletion take time proportional to the height . If keys arrive in sorted order the tree degenerates into a linked list with and operations cost . A balanced tree keeps , so all operations take time (e.g. AVL, red-black trees).
Binary search tree vs multiway search tree
| Binary search tree | Multiway search tree |
|---|---|
| Each node holds 1 key and has at most 2 children | Each node holds many keys and has more than 2 children |
| Height is larger ( for balanced) | Height is smaller (about ) |
| Suited to main memory | Suited to disk-based storage and databases (fewer disk accesses) |
| Examples: BST, AVL tree | Examples: 2-3 tree, B-tree, B+ tree |
B-tree of order 5. Each node has at most 4 keys and 5 children; every non-root node has at least 2 keys. When a node gets 5 keys, it splits at the median, which moves up. The duplicate key 60 (inserted second time) is ignored.
- Insert : leaf .
- Insert : overflow; median 40 moves up. Root with leaves and .
- Insert : right leaf becomes .
- Insert : overflow; median 90 moves up. Root ; leaves , , .
- Insert : leaves , , .
- Insert : overflow; median 120 moves up. Root ; leaves , , , .
- Insert : last leaf becomes . The second is a duplicate and is ignored.
- Insert : it goes to the last leaf, which overflows to . Median 190 moves up, so the root becomes with leaves and .
- Insert : leaf .
- Insert : leaf .
Final B-tree
[ 40 | 90 | 120 | 190 ]
/ | | | \
[20,30] [50,60,80] [100,110] [130,140,170] [200,220,250]
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2023 AD Model · 10 marks
List out the application of minimum spanning tree. How Kruskal's algorithm differ from Prim's algorithm? Find the shortest path from node s to node t from following graph by using Dijkstra algorithm. (A weighted graph on vertices s, p, q, r, t, u is given in a figure in the original paper.)
Answer
Applications of a minimum spanning tree (MST)
- Designing least-cost networks: computer, telephone, electrical, water and road networks
- Cluster analysis in data mining and image segmentation
- Approximation algorithms for the travelling salesman problem
- Circuit design (minimising wire length)
Kruskal's vs Prim's algorithm
| Kruskal's | Prim's |
|---|---|
| Edge-based: sorts all edges and adds the smallest edge that creates no cycle | Vertex-based: grows a single tree from a start vertex by adding the cheapest edge leaving it |
| Intermediate result can be a forest (several components) | Intermediate result is always one connected tree |
| Needs cycle detection (union-find) | Needs a priority queue or key array |
| Time ; good for sparse graphs | Time (or ); good for dense graphs |
Dijkstra's algorithm (shortest path from to )
- Set and for every other vertex; mark all vertices unvisited.
- Pick the unvisited vertex with the smallest and mark it visited.
- For each neighbour of , if , set and .
- Repeat steps 2-3 until is visited. The value is the shortest distance, and following pointers back from to gives the path.
The weighted graph is given as a figure in the original question and is not reproduced here. Applying the above steps, starting from , to its edge weights gives the shortest distance and path to .
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
Questions from TU BIM Third Semester Model Questions 2023 (IT 237, ACC 201, IT 236, STT 201, IT 238) (Faculty of Management model question set 2023, BIM third semester (new course)), TU BIM Third Semester Model Question 2023 ACC 201 Financial Accounting (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 IT 236 Microprocessor and Computer Architecture (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 STT 201 Business Statistics (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 IT 238 Data Structure and Algorithms (Faculty of Management model question 2023), TU BIM Third Semester Model Question 2023 STT 201 Business Statistics (Lab) (Faculty of Management model question 2023, MS-Excel practical), TU BIM 2014 Third Semester IT 215 Web Programming I (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BIM 2014 Third Semester IT 216 Java Programming I (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BIM 2014 Third Semester IT 217 Computer Organization (model question) (Faculty of Management model question 2014 (old course), via EducateNepal), TU BBA/BIM/BBM 2015 Third Semester STT 201 Business Statistics (model question) (Faculty of Management model question 2015 (old course), via EducateNepal), TU BBA/BIM/BBM 2015 Third Semester STT 201 Business Statistics Lab (model question) (Faculty of Management model question 2015, lab work using MS-Excel), TU BIM Computer Organization (IT 217) 2012 AD (Board exam paper, 2012 AD), TU BIM Computer Organization (IT 217) 2014 AD (Board exam paper, 2014 AD), TU BIM Computer Organization (IT 217) 2015 AD (Board exam paper, 2015 AD), TU BIM Computer Organization (IT 217) 2016 AD (Board exam paper, 2016 AD), TU BIM Computer Organization (IT 217) 2017 AD (Board exam paper, 2017 AD), TU BIM Computer Organization (IT 217) 2018 AD (Board exam paper, 2018 AD), TU BIM Computer Organization (IT 217) 2019 AD (Board exam paper, 2019 AD), TU BIM Computer Organization (IT 217) 2021 AD (Board exam paper, 2021 AD), TU BIM Web Programming I (IT 215) 2014 AD (Board exam paper, 2014 AD), TU BIM Web Programming I (IT 215) 2015 AD (Board exam paper, 2015 AD), TU BIM Web Programming I (IT 215) 2016 AD (Board exam paper, 2016 AD), TU BIM Web Programming I (IT 215) 2017 AD (Board exam paper, 2017 AD), TU BIM Web Programming I (IT 215) 2018 AD (Board exam paper, 2018 AD), TU BIM Web Programming I (IT 215) 2019 AD (Board exam paper, 2019 AD), TU BIM Web Programming I (IT 215) 2021 AD (Board exam paper, 2021 AD), TU BIM Java Programming I (IT 216) 2015 AD (Board exam paper, 2015 AD), TU BIM Java Programming I (IT 216) 2017 AD (Board exam paper, 2017 AD), TU BIM Java Programming I (IT 216) 2018 AD (Board exam paper, 2018 AD), TU BIM Java Programming I (IT 216) 2019 AD (Board exam paper, 2019 AD), TU BIM Java Programming I (IT 216) 2021 AD (Board exam paper, 2021 AD), TU BIM Business Statistics (STT 201) 2009 AD (Board exam paper, 2009 AD), TU BIM Business Statistics (STT 201) 2010 AD (Board exam paper, 2010 AD), TU BIM Business Statistics (STT 201) 2021 AD (Board exam paper, January 2021 (Full Marks 36, answer any six)), TU BIM Business Statistics (STT 201) 2013 AD (Board exam paper, 2013 (Full Marks 36)), TU BIM Business Statistics (STT 201) 2014 AD (Board exam paper, 2014 AD), TU BIM Business Statistics (STT 201) 2015 AD (Board exam paper, 2015 AD), TU BIM Business Statistics (STT 201) 2016 AD (Board exam paper, 2016 AD), TU BIM Business Statistics (STT 201) 2018 AD (Board exam paper, 2018 AD), TU BIM Business Statistics (STT 201) 2019 AD (Board exam paper, 2019 AD), TU BIM Financial Accounting (ACC 201) 2015 AD (Board exam paper, 2015 AD), TU BIM Financial Accounting (ACC 201) 2016 AD (Board exam paper, 2016 AD), TU BIM Financial Accounting (ACC 201) 2017 AD (Board exam paper, 2017 AD), TU BIM Financial Accounting (ACC 201) 2018 AD (Board exam paper, 2018 AD), TU BIM Financial Accounting (ACC 201) 2019 AD (Board exam paper, 2019 AD), TU BIM Financial Accounting (ACC 201) 2021 AD (Board exam paper, 2021 AD), TU BIM Financial Accounting (ACC 201) 2014 AD (Board exam paper, 2014 AD), TU BIM Financial Accounting (ACC 201) 2013 AD (Board exam paper, 2013 AD), TU BIM Financial Accounting (ACC 201) 2012 AD (Board exam paper, 2012 AD), TU BIM Financial Accounting (ACC 201) 2010 AD (Board exam paper, 2010 AD) and TU BIM Financial Accounting (ACC 201) 2009 AD (Board exam paper, 2009 AD). Answers are written for this site; check them against your class notes.