1.1 Data structures Flashcards
What is a data structure
a collection or group of related data items
why are data structures useful
collects together basic data types (e.g. integer, real etc.) and allows data to be organised in a convenient, logical manner related to the program being developed.
can be accessed, searched, sorted etc. more quickly than data held in a file as data structures are held in memory
name 2 types of data structure
arrays, records
give an example of data to be stored in a 2 dimensional array
the sales of different products (downwards column) per month (across column)
give an example of data stored in a 3d array
the test scores of different students, per form group
what is a record data structure and where would it be used?
The record data structure allows items of data relating to something to be grouped together into a single record type.
cam be used in e.g. pseudocode
What is a stack data structure
a stack is a LIFO data structure
is a limited access data structure
is used as e.g.
run time stack mechanism (keep track of where it is up to with procedure calls)
undo feature in an application
explain adding an item to a stack
increment the stackpointer (add 1 to) and place the new item in the position indicated by the stackpointer
explain removing an item from a stack
display the item indicated by stack pointer (e.g. pressing undo in a web browser displays the previous page) and the decrement (take 1 from) stackpointer
how could a stack be implemented using an array and variable
the array stores the items in the stack, the variable (e.g. the stack pointer) always points at the last element added to the stack
pseudocode procedure to add data to a stack
Procedure AddToStack
Get Item
IF Stack pointer = limit
Error message “stack full”
ELSE
Stackpointer := Stackpointer + 1
Stack[Stackpointer] := Item
END IF
End Procedure
pseudocode procedure to remove data from stack
Procedure RemoveFromStack
IF Stack pointer = 0
Error “Stack empty”
ELSE
Output stack[Stackpointer]
Stack pointer := Stackpointer –1
END IF
END Proc
what is a queue data structure and how is it implemented
a FIFO data structure (First In First Out)
e.g. queuing up in a shop, processes in a ‘round-robin scheduling policy’
often implemented using an array and two pointers to indicate the start and the end of a queue
explain removing an item from a queue data structure
involves displaying the data in position indicated by start pointer (front of queue) and then incrementing (+1) the start pointer
explain adding an item to a queue data structure
involves incrementing (+1) the end pointer (back of queue) and putting data into that position