Data Structures and Data Manipulation
Data Structures and Data Manipulation
and Data
Manipulation
What the Specification Says:
Explain how static data structures may be used to implement dynamic data structures;
Describe algorithms for the insertion, retrieval and deletion of data items stored in
stack, queue and tree structures;
Explain the difference between binary searching and serial searching, highlighting the
disadvantages and disadvantages of each;
Explain how to merge data files;
Explain the differences between the insertion and quick sort methods, highlighting the
characteristics, advantages and disadvantages of each.
Static and Dynamic Data Structures
Static data structures are those which do not change in size while the program is
running. Most arrays are static, once you declare them, they cannot change in
size.
Dynamic data structures can increase and decrease in size while the program is
running.
Stacks
A stack is a last in first out (LIFO or FILO) data
structure. The head pointer will point to the most
recent item of data which will be at the top. There are
only two operations that can be applied, inserting and
deleting/reading.
Binary Tree’s
A binary tree is a data structure, where each item
of data points to another two items, and a rule is
needed to determine the route taken from any
data item.
The data items are held in nodes.
The possible routes are called paths.
Each node has two possible paths.
The nodes are arranged in layers.
The first node is called the root, or root node.
Binary Search
Where the list is arranged in a particular order.
The list is split in two, and compared to be either higher or lower than the value
being searched for.
The list is continually split further halving each time until the value is found.
The algorithm for this is:
1. While the list is not empty do
a. Find the mid-point cell in the current list.
b. If the value in this cell is the required value, return the cell
position and stop.
c. If the value to be found is less than the value in the mid-point
cell then
Make the search list the first half of the current search list
Else make the search list the second half of the current
search list.
2. Report error, item not in the list.
Sorting
Sorting is placing values in order, such as numeric or alphabetic. There are two main
types we need to know about. Insertion sort and quick sort.
Insertion Sort
Where the data of the files is copied into a new file, but copied into the correct location.
The result is that the new file is in the correct order, although it’s very time consuming.
Quick Sort
First the data is placed in a row with an arrow under the first and last values,
pointing at each other, one is fixed where as one is movable.
If the two values are in the correct order then move the movable arrow towards
the fixed arrow, else swap the items and the arrows.
Continue to repeat this until the arrows collide.
Continue to repeat this process until the files are of a length of one.
Key Words
Data Structure – Method of storing a group of related data.
List – A simple one dimensional array
Pointers – The numbers after the data, they point to the next data item.
Linked List – A dynamic data structure similar to an array.
Queue – A fist in first out data structure, containing a head and tail pointer.
Tree – A data structure where each item of data points to two others.
Nodes – These hold the data items.
Paths – These are the routes between the nodes in a tree.
Layers – Binary trees are arranged into layers, by the different levels.
Root – The first node in a tree.
Insertion Sort – A method of sorting data where all the items are copied to a
new file, and put into the correct order.
Quick Sort – A faster method of sorting data, involving two pointers which move
towards each other, and swap values if data pointed at are in the wrong order.
**
highlight first number in the list (the ‘search number’)
pointer at each end of list
repeat:
compare numbers being pointed to…
…f in wrong order, swap
move pointer of non-search number
until pointers coincide so search number in correct position
split list into 2 sublists
quick sort each sublist
repeat until all sublists have a single number
put sublists back together
**
list of sorted numbers is built up…
…ith one number at a time being inserted into correct position
plus 1 mark per correct row [max 4 rows] *
What steps are needed to be taken to pop a data item from a stack?
if stack is empty…
…eport error and stop
output data(stack_pointer)
decrement stack_pointer
start at root
repeat
compare new data with current data
if new data < current data, follow left pointer
else follow right pointer
until pointer is null
write new data
create (null) pointers for new data