Worksheets202508500001
Total questions: 40
Worksheet time: 21mins
In OOP, what is delegation?
Overriding base method
Passing responsibility to another object
Inheriting from multiple classes
Creating private methods
Applying a constructor
What is the outcome of calling a method that’s been overloaded, not overridden?
Runtime resolution
Static (compile-time) resolution
Causes ambiguity
Calls base method
Depends on inheritance
Which of the following is a violation of encapsulation?
Using getter methods
Making all variables public
Making methods private
Declaring variables protected
Defining constructors
In which situation would you prefer an interface over an abstract class?
You want to reuse code
You want multiple inheritance
You have default implementation
You need private constructors
You want final methods
Which concept allows an object to behave differently in different contexts?
Encapsulation
Inheritance
Polymorphism
Composition
Static binding
The Decorator pattern is used to:
Allow dynamic behavior extension
Compress data
Authenticate users
Avoid subclassing
Enforce abstraction
You are given an array of integers. Which algorithm efficiently finds the majority element (occurs more than n/2 times)?
Merge Sort
Binary Search
Kadane’s
Boyer-Moore Voting Algorithm
Floyd-Warshall
What is the best time complexity to search for an element in a sorted and rotated array?
O(n)
O(log n)
O(1)
O(n log n)
O(n²)
Which approach is optimal to find the smallest missing positive number in an unsorted array?
Sorting
HashMap
In-place Indexing
Binary Search
Greedy
Which of the following is used to implement two stacks in an array without wastage of space?
Push one after another
Use two arrays
Divide array equally
One from start and one from end
Use doubly linked list
What’s the optimal way to design a circular queue using array?
Push from front
Push using two arrays
Use front and rear pointers with modulo
Doubly Linked List
Prefix tree
In a queue implemented using two stacks, what ensures amortized O(1) dequeue?
Transfer on every operation
Use priority queue
Transfer only when needed
Use three stacks
FIFO list
Which traversal is used to serialize/deserialize a binary tree without ambiguity?
In-order
Post-order
Level-order
Pre-order
Any traversal
In a Binary Tree, the diameter is the:
Max number of leaves
Depth of root
Longest path between any two nodes
Height + width
Sum of left subtree
What is the maximum number of nodes in a binary tree of height h?
2^h
2^h – 1
2^(h+1) – 1
h²
log h
Which condition must be satisfied for a binary tree to be complete?
Every node has 2 children
All leaves are at same depth
All levels are filled except possibly last
Only root has two children
Balanced height difference < 1
Which algorithm finds all pairs shortest paths in a graph?
Dijkstra
Prim
Floyd-Warshall
DFS
Kruskal
Which traversal ensures the shortest path in unweighted graphs?
DFS
BFS
Dijkstra
Topological
Kruskal
Which sorting is NOT stable?
Merge Sort
Insertion Sort
Bubble Sort
Heap Sort
Tim Sort
What is strongly connected component (SCC) in a directed graph?
A cycle
Nodes connected to a root
Every node is reachable from every other node
Graph with in-degree = out-degree
MST root node
Which graph representation is more efficient for sparse graphs?
Adjacency Matrix
Incidence Matrix
Adjacency List
Edge List
Cartesian Matrix
Which algorithm performs better for nearly sorted arrays?
Bubble Sort
Merge Sort
Insertion Sort
Quick Sort
Selection Sort
Which technique helps to reduce space complexity in bottom-up DP?
Tree traversal
Memoization
Tabulation
State compression
Randomization
Which technique converts a recursive algorithm into a bottom-up form?
Top-down DP
Memoization
Tabulation
Divide and Conquer
Greedy method
In the Longest Common Subsequence (LCS) problem, what does dp[i][j] represent?
The length of the input strings
Whether substrings match
The LCS of first i characters of string A and first j of B
Number of matches found so far
None of the above
What’s the optimal substructure property in DP?
Solutions are always unique
Bigger problems depend on smaller ones
All solutions are exponential
Subproblems are disjoint
Uses greedy decisions
The Banker's Algorithm is used for:
CPU scheduling
Deadlock detection
Memory allocation
Deadlock avoidance
File system protection
What is thrashing in OS?
Frequent page faults
Buffer overflow
Deadlock
File fragmentation
Process starvation
Which condition is necessary for a deadlock to occur?
Starvation
Cyclic wait
CPU-bound processes
Spooling
Preemption
Which one is used in LRU page replacement?
FIFO queue
Priority queue
Stack
Circular queue
Random selection
Which one is a Class C IPv4 address?
126.22.33.4
191.255.255.255
200.1.1.1
10.0.0.1
224.1.1.1
Which of the following is not connection-oriented?
TCP
SCTP
FTP
UDP
Telnet
Which function is used to assign a unique sequential integer to rows within a result set partition?
DENSE_RANK()
RANK()
ROW_NUMBER()
PARTITION()
NTILE()
Which query finds employees who earn the same as someone in department 10?
SELECT *
FROM employees
WHERE salary IN (SELECT salary FROM employees WHERE department_id = 10);
SELECT *
FROM employees
WHERE salary = salary IN department 10;
SELECT *
FROM employees
WHERE salary BETWEEN (SELECT MIN(salary) FROM employees WHERE department_id = 10)
AND (SELECT MAX(salary) FROM employees WHERE department_id = 10);
SELECT *
FROM employees
GROUP BY salary = department_id;
SELECT salary
FROM employees
HAVING department_id = 10;
What is true about the following query?
SELECT * FROM employees e1
WHERE EXISTS (
SELECT 1 FROM employees e2
WHERE e1.salary = e2.salary AND e1.employee_id <> e2.employee_id
);
Returns all employees with unique salaries
Returns employees who share the same salary with others
Returns NULL
Returns top-paid employees
Returns department heads
The __________ clause is used in a SELECT query to group rows sharing a common field.
HAVING
PARTITION
GROUP BY
AGGREGATE
UNION
The __________ operator is used to combine the results of two SELECT statements and include all rows.
JOIN
UNION
UNION ALL
INTERSECT
COMBINE
Which statements are correct regarding foreign keys?
A table can have only one foreign key
A foreign key must reference a primary or unique key
Foreign key values must always be unique
Foreign key enforces referential integrity
Foreign keys are always nullable
Which statements about 3NF (Third Normal Form) are true?
It removes transitive dependencies
Every non-prime attribute is fully functionally dependent on the candidate key
It allows partial dependencies
It eliminates foreign keys
It denormalizes data
What does the UNION operator do?
Combines rows and removes duplicates
Joins two tables
Combines rows with duplicates
Merges databases
Overwrites rows with common data
