1.4.2 Data Structures Flashcards
Arrays
An ordered, finite set of elements of a single type
You can make an array of tuples
Index of arrays
0-based
Find a value with arrayname[index]
arrayname[row,column] for 2d
Multi-dimensional arrays
You can have any number of dimensions
Tuples
An ordered set of values, can have elements of mixed type and it is immutable (elements cannot change)
Records
Composed of a fixed number of fields of different data types
Access a value with the name of the record
Dynamic data structure
They can change size when required
Static data structure
They cannot change size
Abstract Data Type
A logical description of how we view the data and possible operations
Where does the rear of the queue start at?
-1
isFull() pseudocode
function isFull() if size == maxSize: return True else: return False end if end function
isEmpty() pseudocode
function isEmpty() if size == 0; return True: else: return False end if end function
enQueue() pseudocode
function enQueue() if size < maxSize: rear ++ rear = rear MOD maxSize Q[rear] = item size ++ else: print (queue is full) end if end function
deQueue() pseudocode
function deQueue() if size == 0: item = null print (queue is empty) else: item = Q[front] front = (front + 1) MOD maxSize size -- end if return item end function
Priority Queue
Items are ordered in a queue first based on their priority and then based on FIFO, items move backward to allow a higher priority item to join.
Hash Table
A data structure where keys are mapped to index values, used where faster searching is needed e.g. police records
Collisions/synonyms and how to deal with them
When an algorithm generates the same address for different primary keys
Methods include putting the value in the next free location or incrementing how far you skip by
Searching in a hash table
Apply the hash function to the key and first check that position, if not increment by 1 and check each
If the original position is empty or you cycle back the value isn’t in the table
Mid-square hashing algorithm
Square the number, extract some portion of the resulting digits (likely the middle), then mod by the size of the table
Folding hashing algorithm
Divide the item into equal sized pieces (excluding maybe the last piece, sum them and carry out the mod with the size of the table
Hashing alphanumeric data
Take the ASCII of each character, sum them and mod with the size
Hash table deletion
When a value is deleted, a placeholder is used to represent that a value has not been deleted.
Lists
A dynamic data type containing a number of ordered items that can be repeated. The elements are stored non-contiguously on the heap and can be of different types
Linked list
A dynamic abstract data structure which is implemented as an array and pointers
What is a node composed of linked list?
The data and a pointer to the next node