Data Structures Flashcards
(136 cards)
Data Type
Defines potential set of values a variable can hold and the operations that can be performed on it
Aspects of Data types
- Range of values
- Size of memory required
- How binary data is interpreted
- Operations that can be performed on it
Abstract Data Type (ADT)
Conceptual model of how data is to be stored and the operations that can be carried out on it
Data Structure
- (Partial) implementation of user-defined types (ADTs)
- Each item known as member and can be of different data types
Purpose of data structures
To combine multiple data items under a single identifier
Key ADTs
- Stacks
- Queues
- Graphs
- Trees
- Hash tables
Static data structures
- Max size fixed at compilation
- Data stored in contiguous memory locations
Advantages of static data structures
- Fast to access
- (Sometimes) require less memory
Disadvantages of static data structures
- Inflexible
- (Sometimes) wastes space
- Operations like insertion and deletion are very slow
Dynamic data structures
- Can change size at run-time
- Data not (usually) stored contiguously
- Each item points to the next item in the structure
Advantages of dynamic data structures
- More flexible
- No wasted space or limits
- (Sometimes) require less memory
Disadvantages of dynamic data structures
- (Sometimes) require more memory (have to store pointers)
- Slower to access
Queue
Data structure comprised of sequence of items and front and rear pointers
Order of item insertion in Queue
Items added at rear and retrieved from front in First-in-First-Out (FIFO)
Key operations of Queue
- Enqueue
- Dequeue
- isEmpty
- isFull
Enqueue
If not isFull() then add new item to rear
Dequeue
If not isEmpty() then remove front item
isFull
Test whether queue is full
isEmpty
Test whether queue is empty
Uses of queues
- Queues of print jobs
- Managing input buffers
- Handling multiple file downloads
- Priority-based resource allocation
- …
Queue implementations
- Linear queues
- Circular queues
- Priority queues
Linear queues
- Stores items in ‘line’
- Front and rear pointers move down memory
Advantages of linear queues
- Simple to program
- Limited capacity useful when representing finite resources
Disadvantages of linear queues
Wasted capacity (whole queue shifts down)