array
-a variable that can contain more than one data item
-items can be changed or replaced
contiguous
all data is stored together
heterogeneous
can support more than one data type
homogenous
only support a single data type
tuples
-lists that can’t be changed once created
-fixed size
-immutable so cannot be changed or replaced
-can store more than one data type
lists
-can be changed after created
-not a fixed size but can grow or shrink in size
-mutable as items can be changed or replaced
file handling
opening, closing, writing to and reading from files by program codes
binary file
-considered to be any file that isn’t a text file
-contains records of many different types of data
-stored as a pure binary number takes up less space
-reading it is language-specific so it requires you to know exact structure of file
writing data to a file
1-open the file
2-write the data to the file
3-close the file
reading / searching data from a file
1-open the file
2-create a boolean variable and set it to false, to indicate the end of file is not reached
3-while the end of file has not been reached , continue reading data from the file
4-compare if data matches the search criteria and if it does output it
5-check if end of file is reached and set boolean variable to true
6-close the file
reading data from text files
1-open the file
2-use a flag to indicate end of file is reached
3-iterate through all the data in the file
4-end of file or output data from file
5-close the file
writing data from files
1-open the file
2-write character data to the file
3-close the file of characters
text file
contains human-readable characters organised into lines and can be read, created or edited by a computer program
data structure
way of organising and storing data in a computer so it can be accessed and modified
examples of data structure
-stacks
-queues
-graphs
-trees
-hash tables
-dictionaries
-vectors
static data structures
-organisations or collections of data in memory that are fixed in size
-max size needs to be known in advance
-memory can’t be relocated once program is running
dynamic data structures
-organisations or collections of data in memory that have the flexibility to grow or shrink in size
-programmer has control over how many memory is used
static data advantages
-fixed memory allocation so no issues with adding or removing items from data structure
-easier to program as no need to check the size of data structure before accessing it
static data disadvantages
-can be inefficient as memory for data structure is set aside at start so may not be utilised
dynamic data advantages
-makes efficient use of memory as data structure only uses as much memory as it needs
dynamic data disadvantages
-runs risk of overflow if it exceeds limit or underflow it its too empty
-harder to program as code needs to keep track of data structure size and location of items inside
stack
-data structure that is essential for the operation of a computer
-LIFO (Last In First Out) structure as last item to be pushed onto stack must also be the the first to be popped off
-has a stack pointer that always points to the node at the top
stack underflow
-attempt to pop an item off a empty stack
stacks are used for:
-performing depth first searches on graph data structures
-keeping track of user inputs for undo operations
-backtracking algorithms , e.g maze
-evaluating mathematical expressions without brackets