CS504 Midterm Preparation File by ZB
CS504 Midterm Preparation File by ZB
CS504
MCQS Midterm preparation file ZB
ZB
MCQS
1. Which of the following is a characteristic of a good algorithm?
a) Complexity
b) Efficiency
c) Correctness
a) Queue
b) Stack
c) Linked list
d) Array
Answer: b) Stack
a) Merge Sort
b) Linear Search
c) Insertion Sort
d) Bubble Sort
Answer: c) Left child node is always less than the parent node
6. Which of the following algorithms has the best worst-case time complexity for sorting?
a) Quick Sort
b) Merge Sort
c) Insertion Sort
d) Heap Sort
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)
9. What is the space complexity of the recursive implementation of the Fibonacci sequence?
ZB
a) O(1)
b) O(n)
c) O(n^2)
d) O(log n)
Answer: b) O(n)
10. Which of the following data structures is best for implementing a priority queue?
a) Stack
b) Queue
c) Heap
d) Array
Answer: c) Heap
a) Merge Sort
b) Bubble Sort
c) Quick Sort
d) Counting Sort
12. In a hash table, what is the primary goal of the hash function?
ZB
ZB
a) Directed graph
b) Bipartite graph
c) Tree
d) Acyclic graph
a) O(n)
b) O(log n)
c) O(n^2)
d) O(n log n)
Answer: c) O(n^2)
16. Which of the following algorithms is used for finding the shortest path in a graph?
a) Merge Sort
b) Dijkstra's Algorithm
c) Bubble Sort
d) Quick Sort
ZB
17. In a doubly linked list, how many pointers are needed for each node?
a) One pointer
b) Two pointers
c) Three pointers
d) Four pointers
Answer: b) Two pointers
20. Which algorithm is best for solving the "travelling salesman problem"?
a) Greedy algorithm
b) Dynamic programming
c) Brute force
d) There is no optimal solution
Answer: d) There is no optimal solution
ZB
ZB
MCQS Midterm preparation file
22. In an AVL tree, what must be true about the heights of the two child subtrees of any node?
a) Quick Sort
b) Merge Sort
c) Heap Sort
d) Selection Sort
a) Merge Sort
b) Quick Sort
c) Huffman coding
d) Bellman-Ford algorithm
a) Binary Search
b) Merge Sort
c) Selection Sort
d) Quick Sort
a) Sorted data
b) Unsorted data
ZB
Midterm preparation file
33. Which sorting algorithm is best for large datasets when memory usage is a concern?
a) Quick Sort
b) Merge Sort
c) Heap Sort
d) Bubble Sort
a) O(log n)
b) O(n)
c) O(n log n)
d) O(1)
Answer: b) O(n)
a) Depth-first search
b) Quick sort
c) Dijkstra’s algorithm
ZB
Midterm preparation file
b) AVL Tree
c) Binary Heap
d) Red-Black Tree
38. Which of the following graph traversal techniques is most suitable for
finding the shortest path in an unweighted graph?
c) Dijkstra’s Algorithm
d) Floyd-Warshall Algorithm
ZB
MCQS
Midterm preparation file
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: c) O(log n)
a) Stack
b) Queue
c) Linked List
d) Binary Search Tree
Answer: a) Stack
41. What is the primary drawback of using a brute force algorithm to solve a
problem?
42. Which of the following algorithms is typically used to find the maximum
subarray sum in a given array?
a) Merge Sort
b) Quick Sort
c) Kadane’s Algorithm
d) Bellman-Ford Algorithm
Answer: c) Kadane’s Algorithm
ZB
ZB
MCQS
Midterm preparation file
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: c) O(log n)
a) Stack
b) Queue
c) Linked List
d) Binary Search Tree
Answer: a) Stack
a) Merge Sort
b) Quick Sort
c) Kadane’s Algorithm
d) Bellman-Ford Algorithm
Answer: c) Kadane’s Algorithm
ZB
MCQS ZB
Midterm preparation file
a) Breaking the problem into smaller subproblems and solving them independently
b) Sorting the data and then dividing it into parts
c) Combining smaller problems into one big problem
d) Repeating the same step until a solution is found
Answer: a) Breaking the problem into smaller subproblems and solving them independently
44. Which of the following is an advantage of using a doubly linked list over a singly linked list?
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