-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2270-mcq.html
153 lines (152 loc) · 8.19 KB
/
2270-mcq.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Binary Search Tree Quiz</title>
</head>
<body>
<h1>Binary Search Tree Quiz</h1>
<form id="quiz">
<div id="q1">
<h2>Question 1</h2>
<p>Which of the following is true for a BST?</p>
<input type="radio" name="q1" value="a"> a) The left subtree of a node contains values smaller than the node's value<br>
<input type="radio" name="q1" value="b"> b) The right subtree of a node contains values greater than the node's value<br>
<input type="radio" name="q1" value="c"> c) Both a and b<br>
<input type="radio" name="q1" value="d"> d) None of the above<br>
</div>
<div id="q2">
<h2>Question 2</h2>
<p>What is the worst-case time complexity of searching for an element in a BST?</p>
<input type="radio" name="q2" value="a"> a) O(1)<br>
<input type="radio" name="q2" value="b"> b) O(log n)<br>
<input type="radio" name="q2" value="c"> c) O(n)<br>
<input type="radio" name="q2" value="d"> d) O(n log n)<br>
</div>
<div id="q3">
<h2>Question 3</h2>
<p>What is the worst-case time complexity of searching for an element in a balanced BST?</p>
<input type="radio" name="q3" value="a"> a) O(1)<br>
<input type="radio" name="q3" value="b"> b) O(log n)<br>
<input type="radio" name="q3" value="c"> c) O(n)<br>
<input type="radio" name="q3" value="d"> d) O(n log n)<br>
</div>
<div id="q4">
<h2>Question 4</h2>
<p>Which of the following traversal methods visits the root node first, then the left subtree, and then the right subtree?</p>
<input type="radio" name="q4" value="a"> a) In-order traversal<br>
<input type="radio" name="q4" value="b"> b) Pre-order traversal<br>
<input type="radio" name="q4" value="c"> c) Post-order traversal<br>
<input type="radio" name="q4" value="d"> d) Level-order traversal<br>
</div>
<div id="q5">
<h2>Question 5</h2>
<p>What is the height of a balanced BST with n nodes?</p>
<input type="radio" name="q5" value="a"> a) log n<br>
<input type="radio" name="q5" value="b"> b) n<br>
<input type="radio" name="q5" value="c"> c) n log n<br>
<input type="radio" name="q5" value="c"> d) sqrt(n)<br>
</div>
<div id="q6">
<h2>Question 6</h2>
<p>What is the time complexity of inserting an element in a balanced BST?</p>
<input type="radio" name="q6" value="a"> a) O(1)<br>
<input type="radio" name="q6" value="b"> b) O(log n)<br>
<input type="radio" name="q6" value="c"> c) O(n)<br>
<input type="radio" name="q6" value="d"> d) O(n log n)<br>
</div>
<div id="q7">
<h2>Question 7</h2>
<p>Which of the following statements is true for a BST?</p>
<input type="radio" name="q7" value="a"> a) The inorder traversal of a binary search tree returns a sorted list of elements<br>
<input type="radio" name="q7" value="b"> b) The height of a binary search tree is always log n<br>
<input type="radio" name="q7" value="c"> c) The minimum element in a binary search tree is always the root node<br>
<input type="radio" name="q7" value="d"> d) All binary search trees are balanced<br>
</div>
<div id="q8">
<h2>Question 8</h2>
<p>What is the maximum number of nodes at level k in a BST (where root is at level 1)?</p>
<input type="radio" name="q8" value="a"> a) k<br>
<input type="radio" name="q8" value="b"> b) 2^k<br>
<input type="radio" name="q8" value="c"> c) 2^(k+1) - 1<br>
<input type="radio" name="q8" value="d"> d) 2^(k-1)<br>
</div>
<div id="q9">
<h2>Question 9</h2>
<p>What is the time complexity of finding the maximum element in a BST?</p>
<input type="radio" name="q9" value="a"> a) O(1)<br>
<input type="radio" name="q9" value="b"> b) O(log n)<br>
<input type="radio" name="q9" value="c"> c) O(n)<br>
<input type="radio" name="q9" value="d"> d) O(n log n)<br>
</div>
<div id="q10">
<h2>Question 10</h2>
<p>What is the time complexity of finding the maximum element in a balanced BST?</p>
<input type="radio" name="q10" value="a"> a) O(1)<br>
<input type="radio" name="q10" value="b"> b) O(log n)<br>
<input type="radio" name="q10" value="c"> c) O(n)<br>
<input type="radio" name="q10" value="d"> d) O(n log n)<br>
</div>
<div id="q11">
<h2>Question 11</h2>
<p>How is a new element inserted into a binary search tree?</p>
<input type="radio" name="q11" value="a"> a) The new element is added as a new root node<br>
<input type="radio" name="q11" value="b"> b) The new element is added as a new leaf node<br>
<input type="radio" name="q11" value="c"> c) The new element is inserted randomly in the tree<br>
<input type="radio" name="q11" value="d"> d) The new element cannot be inserted in a binary search tree<br>
</div>
<div id="q12">
<h2>Question 12</h2>
<p>What is the time complexity of deleting an element from a balanced BST?</p>
<input type="radio" name="q12" value="a"> a) O(1)<br>
<input type="radio" name="q12" value="b"> b) O(log n)<br>
<input type="radio" name="q12" value="c"> c) O(n)<br>
<input type="radio" name="q12" value="d"> d) O(n log n)<br>
</div>
<div id="q13">
<h2>Question 13</h2>
<p>How is a node with no children deleted from a binary search tree?</p>
<input type="radio" name="q13" value="a"> a) The node is removed from the tree<br>
<input type="radio" name="q13" value="b"> b) The node is replaced with its right child<br>
<input type="radio" name="q13" value="c"> c) The node is replaced with its left child<br>
<input type="radio" name="q13" value="d"> d) The deletion operation cannot be performed on a node with no children<br>
</div>
<div id="q14">
<h2>Question 14</h2>
<p>How is a node with two children deleted from a binary search tree?</p>
<input type="radio" name="q14" value="a"> a) The node is removed from the tree<br>
<input type="radio" name="q14" value="b"> b) The node is replaced with its left child<br>
<input type="radio" name="q14" value="c"> c) The node is replaced with its right child<br>
<input type="radio" name="q14" value="d"> d) The node is replaced with its successor (smallest node in right subtree)<br>
</div>
<div id="q15">
<h2>Question 15</h2>
<p>How is a node with one child deleted from a binary search tree?</p>
<input type="radio" name="q15" value="a"> a) The node is removed from the tree<br>
<input type="radio" name="q15" value="b"> b) The node is replaced with its child<br>
<input type="radio" name="q15" value="c"> c) The node is replaced with its successor (smallest node in right subtree)<br>
<input type="radio" name="q15" value="d"> d) The deletion operation cannot be performed on a node with one child<br>
</div>
<br>
<input type="submit" value="Submit">
</form>
<script>
const form = document.querySelector('form');
form.addEventListener('submit', (event) => {
event.preventDefault();
const answers = ['c', 'c', 'b', 'b', 'a', 'b', 'a', 'd', 'c', 'b', 'b', 'b', 'a', 'd', 'b'];
let score = 0;
for (let i = 1; i <= 15; i++) {
const radios = document.getElementsByName('q' + i);
for (let j = 0; j < radios.length; j++) {
const radio = radios[j];
if (radio.value === answers[i - 1] && radio.checked) {
score++;
}
}
}
alert('You scored ' + score + ' out of 15');
});
</script>
</body>
</html>