0% found this document useful (0 votes)
24 views

CS301 Midterm Preparation File by ZB

Uploaded by

Amir Maqbol
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

CS301 Midterm Preparation File by ZB

Uploaded by

Amir Maqbol
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

MCQS CS301 midterm preparation file ZB

In the name of God , Most


Gracious, Most merciful

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

2. Which of the following is a characteristic of a stack data structure?


a) FIFO (First In First Out)
b) LIFO (Last In First Out)
c) Random Access
d) Ordered traversal
Answer: b) LIFO (Last In First Out)

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

4. What is the time complexity of accessing an element in an array?


a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: a) O(1)

5. Which of the following sorting algorithms is not stable?


a) Merge Sort
b) Insertion Sort
c) Selection Sort
d) Bubble Sort
Answer: c) Selection Sort
ZB
MCQS ZB
Midterm preparation file

6. What is the worst-case time complexity of Quick Sort?


a) O(n)
b) O(n log n)
c) O(log n)
d) O(n^2)
Answer: d) O(n^2)

---

7. Which of the following is true for a binary search tree (BST)?


a) Inorder traversal results in a sorted sequence of elements
b) Left child is greater than the parent
c) Right child is always smaller than the parent
d) All children are always on the left of the parent
Answer: a) Inorder traversal results in a sorted sequence of elements

---

8. In a linked list, the time complexity of inserting an element at the beginning is


a) O(n)
b) O(1)
c) O(log n)
d) O(n^2)
Answer: b) O(1)

---

9. Which data structure is used in the implementation of recursion?


a) Stack
b) Queue
c) Linked List
d) Array
Answer: a) Stack

---

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

---

14. Which of the following is a characteristic of a queue data structure?


a) FIFO (First In First Out)
b) LIFO (Last In First Out)
c) Random access
d) Circular traversal
Answer: a) FIFO (First In First Out)

---

15. Which of the following is an example of a non-linear data structure?


a) Array
b) Stack
c) Binary tree
d) Queue
Answer: c) Binary tree
MCQS Midterm preparation file

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

18. What is the time complexity of the Binary Search algorithm?


a) O(n)
b) O(log n)
c) O(n log n)
d) O(n^2)
Answer: b) O(log n)

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

20. Which of the following is not an example of a graph traversal algorithm?


a) Depth-First Search (DFS)
b) Breadth-First Search (BFS)
c) Dijkstra’s Algorithm
d) Merge Sort
Answer: d) Merge Sort
MCQS MIDTERM PREPARATION FILE ZB

21. Which of the following is an example of a recursive function?

ZB
a) Factorial computation
b) Linear search
c) Binary search
d) Bubble sort
Answer: a) Factorial computation

---

22. Which of the following is a greedy algorithm?


a) Dijkstra’s Algorithm
b) Merge Sort
c) Quick Sort
d) Binary Search
Answer: a) Dijkstra’s Algorithm

23. Which of the following is not a property of a tree?


a) It has a root node
b) Each node has at most two children
c) It is a connected acyclic graph
d) There are cycles in the tree
Answer: d) There are cycles in the tree

24. Which sorting algorithm works by repeatedly swapping adjacent elements


if they are in the wrong order?
a) Bubble Sort
b) Merge Sort
c) Quick Sort
d) Insertion Sort
Answer: a) Bubble Sort

25. What is the time complexity of the Merge Sort algorithm?


a) O(n^2)
b) O(n log n)
c) O(log n)
d) O(n)
Answer: b) O(n log n)
ZB
ZB
MCQS Midterm preparation file

26. In a graph, a vertex with no outgoing edges is called a ______.


a) Sink
b) Source
c) Root
d) Leaf
Answer: a) Sink

---

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

Midterm preparation file

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

---

37. Which of the following is a disadvantage of using an adjacency


matrix to represent a graph?
a) It requires O(n) space
b) It is difficult to traverse the graph
c) It is inefficient for sparse graphs
d) It is slower than an adjacency list for dense graphs
Answer: c) It is inefficient for sparse graphs

---

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

---

39. What does the term "cycle" mean in graph theory?


a) A path that starts and ends at the same vertex
b) A path that connects all vertices exactly once
c) A path with the least number of edges
d) A path from one vertex to another
Answer: a) A path that starts and ends at the same vertex
MCQS ZB

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

---

42. In a linked list, which operation takes O(n) time?


a) Insertion at the beginning
b) Insertion at the end
c) Searching for a specific element
d) Deletion from the front
Answer: c) Searching for a specific element
ZB
MCQS

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

46. In a directed acyclic graph (DAG), what is a characteristic of the edges?

a) They form cycles

b) They have no direction

c) They go from one vertex to another with no back edges

d) They form loops

Answer: c) They go from one vertex to another with no back edges

---

47. In dynamic programming, the process of breaking down a problem into

subproblems is called:

a) Greedy approach

b) Decomposition

c) Memoization

d) Divide and Conquer

Answer: b) Decomposition
ZB

ZB
MCQS
Midterm preparation file

48. Which of the following is an example of a greedy

algorithm?

a) Merge Sort

b) Dijkstra’s Algorithm

c) Quick Sort

d) Floyd-Warshall Algorithm

Answer: b) Dijkstra’s Algorithm

---

49. Which sorting algorithm is based on partitioning the array

into two parts?

a) Merge Sort

b) Bubble Sort

c) Quick Sort

d) Heap Sort

Answer: c) Quick Sort


ZB
MCQS ZB
Midterm preparation file

50. Which of the following is true about a red-black tree?


a) It is an unordered binary search tree
b) It is always balanced
c) It is a self-balancing binary search tree
d) It requires manual balancing
Answer: c) It is a self-balancing binary search tree

---

51. What is the time complexity of inserting a node in a linked list?


a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: a) O(1) (if the position is known)

ZB +92 300 5427579


WhatsApp:
https://whatsapp.com/channel/0029VaODheTDp2Q8YVcoO
N2p
Second WhatsApp channel
channel on WhatsApp:
https://whatsapp.com/channel/0029VafvOcy90x2tPbUaX0
2I
YouTube:
https://youtu.be/-AMj4iNz0UE?si=hg29pJZ1kujzg57J

Phone no : +92 300 5427579


Phone no: +92 330 3869586
Email: [email protected]
ZB
MCQS Midterm preparation file

Passing criteria of this course

ZB
Passing Criteria for a Course:

The passing criteria is defined in such a way that it ensures the


student shall be consistent in his studies
throughout the semester.
Therefore, for passing a course/subject, student shall fulfill the
following:
a) Secure minimum 20% score in Formative Assessments/Mid
terms
b) Secure minimum 20% score in Final Term Examinations.
c) Secure at least 40% marks in aggregate while fulfilling the
above requirements
ZB

ZB
MCQS Midterm preparation file

Course Selection and Credit Hours

Q: How do I select courses when the course selection is open?


A: Follow these steps:
1. Check the credit hours allowed by your university (e.g., 21, 18, or 15
credit hours).
2. Each subject typically has 3 credit hours.
3. Divide the total allowed credit hours by 3 to determine how many
subjects you can select.
Examples:
21 credit hours = 7 su18 credit hours = 6 subjects
15 credit hours = 5 subjects
Remember, the university may allow different credit hours for each
student, so check your specific allowance.
By following these steps, you can make informed decisions during
course selection and manage your credit hours
effectively.

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

Izat Zilat shohrat Fame


Izat Zilat Sirf Allah de saqty hn puri dunya mel ke b
apko zra brabr b demage nahe kr saqti Agr ALLAH
Apko izat dena chahay to puri dunya ak tararf ho ke
b apko 1% b nuksan nahe pohancha saqti
Phr Dar ks bat ka ???????????????
Be brave be strong Just put your trust To ALLAH
Hamesha Confident or himat se raho kbi ksi k samne
mat jhuko puri dunya mel k b apka kuch b nahe
beggar saqti
ZB
ZB
MY REQUEST FROM ALL OF YOU

ZB Request from All of you My family


Mjy ap sbki help or support ki zarort ha or wo ye k hum sb Mel
kr Allah ka Quran ki Urdu translation logo tak pohanchy or
Quran ko samjna asaaan kryn dosro k leay sb tak Allah ka Quran
pohanchy it's my compaign hum log 70+ age k ho jaty hn phr b
hmy namaz tak ki translation nahe pta hoti k hum Allah pak se

Kya Dua kr rhy hn so hum youngster's ko Mel kr puri takat or


energy ke sath Allah ka Quran spread krna ha
Hum puri Koshish kr rhy hn k hum sb Mel k Quran ki
translation or most important topics ko maximum share kry with
translation hmara maksad Quran ko spread krna ha be a part of
us
m apni pocket se ye sb kr rha ho Allah ka Quran spread krny k
leay apne or mene sbny Marna ha ak din to q na Allah k leay
Kuch kryn apni energies apni power ko bajay negative use krny k
Allah k leay invest kryn khud ko be a part of us
Agr m 23 ki age m apny sare sources use kr rha ho pocket se
heavy amounts give away kr rha ho Quran spread krny k leay to
ap just share to kr saqty hn itna e krdyn

Contact ZB +92 300 5427579

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

"And indeed, with hardship comes ease." (Quran 94:5)


Remember, I'm here to support you! Stay brave and strong!"

May Allah bless you

You might also like