Download presentation
Presentation is loading. Please wait.
1
3.2.3 Data types and data structures
OCR AS Level F452: Data types and data structures 3.2.3 Data types and data structures c. explain the advantages and disadvantages of different data types and data structures for solving a given problem; d. design and implement a record format; 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; f. store, retrieve and search for data in files; g. estimate the size of a file from its structure and the number of records; h. use the facilities of a procedural language to perform file operations (opening, reading, writing, updating, inserting, appending and closing) on files of different access modes as appropriate.
2
OCR AS Level F452: 3.2.3 Data types and data structures
c. explain the advantages and disadvantages of different data types and data structures for solving a given problem;
3
Selecting suitable data types
OCR AS Level F452: Data types and data structures Selecting suitable data types An online bingo company uses the following variables: Player name Amount won Average score Phone number What data type should each variable be and why?
4
d. design and implement a record format;
OCR AS Level F452: Data types and data structures d. design and implement a record format;
5
Record formats Field Name Data Type Maximum size in bytes CustomerID
OCR AS Level F452: Data types and data structures Record formats Field Name Data Type Maximum size in bytes CustomerID String 6 First name 10 Gender Char 1 Age Integer 2 A record is just a data structure that allows items of data of different types to be stored together in a single file. Data is stored in different fields.
6
OCR AS Level F452: 3.2.3 Data types and data structures
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;
7
OCR AS Level F452: 3.2.3 Data types and data structures
Serial files In serial files records are stored in the order in which they were entered. New records are always added at the end of the file. These files are only searchable by going through each record 1 by 1 from beginning to end (serial search). First name Surname Age David King 12 George Smith 34 Matt Jones 56 Joe Apple 7 Sarah Brain 89 Last record entered First record entered.
8
OCR AS Level F452: 3.2.3 Data types and data structures
Sequential files In sequential files records are stored sequentially according to some key field, for example alphabetically. First name Surname Age Joe Apple 7 Sarah Brain 89 Lucy Charles 13 Sam Charleston 24 Matt Jones 56 David King 12 Craig Pendlby 57 George Smith 34 Files stored sequentially by surname.
9
Indexed sequential files
OCR AS Level F452: Data types and data structures Indexed sequential files In indexed sequential files records are stored according to some key field and one or more indexes are used to make searching even more efficient. Index Sequential File First name Surname Age Joe Apple 7 Sarah Brain 89 Lucy Charles 13 Sam Charleston 24 Matt Jones 56 David King 12 Craig Pendlby 57 George Smith 34 Letter Index A 1 B 2 C 3 J 5 K 6 P 7 S 8
10
OCR AS Level F452: 3.2.3 Data types and data structures
Random files Are files in which records have been placed in the file according to a mathematical hash algorithm. For example by generating a position based on a combination of the customers initials and DOB. These are fast to search because to find a record you just repeat the hash algorithm.
11
Advantages & disadvantages of file types
OCR AS Level F452: Data types and data structures Advantages & disadvantages of file types Advantages Disadvantages Serial Items stored in any order Take a long time to search. Sequential Items stored in a set order so they are faster to search. Inserting new items is more complicated. Indexed Sequential Very fast to find items. Every time an item is inserted the index needs updating. Random The fastest to search. Most complicated to implement.
12
f. store, retrieve and search for data in files;
OCR AS Level F452: Data types and data structures f. store, retrieve and search for data in files;
13
OPEN READ WRITE INSERT APPEND CLOSE
OCR AS Level F452: Data types and data structures Common file operations playerName = “Dave” playerScore = “500” OPEN playerscores.txt count = 0 while count<numLines(playerscores.txt) READ line(count) IF line(count) = playerName WRITE currentScore CLOSE playerscores.txt ELSE count=count+1 CLOSE playerscore.txt OPEN READ WRITE INSERT APPEND CLOSE You dont need to be able to do this in any particular language as long as you know what these basic commands do.
14
OCR AS Level F452: 3.2.3 Data types and data structures
g. estimate the size of a file from its structure and the number of records;
15
Estimating the file size of records
OCR AS Level F452: Data types and data structures Estimating the file size of records Field Name Data Type Maximum size in bytes CustomerID String 6 First name 10 Gender Char 1 Age Integer 2 So if this file had 10 records in it it’s size would be, to get the size of one record (19), then 19*10 for the size of all records together (190), then to give some margin for error. So the estimated file size would be 209. Work out the size of each field Add together the size of each field to get the size of one record. Multiply by the number of records. Add 10%
16
OCR AS Level F452: 3.2.3 Data types and data structures
h. use the facilities of a procedural language to perform file operations (opening, reading, writing, updating, inserting, appending and closing) on files of different access modes as appropriate.;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.