1.1 Flashcards
Data Structure
A data structure is a group / set / collection of related data items / elements
Data Structure Advantages
Convenient / best way of organising data relating to a real problem
An efficient way to deal with various elements as one item
Data Structure Disadvantage
More Complex to program
Array
- An array is a data structure which is a set of data elements of the same data type
- Elements are accessed using an index
- Has a pre determined number of elements
2D Array
A 2D array is a grid-like structure which can hold both rows and columns of the same data type.
Record
- A record is a set of data items related to a single individual / entity
- It can contain data of different data types
- Can be processed as one item by a computer
Linked List
- Nodes in a list contain the data itself and address of the next node (pointer)
- First element is head node, list has to be traveresed from start.
- Dynamic structure (can grow/shrink)
- Last node points to null
Searching Linked List
UNORDERED
Can’t be terminated until all items have been inspected
ORDERED
Can be terminated when a value greater than search is found
Linked List Advantages
- New items can be inserted without rearranging the other elements
- Uses memory more efficiently as is dynamic and can shrink/grow
Linked List Disadvantages
- More complex to program
- Can only be accessed in a linear manner
- Use more memory as store pointer aswell as data
Stack
- Data Structure where items can only be added and removed from the top
- Last in first out (LIFO)
- Push (add), Pop (remove)
- Limited access, can only be accessed from the top
- Can be used as a recursive data structure
Stack Underflow and Overflow
UNDERFLOW
Attempt to POP an empty stack
OVERFLOW
Attempt to PUSH a full stack
Binary Tree
- Each node has a max of 2 children
- Everything on the left is less than or equal to the root
- Everything on the right is greater than the root
Binary Tree nodes contain…
- Data
- Left Node
- Right Node
- Leaf nodes (no children) point to null
Delete a Binary Tree node
DELETE ROOT
Replace root with highest value from left side of tree
1 CHILD
Replace node with child
2 CHILDREN
Replace node with child at left pointer