What is a data structure?
A specific way of organizing and representing data for efficient operations
It defines how data is held and what operations can be performed on it.
At the abstract level, what does a data structure specify?
Examples include sets, maps, and sequences.
What are examples of operations allowed on data structures?
Each operation has specific pre-/postconditions.
What are the roles of data structures?
These roles define the type of data structure and its intended use.
What are two ways a list can be implemented?
The choice of implementation affects performance and memory usage.
What are the possible implementations of a map?
Different implementations have varying time complexities and behaviors.
What does time complexity refer to in data structures?
The efficiency of operations, e.g., find(k) in a hash map is usually O(1) average
In a tree map, it’s O(log n).
What is the difference between a data structure and an algorithm?
Example: Dijkstra’s algorithm uses a priority queue.
In one sentence, how can a data structure be defined?
A disciplined way of organizing data in memory with a defined set of operations
This ensures that important operations can be performed correctly and efficiently.
What does ADT stand for in data structures?
Abstract Data Types
ADTs define the behavior of data structures in terms of their operations and properties.
What are the axes used to compare different ADTs?
These axes help in understanding the roles and functionalities of various data structures.
Define the Sequence / List ADT.
A finite ordered collection of elements, where position matters.
Lists allow duplicates and provide access by position/index.
What are the core operations of the Sequence / List ADT?
get(i)set(i, x)insert(i, x)delete(i)size()isEmpty()These operations allow manipulation and access of list elements.
What is the typical complexity for get/set(i) in a dynamic array?
O(1)
This indicates constant time access for elements in a dynamic array.
When should you use the Sequence / List ADT?
Lists are not ideal for frequent random insertions at large scales.
What is the Stack ADT characterized by?
A sequence where you only touch the top.
Stacks follow Last-In-First-Out (LIFO) access.
What are the core operations of the Stack ADT?
push(x)pop()top() / peek()isEmpty()These operations manage the stack’s elements.
What is the typical complexity for all core operations in a Stack ADT?
O(1)
All stack operations are performed in constant time.
What is the Queue ADT defined as?
First in, first out (FIFO).
Queues manage elements in the order they arrive.
What are the core operations of the Queue ADT?
enqueue(x)dequeue()front()These operations allow adding and removing elements from the queue.
What is the typical complexity for all operations in a Queue ADT?
O(1)
This indicates that all queue operations can be performed in constant time.
Define the Set ADT.
A collection of distinct elements. Membership matters; order doesn’t (conceptually).
Sets do not allow duplicates and focus on membership.
What are the core operations of the Set ADT?
insert(x)remove(x)contains(x)union, intersection, differenceThese operations manage the elements and relationships within the set.
What is the typical complexity for insert/remove/contains in a Hash set?
avg O(1), worst O(n)
This indicates average constant time complexity with potential for linear time in the worst case.