Practice
1. What is the time complexity of applying a dropout layer to an input of size n during training?
easy
Solution
Step 1: Analyze Dropout Operation
Applying dropout involves generating a mask and element-wise multiplication, both O(n) operations.Step 2: Eliminate Wrong Options
O(1) suggests constant time, which is incorrect. O(n^2) suggests quadratic time, which is excessive. O(log n) suggests logarithmic time, which is not applicable.Final Answer:
Option D -> Option DQuick Check:
Dropout involves element-wise operations. [OK]
Hint: Dropout involves element-wise operations. [OK]
Common Mistakes:
2. What is the time complexity of updating the learning rate using PyTorch's
StepLR scheduler for each epoch?easy
Solution
Step 1: Analyze StepLR update mechanism
StepLR updates the learning rate by multiplying it with a constant factor, which is a constant time operation.Step 2: Determine time complexity
Since the update is a simple multiplication, the time complexity is O(1).Final Answer:
Option C -> Option CQuick Check:
StepLR update is a constant time operation. [OK]
Hint: StepLR update is a constant time operation. [OK]
Common Mistakes:
3. In a decision tree, how would you handle a dataset with continuous features?
medium
Solution
Step 1: Consider handling continuous features
Discretizing into bins allows decision trees to handle continuous data effectively.Step 2: Eliminate wrong options
One-hot encoding (A) is for categorical data; ignoring (C) loses information; using directly (D) can lead to overfitting.Final Answer:
Option C -> Option CQuick Check:
Continuous? Discretize into bins [OK]
Hint: Continuous? Discretize into bins [OK]
Common Mistakes:
4. How can you optimize the computation of cosine similarity for a large dataset of vectors?
hard
Solution
Step 1: Identify computational bottlenecks
Looping over pairs is inefficient for large datasets.Step 2: Optimize using matrix operations
Precomputing norms and using matrix multiplication reduces redundant calculations.Final Answer:
Option C -> Option CQuick Check:
Matrix ops reduce redundancy. [OK]
Hint: Matrix ops reduce redundancy. [OK]
Common Mistakes:
5. How can the calculation of precision, recall, and F1-score be optimized for a large confusion matrix?
hard
Solution
Step 1: Identify bottlenecks
Calculating metrics for each class can be parallelized.Step 2: Choose the best optimization strategy
Parallel processing allows simultaneous computation, reducing time complexity.Final Answer:
Option C -> Option CQuick Check:
Parallelize class-wise computations. [OK]
Hint: Parallelize class-wise computations. [OK]
Common Mistakes:
