Questions
1. Which SQL query correctly returns employees whose salary is greater than the average
salary of their own department?
a) SELECT * FROM emp WHERE salary > (SELECT AVG(salary) FROM emp);
b) SELECT * FROM emp e WHERE salary > ALL (SELECT salary FROM emp
WHERE dept=[Link]);
c) SELECT * FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp
WHERE dept=[Link]);
d) SELECT * FROM emp WHERE salary > (SELECT MAX(salary) FROM emp);
2. Which SQL command cannot be rolled back?
a) INSERT b) UPDATE c) DELETE d) TRUNCATE
3.
SELECT COUNT(*)
FROM students
WHERE marks > (SELECT MIN(marks) FROM students);
What will this query return?
a) All students except the lowest scorer
b) All students including the lowest scorer
c) Only students with maximum marks
d) None
4.
function maxNodes(h):
return 2^(h+1) - 1
What is the maximum number of nodes in a perfect binary tree of height 5?
a) 32 b) 63 c) 64 d) 127
5. Which traversal produces sorted order for a Binary Search Tree?
a) Preorder b) Postorder c) Inorder d) Level-order
6.
function height(node):
if node == NULL:
return -1
leftH = height([Link])
rightH = height([Link])
return max(leftH, rightH) + 1
What is the height for a tree with a single root node?
a) -1 b) 0 c) 1 d) 2
7. Which method is used internally by HashMap to resolve collisions?
a) Linear Probing b) Separate Chaining c) Quadratic Probing d) Robin Hood
Hashing
8.
function mystery(n):
if n <= 1:
return 1
return n * mystery(n-2)
What is mystery(7)?
a) 21 b) 105 c) 1050 d) 720
9.
function solveNQueens(n):
if no solution:
return 0
else:
return number of ways
For n = 8, what is the time complexity of this backtracking solution?
a) O(N!) b) O(2^N) c) O(N^2) d) O(N log N)
10.
arr = [2,5,1,8,2,9,1]
k = 3
maxSum = slidingWindow(arr,k)
If the sliding window algorithm is applied, what is the maximum sum of any subarray of size 3?
a) 8 b) 10 c) 9 d) 11
11. Consider two pointers technique to find a pair with sum = 10 in [1,2,3,7,8,9]. Is the pair
(2,8) valid?
a) true b) false c) depends d) none
12. Which algorithm is best for selecting projects with maximum profit under deadlines?
a) 0/1 Knapsack b) Fractional Knapsack c) Job Sequencing with Deadline d)
Dijkstra's
13.
prefix = [0,1,3,6,10,15]
sum = prefix[5] - prefix[2]
What is sum?
a) 6 b) 10 c) 8 d) 12
14. What is the correct order of constructor and destructor calls in C++ for inheritance (Base
→ Derived)?
a) Constructor → Destructor (Base first, then Derived)
b) Constructor → Destructor (Derived first, then Base)
c) Destructor → Constructor (Base first, then Derived)
d) Destructor → Constructor (Derived first, then Base)
15.
class Test {
public:
static int x;
Test() { x++; }
};
int Test::x=0;
Test a,b,c;
cout<<Test::x;
What is the output?
a) 1 b) 0 c) 3 d) 2
16. Which OOP principle allows function overloading in C++?
a) Inheritance b) Encapsulation c) Polymorphism d) Abstraction
17. If 5 partners share profit in ratio [Link] and total profit is 400, what is the share of the
fourth partner?
a) 40 b) 70 c) 80 d) 100
18. Series: 2, 6, 12, 20, 30, ?
a) T b) V c) X d) Z
19. Find the odd one: 125, 216, 343, 512
a) 125 b) 216 c) 343 d) 512
20. If in a code "DOG" is written as "EPH", how is "CAT" written?
a) DBU b) DCT c) CBU d) DBV
21. A man goes 3 km north, 4 km east, then 3 km south. How far is he from start?
a) 3 km b) 4 km c) 5 km d) 6 km
22. In a row of 40 people, A is 14th from left. What is his position from right?
a) 25 b) 26 c) 27 d) 28
23. Which SQL join returns all rows even if there is no match in one of the tables?
a) INNER JOIN b) LEFT JOIN c) RIGHT JOIN d) FULL OUTER JOIN
24. Which command is used to give user permissions in SQL?
a) REVOKE b) GRANT c) PERMIT d) AUTHORIZE
25.
SELECT dept_id, SUM(salary)
FROM employees
GROUP BY dept_id;
What does this return?
a) Each employee salary with department
b) Total salary of each department
c) Only highest salary department
d) None
26. What is the time complexity to push an element in stack using array (no resizing)?
a) O(1) b) O(n) c) O(log n) d) O(n log n)
27. What is the time complexity to insert an element at the head of a linked list stack?
a) O(1) b) O(n) c) O(log n) d) O(n log n)
28. Which sorting algorithm is best for nearly sorted data?
a) Quick Sort b) Merge Sort c) Insertion Sort d) Selection Sort
29. What is the time complexity to find maximum in a Min-Heap of n elements?
a) O(log n) b) O(n log n) c) O(n) d) O(1)
30. Why do we need a virtual destructor in C++?
a) To speed up destruction
b) To allow derived class destructor to execute when deleting base pointer
c) To prevent memory allocation
d) To avoid constructor chaining