wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mock-1

Total questions: 90

Worksheet time: 2hrs 31mins

Name
Class
Date
1.
Anachronistic
a)
Modern
b)
Timeless
c)
Outdated
d)
Historical
2.
Acrimonious
a)
Harmonious
b)
Hostile
c)
Bitter
d)
Caustic
3.
Abstruse
a)
Clear
b)
Profound
c)
Complex
d)
Incomprehensible
4.
Bellicose
a)
Peaceful
b)
Aggressive
c)
Warlike
d)
Combative
5.
Chicanery
a)
Honesty
b)
Trickery
c)
Deception
d)
Fraudulence
6.
Convivial
a)
Sullen
b)
Friendly
c)
Sociable
d)
Festive
7.
Dilatory
a)
Prompt
b)
Tardy
c)
Slow
d)
Delaying
8.
Encomium
a)
Criticism
b)
Praise
c)
Compliment
d)
Tribute
9.
Fatuous
a)
Sensible
b)
Foolish
c)
Silly
d)
Insane
10.
Garrulous
a)
Reticent
b)
Talkative
c)
Verbose
d)
Chatty
11.
Cacophony : Sound :: Garble : ?
a)
Water
b)
Speech
c)
Vision
d)
Taste
12.
Quiescent : Activity :: Desiccated : ?
a)
Energy
b)
Animation
c)
Moisture
d)
Freshness
13.
Indomitable : Subdue :: Immutable : ?
a)
Destroy
b)
Change
c)
Interpret
d)
Enhance
14.
Ephemeral : Lasting :: Languid : ?
a)
Energetic
b)
Tiring
c)
Short-lived
d)
Effortless
15.
Nexus : Connection :: Chasm : ?
a)
Valley
b)
Separation
c)
Peak
d)
Pathway
16.
Ebullient : Enthusiasm :: Lachrymose : ?
a)
Joy
b)
Tears
c)
Anger
d)
Calm
17.
Mendicant : Wealth :: Ascetic : ?
a)
Luxury
b)
Suffering
c)
Spirit
d)
Food
18.
Propitious : Omen :: Salutary : ?
a)
Advice
b)
Medicine
c)
Diet
d)
Practice
19.
Turgid : Subtlety :: Bombastic : ?
a)
Clarity
b)
Simplicity
c)
Loquaciousness
d)
Exaggeration
20.
Miser : Generosity :: Blasphemer : ?
a)
Faith
b)
Devotion
c)
Reverence
d)
Heresy
21.
Despite his reluctance _______ confront the issue, he eventually addressed it head-on.
a)
on
b)
at
c)
to
d)
in
22.
The new policy is aimed _______ reducing the environmental impact of the company’s operations.
a)
at
b)
to
c)
for
d)
with
23.
He was engrossed _______ his book, oblivious to the noise around him.
a)
in
b)
on
c)
with
d)
by
24.
The professor insisted _______ the importance of academic integrity in all research.
a)
on
b)
in
c)
for
d)
about
25.
She prides herself _______ her ability to solve complex problems.
a)
on
b)
in
c)
with
d)
for
26.
The conference will focus _______ the latest developments in artificial intelligence.
a)
in
b)
at
c)
on
d)
to
27.
He was immune _______ the criticism, remaining calm and collected.
a)
to
b)
from
c)
at
d)
by
28.
The results are consistent _______ the hypothesis proposed by the researchers.
a)
to
b)
with
c)
for
d)
on
29.
She has a reputation _______ being one of the most dedicated workers in the company.
a)
for
b)
to
c)
at
d)
on
30.
His ideas were met _______ skepticism by his colleagues.
a)
with
b)
on
c)
Interpret
d)
at
31.
A, B, C, D, E and F are 6 villages situated in a line. Yuvraj has to go from A to F. He can walk at 1 kmph from A to B and from D to E; at 3 kmph from B to C; and at 5 kmph from C to D and E to F. The distance between B and E is 51 km, A and C is 29 km which is equal to the distance between B and D. The distance between C and E is 42 km and the distance between D and F is 37 km. How long would it take for Yuvraj to go from A to F assuming he will not take any rest during the journey?
a)
41 hours
b)
47 hours
c)
52 hours
d)
75 hours
32.
A bath tub can be filled by the cold water pipe in 9 minutes and by the hot water pipe in minutes. A person leaves the bath room after turning on both the pipes simultaneously and return the moment when the bath tub should be just full.However, finding that the waste pipe was open, he closes it and now the bath tub gets filled in more minutes. The time in which the waste pipe empties the bath tub is
a)
6 minutes
b)
6 minutes
c)
6minutes 40 seconds
d)
7 minutes 40 seconds
33.
There are four towns in a straight line at the milestones of A at 10 miles, B at 20 miles, C at 35 miles and D at 45 miles respectively. Sunil wants to set up a shop to service these four towns. If the demand from each of these towns is found to be identical and there are no other shops servicing these towns then, which of the following is the only way to minimize the cost of transportation?
a)
Set up the shop anywhere between towns A and B
b)
Set up the shop anywhere from B to C
c)
Set up the shop at B
d)
Set up the shop at C
34.
Rudrapratap has five children, 3 daughters and 2 sons. Five years ago, the combined age of his daughters is thrice that of his sons and five years hence, the combined age of his daughters will be twice that of his sons. If the present age of Rudrapratap’s youngest child is at least six years, then the present average age of his five children is
a)
11
b)
12
c)
13
d)
Cannot be determined
35.
Number S is obtained by squaring the sum of digits of a two digit number D. If difference between S and D is 27, then the two digit number D is
a)
24
b)
54
c)
34
d)
45
36.
The owner of a local jewellery store hired 3 watchmen to guard his diamonds, but a thief still got in and stole some diamonds. On the way out, the thief met each watchman, one at a time. To each he gave half of the diamonds he had then, and 2 more besides. He escaped with one diamond. How many did he steal originally?
a)
40
b)
36
c)
25
d)
None
37.
If a number 774958A96B is to be divisible by 8 and 9, the respective values of A and B will be
a)
7 and 8
b)
8 and 3
c)
5 and 8
d)
8 and 0
38.
A report consists of 20 sheet each of 55 lines and each such lines consists of 65 characters. This report is reduced onto sheets each of 65 lines such that each line consists of 70 characters. The percentage reduction in number of sheets is closest to
a)
20
b)
5
c)
30
d)
35
39.
A can complete a piece of work in 4 days. B takes double the time taken by A, C takes double that of B and D takes double that of C to complete the same task. They are paired in groups of two each. First pair takes two-thirds the time needed by the second pair to complete the work. The first pair consist of
a)
A,B
b)
A,C
c)
B,C
d)
A,D
40.
The principal wants to arrange 5 students on the platform such that the boy ‘AJAY’ occupies the second position and such that the girl ‘SITA’ is always adjacent to the girl ‘RITA’. How many such arrangements are possible?
a)
2
b)
5
c)
7
d)
8
41.
How many numbers greater than a million can be formed with the digits 2, 3, 0, 3, 4, 2, 3?
a)
360
b)
420
c)
540
d)
298
42.
If the product of the roots of the equation x2 – 3kx + 2e2logk – 1 = 0 is 7, then the roots of the equation are real for k =
a)
2
b)
-2
c)
2.33
d)
Both 1 and 2
43.
The integer sequence a1, a2, a3, ... satisfies an + 2 = an + 1 – an for n > 0. If the sum of the first 1492 terms of this sequence is 1985 and the sum of the first 1985 terms is 1492, then the sum of the first 2001 terms is
a)
986
b)
zero
c)
1476
d)
None
44.
On a TV quiz show, Mr. and Mrs. Nath are given two red blocks and two blue blocks that they must distribute into two boxes any way they wish. Mrs. Nath will then be blindfolded and asked to pick one block at random from one of the boxes, if she picks a red block , then she will win Rs.1 million. The maximum probability of drawing a red block by Mrs. Nath could be
a)
0.4
b)
0.3333333333333333
c)
0.75
d)
None
45.
A hare sees a dog 100 metres away from her and scuds off in the opposite direction at a speed of 12 km an hour. A minute later the dog perceives her and gives chase at a speed of 16 km per hour. How soon will the dog overtake the hare, and at what distance from the spot whence the hare took flight?
a)
200
b)
900
c)
1100
d)
None
46.
Ram and Shyam attended a food festival. Ram gave an order for 3 burgers, 4 pastries and 2 pizzas whereas Shyam placed an order for 2 burgers, a pastry and 3 pizzas. The bill for Ram and Shyam was Rs.1050 and Rs.950 respectively. If Ram exchanges a pizza for a pastry from Shyam, then which of the following is true?
a)
Shyam owes Ram a sum of Rs.150
b)
Shyam owes Ram a sum of Rs.100
c)
Ram owes Shyam a sum of Rs.150
d)
None
47.
The average score of 25 students in a class test in maths is 75. If the top three ranker's are dropped, the average drops by 2. If the maximun marks for the paper is 100 and the second highest score is less than 90, then what could be the least highest score, if all scores are integers?
a)
97
b)
91
c)
99
d)
98
48.
The inhabitants of Planet – X measure time in hours and minutes which is different from our measurement of earth. The day in Planet – X consists of 36 hours with each hour having 120 minutes. The dials of their clock shows 36 hours. What is the angle (in Planet – X degrees) between the hours and the minute hands when it shows a time of 11:24 am? (The angle around the dial in planet – X watch is 720°.)
a)
100
b)
80
c)
120
d)
60
49.
The digits of a four digit number form an arithmetic progression, not necessarily in the same order. If the arithmetic mean of all the digits is an integer, then how many such numbers are possible?
a)
72
b)
84
c)
90
d)
96
50.
A washerman can wash 6 trousers or 8 shirts in 1 hour while his wife can wash 6 trousers or 8 shirts in 2 hours. The couple get a work of 160 trousers and 200 shirts to wash. The man and the woman work on alternate hours and for a total of 12 hours daily. Every morning except the first the lady starts the work. If the couple worked for only 5 hours on the first day with the man starting the work at noon, then
a)
the man finishes the work on 7th day
b)
the woman finishes the work on 6th day
c)
the man finishes the work on 8th day
d)
the woman finishes the work on 8th day
51.
There are triplet brothers who look identical. The oldest is John, he always tells the truth. The second is Jack, he always tells a lie. The third is Joe, he either tells the truth or a lie. Jimmie went to visit them one day. He was wondering who was who? He asked the one who was sitting on the left: "Who is the guy sitting in the middle?" The answer was "He is John." He asked the one who was sitting in the middle: "What is your name?" The answer was "I am Joe." He asked the one who was sitting on the right: "Who is the guy sitting in the middle?" The answer was "He is Jack." The guy sitting in the middle was
a)
john
b)
joe
c)
jack
d)
Cannot be determined
52.
There are two alloys I and II. Alloy I contains metals A, C and D. Alloy II contains metals A and B. Both alloys contain 60% of metal A They are mixed to form a third alloy. The percentage of metal B in the third alloy is half of that of metal A in it. The ratio of percentages of C and D in Alloy I is 3 : 1.The ratio of quantities of C in alloy I and B in alloy II, which are mixed to form the third alloy is
a)
3:2
b)
2:3
c)
3:4
d)
1:4
53.
Mr. Sharma has two containers. He usually keeps them filled up but due to some problem, he found that the smaller one was only 5/6th full on a particular day. He now emptied this smaller container into the bigger one and found that only 4/9th of it was filled up. If we know that the capacity of the smaller container is 536 litres, then the capacity of the larger one would be (litres)
a)
1005
b)
1105
c)
1015
d)
1210
54.
Devilal lives in Sham Sharvan colony where each house has a number. If Devilal’s house number is a multiple of 3, then it is a number from 50 through 59. If his house number is not a multiple of 4, then it is a number from 60 through 69. If his house number is not multiple of 6, then it is a number from 70 through 79. What is his house number?
a)
72
b)
57
c)
76
d)
54
55.
600 people voted on a resolution, but after some discussion, the opponents were increased by 150%. The motion was then rejected by a majority two times as great as that by which it was formerly passed. How many voted for and how many voted against (agst) the initial resolution?
a)
200 (for) 400 (agst)
b)
300 (for) 200 (agst)
c)
400 (for) 200 (agst)
d)
500 (for) 200 (agst)
56.
A merchant buys 40 bicycles and marks them at 25% above the cost price. He allows a discount on the marked price at 10% for cash sales, and at 5% for credit sales. If three-fourth of the stock is sold for cash and the rest for credit, and if the total profit be Rs.2025, what is the cost price of a bicycle?
a)
300
b)
350
c)
400
d)
None
57.
A trader gives a discount of 10% on the list price of goods. Further, to every fourth customer to enter his shop, he gives an article worth Rs. 592 free. If each article cost him Rs. 500 and he makes a profit of 20% on his investment after selling 80 articles. Find at what percentage mark-up is his list price from his cost?
a)
33.6
b)
56
c)
72.8
d)
48.2
58.
A hound takes 5 leaps to every 7 leaps of a hare. But 3 leaps of the hound are equal to 7 leaps of the hare. What is the ratio of the speed of the hound to the speed of the hare?
a)
49:15
b)
7:6
c)
7:3
d)
5:3
59.
Box A contains 25 paise coins alone and box B contains 50 paise coins alone. For every 4 coins transferred from A to B, 3 coins are transferred from B to A. The total amount in both the boxes is Rs 50. If the amounts are same in both the boxes and the number of coins are equal after n such transfers, the value of n is
a)
8
b)
12
c)
10
d)
14
60.

Anil can do a piece of work in 5 days and Ankur in 4 days. How long will they take do the same work, if they work together?

a)

20/9 days

b)

9/20 days

c)

9 days

d)

20 days

61.
Given a binary tree, what is the output of an in-order traversal of the following tree? 4 / \ 2 6 / \ / \ 1 3 5 7
a)
1 2 3 4 5 6 7
b)
4 2 1 3 6 5 7
c)
1 3 2 5 7 6 4
d)
1 2 3 4 5 7 6
62.
Given a linked list with nodes containing values 1, 2, 3, and 4, what will be the output after reversing the linked list?
a)
4 3 2 1
b)
1 2 3 4
c)
2 1 4 3
d)
3 4 1 2
63.
What will be the output of a Depth-First Search (DFS) starting from node 1 for the following graph? lua 1 -- 2 | | 3 -- 4
a)
1 2 4 3
b)
1 3 4 2
c)
1 2 3 4
d)
1 4 3 2
64.
What is the output of the following dynamic programming code for the input array [2, 3, 1, 1, 4]? python Copy code def minJumps(arr): n = len(arr) jumps = [float('inf')] * n jumps[0] = 0 for i in range(1, n): for j in range(i): if i <= j + arr[j]: jumps[i] = min(jumps[i], jumps[j] + 1) return jumps[-1] print(minJumps([2, 3, 1, 1, 4]))
a)
2
b)
3
c)
4
d)
1
65.
What is the output of the following quick sort implementation on the input array [3, 6, 8, 10, 1, 2, 1]? python Copy code def quickSort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quickSort(left) + middle + quickSort(right) print(quickSort([3, 6, 8, 10, 1, 2, 1]))
a)
[1, 1, 2, 3, 6, 8, 10]
b)
[10, 8, 6, 3, 2, 1, 1]
c)
[1, 2, 1, 3, 6, 8, 10]
d)
[3, 6, 8, 10, 1, 2, 1]
66.
What is the output of the following recursive function for n=5? python Copy code def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) print(factorial(5))
a)
120
b)
24
c)
5
d)
60
67.
What will be the output of the following greedy algorithm for the fractional knapsack problem with weights [2, 3, 5, 7] and values [10, 5, 15, 7] and a knapsack capacity of 15? python Copy code def fractionalKnapsack(weights, values, capacity): index = list(range(len(values))) ratio = [v/w for v, w in zip(values, weights)] index.sort(key=lambda i: ratio[i], reverse=True) max_value = 0 for i in index: if weights[i] <= capacity: max_value += values[i] capacity -= weights[i] else: max_value += values[i] * (capacity / weights[i]) break return max_value print(fractionalKnapsack([2, 3, 5, 7], [10, 5, 15, 7], 15))
a)
30
b)
25
c)
20
d)
35
68.
What is the output of the following code for finding the length of the longest increasing subsequence of the array [10, 9, 2, 5, 3, 7, 101, 18]? python Copy code def lengthOfLIS(nums): if not nums: return 0 dp = [1] * len(nums) for i in range(1, len(nums)): for j in range(i): if nums[i] > nums[j]: dp[i] = max(dp[i], dp[j] + 1) return max(dp) print(lengthOfLIS([10, 9, 2, 5, 3, 7, 101, 18]))
a)
4
b)
3
c)
5
d)
6
69.
What is the output of the following code for reversing the words in a string "Hello World"? python Copy code def reverseWords(s): return ' '.join(reversed(s.split())) print(reverseWords("Hello World"))
a)
"World Hello"
b)
"Hello World"
c)
"dlroW olleH"
d)
"olleH dlroW"
70.
What is the output of the following code for generating all subsets of the set [1, 2, 3]? python Copy code def subsets(nums): res = [] def backtrack(start, path): res.append(path) for i in range(start, len(nums)): backtrack(i + 1, path + [nums[i]]) backtrack(0, []) return res print(subsets([1, 2, 3]))
a)
[[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
b)
[[], [3], [2], [1], [3, 2], [3, 1], [2, 1], [3, 2, 1]]
c)
[[1, 2, 3], [1, 2], [1, 3], [2, 3], [1], [2], [3], []]
d)
[[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3], []]
71.
What is the output of the following binary search implementation for the array [1, 2, 3, 4, 5, 6, 7] and target 5? python Copy code def binarySearch(arr, target): left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 print(binarySearch([1, 2, 3, 4, 5, 6, 7], 5))
a)
4
b)
3
c)
5
d)
2
72.
What is the output of the following code to insert elements into a min-heap and then extract the minimum element? python Copy code import heapq heap = [] elements = [3, 1, 4, 1, 5, 9, 2, 6] for element in elements: heapq.heappush(heap, element) min_element = heapq.heappop(heap) print(min_element)
a)
1
b)
2
c)
3
d)
4
73.
What is the output of the pre-order traversal of the following binary tree? markdown Copy code 5 / \ 3 8 / \ \ 1 4 9
a)
5 3 1 4 8 9
b)
1 3 4 5 8 9
c)
5 3 8 1 4 9
d)
1 4 3 9 8 5
74.
What is the output of the following code for rotating a matrix 90 degrees clockwise? python Copy code def rotate(matrix): matrix[:] = zip(*matrix[::-1]) return matrix matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] print(rotate(matrix))
a)
[(7, 4, 1), (8, 5, 2), (9, 6, 3)]
b)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
c)
[(3, 2, 1), (6, 5, 4), (9, 8, 7)]
d)
[(9, 8, 7), (6, 5, 4), (3, 2, 1)]
75.
What will be the output of the following code that uses a stack to check for balanced parentheses? python Copy code def isValid(s): stack = [] mapping = {')': '(', '}': '{', ']': '['} for char in s: if char in mapping: top_element = stack.pop() if stack else '#' if mapping[char] != top_element: return False else: stack.append(char) return not stack print(isValid("()[]{}"))
a)
True
b)
F
c)
None
d)
Error
76.
What is the output of the following code that inserts words into a trie and checks if a word exists? python Copy code class TrieNode: def _init_(self): self.children = {} self.is_end_of_word = False class Trie: def _init_(self): self.root = TrieNode() def insert(self, word): node = self.root for char in word: if char not in node.children: node.children[char] = TrieNode() node = node.children[char] node.is_end_of_word = True def search(self, word): node = self.root for char in word: if char not in node.children: return False node = node.children[char] return node.is_end_of_word trie = Trie() trie.insert("hello") print(trie.search("hello"))
a)
True
b)
F
c)
None
d)
Error
77.
What will be the output of the Breadth-First Search (BFS) starting from node A for the following graph? css Copy code A -- B | | C -- D
a)
A B C D
b)
A C B D
c)
A D C B
d)
A B D C
78.
What is the output of the following code that finds the minimum value in a Binary Search Tree (BST)? python Copy code class TreeNode: def _init_(self, value): self.value = value self.left = None self.right = None def findMin(root): current = root while current.left is not None: current = current.left return current.value root = TreeNode(10) root.left = TreeNode(5) root.right = TreeNode(20) root.left.left = TreeNode(2) root.left.right = TreeNode(8) print(findMin(root))
a)
2
b)
5
c)
8
d)
10
79.
What is the output of the following code for the longest common subsequence of "ABCD" and "ACBAD"? python Copy code def lcs(X, Y): m = len(X) n = len(Y) L = [[None]*(n+1) for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i == 0 or j == 0: L[i][j] = 0 elif X[i-1] == Y[j-1]: L[i][j] = L[i-1][j-1] + 1 else: L[i][j] = max(L[i-1][j], L[i][j-1]) return L[m][n] print(lcs("ABCD", "ACBAD"))
a)
3
b)
2
c)
4
d)
1
80.
What is the output of the following code for finding the maximum subarray sum using the divide and conquer approach for the array [-2, 1, -3, 4, -1, 2, 1, -5, 4]? python Copy code def maxSubArraySum(arr, l, h): if l == h: return arr[l] m = (l + h) // 2 return max(maxSubArraySum(arr, l, m), maxSubArraySum(arr, m+1, h), maxCrossingSum(arr, l, m, h)) def maxCrossingSum(arr, l, m, h): sm = 0 left_sum = float('-inf') for i in range(m, l-1, -1): sm = sm + arr[i] if (sm > left_sum): left_sum = sm sm = 0 right_sum = float('-inf') for i in range(m+1, h+1): sm = sm + arr[i] if (sm > right_sum): right_sum = sm return left_sum + right_sum arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] n = len(arr) print(maxSubArraySum(arr, 0, n-1))
a)
6
b)
5
c)
4
d)
3
81.
What is the output of the following code for finding the single number in an array where every element appears twice except for one? python Copy code def singleNumber(nums): result = 0 for num in nums: result ^= num return result print(singleNumber([4, 1, 2, 1, 2]))
a)
4
b)
2
c)
1
82.
What will be the output of the following code for finding the topological sort of the given graph? python Copy code from collections import defaultdict class Graph: def _init_(self): self.graph = defaultdict(list) def addEdge(self, u, v): self.graph[u].append(v) def topologicalSortUtil(self, v, visited, stack): visited[v] = True for i in self.graph[v]: if not visited[i]: self.topologicalSortUtil(i, visited, stack) stack.insert(0, v) def topologicalSort(self): visited = {i: False for i in self.graph} stack = [] for i in list(self.graph): if not visited[i]: self.topologicalSortUtil(i, visited, stack) return stack g = Graph() g.addEdge(5, 2) g.addEdge(5, 0) g.addEdge(4, 0) g.addEdge(4, 1) g.addEdge(2, 3) g.addEdge(3, 1) print(g.topologicalSort())
a)
[5, 4, 2, 3, 1, 0]
b)
[4, 5, 0, 2, 3, 1]
c)
[5, 4, 0, 1, 3, 2]
d)
[4, 5, 1, 0, 2, 3]
83.
What is the output of the following code for the edit distance between "kitten" and "sitting"? python Copy code def editDistance(str1, str2): m = len(str1) n = len(str2) dp = [[0 for x in range(n+1)] for x in range(m+1)] for i in range(m+1): for j in range(n+1): if i == 0: dp[i][j] = j elif j == 0: dp[i][j] = i elif str1[i-1] == str2[j-1]: dp[i][j] = dp[i-1][j-1] else: dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]) return dp[m][n] print(editDistance("kitten", "sitting"))
a)
3
b)
2
c)
4
d)
5
84.
What will be the output of the following code for finding the minimum spanning tree using Kruskal's algorithm? python Copy code class Graph: def _init_(self, vertices): self.V = vertices self.graph = [] def addEdge(self, u, v, w): self.graph.append([u, v, w]) def find(self, parent, i): if parent[i] == i: return i return self.find(parent, parent[i]) def union(self, parent, rank, x, y): xroot = self.find(parent, x) yroot = self.find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yroot] = xroot else: parent[yroot] = xroot rank[xroot] += 1 def KruskalMST(self): result = [] i = 0 e = 0 self.graph = sorted(self.graph, key=lambda item: item[2]) parent = [] rank = [] for node in range(self.V): parent.append(node) rank.append(0) while e < self.V - 1: u, v, w = self.graph[i] i = i + 1 x = self.find(parent, u) y = self.find(parent, v) if x != y: e = e + 1 result.append([u, v, w]) self.union(parent, rank, x, y) return result g = Graph(4) g.addEdge(0, 1, 10) g.addEdge(0, 2, 6) g.addEdge(0, 3, 5) g.addEdge(1, 3, 15) g.addEdge(2, 3, 4) print(g.KruskalMST())
a)
[[2, 3, 4], [0, 3, 5], [0, 1, 10]]
b)
[[0, 3, 5], [0, 2, 6], [0, 1, 10]]
c)
[[0, 1, 10], [2, 3, 4], [0, 3, 5]]
d)
[[0, 2, 6], [1, 3, 15], [0, 1, 10]]
85.
What will be the output of the following code for finding the minimum number of coins for a given amount using the greedy algorithm? (Denominations are 1, 5, 10, 25) python Copy code def minCoins(coins, amount): coins.sort(reverse=True) count = 0 for coin in coins: while amount >= coin: amount -= coin count += 1 return count print(minCoins([1, 5, 10, 25], 63))
a)
5
b)
6
c)
7
d)
8
86.
What is the output of the post-order traversal of the following binary tree? markdown Copy code 10 / \ 5 20 / \ \ 2 7 30
a)
2 7 5 30 20 10
b)
2 5 7 10 20 30
c)
30 20 7 2 5 10
d)
7 2 5 30 20 10
87.
What will be the output of the following code that finds the height of a binary search tree? python Copy code class TreeNode: def _init_(self, value): self.value = value self.left = None self.right = None def height(root): if root is None: return 0 else: return max(height(root.left), height(root.right)) + 1 root = TreeNode(10) root.left = TreeNode(5) root.right = TreeNode(20) root.left.left = TreeNode(2) root.left.right = TreeNode(7) root.right.right = TreeNode(30) print(height(root))
a)
3
b)
4
c)
5
d)
6
88.
What will be the output of the following code for finding the shortest path using Dijkstra's algorithm for the given graph? python Copy code import heapq def dijkstra(graph, start): heap = [(0, start)] visited = set() distances = {start: 0} while heap: (cost, u) = heapq.heappop(heap) if u in visited: continue visited.add(u) for v, weight in graph[u].items(): if v not in visited: old_cost = distances.get(v, float('inf')) new_cost = distances[u] + weight if new_cost < old_cost: distances[v] = new_cost heapq.heappush(heap, (new_cost, v)) return distances graph = { 'A': {'B': 1, 'C': 4}, 'B': {'A': 1, 'C': 2, 'D': 5}, 'C': {'A': 4, 'B': 2, 'D': 1}, 'D': {'B': 5, 'C': 1} } print(dijkstra(graph, 'A'))
a)
{'A': 0, 'B': 1, 'C': 3, 'D': 4}
b)
{'A': 0, 'B': 2, 'C': 4, 'D': 5}
c)
{'A': 0, 'B': 1, 'C': 2, 'D': 3}
d)
{'A': 0, 'B': 3, 'C': 1, 'D': 2}
89.
What will be the output of the following code for representing a graph as an adjacency list and printing it? python Copy code class Graph: def _init_(self): self.graph = defaultdict(list) def addEdge(self, u, v): self.graph[u].append(v) def printGraph(self): for node in self.graph: print(f"{node} -> {', '.join(map(str, self.graph[node]))}") g = Graph() g.addEdge(0, 1) g.addEdge(0, 4) g.addEdge(1, 2) g.addEdge(1, 3) g.addEdge(1, 4) g.addEdge(2, 3) g.addEdge(3, 4) g.printGraph()
a)
0 -> 1, 4 \n 1 -> 2, 3, 4 \n 2 -> 3 \n 3 -> 4
b)
0 -> 1, 4 \n 1 -> 4, 3, 2 \n 2 -> 3 \n 3 -> 4
c)
0 -> 4, 1 \n 1 -> 4, 3, 2 \n 2 -> 3 \n 3 -> 4
d)
0 -> 1, 2, 3, 4 \n 1 -> 2, 3, 4 \n 2 -> 3 \n 3 -> 4
90.
What is the output of the following code for finding the longest palindromic substring of "babad"? python Copy code def longestPalindrome(s): res = "" for i in range(len(s)): odd = expandAroundCenter(s, i, i) even = expandAroundCenter(s, i, i + 1) res = max(res, odd, even, key=len) return res def expandAroundCenter(s, l, r): while l >= 0 and r < len(s) and s[l] == s[r]: l -= 1 r += 1 return s[l + 1:r] print(longestPalindrome("babad"))
a)
bab
b)
aba
c)
babad
d)
Both 1 and 3