Practice
1. What is the time complexity of computing the numerical gradient for a function with n parameters using central difference?
easy
Solution
Step 1: Analyze the loop structure
The numerical gradient computation involves a loop over n parameters, each requiring constant time operations.Step 2: Determine the complexity
Each parameter requires a constant number of operations, leading to O(n) complexity.Final Answer:
Option D -> Option DQuick Check:
Loop over n parameters, each constant time. [OK]
Hint: Loop over n parameters, each constant time. [OK]
Common Mistakes:
2. 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:
3. In the context of logistic regression, which approach is correct for handling a dataset with highly imbalanced classes?
medium
Solution
Step 1: Identify the problem with imbalanced classes
Imbalanced classes can lead to biased predictions towards the majority class.Step 2: Choose a method to address imbalance
SMOTE (Synthetic Minority Over-sampling Technique) is effective for balancing datasets.Final Answer:
Option B -> Option BQuick Check:
SMOTE balances classes effectively [OK]
Hint: SMOTE balances classes effectively [OK]
Common Mistakes:
4. How would you modify the scaled dot-product attention mechanism to handle variable-length sequences efficiently?
medium
Solution
Step 1: Identify the challenge
Variable-length sequences require handling of different sequence lengths.Step 2: Choose the correct approach
Padding with masking is efficient and maintains sequence integrity.Final Answer:
Option A -> Option AQuick Check:
Pad and mask for variable lengths [OK]
Hint: Pad and mask for variable lengths [OK]
Common Mistakes:
5. How can you optimize the K-Means implementation to improve its performance on large datasets?
hard
Solution
Step 1: Identify performance bottlenecks
The Elkan algorithm optimizes K-Means by reducing the number of distance calculations needed.Step 2: Eliminate wrong options
Increase the number of iterations. increases computation. Decrease the number of clusters. may not be suitable for the data's natural structure. Use a smaller subset of data for training. reduces accuracy.Final Answer:
Option A -> Option AQuick Check:
Elkan reduces distance calculations. [OK]
Hint: Elkan reduces distance calculations. [OK]
Common Mistakes:
