Cse357 MCQ
Cse357 MCQ
options -
a. 8
b. 7
c. 9
d. 6
Q(9) Mutex is a
(a) counter
(b) binary state
(c) both state and counter
(d) neither state nor counter
6. Which type of inheritance allows a class to inherit from multiple parent classes?
A. Single
B. Multi-level
C. Hierarchical
D. Multiple
5: What is the ability of a program to manipulate its own source code called?
A. Debugging
B. Optimization
C. Metaprogramming
D. Compilation
7: Which OOP concept is used to bundle data and methods that operate on the data?
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Abstraction
8: What is the process by which one class acquires the properties of another class?
A. Composition
B. Polymorphism
C. Inheritance
D. Encapsulation
2: Which OOP concept allows a class to have multiple methods with the same name but
different parameters?
A. Overloading
B. Overriding
C. Encapsulation
D. Polymorphism
7: Which OOP principle is violated if a subclass tries to override a final method of its
superclass?
A. Encapsulation
B. Polymorphism
C. Inheritance
D. Abstraction
9: What is the term for the ability of a class to have multiple methods with the same name but
different implementations?
A. Overloading
B. Overriding
C. Polymorphism
D. Encapsulation
10: Which of the following is a correct syntax for implementing an interface in Java?
A. class MyClass implements MyInterface { }
B. class MyClass extends MyInterface { }
C. interface MyInterface implements MyClass { }
D. interface MyInterface extends MyClass { }
4: What is the purpose of the ”try”, ”catch”, and ”finally” blocks in exception handling?
A. To handle errors and exceptions
B. To create objects
C. To define a class
D. To implement polymorphism
6. Which of following data structure is more appropriate for implementing quick sort
iteratively?
A. Deque
B. Queue
C. Stack
D. Priority queue
10. ......... form of access is used to add and remove nodes from a queue.
A. LIFO, Last In First Out
B. FIFO, First In First Out
C. Both a and b
D. None of these
1: The linear relationship between the elements represented by means of pointers is called
.............
A. Arrays
B. Linked list
C. Both
D. None
2: Which of the following data structure is required to convert arithmetic expression in infix
to its equivalent postfix notation?
A. Queue
B. Linked list
C. Binary search tree
D. Stack
4: If two trees have same structure and but different node content, then they are called ........
A. Synonyms trees
B. Joint trees
C. Equivalent trees
D. Similar trees
1: Identify the data structure which allows deletions at both ends of the list but insertion
at only one end.
A. Input restricted dequeue
B. Output restricted queue
C. Priority queues
D. Stack
8: If two trees have same structure and node content, then they are called ..........
A. Synonyms trees
B. Joint trees
C. Equivalent trees
D. Similar trees
9: The worst-case time required to search a given element in a sorted linked list of
length n is
A. O(1)
B. O(log2 n)
C. O(n)
D. O(n log2 n)
10: Traversing a binary tree first root and then left and right subtrees called .........
traversal.
A. Postorder
B. Preorder
C. Inorder
D. None of these
2: A binary tree in which all its levels except the last, have maximum numbers of nodes,
and all the nodes in the last level have only one child it will be its left child. Name the
tree.
A. Threaded tree
B. Complete binary tree
C. M-way search tree
D. Full binary tree
4: ............. deque is a deque which allows deletions at only one end of the list.
A. input-restricted
B. output-restricted
C. Queue
D. Heap
10: A search begins the search with the element that is located in the middle of the
array
A. serial
B. random
C. parallel
D. binary
1: The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which
one of the following is the post order traversal of the tree?
A. 10, 11, 12, 15, 16, 18, 19, 20
B. 11, 12, 10, 16, 19, 18, 20, 15
C. 20, 19, 18, 16, 15, 12, 11, 10
D. 19, 16, 18, 20, 11, 12, 10, 15
4: A program P reads in 500 integers in the range [0, 100], representing the scores of 500
students. It then prints the frequency of each score above 50. What would be the best
way for P to store the frequencies?
A. An array of 50 numbers
B. An array of 100 numbers
C. An array of 500 numbers
D. A dynamically allocated array of 550 numbers
7: Following are pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 7, 14, 56, 22, 25, 8
Pass 2: 7, 8, 56, 22, 25, 14
And so on...
Final: 7, 8, 14, 22, 25, 56 Choose the name of the associated algorithm for the above
results.
A. Selection sort
B. Insertion sort
C. Bubble Sort
D. Merge Sort
8: Following are the pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 14, 22, 56, 7, 25, 8
Pass 2: 14, 22, 56, 7, 25, 8
Pass 3: 7, 14, 22, 56, 25, 8
And so on...
Final: 7, 8, 14, 22, 25, 56 Choose the name of the associated algorithm for the above
results.
A. Selection sort
B. Insertion sort
C. Bubble Sort
D. Merge Sort
9: Following are the pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 14, 22, 7, 25, 8, 56
Pass 2: 14, 7, 22, 8, 25, 56
And so on...
Final: 7, 8, 14, 22, 25, 56 Choose the name of the associated algorithm for the above
results.
1. Find the recurrence relation of the Quick Sort algorithm in the worst case.
A. T(n) = T(n/10) + T(9n/10) + O(n)
B. T(n) = T(n − 1) + T(0) + O(n)
C. T(n) = 2T(n/2) + O(n)
D. T(n) = T(n − 2) + O(n)
2. Let us have an algorithm to find the median of the unsorted array having complexity
O(n). Now we have modified the quicksort algorithm and using the median algorithm to
find the pivot element. What will be the complexity of this modified quicksort algorithm
in the worst case?
A. O(log log n)
B. O(n)
C. O(n 2 )
D. O(n log n)
3. If the array is already sorted or almost sorted then which algorithm will give the best
results?
A. Quick Sort
B. Merge Sort
C. Heap Sort
D. Insertion Sort
4. If Swap operation is very costly then which sorting technique you will choose to sort
the unsorted array?
A. Insertion Sort
B. Selection Sort
C. Merge Sort
D. Heap Sort
5. Suppose you have 2GB Data and you have to sort it, but you have only 100MB main
memory available with you, which sorting technique you are going to apply?
A. Merge Sort
B. Insertion Sort
C. Heap Sort
D. Quick Sort
7. Average number of comparisons in linear search when the element is present in the
list is:
A. n
B. n/2
C. (n + 1)/2
D. (n − 1)/2
8. Average number of comparisons in linear search when the element is present in the
list is:
A. n
B. n/2
C. (n + 1)/2
D. (n − 1)/2
9. If we have 11 sorted elements in an array and we apply Binary search to find the
element and each time it is a successful search. What will be the average number of
comparisons we need to do?
A. 3.46
B. 3.0
C. 3.33
D. 2.81
1: Which of the Hash Function will create a cluster in the hash table?
A. h(k) = k
B. h(k) = k%m
C. h(k) = ( k m + k · m ) + k%m
D. h(k) = (k + 1) %m + k m
2: Hash Table T has 25 slots which are going to store 2000 elements. What will be the
load factor?
A. 0.0125
B. 50000
C. 1.25
D. 80
3: Let a Hash Function distributes keys uniformly in the hash table. The hash table has
size 50. After how many keys are added will the probability of collision become 0.5?
A. 20
B. 25
C. 10
D. 30
5: Insert the characters of the string KRP Y SNJM into a hash table of size 10. Use the
hash function h(x) = (ord(x) − ord(”A”) + 1) mod 10. If linear probing is used to resolve
collisions, then the following insertion causes a collision. ord(x) is a function that
returns the alphabetical order of the letter.
A. P
B. M
C. C
D. K
9: Which of the following algorithms can be used to eeiciently calculate single source
shortest paths in a Directed Acyclic Graph?
A. Topological Sort
B. Bellman-Ford
C. Dijkstra
D. Prim’s
10: Given a directed graph where the weight of every edge is the same, we can eeiciently
find the shortest path from a given source to destination using:
A. DFS
B. BFS
C. Dijkstra
D. Kruskal
3: What is the time complexity of the Greedy Algorithm for Hueman coding?
A. O(n log n)
B. O(n 2 )
C. O(n)
D. O(log n)
5: In the context of the Fractional Knapsack Problem, if the available capacity is 10 and
there are items with weights {5, 3, 8} and values {10, 6, 12}, what is the maximum value
that can be obtained using a greedy approach?
A. 15
B. 18
C. 22
D. 28
6: In the context of Hueman coding, if the frequencies of characters are {2, 3, 7, 10} and
a greedy algorithm is used to build the Hueman tree, what is the total number of bits
needed to represent the entire message?
a. 18
b. 20
c. 24
d. 28
7: For a given graph, if Prim’s algorithm is used to find the minimum spanning tree, and
the graph is represented using an adjacency matrix, what is the time complexity in
terms of the number of vertices (V)?
A. O(V )
B. O(V 2 )
C. O(V log V )
D. O(V 3 )
8: In the Fractional Knapsack Problem, if the available capacity is 15 and there are items
with weights {8, 4, 6} and values {16, 10, 12}, what is the optimal solution obtained using
a greedy approach?
A. 30
B. 28
C. 26
D. 24
9: What is the time complexity of the greedy algorithm for job scheduling with
deadlines?
A. O(n)
B. O(n log n)
C. O(n 2 )
D. O(log n)
10: For a given graph with weighted edges, if Kruskal’s algorithm is applied to find the
minimum spanning tree, what is the time complexity for a graph with V vertices and E
edges?
A. O(V )
B. O(E)
C. O(V log V )
D. O(E log E)
1: In the Merge Sort algorithm, what is the time complexity for sorting an array of n
elements?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n 2 )
5: What is the time complexity of the Merge Sort algorithm for sorting an array of size n?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n 2 )
6: If an algorithm divides the problem into five subproblems and each subproblem is
solved independently, what would be its recurrence relation for time complexity?
A. T(n) = 5 · T(n/5)
B. T(n) = T(n/5) + T(4n/5)
C. T(n) = T(n/2) + 5
D. T(n) = 5 · T(n)
7: If a Divide and Conquer algorithm has a recurrence relation T(n) = T(n/2)+O(n), what is
its time complexity?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n 2 )
8: If the size of the input is halved in each recursive call and an additional linear amount
of work is done, what is the overall time complexity of the algorithm?
A. O(log n)
B. O(n)
C. O(n log n)
D. O(n 2 )
9: Consider a recursive algorithm with a time complexity given by the recurrence
relation T(n) = 3T(n/4) + n 2 . What is the time complexity of this algorithm using the
Master Theorem?
A. O(n)
B. O(n log n)
C. O(n 2 log n)
D. O(n 2 )
10: The time complexity of an algorithm is given by T(n) = T(n/2) + T(n/4) + n. What is the
time complexity of the algorithm?
A. O(n log n)
B. O(n 2 )
C. O(n 2 log n)
D. O(n 3 )
5: Which of the following is an example of a problem that can be eeiciently solved using
dynamic programming?
A. Sorting an array
B. Finding the maximum element in an array
C. Longest Common Subsequence
D. Binary search
6: In the Fibonacci sequence, if F(0) = 0 and F(1) = 1, what is the value of F(5) using
dynamic programming?
A. 3
B. 5
C. 8
D. 13
7: For the Longest Common Subsequence (LCS) problem, if the input sequences are
”ABCD” and ”ACDF,” what is the length of the LCS using dynamic programming?
A. 2
B. 3
C. 4
D. 5
10: For the Knapsack problem, if the maximum capacity is 10 and there are items with
weights [2, 4, 5] and values [6, 8, 7], what is the maximum value that can be achieved
using dynamic programming?
A. 13
B. 14
C. 15
D. 16