modes+of+file+access

=3.2.3 e=
 * ===define different modes of file access: serial, sequential, indexed sequential and random; and justify a suitable mode of file access for a given example===

=__File Access__= Computers have access to a lot of information and they are constantly moving it around the different buffers, memory, and hard drives. A big problem, however, is to find that data again after it has been stored. The computer doesn't just bung in the data anywhere where there is room; it stores it in structures that will help to find the data later on.
 * == KEYWORDS == || == DEFINITIONS (from the BCS Dictionary) == ||
 * File Access || These methods are used to locate and retrieve records in a file. These will influence the structure of the file. ||
 * Serial Access || Records are read one at a time from the start of the file to the end. ||
 * Sequential Access || Records are read one at a time from the start of the file but the records have been ordered by a key field. ||
 * Indexed Sequential || These use index files that contain indexes to records in the file. This allows files to be searched by using indexes and sequential access. ||
 * Random Access || Any record can be retrieved immediately provided its position in the file is known. Items will have to have a known length in order for the position to be calculated. ||
 * Hashing Algorithm || The process of calculating a value or address from one or more data items. ||

=__Serial Access__= This is the **simplest form of data storage** but the **data** is only **stored** in the **order in which it arrives**. This is not good as it is effectively **unstructured** which means that **finding the data** that has been stored can be **very tricky**. This form of storage is only used when the **data** is likely to **not be accessed again** or when the data is needed to be stored in ther order in which it arrives. In some cases, data may be stored in serial format **until enough has been compiled** so it **can then be stored** using a key **field**. An example being a bank sorting their transactions out in key order at the end of the day. To do a **search** in this type of file will involve **looking through every record** **until you find** the record. If the **record isn't there**, then the **computer** will **still search** the records until the **end of the file**. A common device that uses serial access is a cassette tape used for storing music files. Here the data is stored in the order in which it arrives. When it is played back, the data is fed back to the user in the same order.

=__Sequential access__= Whilst this is similar to serial access there is a fundamental difference. **Data arrives** in the order and is then **stored**. After this data has been stored, the data is now **arranged in order** depending upon a **key field**. A scenario where this could be used is in the example of an ATM: The following people take out money at various times during the day: As you may be able to see here, the data has been stored in the order in which it arrives. What usually happens at a bank is that the data will be stored based on a key field. Let's say that the **key field** here is the Account No. . This is what the information will now look like: So now, this data will be written to a storage device using a **sequential access** format. This will make it easier to find certain records. These records are **found** by starting from the **first item** and then **working your way down** until you **reach** the **item** you are **looking for**. If you **find a record** that has a **higher value** than the **key item** (Account No. for example) **you are looking for**, then the **computer** will **detect** that the **record doesn't exist** and will **not return anything**.
 * Initials || Account No. || Time of access || Money withdrawn ||
 * TK || 18 || 12:05 || £50 ||
 * JH || 314 || 12:08 || £10 ||
 * GD || 42 || 12:10 || £40 ||
 * JH || 314 || 12:30 || £100 ||
 * Initials || Account No. || Time of access || Money withdrawn ||
 * TK || 18 || 12:05 || £50 ||
 * GD || 42 || 12:10 || £40 ||
 * JH || 314 || 12:08 || £10 ||
 * JH || 314 || 12:30 || £100 ||

=__Indexed Sequential__= This type of file access is useful when **large records** are needed to be stored. This is a **type of sequential file** where the data has been **stored** using a **key field** (see example above) however, an **index** is also included to **allow records** to be **found directly**. This method of data access will result in the computer **searching up information in an index** which will **narrow down** the data to be searched. After this, the **file** is **searched sequentially** to **find** the **record required**.

=__Direct/Random Access__= If a file doesn't store any information in a particular order, then the **addition** or **taking away** of any **new data** is very **simple**. Furthermore, if the **records** in **any form** of a **sequential file** are **all one length**, then it is **possible** to **read the contents** of the **record directly** if the **position** of that particular **record** in the file is **known**. To **access a random file**, the data itself is used to give the address of where it is stored. The position of the record can be found by using the following formula: Address of Record n = beginning of file + ((n-1) * Size of record)

For example, if I have a file where each record is 50 bytes long, then I know that records will start at the positions: 0, 50, 100, 150, etc. However, if I want to work out where my 19th record will start I can use the above formula to help me ascertain where this record is. So here are the things that I know: beginning of file = 0 - because my **records start from the position of 0** n = 19 - I want to **look** for the **19th record** size of record = 50 - the is is the **size of one record**

Therefore, 19th record address = 0 + ((19-1) * 50) = 900

This type of algorithm is known as a **hashing algorithm**. It is overly simplistic and can fail in some cases, however, it does show the general priciple.

Some practise exam questions are shown below: This is the information stored in the file. Using this, explain what is meant by an inexeded sequential file. || 4 || Describe how a serial search can be used to determine the position of the stop when a name of a stop is entered into the program. || 5 ||
 * == EXAM PAPER == |||| == QUESTION == || == MARKS == ||
 * OCR Jan 2009 |||| 1 (c)(i) - In a recipe creation software, recipes are saved as separate serial files. Explain what is meant by a serial file. || 2 ||
 * |||| 1 (c)(ii) - Gice two reasons why a serial file is better than a sequential file when storing the data about recipes || 2 ||
 * OCR Jan 2010 |||| 1 (c)(i) - A 10-pin bowling club stores information about its members by ranking them according to their bowling average.
 * |||| 1 (c)(ii) - Explain why an indexed sequential file is a sutiable way to organise the member file. || 2 ||
 * OCR Jan 2011 |||| 1 (b)(ii) - The image below shows part of any array to store the names of bus stops on a particular route.
 * OCR Jun 2011 |||| 3 (a)(i) - A mobile phone company get 10,000 users to register for a game. The details are held in an indexed sequentia file. Define what is meant by an indexed sequential file. || 2 ||
 * |||| 3 (a)(ii) - Explain why an indexed sequential file is used to store the details of the players. || 3 ||

=__Sources of information and images__= - Music tape: [] - Information: OCR Computing for A Level - Information: A Level Computing; AS & A2 course texts - Exam questions and extracts taken from OCR