Mock 41243 1712322751002
Mock 41243 1712322751002
com
Questions
1. Consider the following table with weight of the items and their corresponding profit, Knapsack has capacity
50, the maximum profit that can be achieved through fractional Knapsack is using greedy algorithm
________.
A. 290 B. 320
C. 330 D. 350
2. Consider a system having ‘m’ resources of same type. These resources are shared by 4 processes P0,
P1, P2 and P3, which have peak demand 6, 9, 7 and 14 respectively. The maximum value of ‘m’, so
deadlock may occur ____.
A. 30 B. 32
C. 20 D. 33
3. Consider a n processes running on CPU without any deadlock. Each process need common resource to
execute successfully among n processes, 7 process requires maximum of 12 resources, remaining
process require maximum of 10 resources. Total 186 resources are available. How many maximum
number of processes are running in the CPU ?
4. Consider the C code given below:
#include <stdio.h>
#include <string.h>
void f(char * p) {
if (*p! = 0){
printf(“%c”, *p);
www.byjusexamprep.com
f(p + 1);
int main()
f(s);
return 0;
# include<stdio.h>
int main ()
{
www.byjusexamprep.com
int **ptr = p;
ptr++;
The number of topological sorts that are possible from the above graph is ____.
9. void main () {
int i = ‘a’;
www.byjusexamprep.com
switch(i)
case ‘a’:
printf(“Hello”);
case 97:
printf(“world”);
break;
default:
print(“nothing”);
Assume that the processes are scheduled using the Longest non-pre-emptive Longest Job First(LJF)
algorithm. What are the average turnaround time and average waiting time?
A. 10,5 B. 9,8
www.byjusexamprep.com
C. 10,4 D. 9,5
11. Consider the following
code snippet
int a = 7, b = 6, c;
c = a>>2 + 3 * 8 == 8 * 8 + b;
printf(“%d”, c);
while(1) { while(1) {
} }
} }
C. D.
while(1) { while(1) {
} }
} }
14. int * fun (int x)
int y = x + 10%
return (&y);
void main()
www.byjusexamprep.com
int * x;
x = fun (10);
printf(“%d”, *x);
int D[128][128];
Demand paging is used for allocating memory and each physical page frame holds 512 elements of the
array D. The Least Recently Used (LRU) page-replacement policy is used by the operating system. A total
of 30 physical page frames are allocated to a process which executes the following code snippet:
D[j][i] *= 10;
The number of page faults generated during the execution of this code snippet is _______.
17. Suppose there are two singly linked lists both of which intersect at some point and become a single linked
list. The head or start pointers of both the lists are known, but the intersecting node and lengths of lists are
not known.
www.byjusexamprep.com
What is worst case time complexity of optimal algorithm to find intersecting node from two intersecting
linked lists?
B. Θ(n2), where m>n and m, n are lengths of given
A. Θ(n*m), where m, n are lengths of given lists
lists
C. Θ(m+n), where m, n are lengths of given lists D. Θ(min(n, m)), where m, n are lengths of given lists
18. A file system with 512 GB disk uses a file descriptor with 16 direct block addresses, 1 indirect block
address, 1 doubly indirectly block address and 1 triple indirect block addresses. Size of each disk block is
256 bytes and the size of each disk block address is 8 bytes. The maximum possible file size is
__________ (in MB).
19. Consider the following page reference string with 3 frames:
2, 4, 3, 1, 5, 3, 2, 5, 3, 1, 4, 2
Number of page fault occurs if FIFO page replacement algorithm is used ________.
20. The following C function takes single linked list as parameter and rearranges the elements of the list. The
function is called with list containing integers 1, 2, 3, 4, 5, 6 in order.
What will be the content of the list after function completes execution?
A. 2, 1, 4, 3, 6, 5 B. 1, 3, 3, 5, 5, 6
www.byjusexamprep.com
C. 1, 1, 1, 1, 1, 6 D. 1, 1, 1, 1, 1, 1
21. Algorithms A and B use T (n) = c n log n and T (n) = c n2 elementary operations for a problem of size
A A 2 B B
n. Find the fastest algorithm for processing n = 220 data items if A and B spend 10 and 1 operations,
respectively, to process 210 items.
A. Algorithm A B. Algorithm B
C. Both are equal D. None
22. Consider the following pseudo code. (Assume that n > 1)
there are 4 extra frames which can be used by any process once all reserved frames are loaded with
pages by a process. Page size is 1 KB .
Following is the reference string in the form < Process, PageNo> in the sequence:
The total number of page faults by all processes if LRU is used for page replacement is ____.
27. Consider the partially given function in the C programming language is used to find the median of two
sorted arrays A and B each of size n (n can be even or odd) but of same size:
median (A, B, a_low, a_high, b_low, b_high)
if (a_low == a_high)
return (S1);
else
else
else
return (S2);
weight –k and reset each edge weight w to w+k+1. Which of the following is true?
B. Minimum cost spanning trees in the original graph
A. Kruskal's algorithm will identify the same
will not correspond to minimum cost spanning trees
spanning tree on the new graph as on the old graph.
in the new graph.
C. Prim's algorithm will not work on the original D. There are more minimum cost spanning trees in
graph but will work on the modified graph. the modified graph than in the original graph
31. Consider an array consisting of the following elements in unsorted order (placed randomly), but 60 as first
element.
60, 80, 15, 95, 7, 12, 35, 90, 55
Quick sort partition algorithm is applied by choosing first element as pivot element. How many total
number of arrangements of array integers is possible preserving the effect of first pass of partition
algorithm.
A. 718 B. 720
C. 724 D. 728
32. The number of different orders are possible for elements 1, 2, 3, 4, 5, 6, 7 to be inserted in to empty AVL
tree such that no rotation will be done and element ‘4’ is root are ________.
33. Which of the following is the correct decomposition of the directed graph given below into its strongly
connected components?
There are still 2, 1, 2 instances of A, B and C are available respectively. Following requests are made by
processes in the sequence.
(i). Suppose that Dijkstra’s algorithm is run using a priority queue data structure for which insert and
decrease key operations take O(log V) time, the extract-min operation takes O(V) time, then the running
time of Dijkstra’s algorithm on a directed weighted graph G = (V, E) containing non-negative edges will be
O(V + E log V)
(ii). If a topological sort exists for the vertices in a directed graph, then a DFS on the graph will produce no
back edges.
A. None of the above B. Both (i) and (ii)
C. Only (i) D. Only (ii)
www.byjusexamprep.com
38. Consider the following set of processes with their arrival and CPU burst time.
What is the average waiting time of these processes when shortest job first policy is used ________?
39. Consider a computer system with 57-bit virtual addressing using multi-level tree-structured page tables
with L levels for virtual to physical address translation.
The page size is 4 KB (1 KB = 1024 B) and a page table entry at any of the levels occupies 8 bytes.
Over all possible choices of the values at the leaves, the minimum possible values of the expression
represented by the tree is _______.
www.byjusexamprep.com
Solutions
1. B
Sol.
Profit = 180 + 30 + 70
Weight = 20 + 5 + 15 = 40
Remaining weight = 50 – 40 = 10
2. B
Sol. (I) To avoid the deadlock the minimum resources required will be:
(II) Hence, to make the system go into deadlock, subtract one extra resource that we provided to start the
execution of any processes.
www.byjusexamprep.com
(III) If we give one more resource to any processes then one process must complete its execution and
release consumed resources and other processes to complete their execution subsequently.
⇒ r >= n (m – 1) + 1
r = no. or resources = 40
n = no. of process
186 ≥ 77 + 9n – 63 + 1
186 ≥ 15 + 9n
171 ≥ 9n
9n ≤ 171
n ≤ 19
4. D
Sol.
www.byjusexamprep.com
Option B is true. The time complexity of bubble sort in the best case is O(n) and in the worst and average
case is O(n2).
Option C is true. Since selection sort is an in-place sorting algorithm, it does not require additional storage.
Option D is false. The selection sort is not scalable. As the input size increases, the performance of the
selection sort decreases.
6. 250
Sol. (I) Construction array a[] with elements 10, 20, 30, 40, 50.
Now,
www.byjusexamprep.com
++ptr – P = ((P + 1) + 1) – P = 2
So, above statement find the number of elements between the two pointers.(since unary operator has
higher precedence then binary operator).
II. Now, frame bits to locate pages in physical memory = log2 212 = 12 bits
∴ Page table entry size = frame bits = 12 bits 2 bytes
III. Now, page table size = 250 * 21 bytes
= 251 bytes
= 2 Peta bytes.
www.byjusexamprep.com
8. 12
Sol. Since the given graph has 8 vertices.
So, the topological sort consists of order 8, that is:
A __ __ D __ __ __ H
The vertices A, D and H are fixed as there is no other choice. In the remaining vacant places, we have the
choices.
So, the number of topological sorts = 2!*3! = 2 × 6 = 12.
9. D
Sol. case labels cannot be duplicate
and in the above code
case labels are duplicate
i.e.
12. 26
Sol. Given message:’IITBBITSIISC.”
Now, we arrange these in ascending order and merge them using the optimal merge pattern and derive
the Huffman tree.
www.byjusexamprep.com
= (5 × 1) + (2 × 3) + (2 × 3) + (2 × 3) + (1 × 3)
= 5 + 6 + 6 + 6 + 3 = 26.
13. A,D
Sol. The problem defined in the question is Dining Philosopher problem with chopsticks
void process {
while(1) {
Wait( take_resource[i] );
Wait( take_resource[(i+1) % n] ) ;
. Perform task
Signal( put_resource[i] );
}
www.byjusexamprep.com
The code snippet provided represents the solution to the Dining Philosophers problem using the given
pseudocode. Let's break down the code and explain how it addresses the problem:
The code is inside an infinite loop, indicating that the philosopher process will keep repeating its actions
indefinitely.
The first Wait(take_resource[i]) call represents the philosopher trying to acquire the left chopstick. If the
chopstick is available, the philosopher proceeds to the next line; otherwise, it waits until the chopstick
becomes available.
The second Wait(take_resource[(i+1) % n]) call represents the philosopher attempting to acquire the right
chopstick. Similarly, it waits until the right chopstick becomes available.
After successfully acquiring both chopsticks, the philosopher can proceed to perform its task. This is
where the actual eating or any other action the philosopher needs to perform takes place.
Once the task is completed, the philosopher releases the left chopstick using Signal(put_resource[i]) and
the right chopstick using Signal(put_resource[(i+1) % n]). These signals indicate that the chopsticks are
now available for other philosophers to use.
After releasing the chopsticks, the philosopher enters the thinking state, which is not explicitly shown in
the given code snippet. The thinking state represents the period when the philosopher is not actively trying
to eat but instead contemplating or waiting for the next opportunity to eat.
This code follows a solution approach where the philosopher waits until both its left and right chopsticks
are available before proceeding to eat. By utilizing the provided synchronization primitives (such as Wait
and Signal), the code ensures that the philosophers acquire the necessary resources (chopsticks) without
causing conflicts or deadlocks.
∴ option D is correct.
15. 24
Sol. The common subsequence of longest length is:
i. GATE
ii. EXAM
Now, x = 4 and y = 2.
16. 4096
Sol. Given that, 1 frame hold 512 Element,
Array size is 128 × 128 = 214 elements.
Sol. This takes Θ(m+n) time and O (1) space in the worst case, where M and N are the total lengths of the
linked lists.
2. Get back to the heads, then traverse |m − n| nodes on the longer list.
3. Now walk in both the linked list and compare the nodes until you found the common ones.
18. 8
Sol. Direct block addressing = 16 × 256 ⇒ 4 KB
= 25 * 28 B
= 213 B ⇒ 8 KB
= (25)2 * 28 B
= 210 * 28 B
⇒ 256 KB
= (25)3 * 28 B
= 215 * 28 B
www.byjusexamprep.com
⇒ 223 B
⇒ 8 MB
19. 10
Sol.
21. A
Sol. T (210) = 10 ⇒ c = = 2–10
A A
TB(210) = 1 ⇒ cB = = 2–20
so algorithm A is faster.
22. 3
Sol.
www.byjusexamprep.com
23. A
Sol. Here uniform hashing is given so even though its linear probing we won't reduce the size.
For K1 = m/m=1 (it can place anywhere)
For K2 = we have 3 possibilities above K1 below K1 or at same slot as K1 & the collision happen so here
probability is k2 = 3/m
So for K3 there is only one possibility = 1/m
So total probability = 1 * 3/m * 1/m = 3/m2.
So, option (A) is correct.
24. 7
Sol.
In Build-heap method, it is assumed that the leaf nodes are satisfying heap property and heapify
procedure starts from second last level.
Total nodes
= (m-1 / n-1) + m
= (mn-1)/n-1
So, option (A) is correct.
26. 24
Sol. According to the question four frames are there, therefore we have first four-page fault as in the sequence
starting four pages are distinct.
After the 4 pages resides in the frame than another page comes in the sequence and replace the
<P1,100> with <P2,101> and the page fault becomes 5.
As in the sequence no page is repeating in the four pages therefore the total number of pages fault is 24.
27. A
Sol. To find the median of two sorted arrays A and B each of size n(n can be even or odd) but of
same size:
median ( , a_mid, a_high , b_low, b_mid) and
median ( , a_low, a_high high)
Option A is the correct answer.
28. D
Sol.
(a)6, 8, 4, 7, 5 :
After popping element 6, only 4 can be popped, hence this permutation is not possible.
(b)6, 4, 5, 7, 8 :
www.byjusexamprep.com
After performing the pop operation on elements 6, 4 now only element 8 can be popped. Hence, this
permutation is not possible.
(c)6, 4, 7, 8, 5 :
After 6, 4 elements are popped, now element 7 can only be popped if and only if 8 has already been
popped. Hence, this permutation is not possible.
(d)7, 8, 4, 6, 5 :
Hence, the option D is correct as we get the output as the order mentioned in the option.
29. A
Sol.
T(n) = c.n2
N=100, T(N)= 1ms
1ms = c*(100)2
Now, n= 5000
T(n)= (1/ (100)2) * (5000)2
=2500 ms.
So, option (A) is correct.
30. A
Sol. The ascending order of edge weights is unchanged if each edge weight is increased by k+1,
so Kruskal's algorithm runs exactly the same way as before and produces the same tree. In
www.byjusexamprep.com
general, since every spanning tree has exactly n-1 edges, the increase in weight uniformly
affects all spanning trees, so the minimum cost of spanning trees are unchanged. Prim's
algorithm is not affected by negative weights
So, option (A) is correct.
31. B
Sol. We have to choose first element as pivot.
Here 60 is given as first element.
After first pass, the pivot element goes to it’s exact location.
Here 60 goes to 6th place.
All the elements less than 60 go to left of 60 and all the elements greater than 60 go to right
of 60.
After 1st pass
(1, 3, 5, 7) can be inserted in any order since these are leaf nodes. However, 6 needs to be inserted
before 5 and 7 and 2 needs to be inserted before 1 and 3.
4 being the root node, needs to be inserted first of all.
2 and 6 can be inserted in 2! Ways, leaf nodes 1,3,5,7 can be inserted in 4! Ways.
Total Possibilities = 2! * 4! = 2* 24= 48
33. B
Sol. If then i and j belongs to same strongly connected components where i and j are
vertices and means there is a path from i to j.
www.byjusexamprep.com
Solving by elimination
Option (c) : From R we can reach P Q V S T and from P Q V S T we can reach R thus R should not be
separated thus false.
34. A
Sol. If we allocate 1, 1, 1 to P1 then the current availability will be 1, 0, 1.
with this availability, we can have a safe sequence as P2, P3, P1, P4.
35. 1396
Sol. Given that |V| = 200
|E| = 400
By using properties of MST, every MST contain (V - 1) number of edges. So, we have 199 edges in MST.
Thus, number of nodes with degree 2 is always one less than number of leaf nodes present in tree.
37. B
Sol. (i). There are V extract-min operations, and E decreases key operations for Dijkstra’s
algorithm using a priority queue. So, the time complexity is O(V + E log V)
(ii). Both parts of the statement hold if and only if the graph is acyclic.
So, option (B) is correct.
38. 3
Sol.
39. 5
Sol.
www.byjusexamprep.com
=
227 pages, page table size
= 227 PTE’s * 8 bytes
= 230 bytes …(3)