Sign up freeSign in

Practice quiz · by a Quizcard user

Intro to Programming and Data Structures — quiz

18 multiple-choice questions covering Binary search trees, Heaps, Hash tables, Stacks vs queues, Arrays vs linked lists. One answer each; you get a score at the end and the explanation for every question. No account needed.

Take the quiz Study the flashcards first Make a quiz from my notes

Updated 2026-10-24. Keys 1–4 pick an answer, Enter moves on. Redo it any time, in order or shuffled.

The questions

Answers and explanations are shown after you finish.

  1. Binary search trees

    A binary search tree was built by inserting keys that were already in sorted order, so every node has only one child. What happens to search time in this tree?

    • It becomes O(n log n) due to the insertion order
    • It degrades to O(n) because the tree is effectively a linked list
    • It becomes O(1) because keys are ordered
    • It stays O(log n) because it's still a binary search tree
  2. Heaps

    In a min-heap, what must be true about every parent node relative to its children?

    • The parent is greater than or equal to its children
    • The parent equals its children
    • The parent is less than or equal to its children
    • There is no required relationship except at the root
  3. Hash tables

    Two different keys in a hash table compute to the same array slot. What is this situation called, and how is it commonly handled?

    • Overflow, fixed by switching to linear search
    • Overflow, fixed by resizing the array immediately
    • A collision, resolved with chaining or open addressing
    • A collision, resolved by rehashing every stored key
  4. Stacks vs queues

    You're implementing 'undo' in a text editor, where the most recent action should be reversed first. Which structure fits best, and why?

    • A linked list, because it supports O(1) insertion anywhere
    • An array, because it allows O(1) access by index
    • A stack, because the last action performed should be undone first
    • A queue, because actions should be processed first-in-first-out
  5. Arrays vs linked lists

    You need frequent insertions in the middle of a collection and don't require fast access by index. Which structure is the better choice and why?

    • An array, since it has O(1) index access
    • A linked list, since inserting at a known node is O(1) without shifting elements
    • A hash table, since it has O(1) average lookup
    • An array, since it uses contiguous memory
  6. Dynamic programming

    Why does storing (memoizing) results of recursive Fibonacci calls make the computation dramatically faster?

    • It converts the recursive calls into a loop automatically
    • It reduces the space complexity to O(1)
    • It avoids recomputing overlapping subproblems, a core idea of dynamic programming
    • It removes the need for a base case
  7. Dijkstra's algorithm

    Dijkstra's algorithm will give incorrect shortest-path results if the graph contains which feature?

    • Disconnected components
    • Unweighted edges
    • Negative edge weights
    • Cycles
  8. Quicksort

    Quicksort is run on an already-sorted array, always choosing the first element as the pivot. What is the resulting time complexity?

    • Becomes a stable sort
    • Improves to O(n)
    • Degrades to O(n²) in the worst case
    • Stays O(n log n) on average
  9. Merge sort vs quicksort

    What is the main trade-off of merge sort compared to quicksort?

    • Merge sort has a worst case of O(n²) like quicksort
    • Merge sort guarantees O(n log n) in all cases but requires O(n) extra space
    • Merge sort sorts in-place with no extra memory
    • Merge sort has a worse average-case time complexity but uses less memory
  10. BFS vs DFS

    You need the shortest path in an unweighted graph. Which traversal should you use, and what data structure drives it?

    • DFS using a stack
    • BFS using a queue
    • DFS using recursion only
    • BFS using a priority queue
  11. Polymorphism

    A program has Circle and Square classes, each with its own area() method. Calling shape.area() on a mixed list of shapes without checking each type demonstrates which concept?

    • Polymorphism
    • Inheritance
    • Abstraction
    • Encapsulation
  12. Encapsulation

    A class keeps its fields private and only allows changes through getter and setter methods. Which OOP principle does this illustrate?

    • Encapsulation
    • Polymorphism
    • Inheritance
    • Composition
  13. Classes vs objects

    Given 'class Dog' and the code 'my_dog = Dog()', what best describes my_dog?

    • A method belonging to Dog
    • A subclass of Dog
    • An instance (object) of the Dog class
    • An interface that Dog implements
  14. Version control

    Why would a developer create a new Git branch before starting work on a new feature?

    • To permanently delete earlier commits
    • To isolate the changes so they don't affect the main codebase until merged
    • To track which developer wrote each line
    • To automatically run unit tests on the code
  15. Unit testing

    A test that checks one function's behavior in isolation from the rest of the program is best described as which type of test?

    • Regression test
    • Unit test
    • Integration test
    • System test
  16. Big-O comparison

    Which sequence correctly orders these growth rates from fastest to slowest?

    • O(1) < O(log n) < O(n) < O(n log n)
    • O(2^n) < O(n²) < O(n log n)
    • O(n log n) < O(n) < O(log n) < O(1)
    • O(n²) < O(n log n) < O(n)
  17. Binary search

    Why can't binary search be applied directly to an unsorted array?

    • The algorithm relies on the array being sorted so it can discard half the remaining elements each step
    • Binary search only works on linked lists
    • It works fine but ends up slower than linear search
    • It would require O(n) extra space
  18. Recursion

    A recursive factorial function is written without a base case. What will happen when it's called?

    • It runs correctly but more slowly than an iterative version
    • It immediately returns 0
    • It causes infinite recursion, eventually leading to a stack overflow
    • It automatically converts to an iterative loop
Take the quiz

Try it with your own material

Paste notes, upload a PDF, or pick any of your decks and Quizcard writes a quiz with explanations in about a minute. Quizzes from your own decks are free.

Quiz yourself on your own materialSee how Quizcard works