1.4.2 Data Structures Flashcards
1
Q
Array
A
- a static data structure in which data is stored in continuous, Adjacent memory locations [1]
- can only store one data type [1]
- provides direct access to elements
- are usually zero indexed
2
Q
Record
A
- is a row in a file and is made up of fields
- is widely used in databases
- can be implemented using OOP in python
3
Q
Tuple
A
- a static data structure
- An ordered collection of elements that can contain multiple data types
- is immutable - so elements can’t be added or removed once it has been created [1]
- are initialised using regular brackets instead of square ones
4
Q
Static Datastrcute
A
Size can’t change during processing [1]
5
Q
Dynamic data structure
A
- size can change during processing [1]
- disadvantage : storage requirements are unknown initially [1]
6
Q
Linked lists
A
- a dynamic data structure used to hold an ordered sequence [1]
- each item/node consist of a data field and a pointer field [1]
- data field contains the actual data
- pointer field gives the location of the next node/item in the list [1]
- linked list needs to be traversed until desired element is found [1]
- takes longer to search (as more nodes are added) [1]
7
Q
Linked lists + array comparison
A
- array provides direct access to all elements [1] whereas a linked list needs to be traversed until desired element is found [1]
- contents of an array are stored continuously in memory [1]
- whereas contents of linked list do not have to be in continuous data locations [1]
8
Q
Linked list operations
A
- adding node
- deleting node
- traversing linked list
9
Q
Linked list traversal
A
- is used to access each element of the linked list
- first position is indicated by the start pointer [1]
- linked list can be traversed by following each items next pointer until the end of the list is located (null)
- pointer = null means end of list has been reached
10
Q
Linked list : adding node
A
- advantage: nodes can be added or removed easily by editing the pointers
1. Allocate memory and create new node containing the data [1]
2. Change the new node to point to the previous nodes next node [1]
3. Change the previous nodes next node to point to the new node [1] - if the new node is added to the start change its pointer to point to the head node
- if added at the end let it point to null
11
Q
Linked list: Removing node
A
- involves updating nodes to bypass the deleted node
- node is not truly removed but ignored instead which wastes memory
- so to delete a node, change the next pointer of the previous node to bypass the node being deleted and instead point to the next node
- linked list requires more memory than arrays due to storing pointers
12
Q
Stack
A
- is a LIFO data structure [1]
- items can only be added or removed from the top of the stack
- stacks are used to reverse actions eg back buttons and undo buttons use stacks
- stacks use a pointer which points to the top of the stack
- when initialising stack we set TOP pointer = -1
- thus is stack is empty TOP = -1
13
Q
Stack operations
A
- push(value)
- pop()
- isEmpty()
- isfull()
- Size()
14
Q
Push(value)
A
- adds an element to the top of the stack (checks if stack is full first)
- once value is pushed, the top pointer is incremented by 1
- attempting to push an item onto a full stack is called stack overflow
15
Q
Pop()
A
- removes and returns value at the top of the stack (checks if stack is empty first)
- once popped, the pointer is decremented by 1
- attempting to pop an item from an empty stack is called stack underflow
16
Q
IsEmpty()
A
- checks if stack is empty
- eg if Top == -1 return true
- or return len(stack) == 0
17
Q
Isfull()
A
- Checks jf stack is full
- compares stack size to the top pointer
- if len(stack) == Top return true
18
Q
Size()
A
Returns size of the stack
19
Q
Queues
A
- a FIFO data structure
- in which items are added at the end of the queue
- and items are removed from the front of the queue
- Consist of a head and tail pointer
- similar to stacks there is also queue overflow and queue underflow
20
Q
Types of queue
A
- linear queue
- circular queue
- priority queue
21
Q
Queue operations
A
- Enqueue(value)
- dequeue()
- peek()
- isfull()
- isempty()