পরীক্ষা আর্কাইভ

৪৯তম বিসিএস ⎯ কম্পিউটার সায়েন্স (CSE) [৯৭১]

পরীক্ষা৪৯তম বিসিএস ⎯ কম্পিউটার সায়েন্স (CSE) [৯৭১]তারিখতারিখ অনির্ধারিতসময়18 minutes
মোট প্রশ্ন৩০
সিলেবাস
Exam 4 Arrays; linked lists; stacks; queues; sparse/dense matrices; Recursion: applications. [Source: Class–3 and relevant books]
ঘনত্ব
উত্তর
উত্তরিতবর্তমানপুনরায় দেখুনঅসম্পূর্ণ

৪৯তম বিসিএস ⎯ কম্পিউটার সায়েন্স (CSE) [৯৭১]

৪৯তম বিসিএস ⎯ কম্পিউটার সায়েন্স (CSE) [৯৭১] · তারিখ অনির্ধারিত · ৩০ প্রশ্ন

.
Which of the following is the correct way to represent a 1D array in memory? 
  1. Linked list
  2. Contiguous memory locations 
  3. Non-contiguous blocks
  4. Binary tree
সঠিক উত্তর:
Contiguous memory locations 
উত্তর
সঠিক উত্তর:
Contiguous memory locations 
ব্যাখ্যা

Linked list:
A linked list stores elements in nodes scattered across memory connected by pointers.
Contiguous memory locations:(Answer)
A 1D array is stored in a single continuous block of memory where each element is placed right after the previous one. This allows direct indexing with base_address + index * size_of_element.
Non-contiguous blocks:
If memory blocks are scattered, you’d need pointers to connect them — which is again a linked structure, not an array.
Binary tree:
A binary tree is a hierarchical structure, not a linear storage format like arrays.

.
What is the time complexity of accessing an element in an array by index?
  1. O(n2)
  2. O(log n)
  3. O(1) 
  4. O(n) 
সঠিক উত্তর:
O(1) 
উত্তর
সঠিক উত্তর:
O(1) 
ব্যাখ্যা

Indexing in an array is done by calculating Base_Address + (Index * Size_of_Element), which takes constant time O(1).

Time complexity
O(1) (constant time):
If an operation always takes the same amount of time regardless of array size n.
Examples: array access by index, push/pop on stack, hash-table lookup (average case).
O(n) (linear time):
Have to scan all elements.
Example: searching for a number in an unsorted array that's why  you may check every element.
O(log n) (logarithmic time):
If each step halves the problem size.
Example: binary search in a sorted array.
O(n²) (quadratic time):
If you have nested loops over the array.
Example: bubble sort or comparing every element with every other element.

.
If an array starts at memory location 2000, with each element taking 4 bytes, what is the address of A[5]?
  1. 2020 
  2. 2028
  3. 2016 
  4. 2024
সঠিক উত্তর:
2020 
উত্তর
সঠিক উত্তর:
2020 
ব্যাখ্যা

Answer: A-2024
Address formula: Base + (i * Size) = 2000 + (5 * 4) = 2020. Since array index starts from 0, A[5] means the 6th element → 2000 + (5*4) = 2020.

.
What is the worst-case complexity of searching in an unsorted array? 
  1. O(1) 
  2. O(log n) 
  3. O(n) 
  4. O(n log n) 
সঠিক উত্তর:
O(n) 
উত্তর
সঠিক উত্তর:
O(n) 
ব্যাখ্যা

Searching in an unsorted array
Since the array is unsorted, cannot use tricks like binary search (which requires sorted data).
The only way is to check elements one by one until  find the element or reach the end of the array.
Worst-case
If the element is not present,  have to check all ?
Even if the element is present, in the worst case it could be at the last position (index n−1).
So the number of comparisons = n.
Worst-case time complexity=O(n)

.
Which data structure works on the principle of LIFO (Last-In-First-Out)?
  1. Queue 
  2. Stack 
  3.  Heap
  4. Linked list
সঠিক উত্তর:
Stack 
উত্তর
সঠিক উত্তর:
Stack 
ব্যাখ্যা

Answer: B 
Stack: A stack follows the LIFO principle: the last element inserted is the first one removed. 
​Think of a stack of plates: you place plates on top (push), and you remove from the top (pop). 
​Used in function calls, recursion, expression evaluation, and backtracking.

​Queue: Linear data structure that follows FIFO (First In, First Out).
example: A line of people at a ticket counter.

​Linked List: A sequence of nodes, where each node stores data + pointer (address of next node).

​ Heap: A special binary tree (complete tree) used for fast retrieval of min/max element.


.
What happens if we try to pop an empty stack?
  1. Underflow 
  2. Overflow
  3. Segmentation fault 
  4. Nothing 
সঠিক উত্তর:
Underflow 
উত্তর
সঠিক উত্তর:
Underflow 
ব্যাখ্যা

Answer: A 
​Stack underflow occurs when we try to remove an element from an empty stack. 
​Stack overflow happens when we try to push into a full stack (in fixed-size array implementation).

.
Which queue allows insertion and deletion from both ends? 
  1. Priority queue 
  2. Simple queue
  3. Circular queue 
  4. Deque
সঠিক উত্তর:
Deque
উত্তর
সঠিক উত্তর:
Deque
ব্যাখ্যা

 Answer: D
​Deque (Double Ended Queue) supports Insertion/deletion at front & rear
​Input-restricted deque: insertion at one end only. Output-restricted deque: deletion at one end only

.
Which traversal uses a queue?
  1. DFS
  2. BFS 
  3. Inorder
  4. Postorder
সঠিক উত্তর:
BFS 
উত্তর
সঠিক উত্তর:
BFS 
ব্যাখ্যা

Answer: B 
Breadth-First Search (BFS) uses a queue to explore level by level. 
How it works:
o Visit the root.
o Visit all nodes at the current level, left to right.
o Then move to the next level

​DFS uses a stack (or recursion) ,it has three main variants Preorder, Inorder, Postorder.

.
Which data structure is used in Undo/Redo operations? 
  1. Queue 
  2. Tree 
  3. Stack 
  4. Graph 
সঠিক উত্তর:
Stack 
উত্তর
সঠিক উত্তর:
Stack 
ব্যাখ্যা

Answer: C
​  Undo/Redo maintains history in two stacks: Undo stack, Redo stack
​  Undo → follows LIFO (Last In, First Out).
The last action you performed is the first one you want to undo.
So each action is pushed onto an Undo stack.
Redo → uses another stack.
When you undo an action, it is moved (popped from Undo, pushed to Redo).
If you choose redo, it pops from the Redo stack and reapplies the action.

১০.
Which of the following is true about stacks and queues? 
  1. Stack → LIFO, Queue → FIFO 
  2. Both are LIFO 
  3. Both are FIFO 
  4. Stack → FIFO, Queue → LIFO 
সঠিক উত্তর:
Stack → LIFO, Queue → FIFO 
উত্তর
সঠিক উত্তর:
Stack → LIFO, Queue → FIFO 
ব্যাখ্যা

Answer: A 
 Stack = LIFO (last element removed first). Queue = FIFO (first element removed first).

১১.
What is the major difference between an array and a linked list? 
  1. Arrays are dynamic, linked lists are static 
  2. Arrays have contiguous memory, linked lists are non-contiguous
  3. Arrays use pointers, linked lists do not 
  4. None 
সঠিক উত্তর:
Arrays have contiguous memory, linked lists are non-contiguous
উত্তর
সঠিক উত্তর:
Arrays have contiguous memory, linked lists are non-contiguous
ব্যাখ্যা

Answer: B 
Arrays = contiguous memory, fixed size. 
​Linked lists = nodes linked via pointers, non-contiguous, dynamic size.

১২.
What is the main advantage of linked lists over arrays? 
  1. Faster searching 
  2. Random access
  3. Dynamic size and easy insertion/deletion
  4. Less memory
সঠিক উত্তর:
Dynamic size and easy insertion/deletion
উত্তর
সঠিক উত্তর:
Dynamic size and easy insertion/deletion
ব্যাখ্যা

 Answer: C 
​Dynamic memory allocation & easy insertions/deletions
Arrays have a fixed size. Once declared, you cannot easily resize them (in languages like C/C++). 
​Expanding means creating a new larger array and copying all elements (O(n)).
Linked Lists can grow or shrink dynamically because each element (node) is allocated separately and connected via pointers.
Insertions and deletions in a linked list are efficient (O(1)) if you already have the pointer to the node, since you only adjust pointers.

১৩.
What is the time complexity to search an element in a linked list in the worst and average case.
  1. O(1)
  2. O(n log n)
  3. O(log n)
  4. O(n)
সঠিক উত্তর:
O(n)
উত্তর
সঠিক উত্তর:
O(n)
ব্যাখ্যা

Answer: D 
Time Complexity for Linked List
Best case:
The element is at the head (first node) → only 1 comparison → O(1).
Worst case:
The element is at the last node or not present at all → must traverse all n nodes → O(n).
Average case:
On average, you’ll search through n/2 nodes before finding it → but in Big-O, that’s still O(n).
​Example
Linked list: 10 → 20 → 30 → 40 → 50
Search for 10: found at head → O(1).
Search for 50: must traverse all → O(n).
Search for 60: not present → traverse all → O(n).

১৪.
Which of the following best defines a binary tree?
  1. A tree where each node has at most one child 
  2. A tree where each node has at most two children
  3.  A tree where each node has exactly two children 
  4. A tree with only one root 
সঠিক উত্তর:
A tree where each node has at most two children
উত্তর
সঠিক উত্তর:
A tree where each node has at most two children
ব্যাখ্যা

Answer B 
 A binary tree is a hierarchical structure where each node has at most two children (left and right).
​ Option C is full binary tree (every node has 0 or 2)

১৫.
Maximum number of nodes at level L in a binary tree is: 
  1. L
  2. 2L-1
  3. 2L
  4. L2
সঠিক উত্তর:
2L
উত্তর
সঠিক উত্তর:
2L
ব্যাখ্যা

Answer: C
Level numbering starts at 0 for root. At level l, maximum nodes = 2L .
Maximum number of nodes at level l in a binary tree
A binary tree is such that each node can have at most 2 children.
At level 0 → only 1 node (the root).
At level 1 → at most 2 nodes.
At level 2 → at most 4 nodes.
​At level L → at most:



১৬.
Maximum number of nodes in a binary tree of height h is:
  1. 2h + 1 - 1
  2. 2h
  3. h
  4. h2
সঠিক উত্তর:
2h + 1 - 1
উত্তর
সঠিক উত্তর:
2h + 1 - 1
ব্যাখ্যা

2h + 1 - 1
Answer: A
 A complete binary tree of height h has: 1 + 2 + 4 + ... + 2ʰ = 2ʰ⁺¹ − 1 nodes.


​Here, h= 3 (level 0-3)
​Number of total nodes = 2ʰ⁺¹ − 1 =23+1 −1= 15

১৭.
What is the main difference between a dense and sparse matrix?
  1. Sparse matrix stores more elements 
  2. Dense matrix has mostly zero values 
  3. Sparse matrix has mostly zero values 
  4. Both are the same
সঠিক উত্তর:
Sparse matrix has mostly zero values 
উত্তর
সঠিক উত্তর:
Sparse matrix has mostly zero values 
ব্যাখ্যা

  Answer: C
Dense Matrix: Most of the elements are non-zero, Stored in a regular 2D array form.
Efficiency: Simple to access any element using row & column indices → O(1).
Memory: Uses a lot of memory if the matrix is very large.
​Sparse Matrix: Most of the elements are zero.
Storage: Instead of storing all elements, only the non-zero elements with their positions (row, column) are stored 
Efficiency: Saves space but access can be slower since you may need to search through the stored entries.
Memory: Very efficient for large matrices with many zeros

১৮.
Which of the following is a linear data structure?
  1. Stack
  2. Queue
  3. Linked List
  4. All of the above
সঠিক উত্তর:
All of the above
উত্তর
সঠিক উত্তর:
All of the above
ব্যাখ্যা

Linear Data Structure
A data structure is linear if its elements are arranged in a sequential (linear) order, and each element has a unique predecessor and successor (except the first and last). ​Example: Array, Linked List, Stack, Queue 
 Non-linear Data Structure
A data structure is non-linear if its elements are not stored sequentially. Each element can connect to multiple elements, forming a hierarchical or network structure. Example: Tree, Graph

১৯.
Which of the following is a Stack operation?
  1. PUSH
  2. POP
  3. Both A & B
  4. None of the above
সঠিক উত্তর:
Both A & B
উত্তর
সঠিক উত্তর:
Both A & B
ব্যাখ্যা

Stack
A stack is a linear data structure that follows the LIFO (Last In, First Out) principle.
Operations:
PUSH → Insert an element (on top).
POP → Remove an element (from top).
PEEK / TOP → View the top element without removing.
isEmpty / isFull → Check stack status.

Representation: Can be implemented using Array or Linked List.

২০.
Which of the following is a dynamic data structure?
  1. Array
  2. Stack
  3. Queue
  4. None of the above
সঠিক উত্তর:
None of the above
উত্তর
সঠিক উত্তর:
None of the above
ব্যাখ্যা

Dynamic data structures allocate/deallocate memory at runtime/ dynamically, are flexible in size, and include linked lists, trees, and graphs.
​Where Array, Stack, Queue are Static Data structure.

২১.
Which of the following is true about binary search trees? 
  1. All nodes in left subtree > root 
  2. All nodes in right subtree < root 
  3. Left subtree < root < right subtree 
  4. Root < left subtree < right subtree 
সঠিক উত্তর:
Left subtree < root < right subtree 
উত্তর
সঠিক উত্তর:
Left subtree < root < right subtree 
ব্যাখ্যা

Answer: C 
​ BST property = Left < Root < Right.
​In a Binary Search Tree (BST):
The left subtree of a node contains only nodes with values less than the node’s key.
The right subtree of a node contains only nodes with values greater than the node’s key.
both left and right subtrees themselves must also be BSTs.
​Following is a pictorial representation of BST −

২২.
Which data structure is best for implementing recursion? 
  1. Queue
  2. Stack
  3. Graph
  4. Linked list
সঠিক উত্তর:
Stack
উত্তর
সঠিক উত্তর:
Stack
ব্যাখ্যা

Answer: B) Stack
​ Reason:
Recursion follows LIFO, and Stack is the best structure for LIFO operations.
Every recursive call is pushed onto the call stack, and when the function ends, it is popped.

২৩.
What is the main advantage of a circular queue over a linear queue? 
  1. Faster insertion
  2. Simpler implementation
  3. Better memory utilization 
  4. Faster searching 
সঠিক উত্তর:
Better memory utilization 
উত্তর
সঠিক উত্তর:
Better memory utilization 
ব্যাখ্যা

Answer: C Better memory utilization 
​Explanation: In a linear queue, once rear reaches the end, we can’t insert more elements even if space is free at the beginning. A circular queue reuses empty slots, so memory is used more efficiently.Both

২৪.
What is the condition for queue full in a circular queue of size N? 
  1. front == rear 
  2. (rear + 1) % N == front 
  3. rear == N-1
  4. front == -1 
সঠিক উত্তর:
(rear + 1) % N == front 
উত্তর
সঠিক উত্তর:
(rear + 1) % N == front 
ব্যাখ্যা

Answer: B) (rear + 1) % N == front 
Circular queue full condition
​If advancing rear by one position (circularly) makes it equal to front, then the queue is full.
Because rear cannot move to the front position (that slot is reserved to distinguish full from empty).
Example (size = 5):
​Index: 0 1 2 3 4
Queue: [10][20][30][40][50]
front = 0
rear = 4
Now,
(rear + 1) % size = (4 + 1) % 5 = 0
And since front = 0, condition is trueQueue is Full.

২৫.
Which of the following is NOT a common representation of sparse matrices? 
  1. Triplet representation
  2. Compressed Sparse Row (CSR) 
  3. Compressed Sparse Column (CSC) 
  4. AVL tree 
সঠিক উত্তর:
AVL tree 
উত্তর
সঠিক উত্তর:
AVL tree 
ব্যাখ্যা

Answer: D
Sparse matrices  are usually represented using Triplet, CSR, or CSC.
​An AVL tree
is a data structure for fast searching, not a typical sparse matrix storage method.

২৬.
Which of the following operations is not possible in a simple queue? 
  1. Enqueue at rear 
  2. Dequeue at front C
  3. Insertion at front 
  4. Deletion at rear 
সঠিক উত্তর:
Insertion at front 
উত্তর
সঠিক উত্তর:
Insertion at front 
ব্যাখ্যা

Answer: C 
Queue is a linear data structure that follows the First-In-First-Out (FIFO
 Enqueue(insert) → rear (End)
Dequeue(remove) → front 



২৭.
Which of the following is TRUE about a double-ended queue (deque)? 
  1.  Insertion is restricted to one end only 
  2.  Deletion is restricted to one end only 
  3. Both insertion and deletion can occur at both ends 
  4.  None of the above 
সঠিক উত্তর:
Both insertion and deletion can occur at both ends 
উত্তর
সঠিক উত্তর:
Both insertion and deletion can occur at both ends 
ব্যাখ্যা

Answer: C 
​A deque (short for double-ended queue) is a data structure that allows insertion and deletion of elements from both ends, making it more flexible than a standard queue. Unlike a regular queue that follows the FIFO (First In First Out) principle, a deque allows operations at both the front and rear ends. That’s why it is called a double-ended queue.

২৮.
A deque where insertion is restricted at one end but deletion is allowed at both ends is called: 
  1. Input-Restricted Deque 
  2. Output-Restricted Deque
  3. Circular Deque 
  4. Priority Deque 
সঠিক উত্তর:
Input-Restricted Deque 
উত্তর
সঠিক উত্তর:
Input-Restricted Deque 
ব্যাখ্যা

Answer: A 
Input-restricted → Insert only at one end; delete from both ends. 
​Output-restricted → Delete only at one end; insert at both ends.

২৯.
A stack is implemented using an array of size n. If top = n-1, what happens?
  1. Stack underflow 
  2. Stack overflow 
  3. Stack is empty 
  4. None 
সঠিক উত্তর:
Stack overflow 
উত্তর
সঠিক উত্তর:
Stack overflow 
ব্যাখ্যা

Answer: B 
​Stack Overflow occurs when we try to push an element into a stack that is already full.

For an array-based stack of size n: Index ranges: 0 to n-1
top points to the current top element.
If top = n-1, the stack is full, and any further push causes overflow.

Stack Underflow occurs when we try to pop from an empty stack (top = -1).

৩০.
Which of the following is TRUE about a priority queue? 
  1. Elements are always served in FIFO order 
  2. Priority queue is same as a stack
  3. Only integers can be used as elements 
  4. Elements are served according to priority
সঠিক উত্তর:
Elements are served according to priority
উত্তর
সঠিক উত্তর:
Elements are served according to priority
ব্যাখ্যা

Answer: D Elements are served according to priority
Priority queue is a special type of queue in which each element is associated with a priority.
​Higher priority elements are served before lower priority ones.
If two elements have the same priority, they are served according to FIFO (first-come-first-served) or implementation-specific rules.
In  Priority queue 
Each element has a priority.
Insertion can happen at any position based on priority.
Deletion always removes the highest-priority element.