1. Home
  2. Explore
  3. Computer Science
  4. Introduction to Data Structures

Study methods

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

Introduction to Data Structures

  • 42Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Interface vs. Data Structure
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is the primary distinction between an interface (API/ADT) and a data structure?

Tap to flipClick to flipspace

An interface specifies what operations can be performed on data, while a data structure specifies how those operations are implemented and how data is stored.

Or swipe the card

42 cards

  1. What is the primary distinction between an interface (API/ADT) and a data structure?

    An interface specifies what operations can be performed on data, while a data structure specifies how those operations are implemented and how data is stored.

  2. In the context of data structures, what does an interface define regarding data and operations?

    An interface defines what data can be stored and what operations are supported, along with their meaning.

  3. What does a data structure define regarding data and operations?

    A data structure defines the actual representation of the data and provides algorithms for how to support the operations defined by the interface.

  4. What are the two main interfaces focused on in this course for storing nnn items?

    The two main interfaces are Set and Sequence.

  5. What is the primary characteristic of a Set interface?

    A Set interface primarily cares about values (keys) and might involve maintaining them in sorted order to support searching for a given value.

  6. What is the primary characteristic of a Sequence interface?

    A Sequence interface cares about representing a particular order of items, where there is a first item, a second item, and so on.

  7. What are the two main data structure tools or approaches discussed?

    The two main data structure tools are arrays and pointers (or linked data structures).

  8. What defines a static sequence interface?

    A static sequence interface is where the number of items (nnn) does not change, although the actual items themselves might.

  9. List the five core operations supported by the static sequence interface.

    The five core operations are: build, length, iteration, get_at, and set_at.

  10. Describe the build(xxx) operation in a static sequence interface.

    The build(xxx) operation takes a collection of items (xxx) in a specific order and creates a new static sequence of size nnn with those items in that order.

  11. What does the length() method return in a static sequence?

    The length() method returns the fixed number of items (nnn) in the static sequence.

  12. What does the iter_sequence() operation do?

    The iter_sequence() operation outputs items x0x_0x0​ through xn−1x_{n-1}xn−1​ in their specified sequence order, iterating through all items.

  13. Explain the get_at(iii) operation in a static sequence.

    The get_at(iii) operation returns the iii-th item (xix_ixi​) from the sequence, given its index iii.

  14. Explain the set_at(iii, new_item) operation in a static sequence.

    The set_at(iii, new_item) operation changes the iii-th item (xix_ixi​) to the new_item value.

  15. What is the natural data structure to solve the static sequence interface problem?

    A static array (or what Python calls a list) is the natural data structure to solve the static sequence interface problem.

  16. How is memory modeled in the word RAM model?

    In the word RAM model, memory is an array of www-bit words, indexed from 0, where any word can be accessed randomly (at equal speed).

  17. How is a static array stored in the word RAM memory model?

    A static array is stored as a consecutive chunk of memory.

  18. Why do get_at and set_at operations take constant time in a static array?

    They take constant time because a static array is a consecutive chunk of memory, allowing the iii-th item to be accessed via simple offset arithmetic in constant time.

  19. What is the time complexity for the length() method in a static array?

    The length() method takes constant time in a static array, as the array's size (nnn) can be stored and directly returned.

  20. What is the time complexity for the build and iteration operations in a static array?

    Both build and iteration operations take linear time (heta(n) heta(n)heta(n)) in a static array.

  21. In the memory allocation model, what is the assumed cost to allocate an array of size nnn?

    It is assumed to cost heta(n) heta(n)heta(n) time to allocate an array of size nnn.

  22. Why is it assumed that the machine word size (www) must be at least extlogn ext{log } nextlogn in the word RAM model?

    The machine word size (www) must be at least extlogn ext{log } nextlogn to be able to address nnn things in memory, as the index iii (from 000 to n−1n-1n−1) must fit within a word to be accessed in constant time.

  23. What additional operations does the dynamic sequence interface add to the static sequence operations?

    The dynamic sequence interface adds insert_at and delete_at operations, allowing for changes in the number of items and their indices.

  24. How does insert_at(iii, x) conceptually change a sequence?

    It inserts a new item x at position iii, causing all items originally at or after index iii to shift over by one position and their indices to increment by one. The sequence's length increases by one.

  25. What are the special cases for insertion and deletion at the ends of a sequence?

    The special cases are insert_first, delete_first, insert_last, and delete_last.

  26. Why are special cases like insert_first or insert_last particularly interesting in an algorithms context?

    They are interesting because the algorithms to support them might be more efficient than general insert_at or delete_at operations.

  27. What is the worst-case time complexity for insert and delete operations in a static array?

    All insert and delete operations (including insert_at, delete_at, insert_first, delete_first, insert_last, delete_last) take heta(n) heta(n)heta(n) time in a static array.

  28. Describe the structure of a linked list.

    A linked list stores items in a bunch of nodes, where each node contains an item and a next field (a pointer to the next node). The data structure keeps track of the head of the list.

  29. How are pointers implemented in the word RAM model?

    Pointers are just indices into the giant memory array (memory addresses) that say where in memory a particular data structure or node is located.

  30. What are the time complexities for insert_first and delete_first operations in a linked list?

    Both insert_first and delete_first operations take constant time in a linked list.

  31. What is the worst-case time complexity for get_at(iii) and set_at(iii, new_item) operations in a linked list?

    Both get_at(iii) and set_at(iii, new_item) operations take heta(i) heta(i)heta(i) time, which is heta(n) heta(n)heta(n) in the worst case (e.g., accessing the last element).

  32. How can get_last be solved efficiently (in constant time) in a singly linked list?

    By augmenting the data structure to always store an additional pointer to the tail (the last element) of the list, alongside the head pointer.

  33. What is the main goal of dynamic arrays (Python's lists)?

    The main goal of dynamic arrays is to get the benefits of both static arrays and linked lists, specifically constant-time random access (like arrays) and efficient dynamic operations (like linked lists at the ends).

  34. What is the key invariant that a dynamic array relaxes compared to a static array?

    A dynamic array relaxes the invariant that the size of the underlying array must exactly equal nnn (the number of items in the sequence). Instead, the array size is maintained to be heta(n) heta(n)heta(n).

  35. What are the time complexities for get_at and set_at operations in a dynamic array?

    Both get_at and set_at operations take constant time in a dynamic array.

  36. How does insert_last typically work in a dynamic array when there is enough space?

    If there is enough space, insert_last works by simply placing the new item at a[length] and then incrementing length. This takes constant time.

  37. When does a dynamic array need to resize during an insert_last operation?

    A dynamic array needs to resize when the number of items (nnn) equals the capacity of the underlying array (size), meaning there is no more available space.

  38. What is the common strategy for growing a dynamic array when it needs to resize?

    The common strategy is to allocate a new array that is a constant factor larger than the current size, typically twice the current size (e.g., 2 * size).

  39. Why is doubling the array size a good strategy for dynamic arrays?

    Doubling the array size allows the total cost of resizing over a sequence of nnn insertions to be linear (heta(n) heta(n)heta(n)), leading to constant amortized time per insert_last operation.

  40. What does it mean for an operation to take amortized time?

    An operation takes amortized time t(n)t(n)t(n) if a sequence of kkk operations takes, at most, kimest(n)k imes t(n)kimest(n) total time, meaning the average cost per operation over the sequence is t(n)t(n)t(n).

  41. What is the amortized time complexity for insert_last in a dynamic array using a doubling strategy?

    Insert_last in a dynamic array takes constant amortized time (O(1)O(1)O(1) amortized).

  42. In a dynamic array, how can delete_last be implemented efficiently, and what is its time complexity?

    Delete_last can be implemented by simply decrementing the length variable. This is a constant-time operation.

Card 1 of 42
Card 1 of 42

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent