Practice
1. What is the time complexity of computing the covariance matrix for a dataset with n samples and d features?
easy
Solution
Step 1: Analyze the covariance matrix computation
Computing the covariance matrix involves calculating pairwise covariances for d features, each requiring O(n) operations.Step 2: Eliminate wrong options
O(n^2) is incorrect as it doesn't account for features. O(d^2) is incorrect because it ignores the sample size. O(nd^2) overestimates the complexity.Final Answer:
Option D -> Option DQuick Check:
Covariance: O(nd) for n samples, d features. [OK]
Hint: Covariance: O(nd) for n samples, d features. [OK]
Common Mistakes:
2. You implemented stratified K-Fold cross-validation but notice class imbalance in some folds. What is the most likely cause?
medium
Solution
Step 1: Identify stratification issue
Stratification ensures class distribution is preserved in each fold.Step 2: Eliminate wrong options
Incorrect number of splits and D relate to fold count, not class distribution. Data shuffling before splitting affects randomness, not stratification.Final Answer:
Option A -> Option AQuick Check:
Check stratification parameter for class balance. [OK]
Hint: Check stratification parameter for class balance. [OK]
Common Mistakes:
3. You implemented early stopping in your training loop, but the model still overfits. What is the most likely reason?
medium
Solution
Step 1: Analyze early stopping behavior
Early stopping relies on validation performance to halt training.Step 2: Identify the root cause of overfitting
If the validation set is too small, it may not accurately reflect generalization, leading to overfitting despite early stopping.Final Answer:
Option A -> Option AQuick Check:
Small validation set can mislead early stopping. [OK]
Hint: Small validation set can mislead early stopping. [OK]
Common Mistakes:
4. How would you apply sinusoidal positional encoding in a transformer model for a sequence of variable length?
medium
Solution
Step 1: Consider variable sequence lengths
Each sequence should have positional encoding applied based on its actual length to maintain positional information.Step 2: Eliminate wrong options
Pad all sequences to the maximum length and apply encoding. is inefficient and may introduce unnecessary padding. Apply encoding only to the first few positions of each sequence. ignores the rest of the sequence. Use a fixed-length encoding for all sequences, regardless of length. loses positional information for longer sequences.Final Answer:
Option B -> Option BQuick Check:
Encode based on actual sequence length. [OK]
Hint: Encode based on actual sequence length. [OK]
Common Mistakes:
5. Which optimization would most effectively reduce the computational cost of the scaled dot-product attention mechanism for very large input sequences?
hard
Solution
Step 1: Identify the bottleneck
Computational cost is high due to dense matrix operations.Step 2: Choose the best optimization
Sparse matrices reduce computation by focusing on non-zero elements.Final Answer:
Option D -> Option DQuick Check:
Sparse matrices for large inputs [OK]
Hint: Sparse matrices for large inputs [OK]
Common Mistakes:
