Data+Structures+and+Data+Manipulation

Static and Dynamic Data Structures
Static data structures are fixed when compiled, but dynamic data structures aren't so can be changed. Static data structures can be used to store dynamic data, as long as they are big enough to hold all of the data.

An array is an example of a static data structure, as its contents can be changed, but the array can't be increased so more value can be added while the program is running. Static structures take us less space in memory and are easier to program, but can waste space if parts of the structure are unused.

An example of a dynamic data structure would be a list as it can grow as new data is added. Dynamic structures are effificient because they only use the amount of memory needed and empty space can be used for other processes. However they are more difficult to program and are slower to search because they only allow serial access.

Stacks
A stack is a Last in First Out (LIFO) data structure. When data is added to a stack, it is "pushed" on and when data is removed, it is "popped" off.

To add to a stack:
 * 1) If stack is full, stop (and report error)
 * 2) Increment the pointer
 * 3) Push data on to stack

To remove from a stack (although the data is not actually deleted):
 * 1) If stack is empty stop (and report error)
 * 2) Copy data from pointer
 * 3) Decrement pointer

=Queues=

A queue is a First in First Out (FIFO) data structure.

To add to a queue: To remove from a queue (although the data is not actually deleted):
 * 1) If queue is full, stop (and report error)
 * 2) Increment the pointer
 * 3) Add data to queue
 * 1) If queue is empty stop (and report error)
 * 2) Copy data from pointer
 * 3) Decrement pointer

=Trees=

In a tree, each item points to another two items. Each item is a in **node** and the routes taken to get to other items are called **paths** (so each node can have two paths). The first node is called the **root node** and the nodes are arranged in layers. Trees like this, that have two paths out of a node are called **binary trees**.

=Searching=

A **serial search** goes through all the items in a list one by one until the item is found. It is useful for unordered lists with a small number of items. A **binary search** starts with the middle item and discards the half the item is not in and repeats this process until the item is found. It is useful for long lists, as it is faster than serial searching.

=Merging 2 data files=

To merge 2 data files:
 * 1) Order the data in each file
 * 2) Compare smallest in one file with smallest in other file (using pointers)
 * 3) Add smallest to new file
 * 4) Repeat this until no more items (If 2 are equal use <=)

=Sorting Algorithms=


 * Quick Sort:**
 * 1) Pick a start value
 * 2) Sort into two groups, one with values < start value, the other with values > start value
 * 3) Pick a value in each group and repeat step 2 for these groups
 * 4) Repeat 3 until only 1 value in each group.