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

CS504 Midterm Preparation File by ZB

Uploaded by

mishalaslam17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

CS504 Midterm Preparation File by ZB

Uploaded by

mishalaslam17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

MCQS CS504 midterm preparation file ZB

In the name of God , Most


Gracious, Most merciful

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

d) All of the above

Answer: d) All of the above

2. What does O(n) represent in terms of algorithm analysis?

a) Constant time complexity

b) Linear time complexity

c) Exponential time complexity

d) Logarithmic time complexity

Answer: b) Linear time complexity

3. Which data structure is used for implementing recursive function calls?

a) Queue

b) Stack

c) Linked list

d) Array

Answer: b) Stack

4. Which of the following is an example of a divide-and-conquer algorithm?

a) Merge Sort

b) Linear Search

c) Insertion Sort

d) Bubble Sort

Answer: a) Merge Sort


ZB
MCQS ZB
Midterm preparation file

5. Which of the following is true about a binary search tree (BST)?

a) Left child node is always greater than the parent node

b) Right child node is always less than the parent node

c) Left child node is always less than the parent node

d) Right child node is always greater than the parent node

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

Answer: b) Merge Sort

7. What is the time complexity of accessing an element in an array by index?

a) O(1)

b) O(n)

c) O(log n)

d) O(n^2)

Answer: a) O(1)

8. Which of the following is not a type of linked list?

a) Doubly Linked List

b) Singly Linked List

c) Circular Linked List

d) Binary Linked List

Answer: d) Binary Linked List


MCQS ZB
Midterm preparation file

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

11. Which sorting algorithm is not comparison-based?

a) Merge Sort

b) Bubble Sort

c) Quick Sort

d) Counting Sort

Answer: d) Counting Sort

12. In a hash table, what is the primary goal of the hash function?

a) To sort the data

b) To assign a unique key to each data element

c) To compute the index for storing data

d) To ensure data is stored in a linked list

Answer: c) To compute the index for storing


MCQS Midterm preparation file

ZB
ZB

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

a) Last in, first out (LIFO)

b) First in, first out (FIFO)

c) Supports random access

d) Allows inserting and deleting elements at both ends

Answer: b) First in, first out (FIFO)

14. Which of the following best describes a graph with no cycles?

a) Directed graph

b) Bipartite graph

c) Tree

d) Acyclic graph

Answer: d) Acyclic graph

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

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

Answer: b) Dijkstra's Algorithm


MCQS MIDTERM PREPARATION FILE ZB

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

18. Which of the following operations can be performed efficiently on a stack?


a) Peek
b) Pop
c) Push
d) All of the above
Answer: d) All of the above

19. What is the time complexity of inserting an element at the beginning of a


singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)

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

21. Which of the following is a characteristic of a depth-first search (DFS) algorithm?

a) It uses a queue for processing nodes

b) It explores the nearest nodes first

c) It explores as far as possible along a branch before backtracking

d) It is not suitable for traversing trees

Answer: c) It explores as far as possible along a branch before backtracking

22. In an AVL tree, what must be true about the heights of the two child subtrees of any node?

a) They must be equal

b) They must differ by at most one

c) They must be balanced

d) One must be greater than the other

Answer: b) They must differ by at most one

23. Which of the following is true about recursion?

a) Recursive algorithms can never be more efficient than iterative algorithms

b) Recursion can be used for problems like tree traversal

c) Recursion does not use any memory

d) Recursive functions cannot be optimized

Answer: b) Recursion can be used for problems like tree traversal

24. Which of the following sorting algorithms is stable?

a) Quick Sort

b) Merge Sort

c) Heap Sort

d) Selection Sort

Answer: b) Merge Sort


ZB
MCQS ZB

Midterm preparation file


25. What is the primary use of a hash table?

a) To store elements in sorted order

b) To implement a priority queue

c) To provide fast access to data using a key

d) To search data in linear time

Answer: c) To provide fast access to data using a key

26. Which of the following is a greedy algorithm?

a) Merge Sort

b) Quick Sort

c) Huffman coding

d) Bellman-Ford algorithm

Answer: c) Huffman coding

27. Which of the following is a type of searching algorithm?

a) Binary Search

b) Merge Sort

c) Selection Sort

d) Quick Sort

Answer: a) Binary Search

28. In which of the following cases does binary search work?

a) Sorted data

b) Unsorted data

c) Data with duplicates only

d) Data with no duplicates

Answer: a) Sorted data


MCQS ZB

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

Answer: c) Heap Sort

34. What is the time complexity of finding an element in an unsorted array?

a) O(log n)

b) O(n)

c) O(n log n)

d) O(1)

Answer: b) O(n)

35. Which of the following is an example of a non-recursive algorithm?

a) Depth-first search

b) Quick sort

c) Dijkstra’s algorithm

d) Fibonacci sequence calculation using recursion

Answer: c) Dijkstra’s algorithm


ZB
MCQS

ZB
Midterm preparation file

36. Which of the following is a feature of the quicksort algorithm?

a) It is a comparison-based sorting algorithm

b) It has a time complexity of O(n^2) in the average case

c) It is a stable sorting algorithm

d) It selects a pivot element to divide the array

Answer: d) It selects a pivot element to divide the array

37. Which type of tree is used for implementing a priority queue?

a) Binary Search Tree

b) AVL Tree

c) Binary Heap

d) Red-Black Tree

Answer: c) Binary Heap

38. Which of the following graph traversal techniques is most suitable for
finding the shortest path in an unweighted graph?

a) Depth-First Search (DFS)

b) Breadth-First Search (BFS)

c) Dijkstra’s Algorithm

d) Floyd-Warshall Algorithm

Answer: b) Breadth-First Search (BFS)


ZB

ZB
MCQS
Midterm preparation file

39. What is the time complexity of performing a binary search on a sorted


array?

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

40. Which data structure is used to implement depth-first search (DFS)?

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?

a) It is the most efficient solution


b) It requires too much memory
c) It has a high time complexity
d) It produces incorrect results
Answer: c) It has a high time complexity

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

39. What is the time complexity of performing a binary search on a


sorted array?

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

40. Which data structure is used to implement depth-first search


(DFS)?

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?

a) It is the most efficient solution


b) It requires too much memory
c) It has a high time complexity
d) It produces incorrect results
Answer: c) It has a high time complexity

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
MCQS ZB
Midterm preparation file

43. What does the "divide and conquer" approach involve?

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?

a) Faster insertion at the end


b) Faster search for elements
c) Faster deletion from both ends
d) Requires less memory
Answer: c) Faster deletion from both ends

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