Practice
1. What is the time complexity of the following non-max suppression implementation?
def non_max_suppression(boxes, scores, iou_threshold):
indices = np.argsort(scores)[::-1]
keep = []
while len(indices) > 0:
current = indices[0]
keep.append(current)
indices = indices[1:]
indices = [i for i in indices if iou(boxes[current], boxes[i]) < iou_threshold]
return keepeasy
Solution
Step 1: Analyze the loop structure
The outer loop runs n times, and the inner loop (IoU calculation) also runs n times in the worst case.Step 2: Determine complexity
Each IoU calculation is O(1), making the overall complexity O(n^2).Final Answer:
Option B -> Option BQuick Check:
Nested loops suggest O(n^2) [OK]
Hint: Nested loops suggest O(n^2) [OK]
Common Mistakes:
2. What is the time complexity of generating a sinusoidal positional encoding matrix of size
position x d_model?easy
Solution
Step 1: Analyze the operations
The code iterates over each position and each dimension, performing constant-time operations.Step 2: Eliminate wrong options
O(position^2) is incorrect because the complexity is not quadratic in position. O(d_model^2) is incorrect because the complexity is not quadratic in d_model. O(1) is incorrect because the complexity is not constant.Final Answer:
Option C -> Option CQuick Check:
Iterate over position and dimension. [OK]
Hint: Iterate over position and dimension. [OK]
Common Mistakes:
3. In a dataset with highly imbalanced classes, which cross-validation technique is most appropriate?
medium
Solution
Step 1: Consider class imbalance
Stratified K-Fold ensures each fold has the same class distribution as the entire dataset.Step 2: Eliminate wrong options
Standard K-Fold and D do not preserve class distribution. Leave-One-Out is inefficient for large datasets.Final Answer:
Option A -> Option AQuick Check:
Use Stratified K-Fold for class balance. [OK]
Hint: Use Stratified K-Fold for class balance. [OK]
Common Mistakes:
4. In a Random Forest implementation, how would you apply feature sampling to handle high-dimensional data effectively?
medium
Solution
Step 1: Understand Feature Sampling
Feature sampling involves selecting a random subset of features for each tree to reduce dimensionality.Step 2: Evaluate Options
Using all features (A) or a fixed subset (C) doesn't reduce dimensionality; correlation-based selection (D) isn't random.Final Answer:
Option C -> Option CQuick Check:
Random subsets reduce dimensionality [OK]
Hint: Random subsets reduce dimensionality [OK]
Common Mistakes:
5. How can you optimize the implementation of a Gaussian Naive Bayes classifier for a large dataset?
hard
Solution
Step 1: Identify optimization needs
For large datasets, memory efficiency is crucial.Step 2: Evaluate optimization strategies
Using a sparse matrix (Use a sparse matrix representation for input data.) reduces memory usage and speeds up computation. Use a more complex model like SVM. increases complexity unnecessarily. Implement batch processing for training. is less relevant as GaussianNB is already efficient. Increase the number of features by adding polynomial terms. increases computational load.Final Answer:
Option A -> Option AQuick Check:
Use sparse matrices for memory efficiency. [OK]
Hint: Use sparse matrices for memory efficiency. [OK]
Common Mistakes:
