CS301 Midterm Preparation File by ZB
CS301 Midterm Preparation File by ZB
CS301
MCQS Midterm preparation file ZB
ZB
MCQS
1. What is the primary function of the ALU in a computer system?
a) Store data
b) Perform arithmetic and logical operations
c) Control the flow of data
d) Provide network connectivity
Answer: b) Perform arithmetic and logical operations
3. In a binary tree, the number of edges is always ______ the number of nodes.
a) Equal to
b) One more than
c) One less than
d) Twice
Answer: c) One less than
---
---
---
---
10. What is the space complexity of the recursive implementation of the factorial function?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
MCQS ZB
Midterm preparation file
11. In a directed graph, an edge has a direction. What is the out-degree of a vertex?
a) The number of edges directed into the vertex
ZB
b) The number of edges directed out of the vertex
c) The total number of edges in the graph
d) The number of vertices connected to it
Answer: b) The number of edges directed out of the vertex
---
12. Which of the following is the best way to find a path from one node to another in a graph?
a) Depth-First Search (DFS)
b) Binary Search
c) Breadth-First Search (BFS)
d) Merge Sort
Answer: a) Depth-First Search (DFS)
---
13. The Big O notation O(n^2) describes which of the following algorithms?
a) Linear search
b) Bubble sort
c) Quick sort
d) Binary search
Answer: b) Bubble sort
---
---
ZB
ZB
16. In a hash table, what happens if two keys hash to the same index?
a) A collision occurs
b) The key is deleted
c) The table is resized
d) The key is ignored
Answer: a) A collision occurs
---
17. Which of the following sorting algorithms is considered divide and conquer?
a) Selection Sort
b) Merge Sort
c) Bubble Sort
d) Insertion Sort
Answer: b) Merge Sort
19. What is the main disadvantage of using an array for storing data?
a) Random access is not possible
b) Insertion and deletion are slow
c) It requires too much memory
d) The size of the array cannot be changed
Answer: d) The size of the array cannot be change
ZB
a) Factorial computation
b) Linear search
c) Binary search
d) Bubble sort
Answer: a) Factorial computation
---
---
27. What is the best use case for a stack data structure?
a) Undo operations in text editors
b) Managing web browser history
c) Storing elements in a priority queue
d) Sorting elements
Answer: a) Undo operations in text editors
28. The primary advantage of a doubly linked list over a singly linked list is that
a) It uses less memory
b) It allows traversal in both directions
c) It is simpler to implement
d) It has a faster search time
Answer: b) It allows traversal in both directions
29. Which data structure is best suited for implementing a priority queue?
a) Array
b) Linked List
c) Binary Heap
d) Stack
Answer: c) Binary heap
30. What does the term “time complexity” of an algorithm refer to?
a) The amount of memory an algorithm uses
b) The number of steps an algorithm takes relative to the input size
c) The number of elements an algorithm can process
d) The total number of inputs an algorithm accepts
Answer: b) The number of steps an algorithm takes relative to the input size
ZB
MCQS ZB
36. Which of the following graph algorithms is used for finding the
shortest path in a weighted graph?
a) Depth-First Search
b) Breadth-First Search
c) Dijkstra’s Algorithm
d) Prim’s Algorithm
Answer: c) Dijkstra’s Algorithm
---
---
38. Which algorithm is used for finding the minimum spanning tree of
a graph?
a) Dijkstra’s Algorithm
b) Bellman-Ford Algorithm
c) Prim’s Algorithm
d) Floyd-Warshall Algorithm
Answer: c) Prim’s Algorithm
---
ZB
Midterm preparation file
40. Which of the following is a non-recursive algorithm for solving the Tower of Hanoi problem?
a) Dynamic Programming
b) Iterative Method
c) Greedy Approach
d) Divide and Conquer
Answer: b) Iterative Method
---
41. Which type of data structure is used to implement the "visited" feature in graph algorithms like
DFS and BFS?
a) Stack
b) Queue
c) Array
d) Set
Answer: c) Array
---
ZB
Midterm preparation file
43. In the worst case, what is the time complexity of inserting an element into a balanced binary
search tree (BST)?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: b) O(log n)
---
44. What is the primary advantage of a binary search tree (BST) over an unsorted list?
a) Faster sorting
b) Faster search operations
c) Lower memory usage
d) Easier to implement
Answer: b) Faster search operations
---
45. In a depth-first search (DFS) of a graph, which data structure is used to store the vertices?
a) Queue
b) Stack
c) Linked List
d) Array
Answer: b) Stack
ZB
ZB
MCQS
Midterm preparation file
---
subproblems is called:
a) Greedy approach
b) Decomposition
c) Memoization
Answer: b) Decomposition
ZB
ZB
MCQS
Midterm preparation file
algorithm?
a) Merge Sort
b) Dijkstra’s Algorithm
c) Quick Sort
d) Floyd-Warshall Algorithm
---
a) Merge Sort
b) Bubble Sort
c) Quick Sort
d) Heap Sort
---
ZB
Passing Criteria for a Course:
ZB
MCQS Midterm preparation file
ZB
Advice
Hmaesha relax ho ke parha kryn panic mat hua kryn apky
parents ky bohat khawab hoty hn wo pura krny ki puri koshish
kea kryn kbi b ksi pe depend na kea kryn apko bs ak insan
success kr saqta ha or wo insan ap khud hn apky elawa koi nahe
ap bs koshish kryn Allah pak pe strong yakeen rakha kryn or
mehnat krke sb Allah ke hawaly kr dea kryn everything is
possible be brave be strong stay blessed
Hum insan hamesha moat se darty or bhagty hn or moat se
bachny ki koshish krty hn jabke moat ny ana hi ana ha hum
ZB
moat se nahe bach saqty humy jahanam se bachny ki koshish
krni chaheay hum jahanam se bach saqty hn
Insan ko 3 chezo se dar lagta ha Moat Risk/Dolat Ezat Shohrat
Fame
Moat
Humy pta hona chaheay Moat tab ani ha jab Allah
chahy us se pehly puri dunya bi ak tararf ho ke apko
marna chahy to apka kuch nahe beggar saqti
Risk/Dolat
Risk Dolat sb Allah pak ke hath m ha puri dunya ak
taraf b ho jay na apsy apka risk cheen saqti ha na de
saqti ha Ye sirf ALLAh pak ky hath m ha
ZB
Agr ap mujsy contact na kr sky too b ap jo b hn jaha bi hn waha
Allah ka quran pheelay zada se zada with urdu translation jitni
himat ha utna share kryn
ZB
MY Family
ust Relax and focus! Exams are not difficult. Put in your
100% effort and trust in Allah.
AL-Quran