3.1 Data Structures Flashcards
Data structure
An organised means of storing related data.
7 examples of data structures
- Arrays
- Records
- Stacks
- Queues
- Trees
- Linked Lists
- Hash tables.
Array
A data structure that stores multiple data items of the same data type.
Element of an array (2)
- The index of each data value in the array.
- Accessed by its index - 0,1,2,3 etc.
3 advantages of an array.
- Allows direct accessing of elements.
- Can be used to implement other data structures e.g. stacks/queues.
- No need to declare large number of variables individually.
Disadvantage of an array.
Cannot be dynamically resized in most languages.
Record
A data structure to store multiple pieces of data with may have different data types.
Field
A single item of data within a record.
Stack
A FILO or LIFO data structure where data items can be pushed or popped.
FILO
First In Last Out
LIFO
Last In First Out
Pushed
When an item is added to the top of the stack.
Popped
When an item is taken from the top of the stack.
What is significant about the top of the stack?
It is the only position where a record can be added or removed.
How can a stack be implemented? (2)
- Can be implemented using an array and one integer variable.
- A variable, called “Top” can be used as the stack pointer.