3. Data Structures

Data structures are arrangements of data items; 

  • the aim being to simplify access and processing of the data. 
  • When designing data structures for particular problems it is important to carefully consider the nature of the processing that will be required. 
  • Well-designed data structures can significantly reduce the complexity of the processing required.
  • Conversely poor or inappropriate data structures can greatly increase the processing required and reduce the software’s performance.
In the preliminary course we introduce three data structures: arrays, records and files.

These three structures can be combined in various ways to suit the data and processing requirements of individual problems.

One-dimensional array
  • Arrays are used to store multiple data items where each data item is of the same data type. 
  • Each element within the array has a unique index that is used to access the data contained within the element. 
  • Structures similar to arrays are used extensively in non-computing applications.
  • For example, post office boxes (PO boxes). 
    • PO boxes are numbered sequentially within each post office. 
    • These numbers are used as indexes when locating a particular PO box. 
    • Each PO box is a storage container for mail. 
    • The mail (data items) will change within a particular storage container but the container and its index remain constant. 
    • The ordered and sequential nature of the PO box numbers together with the boxes physical arrangement simplifies the sorting and distribution of mail. 
    • In the case of PO boxes there is a single index, the PO box number. 
  • In the HSC course we examine arrays that use multiple indexes, called multidimensional arrays. At this stage we restrict our discussion to arrays with single indexes, one-dimensional arrays.

    Simple One Dimensional Array


    Record
    • A data structure containing data items that are related but not necessarily of the same data type is called a record. 
    • Records are used extensively for database applications.
    • Generally individual records contain all the information about a particular entity (or individual) within the database. 
    • For example, an address book contains details of individual people. Each person is an entity within the address book and has their own record.
    • Before a record structure can be used as a data type, its fields must be named and each assigned a data type. The record structure then becomes a user-defined data type that can be used in the same way as the predefined included data types.

    Sequential files
    • Files are used to permanently store data on secondary storage devices. 
    • Data can be  written to a file or read from a file. 
    • Different types of access to files suit different requirements. 
    • Sequential files can only be accessed from start to finish. 
    • That is, to read or write to the middle of a sequential file requires accessing all the data prior to that position in the file. 
    • It is not possible to jump directly to a particular data item.
    • Sequential files are continuous streams of data (usually characters). 
      • The structure of the data is not coded as part of the file. 
      • If the data within the file has some structure then the software must understand this structure; the file itself does not contain this information. 
        • This structure can be defined using a RECORD datatype.
      • Many languages contain statements that allow data to be written and read a single character at a time, a data item at a time, record at a time or a line at a time.
      • Separators are inserted by the programming language to separate data items e.g. commas or tabs. 
      • Carriage returns and/or line feed characters are added after each line.





    Subpages (1): 1. Student Activity
    Comments