Chapter 13 Flashcards
"Data Representation"
user-defined types
derived from one or more existing datatypes
used to extend the built-in datatypes
programmer’s requirement
why are user-defined types necessary
if no suitable datatype is provided by the language used
to provide more flexibility
if a programmer needs a specific datatype/needs to create a new data type
that meets program requirements
composite data types
data types constructed from other types
e.g: record, list, set, array, class, queue, linked list, dictionary
non-composite
datatype that does not refer to another datatype
e.g: enumerated, pointer, real, string, char, boolean
enumerated
non-composite
defines an ordered list of all possible values
enumerated TYPE pseudocode declaration
the values do not need any speech marks etc.
TYPE identifier = (value1, value2, …)
pointer
non-composite
used to reference a memory location
pointer TYPE pseudocode declaration
this is a declaration of the TYPE, not of the variable. if you wish to declare a variable of this pointer type:
TYPE pointerTypeName = ^DATATYPE
DECLARE variableName : pointerTypeName
set
stores groups of values and supports mathematical operations
record
composite
collection of related items with multiple datatypes
a fixed number of components
allows the user to collect values with different data types together.
list
indexed collection that can contain different datatypes
array
indexed collection of items of the same datatype
serial file organization
- data is stored in chronological order (no predefined order)
- data is appended to the end of the file - into the next available space
- (easy to add)
- records need to be accessed one after the other
- allows the data to be read in order of when they were taken
no KEY FIELDS need to be added
when is serial used?
- when chronological order matters
- when wanting to append records
- small file, so easy to search
- when re-organizing as re-sorting is not required
sequential file organization
- records are stored in a predefined order (particular order), stored in the order of the value in the key field
- new records are inserted in the correct position
- a new version of the file has to be created to update the file
- records need to be accessed one after the other
- records can be found by searching from the beginning of the file,
- record by record, until the required record is found or key field value is exceeded.
when is sequential used?
- when there are unique fields, so it can be used for indexing
- when it needs to be sorted in an order
random/direct file organization
- records are stored in no particular order
- record location is calculated
- using a hashing algorithm on a key field
- speed of data access is increased
- can be used as lookup file
- ** updates to the file can be carried out directly**
what happens if a collision occurs in direct access
A collision occurs when the record location is taken.
the location from the hashed key field is in use for another record.
If the record is to be stored
* Search the file linearly
* … to find the next available storage space (closed hash)
* Search the overflow area linearly
* … to find next available storage space (open hash)
If the record is to be found
* … search the overflow area linearly
* … search linearly from where you are
* If not found record is not in file
hashing algorithm
a mathematical function to find a hash key to access data
sequential access
- searches from the beginning of the file
- checks records linearly (record by record)
- until the record is found or its the end of the file (key field value is exceeded)
direct access
value in key field is submitted to hashing algorithm which provides position used at data input
twos complement
start from the right side and copy down every digit until you encounter a 1
copy down the 1, and then flip all the rest of the bits after the 1
format of binary floating point
plus or minus M x 2^E
M = mantissa
E = exponent
more bits in mantissa = more accurate
more bits in exponent = larger range
normalisation rules
for positives, shift left until it starts with a 01
for negatives, shift left until it starts with a 10