Practice
1. What is the time complexity of calculating the Euclidean distance between two vectors of length n?
easy
Solution
Step 1: Understand Euclidean distance calculation
Euclidean distance involves element-wise operations and a square root.Step 2: Analyze operations
Each element is processed once, leading to O(n) complexity.Final Answer:
Option D -> Option DQuick Check:
Element-wise operations imply O(n). [OK]
Hint: Element-wise operations imply O(n). [OK]
Common Mistakes:
2. What does the following Python code output?
import numpy as np
def softmax(x):
e_x = np.exp(x - np.max(x))
return e_x / e_x.sum(axis=0)
x = np.array([2.0, 1.0, 0.1])
print(softmax(x))easy
Solution
Step 1: Calculate softmax
Compute the exponentials of the input array after subtracting the max value for numerical stability.Step 2: Normalize
Divide each exponential by the sum of all exponentials to get probabilities.Final Answer:
Option A -> Option AQuick Check:
Softmax outputs sum to 1 [OK]
Hint: Softmax outputs sum to 1 [OK]
Common Mistakes:
3. You need to apply non-max suppression on a batch of images. Which approach is most efficient?
medium
Solution
Step 1: Consider independence of images
Each image's boxes are independent, so process them separately.Step 2: Evaluate efficiency
Concatenating boxes would mix unrelated data, and focusing on one image or thresholding scores misses other valid boxes.Final Answer:
Option A -> Option AQuick Check:
Process each image independently [OK]
Hint: Process each image independently [OK]
Common Mistakes:
4. You implemented a KNN classifier using a KD-Tree, but it returns incorrect classifications. What is the most likely cause?
medium
Solution
Step 1: Identify potential issues
Incorrect classifications often stem from using an inappropriate distance metric.Step 2: Eliminate other options
A: Balancing affects efficiency, not correctness. C: Insufficient data affects accuracy, not correctness. D: High-dimensionality affects efficiency, not correctness.Final Answer:
Option A -> Option AQuick Check:
Check distance metric for KD-Tree issues [OK]
Hint: Check distance metric for KD-Tree issues [OK]
Common Mistakes:
5. 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:
