1. Home
  2. Explore
  3. Computer Science
  4. Data Structures & Algorithms Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Data Structures & Algorithms Basics

  • 30Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Big O Notation
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is Big O notation used for?

Tap to flipClick to flipspace

To describe the performance or scalability of an algorithm as the input size grows.

Or swipe the card

30 cards

  1. What is Big O notation used for?

    To describe the performance or scalability of an algorithm as the input size grows.

  2. What does O(1) constant time mean? Give an example.

    An algorithm runs in constant time if its runtime does not depend on the input size. Example: accessing an array element by its index.

  3. What does O(n) linear time mean? Give an example.

    An algorithm runs in linear time if its runtime grows proportionally to the input size n. Example: iterating through all elements of an array with a single loop.

  4. Why are constants dropped in Big O notation? (e.g., O(2n) simplifies to O(n))

    Because Big O describes growth rate, not exact timing. Constants become insignificant for large n; the linear growth pattern remains the same.

  5. What does O(n^2) quadratic time mean? Give an example.

    Runtime grows proportionally to the square of the input size. Example: nested loops iterating over the same array (e.g., printing all pairs).

  6. What does O(log n) logarithmic time mean? Give an example.

    Runtime grows slowly because the algorithm reduces the problem size by half each step. Example: binary search on a sorted array.

  7. How does binary search achieve O(log n) time?

    By repeatedly comparing the target to the middle element and discarding the half where the target cannot be, reducing the search space by half each step.

  8. What does O(2^n) exponential time mean?

    Runtime doubles with each additional input element, growing very quickly. It is the opposite of logarithmic growth and is not scalable.

  9. When analyzing Big O, why do we consider the worst-case scenario?

    To guarantee the algorithm's performance upper bound. The worst-case gives the maximum time the algorithm could take for any input of size n.

  10. What is space complexity? Give an example of O(1) and O(n) space.

    Space complexity measures the extra memory an algorithm uses relative to input size. O(1): a loop variable. O(n): copying an array of size n.

  11. How do arrays store elements in memory?

    Elements are stored sequentially in contiguous memory locations. The address of element at index i is base_address + i * size_of_element.

  12. What is the runtime complexity of accessing an array element by its index?

    O(1) constant time.

  13. What are the limitations of static arrays (e.g., in Java)?

    They have a fixed size that cannot be changed after creation. If the array is full, resizing is expensive (O(n)).

  14. Why is resizing an array an O(n) operation?

    Because all n existing elements must be copied from the old array to the new larger array.

  15. What are the best-case and worst-case runtimes for removing an element from an array?

    Best case: O(1) when removing the last element (no shifting). Worst case: O(n) when removing the first element (all elements must shift left).

  16. In Java, what classes provide dynamic array functionality? How do they differ?

    Vector and ArrayList. Vector grows by 100% of its size and has synchronized methods. ArrayList grows by 50% and is not synchronized.

  17. In a custom dynamic array (like the Array class built in the video), why do we need a separate count field instead of using the array's length?

    count tracks the actual number of items stored, while length is the allocated capacity. This allows the array to have extra capacity without showing empty slots.

  18. How does the insert method work in a custom dynamic array when the array is full?

    Create a new array of double the size, copy all existing items to it, then set the new array as the backing array and insert the new item.

  19. In a custom dynamic array, what does the removeAt method do?

    It validates the index (throws exception if out of bounds), then shifts all elements to the right of the index one step left to fill the hole, and decrements count.

  20. What is the runtime of the indexOf method in a custom dynamic array?

    O(n) worst-case, because it may need to scan all items if the target is at the end or not present.

  21. What is a linked list composed of? Define head and tail.

    A linked list is composed of nodes. Each node contains a value and a pointer to the next node. The head is the first node, the tail is the last node.

  22. What is the runtime of inserting a node at the beginning or end of a linked list?

    O(1) constant time in both cases (assuming we maintain head and tail references).

  23. Why is looking up an element by index in a linked list O(n)?

    Because nodes are not stored contiguously in memory; you must traverse from head to the desired index, following next pointers.

  24. How do you delete the first node of a linked list?

    Set head to head.next, then remove the link from the old head to the second node (set old head.next = null) to allow garbage collection.

  25. How do you delete the last node of a linked list?

    Traverse the list to find the node before the tail (previous), then set tail = previous and set tail.next = null.

  26. What edge case must be handled when deleting the first or last node of a linked list?

    When the list has only one node (head == tail), both head and tail must be set to null after removal.

  27. How does the indexOf method work in a custom linked list?

    Traverse from head with an index counter. If a node's value equals the target, return the current index. If traversal ends, return -1.

  28. In a custom linked list, how is the contains method typically implemented?

    By calling indexOf(item) and checking if the result is not -1. If indexOf returns a valid index, the item exists; otherwise, it does not.

  29. What is the purpose of removing the link (setting next to null) when deleting a node from a linked list?

    To allow the garbage collector to reclaim the memory of the removed node. If other objects still reference it, it won't be freed.

  30. Why is the Node class in a custom linked list often made private or internal?

    Because it is an implementation detail; users of the linked list should only interact through public methods like add, remove, etc.

Card 1 of 30
Card 1 of 30

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent