13 - Data Representation

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

13- Data Representation

Primitive Data Types:


Basic data types which allow to construct user defined data types.
Such as: String, Integer, Boolean, Char.
User Defined Data Types:
Data types defined by users based on primitive data types.
Non-Composite Data Types:
Defined without referencing to other data types.
Can be primitive or user defined.
Enumerated Data Types:
Defined without references to other data types.
TYPE <identifier> = (value1, value2, value3, ...)
Pointer Data Type:
It is used to reference a memory location.
TYPE <Pointer> = ^<Referencename>
To dereference:
<Identifiername>^
Composite Data Types:
Defined by referring to other data types.
For example, Records, Sets and Classes.
Record:
TYPE TbookRecord
DECLARE title : STRING
DECLARE author : STRING
DECLARE publisher : STRING
DECLARE noPages : STRING
DECLARE fiction : STRING
ENDTYPE
13- Data Representation
Sets:
Given list of unordered elements that can use set operations like intersection and
union.
TYPE<set-identifier> = SET OF <Basetype>

DEFINE<identifier> (value1, value2, value3…): <set-identifier>


Classes:
Include variables of different data types and methods.
Several objects can be derived from the same class.
Methods of File Organization:
1. Serial File Organization
 Stores records of data in file, one after the other.
 They are stored in the order in which they are added.
 Used for temporary files.
 For example, storing electricity bills before they’re sent to customers.

2. Sequential File Organization


 Stores records of data in a file, one after the other.
 They are stored in a given order.
 Order is based on the key field of the records.
 For example, they’re used to store customer electricity bills in an
order, according to customer number.
 High hit rate.

3. Random File Organization


 Stores records of data in a file, in any available space.
 The data is not stored in any order; completely random.
 Location of a record is found via hashing algorithm.
13- Data Representation
 Provides fastest access to records.
 Low hit rate.

File Access
1. Sequential Access
 Used for serial and sequential files.
 This method searches for records from the start of the file until the
required record is found.
For a serial file:
 The whole file is searched for the record.
 New records are appended to the end of the file.
For a sequential file:
 The whole file isn’t searched for the record as the records are stored
using key values which are appended to look for the record.
 New records are stored in the correct position in the file.
2. Direct Access
 Used for sequential and random files.
 This method finds a record without the file being read.
 It allows specific records to be found more quickly.
For a sequential file:
 Index of key fields is used to look up the record in a file.
For a random file:
 Hashing algorithm is used to look up the record in a file.
Hashing algorithm:
 It is used to perform calculations on the key fields of the records
which in turn give the address of the record.
Use of a hashing algorithm:
 The value of key field is divided by 2000.
 The remainder is obtained.
 The remainder is multiplied by the sum of the start address and the
size allocated to each record.
13- Data Representation

 A conflict occurs when the remainders of the key fields are the same.
Dealing with a conflict:
 Open hash- Record is stored in the next free space.
 Closed hash- An overflow area is allocated and the record is stored in the
next free area in the overflow area.
Past papers:
Serial: Used by text files, left to right, or when storing data to end of file.
Sequential: Data is stored in a fixed order; personal data/ info about user.
Random: Fastest access to data; store logins.
Increasing the exponent increases the range.
Increasing the mantissa increases the precision.

You might also like