Big-O on game-loop hot paths Quiz

Test your understanding of Big-O notation applied to game-loop hot paths, collision detection, data structure choices, and strategies for minimizing memory allocations while optimizing per-frame performance. This quiz helps reinforce best practices for reducing unnecessary work and finding the right balance between time and space complexity in real-time game development.

  1. Understanding Nested Loops in Game Loops

    When checking every pair of enemy objects for collisions in a single loop pass, what is the typical Big-O time complexity?

    1. O(1)
    2. O(N)
    3. O(N^2)
    4. O(log N)
  2. Choosing Data Structures for Fast Lookups

    If you frequently check whether an object is present in a collection within the update loop, which data structure generally provides the fastest membership test?

    1. Linked List
    2. Array
    3. Hash Set
    4. Stack
  3. Reducing Candidate Pairs in Collision Detection

    Using a spatial partitioning technique like grid bucketing in per-frame collision checks usually aims to reduce which aspect of performance cost?

    1. The number of collision candidate checks
    2. The number of memory allocations
    3. The size of code files
    4. The frequency of rendering frames
  4. Arrays vs. Hash Sets: Use Case

    When updating every game entity each frame in a fixed order, which data structure is most space-efficient while providing fast iteration?

    1. Array
    2. Binary Tree
    3. Hash Set
    4. Queue
  5. Avoiding Unnecessary Allocations

    To minimize performance drops due to memory usage in per-frame updates, which practice should you generally avoid inside hot loops?

    1. Reusing pre-allocated objects
    2. Iterating with for-loops
    3. Using object pools
    4. Allocating new large temporary arrays
  6. Amortized Time for Adding Objects

    What is the worst-case time complexity for inserting a new object into a dynamically resizing array when the storage is full?

    1. O(N^2)
    2. O(log N)
    3. O(N)
    4. O(1)
  7. Impact of Per-Frame Allocations

    Constantly allocating and discarding objects every frame can lead to which common runtime issue?

    1. Heap fragmentation and garbage collection spikes
    2. Network latency
    3. Stack overflow
    4. Graphics driver crashes
  8. Big-O of Iterating Over All Entities

    What is the Big-O time complexity of processing every item in an array with a single for-loop, as seen in typical game-loop updates?

    1. O(N^2)
    2. O(log N)
    3. O(1)
    4. O(N)
  9. Time vs. Space Trade-Off in Collision Detection

    Using a data structure that consumes more memory to store spatial information (like a grid or tree) for collision checks is an example of which optimization strategy?

    1. Increasing time complexity
    2. Minimizing space complexity
    3. Reducing code readability
    4. Trading space for time
  10. Choosing When to Use Hash Sets

    In a game update loop, when does a hash set generally outperform an array for searching for specific entities?

    1. When you need stable index-based access
    2. When you only need to iterate in order
    3. When frequent membership checks are needed
    4. When fast addition of new items is required