Short answers
In the context of SLAM, explain the loop closure problem and describe two different strategies to detect and handle loop closures in a graph-based SLAM system. What are the key trade-offs between these strategies?
Your answer
Loop closure is allowing the robot to recognize a location it has scanned previously to understand and correct its current drift. In vision, if we detect an image that is close to what the robot has seen before, we can extract visual features and store the current pose positions in graph. In sensor, if our current pose is close to a previous pose, we can compare current scan with previous scan and accept it as a loop closure.
Model ideal answer
The loop closure problem arises when a robot revisits a previously mapped area, and the accumulated drift in the trajectory must be corrected by recognizing the revisit and optimizing the graph. Two common detection strategies are: (1) Bag-of-Visual-Words (BoW) using feature descriptors and a vocabulary tree to perform place recognition, and (2) scan matching (e.g., ICP) on LIDAR data combined with a short-term pose estimate to identify geometric similarity. Once detected, handling involves adding a constraint (edge) in the pose graph and running a global optimization (e.g., using g2o or Ceres). Trade-offs: BoW is robust to viewpoint change and works well in appearance-based scenarios, but can produce false positives in environments with repeated structure; it also requires a pre-trained vocabulary. Scan matching is more accurate for geometric integrity, but is computationally heavier per candidate and may fail under large viewpoint differences. Additionally, false positive handling requires techniques like verification with RANSAC or temporal consistency checks.
The double descent phenomenon in modern machine learning contradicts the classical bias-variance tradeoff. Describe double descent and explain why it occurs in overparameterized models. How does this phenomenon relate to the notion of 'benign overfitting'?
Your answer
The classical bias-variance tradeoff is when you need to balance between bias and variance, where a simple model has low variance, high bias and may cause underfitting. On the other hand, a more complicated model has high variance, low bias, causing overfitting. However, in an overparameterized model, with the complex network it is able to learn multiple ways to overfit the training data, making it back able to generalize well for test examples.
Model ideal answer
Double descent refers to the observation that as model complexity (e.g., number of parameters) increases, test error first descends, then ascends (like the traditional bias-variance tradeoff), but then descends again when the model becomes highly overparameterized. This occurs because in the overparameterized regime, the model can interpolate the training data perfectly while still maintaining good generalization due to implicit regularization from the optimization algorithm (e.g., SGD converges to a minimum-norm solution). Benign overfitting is a related concept where a model fits noisy training data exactly but still generalizes well; it happens when the noise is 'benign' (e.g., concentrated in low-variance directions). The double descent phenomenon is a manifestation of benign overfitting: the test error peaks near the interpolation threshold where the model just barely fits the data (a critical regime), but then decreases as the model becomes even more overparameterized, allowing it to fit the noise without harming generalization.
In reinforcement learning, the 'deadly triad' refers to the instability that arises when combining function approximation, bootstrapping, and off-policy learning. Explain why each component is necessary for the instability, and describe a practical algorithm (e.g., DQN) that mitigates this instability. What specific techniques does DQN use to address the triad?
Your answer
Approximation is used so we can estimate the reward instead of calculating / simulating entire trajectory, needed for practical computational ability. Bootstrapping is only using a small set of future state's reward to determine current reward instead of accounting for the entire rest of trajectory, as that is higher variance and less predictable. Off-policy learning can give better exploration. DQN can, for example, create two networks, and only updating the slower policy network after the fast policy network updates more frequently to reduce variance.
Model ideal answer
The deadly triad is a set of three components that can cause value function divergence: (1) function approximation (e.g., neural networks) leads to generalization and potential interference; (2) bootstrapping (updating estimates from other estimates) introduces bias and can propagate errors; (3) off-policy learning (learning from data not generated by the current policy) increases variance due to differing state-action distributions. When combined, the approximation error can be amplified, leading to unbounded estimates. DQN mitigates this by using two key techniques: a target network (reducing bootstrapping by fixing the target for a number of steps) and experience replay (which breaks temporal correlations and stabilizes updates, but still off-policy). These techniques reduce the interaction between the components, particularly by reducing the severity of bootstrapping and off-policy instability through slower updates and more i.i.d. data.
Denoising diffusion probabilistic models (DDPMs) can be interpreted as learning the score function of the data distribution. Show mathematically how the training objective of DDPMs (simplified MSE on noise) is equivalent to score matching. What is the connection to Langevin dynamics?
Your answer
I don't know. Can you explain this answer to me?
Model ideal answer
In DDPMs, the forward process adds noise to data: x_t = sqrt(1-beta_t) x_{t-1} + sqrt(beta_t) epsilon. The reverse process is parameterized as p_theta(x_{t-1}|x_t) = N(x_{t-1}; mu_theta(x_t, t), sigma_t^2 I). The training objective is to predict the added noise epsilon: E_{t,x_0,epsilon}[ ||epsilon - epsilon_theta(x_t, t)||^2]. With Tweedie's formula, the optimal denoiser relates to the score: grad_{x_t} log q(x_t) = - (1/sqrt(1-bar_alpha_t)) E[epsilon | x_t]. Hence, minimizing the noise prediction MSE is equivalent to score matching: E[ ||grad_{x_t} log q(x_t) - s_theta(x_t, t)||^2] up to a scaling factor. The sampling process (starting from pure noise and iteratively denoising) corresponds to Langevin dynamics, where each step is a gradient ascent in the data log-density plus added noise, approximating sampling from the data distribution. The connection is that the reverse diffusion process is essentially performing annealed Langevin dynamics with the learned score.
In ROS2, the executor is responsible for scheduling and executing callbacks. Compare the SingleThreadedExecutor with the MultiThreadedExecutor. Under what circumstances would you choose a StaticSingleThreadedExecutor, and what are the trade-offs regarding priority inversion and spin callbacks?
Your answer
SingleThreadedExecutor has lass room for error, waits for one thread to finish before moving onto the next. Drawback is each thread is waiting for previous threads to complete, could be slower. Multi is just having multiple threads active at once, more prone to concurrency related errors, but could be faster, for example lidar, imu, camera can report their sensor values back concurrently instead of waiting for each other to finish first.
Model ideal answer
The SingleThreadedExecutor runs all callbacks sequentially in one thread, ensuring no concurrency issues but limited throughput. The MultiThreadedExecutor uses a thread pool to execute callbacks concurrently, potentially improving performance for CPU-bound or I/O-bound tasks but introducing data race risks. The StaticSingleThreadedExecutor assigns each callback to a specific executor entity (e.g., a node) and does not support dynamic addition of nodes; it yields lower overhead because it avoids callback group arbitration. A key trade-off: in the standard SingleThreadedExecutor, if a callback takes a long time, it blocks others (priority inversion possible if high-priority callbacks are queued). StaticSingleThreadedExecutor can mitigate this by separating callbacks into different executors, but requires careful configuration. Spin callbacks (e.g., timer callbacks) can cause deadlocks if they are interdependent and executed by different threads; the multi-threaded executor is more susceptible to such issues without proper synchronization.
In embedded systems with limited memory, dynamic memory allocation (e.g., malloc/free or new/delete) is often discouraged. Explain the specific reasons why dynamic allocation can be problematic in such systems. Under what circumstances might a static allocation strategy be insufficient, and how can a memory pool allocator be used to bridge the gap?
Your answer
There is much less memoy on an embedded system, so when it ran into OOM problems, it is much more likely to crash and fail compared to a computer with more memory to prevent entire system crashing. Static memory may be insufficient if we don't know the exact amount of messages that will come back, so setting it to a higher bound array is wasting space. A memory pool allocator allocates a fixed block of memory during start up, then divides it into fixed-size chunks to be used.
Model ideal answer
Dynamic allocation is problematic because: (1) heap fragmentation can cause allocation failures even if total free memory is sufficient; (2) allocation and deallocation times are unbounded, breaking real-time guarantees; (3) memory leaks are hard to debug; (4) overhead due to tracking allocations. Static allocation (all sizes known at compile time) avoids these issues but is inflexible for variable-sized data or runtime configurable buffers. A memory pool allocator pre-allocates a fixed-size block or multiple fixed-size slots (e.g., slab allocator) and hands them out in constant time, reducing fragmentation (no external fragmentation for same-size blocks) and providing deterministic runtime. This works well for objects of known, bounded size that need to be created dynamically (e.g., message buffers in a communication stack).
Explain the MESI cache coherence protocol. Under what conditions does a cache line in the 'Shared' state transition to 'Modified'? What is the role of the 'Invalid' state in ensuring correctness, and how does a write miss handled in a write-back cache differ from that in a write-through cache?
Your answer
I don't know this one. Can you explain to me.
Model ideal answer
MESI has four states: Modified, Exclusive, Shared, Invalid. A line in Shared can transition to Modified only if the core performs a write and it has exclusive access; the core must invalidate all other copies by sending an invalidate message on the bus. The 'Invalid' state marks a line as not present or stale; it is crucial because it ensures that before a core reads a line, it gets the most recent data from another cache or memory, preventing stale reads. In a write-back cache, a write miss (line not in cache or in Invalid) first fetches the line (read-for-ownership), modifies it, marks it Modified, and writes to memory only when evicted. In a write-through cache, a write miss typically allocates a line in the cache (or not, depending on policy) and immediately writes through to memory; this simplifies coherence because memory is always up-to-date but increases bus traffic.
Consider the following C++ code snippet. Identify all issues related to memory management, move semantics, and ownership. Propose fixes using modern C++ features (C++11 and later).
class Buffer {
public:
Buffer(size_t size) : data(new int[size]), size_(size) {}
~Buffer() { delete[] data; }
int* data;
size_t size_;
};
Buffer createBuffer() {
Buffer b(100);
return b; // (A)
}
int main() {
Buffer b1 = createBuffer();
Buffer b2 = b1; // (B)
b2.data[0] = 42;
}
Your answer
I don't know. Can you explain.
Model ideal answer
Issues: (1) No copy constructor or copy assignment operator defined, leading to shallow copies (double deletion). (2) No move constructor/assignment, so returning from createBuffer may copy (if RVO not applied) causing same issue. (3) The class has a raw pointer but no rule-of-five adherence. (4) In main, b2 = b1 results in two objects pointing to the same data, and both will attempt to delete it in destructor — undefined behavior. Fixes: Implement copy constructor (deep copy), copy assignment (copy-swap idiom), move constructor and move assignment (stealing the resource and setting other's data to nullptr), or better, use std::vector
You are debugging a multi-threaded application that deadlocks. The code uses two mutexes: mutexA and mutexB. Thread 1 locks mutexA then mutexB; Thread 2 locks mutexB then mutexA. A colleague suggests using std::lock() to lock both mutexes simultaneously. Write a C++ snippet demonstrating the correct usage and explain why it prevents deadlock. Additionally, describe a scenario where even using std::lock() could still result in deadlock (if any) or other issues.
Your answer
If they are executed at the same time, there could be the case where thread 1 locks mutex A, thread 2 locks mutex B, then thread 1 can't get to mutexB and thread 2 can't use thread A. Can you show me how to use the C++ correctly? Maybe add a synchronization to it to prevent it?
Model ideal answer
Correct usage:
std::mutex mutexA, mutexB;
void thread1() {
std::lock(mutexA, mutexB);
std::lock_guard<std::mutex> lock1(mutexA, std::adopt_lock);
std::lock_guard<std::mutex> lock2(mutexB, std::adopt_lock);
// work
}
void thread2() {
std::lock(mutexA, mutexB);
std::lock_guard<std::mutex> lock1(mutexA, std::adopt_lock);
std::lock_guard<std::mutex> lock2(mutexB, std::adopt_lock);
// work
}
std::lock() uses a deadlock-avoidance algorithm (e.g., back-off) to lock the mutexes without deadlock if possible. It prevents the classic deadlock because it ensures that the two mutexes are locked atomically (or at least without interleaving that causes circular wait). However, a scenario where deadlock could still occur: if the code has multiple lock requests spread across functions or conditional locking, or if there is a third mutex not managed by the same std::lock call. Also, if threads use try_lock() incorrectly, or if resources are locked in a recursive manner without proper ordering. Moreover, std::lock does not protect against deadlocks that involve other synchronization primitives (e.g., condition variables) or if the locking order is not consistent across all code paths (at least across all callers of this function, but here both threads use the same order so it's fine). Another issue: if the threads try to lock in a different order elsewhere, deadlock may still occur.
In finance, the Black-Scholes model assumes constant volatility and no dividends. Explain the concept of the volatility smile and why it suggests that the Black-Scholes model is an incomplete description of market behavior. How does the implied volatility surface incorporate market data, and what role does it play in pricing exotic options?
Your answer
I don't know this one.
Model ideal answer
The volatility smile is the pattern where, for a fixed maturity, implied volatilities of options plotted against strike prices form a 'smile' shape—higher for deep in/out-of-the-money options and lower for at-the-money. This contradicts Black-Scholes' assumption of constant volatility, suggesting that market participants expect future volatility to vary with moneyness and time. Reasons include leptokurtic distributions (fat tails) and leverage effects. The implied volatility surface extends this to different maturities, creating a 3D surface (strike vs. time). It is used to calibrate stochastic volatility models (e.g., Heston) or local volatility models (e.g., Dupire) that better match market prices. For exotic options (e.g., barriers, Asian options), the volatility surface is critical because these options have path-dependent payoffs; a simple Black-Scholes model misprices them significantly. Traders use the surface to compute the cost of hedging and to quote consistent prices.
Multiple-choice review
In the context of simultaneous localization and mapping (SLAM), which of the following best describes the primary challenge of 'loop closure'?
In a Transformer-based language model, which of the following is a key property of the attention mechanism that makes it more computationally expensive than recurrence for long sequences?
In reinforcement learning, the policy gradient theorem provides the gradient of the expected return with respect to policy parameters. Which of the following is a correct expression for the gradient in the case of a stochastic policy π_θ(a|s)?
In diffusion models, the reverse process is typically parameterized as a denoising function that predicts the noise component of a noisy sample. Which of the following is a correct interpretation of the training objective for a continuous-time diffusion model?
In machine learning, which of the following best describes the bias-variance decomposition of expected squared error?
In ROS2, which of the following best describes the role of the rmw (ROS Middleware) layer?
In embedded systems, which of the following best describes a primary advantage of using a real-time operating system (RTOS) over a bare-metal scheduler?
In computer science, which of the following statements about the halting problem is true?
In C++, which of the following is true about the use of std::move?
In memory management, which of the following is a potential advantage of using a buddy allocator over a slab allocator?
In concurrency, which of the following describes a scenario where a deadlock is possible?
In multithreaded programming, which of the following is true about the difference between a mutex and a semaphore?
In concurrency, what is the purpose of a memory barrier (fence)?
In finance, what is the primary risk associated with an inverse floater bond?
Which of the following factors is considered a primary cause of the collapse of the Roman Republic?
In robotics, the concept of 'differential flatness' is particularly useful for controlling which type of system?
In the context of neural network training, the 'double descent' phenomenon refers to:
In distributional reinforcement learning, the categorical algorithm (C51) represents the value distribution as a set of discrete atoms. A key challenge is:
In diffusion models, the use of the 'score function' (∇_x log p(x)) is central to generation. One advantage of score-based modeling over directly modeling the density is:
In high-dimensional linear regression, the 'curse of dimensionality' manifests in the phenomenon that the k-nearest neighbors algorithm's effective distance metric becomes:
In ROS2, which of the following is the primary mechanism to achieve zero-copy data transfer between nodes?
In embedded systems, a 'watchdog timer' that is configured to generate a reset upon timeout is most effective when:
The Cook-Levin theorem establishes that the Boolean satisfiability problem (SAT) is NP-complete. Which of the following is a direct corollary of this result?
In C++, which of the following statements about the 'rule of five' (or rule of three/zero) is correct?
In virtual memory systems, 'thrashing' specifically refers to:
In the context of deadlock detection, which of the following best describes why it is often impractical to detect deadlocks using the 'wait-for graph' approach in a system with many resources?
In real-time systems, priority inversion occurs when a lower-priority thread holds a mutex needed by a higher-priority thread. Which of the following mechanisms specifically solves priority inversion?
In lock-free concurrent programming with compare-and-swap (CAS), the 'ABA problem' refers to:
In the Black-Scholes option pricing model, which of the following assumptions is critical for the derivation of the partial differential equation (PDE) that leads to the formula?
Which of the following was a significant direct consequence of the 'Plague of Athens' during the Peloponnesian War (430-426 BCE)?