Prep Final
Prep Final
### 3. How do you teach students with varying proficiency levels in computer
science?
**Answer:** I use differentiated instruction, assessing prior knowledge to tailor
lessons. Beginners get foundational exercises, while advanced students tackle
complex projects. Peer tutoring and group work foster collaboration across levels.
## PYTHON
@log_function
def add(a, b):
return a + b
```
### 8. What are Python list comprehensions and how are they useful?
**Answer:** List comprehensions provide a concise way to create lists based on
existing lists. They combine a for loop and conditional logic in a single line.
Example: `[x*2 for x in range(10) if x % 2 == 0]` creates [0, 4, 8, 12, 16]. They
improve readability and performance compared to traditional loops.
### 9. Explain the difference between shallow copy and deep copy.
**Answer:** Shallow copy (list.copy() or copy.copy()) creates a new container but
references the same objects, so changes to nested objects affect both copies. Deep
copy (copy.deepcopy()) creates a completely independent copy, duplicating
everything recursively, ideal for nested structures where complete independence is
needed.
### 12. What is the difference between `is` and `==` in Python?
**Answer:** `==` checks if two objects have the same value (equality of contents),
while `is` checks if two references point to exactly the same object in memory
(identity). Example: `a = [1, 2, 3]; b = [1, 2, 3]` will make `a == b` True but `a
is b` False because they're equal in value but distinct objects.
### 13. What are Python generators and how do they work?
**Answer:** Generators are functions that return an iterator using the yield
statement instead of return. They generate values on-the-fly without storing the
entire sequence in memory, making them memory-efficient for large datasets.
Example:
```python
def count_up_to(n):
i = 0
while i < n:
yield i
i += 1
```
## JAVA
### 12. What is the difference between static and non-static methods?
**Answer:** Static methods belong to the class rather than instances, accessed via
the class name (e.g., `Math.sqrt()`). They cannot access instance variables or
methods directly, cannot use `this` or `super`, and are resolved at compile time.
Non-static methods belong to instances, can access all class members, and are
resolved at runtime.
### 14. What are Java collections and how is `HashMap` used?
**Answer:** Java Collections Framework provides interfaces and classes for storing
and manipulating groups of objects. HashMap is a collection that stores key-value
pairs, allowing fast lookups without ordering guarantees:
```java
HashMap<String, Integer> studentScores = new HashMap<>();
studentScores.put("Alice", 95);
studentScores.put("Bob", 87);
int score = studentScores.get("Alice"); // Returns 95
```
It provides O(1) average time complexity for get/put operations.
## SQL
### 2. Explain the difference between INNER JOIN and LEFT JOIN.
**Answer:**
- INNER JOIN: Returns only rows with matching values in both tables. Example:
`SELECT * FROM Students INNER JOIN Courses ON Students.CourseID = Courses.ID`
- LEFT JOIN: Returns all rows from the left table and matching rows from the right
table (with NULL for non-matches). Example: `SELECT * FROM Students LEFT JOIN
Courses ON Students.CourseID = Courses.ID`
### 10. What is the difference between `DELETE`, `TRUNCATE`, and `DROP`?
**Answer:**
- DELETE: Removes specific rows based on a condition; can be rolled back; preserves
table structure
- TRUNCATE: Removes all rows; cannot be rolled back; preserves table structure but
resets auto-increment
- DROP: Removes the entire table including structure; cannot be rolled back
Example: DELETE is like erasing entries in a notebook, TRUNCATE is tearing out all
pages but keeping the notebook, DROP is throwing away the notebook completely.
### 11. Explain SQL constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK).
**Answer:**
- PRIMARY KEY: Uniquely identifies each record
- FOREIGN KEY: Enforces relationships between tables
- UNIQUE: Ensures all values in a column are different
- CHECK: Ensures values meet a condition
Example: `CREATE TABLE Students (ID INT PRIMARY KEY, Email VARCHAR(100) UNIQUE, Age
INT CHECK (Age > 10))`
### 12. What are aggregate functions in SQL?
**Answer:** Aggregate functions perform calculations on multiple rows and return a
single value. Common functions include:
- COUNT(): Counts rows
- SUM(): Adds values
- AVG(): Calculates average
- MIN()/MAX(): Finds minimum/maximum values
Example: `SELECT AVG(score) FROM Exams WHERE subject = 'Computer Science'`
### 13. What are views and how are they used?
**Answer:** Views are virtual tables based on SQL statements' results, useful for
simplifying complex queries, restricting data access, and presenting data
differently. Example:
```sql
CREATE VIEW StudentGrades AS
SELECT s.name, c.title, g.grade
FROM Students s
JOIN Grades g ON s.id = g.student_id
JOIN Courses c ON g.course_id = c.id;
```
Unlike actual tables, views don't store data physically.
### 15. What is a transaction? How do you start and end one?
**Answer:** A transaction is a sequence of operations performed as a single logical
unit of work. Start with BEGIN TRANSACTION or START TRANSACTION (syntax varies by
database); end with COMMIT to save changes or ROLLBACK to undo them. Example:
```sql
BEGIN TRANSACTION;
UPDATE Accounts SET balance = balance - 100 WHERE id = 1;
UPDATE Accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
```
### 16. What is the difference between clustered and non-clustered indexes?
**Answer:**
- Clustered index: Determines the physical order of data in a table; only one per
table
- Non-clustered index: Creates a separate structure with pointers to the actual
data; multiple allowed per table
Example: A clustered index on StudentID orders the student table physically by ID,
while a non-clustered index on LastName creates a separate sorted structure
pointing to the actual records.
## NETWORKING
### 10. What are firewalls and how do they protect a network?
**Answer:** Firewalls monitor and control incoming/outgoing network traffic based
on security rules. They function as barriers between trusted internal networks and
untrusted external networks. Types include:
- Packet filtering: Examines individual packets
- Stateful inspection: Tracks connection states
- Application-level gateways: Inspect application-layer data
Firewalls block unauthorized access, prevent malware entry, and control what
services can be accessed from outside the network.
## SCHOOL-SPECIFIC QUESTIONS
## GENERAL IT