Practice
1. What is the time complexity of cropping an image of size
n x n to a smaller size m x m using NumPy slicing?easy
Solution
Step 1: Understand NumPy slicing
NumPy slicing creates a view, not a copy, so it operates in constant time.Step 2: Evaluate the complexity
The operation does not depend on the size of the arrays but on the slicing indices.Final Answer:
Option B -> Option BQuick Check:
NumPy slicing is O(1) due to views. [OK]
Hint: NumPy slicing is O(1) due to views. [OK]
Common Mistakes:
2. You implemented a 2D convolution but the output is all zeros. What is the most likely cause?
medium
Solution
Step 1: Identify the zero output cause
If the kernel is filled with zeros, every convolution operation will result in zero, regardless of the image content.Step 2: Eliminate wrong options
The kernel is not normalized. affects scaling, not zero output. The image is padded incorrectly. affects boundary handling, not zero output. The stride is set too high. affects output size, not zero output.Final Answer:
Option B -> Option BQuick Check:
Zero kernel leads to zero output. [OK]
Hint: Zero kernel leads to zero output. [OK]
Common Mistakes:
3. In a recommendation system, why might you choose NDCG over precision at k?
medium
Solution
Step 1: Understand NDCG vs Precision
NDCG accounts for the position of relevant items, giving higher scores to relevant items at higher ranks.Step 2: Evaluate Options
Precision at k does not consider the order of items, only their presence.Final Answer:
Option B -> Option BQuick Check:
NDCG values position. [OK]
Hint: NDCG values position. [OK]
Common Mistakes:
4. You implemented PCA but the variance explained by the first principal component is unexpectedly low. What is the most likely cause?
medium
Solution
Step 1: Identify the impact of centering data
Centering data is crucial for PCA as it ensures the covariance matrix reflects true variance.Step 2: Eliminate wrong options
Eigenvectors were not normalized. is incorrect because normalization affects direction, not variance. Covariance matrix was computed using rowvar=True. affects orientation, not variance. Too few principal components were selected. is irrelevant to the variance of the first component.Final Answer:
Option A -> Option AQuick Check:
Center data before PCA to capture variance. [OK]
Hint: Center data before PCA to capture variance. [OK]
Common Mistakes:
5. How can you optimize the train-test split with stratification for a very large dataset to reduce memory usage?
hard
Solution
Step 1: Identify memory optimization techniques
Using a generator allows processing data in batches, reducing memory footprint.Step 2: Evaluate options
In-place operations and smaller data types help, but generators are more effective for large datasets.Final Answer:
Option C -> Option CQuick Check:
Generators reduce memory by processing in batches. [OK]
Hint: Generators reduce memory by processing in batches. [OK]
Common Mistakes:
