0% found this document useful (0 votes)
20 views13 pages

Questions For Practice

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views13 pages

Questions For Practice

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Database Management Systems (DBMS):

1. What is a primary key and why is it used?


2. Explain the difference between DELETE and TRUNCATE
commands
3. What is the difference between WHERE and HAVING
clauses?
4. Explain what is meant by ACID properties in DBMS
5. What is the difference between DDL and DML?
6. Explain what a foreign key is with a simple example
7. What is the purpose of the GROUP BY clause?
8. What is normalization and why do we need it?
9. Explain the difference between UNION and UNION ALL
10. What is an index in SQL and why is it used?
11. What is the difference between CHAR and VARCHAR?
12. Explain what a JOIN is and list its basic types
13. What is a NULL value and how is it different from zero or
blank space?
14. What is the purpose of the DISTINCT keyword?
15. Explain what a view is in SQL
16. What is the difference between DELETE and DROP?
17. What is a database transaction?
18. Explain the purpose of the ORDER BY clause
19. What is data redundancy?
20. What is referential integrity?
Object-Oriented Programming (OOP):

1. What are the four main principles of OOP?


2. What is the difference between a class and an object?
3. Explain inheritance with a simple example
4. What is method overloading?
5. What is method overriding?
6. What is encapsulation and why is it important?
7. Explain the difference between public, private, and protected
access modifiers
8. What is polymorphism?
9. What is the difference between compile-time and runtime
polymorphism?
10. What is a constructor?
11. What is the difference between abstract class and
interface?
12. What is the super keyword used for?
13. What is the 'this' keyword?
14. Explain the concept of multiple inheritance
15. What is the difference between static and non-static
methods?
16. What is method overloading vs method overriding?
17. What is the difference between abstraction and
encapsulation?
18. What are getter and setter methods?
19. What is the purpose of a final keyword?
20. What is a default constructor?
Data Structures and Algorithms (DSA):

1. What is the difference between an array and a linked list?


2. Explain what a stack is and give two real-world examples
3. What is a queue data structure?
4. What is the difference between BFS and DFS?
5. Explain what binary search is and when to use it
6. What is the time complexity of linear search?
7. What is a hash table and where is it used?
8. Explain what recursion is with a simple example
9. What is the difference between linear and non-linear data
structures?
10. What is the time complexity of bubble sort?
11. Explain what a binary tree is
12. What is the difference between stack and queue?
13. What is an infix, prefix, and postfix notation?
14. What is the difference between static and dynamic
arrays?
15. Explain what a doubly linked list is
16. What is the purpose of a heap data structure?
17. What is the time complexity to insert an element in an
array?
18. Explain what a circular queue is
19. What is the difference between a tree and a graph?
20. What is the best case time complexity of bubble sort?
DBMS Answers:

1. Primary Key:
○ A primary key is a column or combination of columns
that uniquely identifies each row in a table
○ Example: Student ID in a students table
○ Cannot be NULL or duplicate
2. DELETE vs TRUNCATE:
○ DELETE removes specific rows and can be rolled back
(recoverable)
○ TRUNCATE removes all rows at once, can't be rolled
back (faster but non-recoverable)
3. WHERE vs HAVING:
○ WHERE filters individual rows before grouping
○ HAVING filters groups after GROUP BY
○ Example: WHERE salary > 5000 (filters rows) vs
HAVING AVG(salary) > 5000 (filters groups)
4. ACID Properties:
○ Atomicity: Transaction completely succeeds or
completely fails
○ Consistency: Database remains in a valid state
○ Isolation: Transactions don't interfere with each other
○ Durability: Completed transactions are permanent
5. DDL vs DML:
○ DDL (Data Definition Language): CREATE, ALTER,
DROP, TRUNCATE
○ DML (Data Manipulation Language): SELECT, INSERT,
UPDATE, DELETE
6. Foreign Key:
○ Links two tables together
○ Example: In Orders table, CustomerID references ID in
Customers table
○ Maintains referential integrity
7. GROUP BY:
○ Groups rows with similar values
○ Used with aggregate functions (COUNT, SUM, AVG)
○ Example: GROUP BY department to find average
salary per department
8. Normalization:
○ Process of organizing data to reduce redundancy
○ Helps maintain data integrity
○ Divides larger tables into smaller, related tables
9. UNION vs UNION ALL:
○ UNION: Combines results and removes duplicates
○ UNION ALL: Combines results and keeps duplicates
(faster)
10. Index:
○ Speeds up data retrieval
○ Like a book's index
○ Trade-off: Faster reads, slower writes
11. CHAR vs VARCHAR:
○ CHAR: Fixed length, padded with spaces
○ VARCHAR: Variable length, saves space
○ Example: CHAR(10) always uses 10 bytes,
VARCHAR(10) uses only needed bytes
12. JOINs:
○ INNER JOIN: Matches only rows with matching values
in both tables
○ LEFT JOIN: All rows from left table, matching from right
○ RIGHT JOIN: All rows from right table, matching from
left
○ FULL JOIN: All rows from both tables
13. NULL:
○ Represents absence of value
○ Different from zero or empty string
○ Can't be compared using = or !=, must use IS NULL
14. DISTINCT:
○ Removes duplicate values from results
○ Example: SELECT DISTINCT city FROM customers
15. View:
○ Virtual table based on SQL statement
○ Doesn't store data physically
○ Can simplify complex queries
16. DELETE vs DROP:
○ DELETE removes rows from table
○ DROP removes entire table structure
17. Transaction:
○ Unit of work performed against database
○ Must be ACID compliant
○ Example: Transfer money between accounts
18. ORDER BY:
○ Sorts results
○ ASC for ascending (default)
○ DESC for descending
19. Data Redundancy:
○ Same data stored in multiple places
○ Wastes storage
○ Can lead to inconsistencies
20. Referential Integrity:
○ Ensures relationships between tables remain valid
○ Prevents orphaned records
○ Enforced by foreign keys

OOP Answers:

1. Four Main OOP Principles:


○ Encapsulation: Bundling data and methods that operate
on that data
○ Inheritance: Creating new classes from existing ones
○ Polymorphism: Same interface, different
implementations
○ Abstraction: Hiding complex implementation details
2. Class vs Object:
○ Class: Blueprint/template (like house plan)
○ Object: Instance of class (actual house)
○ Example: Car class, myHonda object
3. Inheritance Example:

class Animal {
void eat() { }
}
class Dog extends Animal {
void bark() { }
}

4. Method Overloading:
○ Same method name, different parameters
○ Happens in same class
void add(int a, int b) { }
void add(int a, int b, int c) { }

5. Method Overriding:
○ Same method in parent and child class
○ Same signature
class Animal {
void makeSound() { }
}
class Dog extends Animal {
void makeSound() { // bark }
}

6. Encapsulation:
○ Wraps data and code together
○ Protects data from outside access
○ Uses private variables with public getters/setters
7. Access Modifiers:
○ public: Accessible everywhere
○ private: Only within same class
○ protected: Within same package and subclasses
8. Polymorphism:
○ Object taking multiple forms
○ Example: Method behaving differently in different
classes
○ Compile-time (overloading) and Runtime (overriding)
9. Compile-time vs Runtime Polymorphism:
○ Compile-time: Method overloading
○ Runtime: Method overriding
10. Constructor:
○ Special method to initialize objects
○ Same name as class
○ Called automatically when object created
11. Abstract Class vs Interface:
○ Abstract class: Can have implementation
○ Interface: Only method declarations
○ Class can implement multiple interfaces but extend only
one abstract class
12. Super Keyword:
○ Refers to parent class
○ Calls parent class methods
○ Access parent class constructor
13. This Keyword:
○ Refers to current instance
○ Differentiates instance variables from parameters
○ Used to call current class methods
14. Multiple Inheritance:
○ Class inheriting from multiple classes
○ Java doesn't support through classes
○ Possible through interfaces
15. Static vs Non-static:
○ Static: Belongs to class
○ Non-static: Belongs to instance
○ Static methods can't access non-static members
directly
16. Already covered in 4 and 5
17. Abstraction vs Encapsulation:
○ Abstraction: Hiding implementation
○ Encapsulation: Wrapping data and methods
○ Example: Car steering (abstraction) vs Car engine
(encapsulation)
18. Getter/Setter:
○ Methods to access private variables
○ Getter returns value
○ Setter sets value
19. Final Keyword:
○ Variable: Can't change value
○ Method: Can't override
○ Class: Can't inherit
20. Default Constructor:
○ Created by compiler if no constructor defined
○ No parameters
○ Initializes instance variables to default values

DSA Answers:

1. Array vs Linked List:


○ Array: Continuous memory, fixed size, direct access
○ Linked List: Scattered memory, dynamic size,
sequential access
2. Stack:
○ LIFO (Last In First Out)
○ Examples: Browser back button, Undo operation
○ Operations: push, pop, peek
3. Queue:
○ FIFO (First In First Out)
○ Example: Print spooler
○ Operations: enqueue, dequeue
4. BFS vs DFS:
○ BFS: Level by level traversal
○ DFS: Go deep first
○ BFS uses queue, DFS uses stack
5. Binary Search:
○ Works on sorted arrays
○ Divides search interval in half
○ Time complexity: O(log n)
6. Linear Search Time Complexity:
○ O(n) - worst case
○ Must check each element
○ Good for small or unsorted lists
7. Hash Table:
○ Key-value pairs
○ Fast access O(1) average
○ Used in dictionaries, caches
8. Recursion Example:
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n-1);
}

9. Linear vs Non-linear:
○ Linear: Arrays, lists (one after another)
○ Non-linear: Trees, graphs (branching)
10. Bubble Sort Time Complexity:
○ O(n²) - worst and average case
○ O(n) - best case (already sorted)
11. Binary Tree:
○ Each node has at most 2 children
○ Left child < parent < right child
○ Used for efficient searching
12. Stack vs Queue:
○ Stack: LIFO (plates stack)
○ Queue: FIFO (people in line)
○ Different use cases
13. Infix, Prefix, Postfix:
○ Infix: a + b
○ Prefix: +ab
○ Postfix: ab+
14. Static vs Dynamic Arrays:
○ Static: Fixed size
○ Dynamic: Can grow/shrink
○ Example: Array vs ArrayList in Java
15. Doubly Linked List:
○ Nodes have next and previous pointers
○ Can traverse both directions
○ More memory than singly linked list
16. Heap:
○ Complete binary tree
○ Max-heap or min-heap
○ Used in priority queues
17. Array Insertion Time:
○ At end: O(1)
○ At beginning: O(n)
○ At middle: O(n)
18. Circular Queue:
○ Regular queue with connected ends
○ Better memory utilization
○ Used in scheduling
19. Tree vs Graph:
○ Tree: Hierarchical, no cycles
○ Graph: Can have cycles
○ Tree is a special type of graph
20. Bubble Sort Best Case:
○ O(n) when array is already sorted
○ Needs one pass to confirm
○ Can be optimized with flag

You might also like