Docsity

Data Organization and Management: Files and Data Structures, Lecture notes of Computer Science

Toggle sidebar
bg1
1
CSC 223 LECTURE NOTES
FILES ORGANIZATION, DATA STRUCTURE, DECISION TABLES, SORTING AND
MERGING
THE DATA HIERARCHY
A computer system organizes data in a hierarchy that starts with bits and bytes and progresses to
fields, records, files, and databases.
1. Bit: This represents the smallest unit of data a computer can handle. A group of bits, called a byte,
represents a single character, which can be a letter, number or other symbol.
2. Field: A field is a particular place in a record where an item of information can be held or a
grouping of characters into a word, group of words or a complete number (e.g. a person's first name or
age), is called a field.
3. Record: A group of related fields, such as a student's name, class, date admitted, age or record is a
collection of related items of data treated as a unit.
4. File:A file is organized collection of related records which are processed together. It is also referred
to as a data set. The files is a collection of records relating to some class of object e.g. records of all
insurance policies issue by an insurance company, records of all employees of firm, student records
etc. A group of records of the same type (e.g. the records of all students in the class) is called a file.
5. Database: A group of related files (e.g. the personal history, examinations records and payments
history files) make up a database. A record describes an entity. An entity is a person, place, thing, or
event on which we maintain information. An employee record is an entity in a personnel records file
and maintains information on the employees in that organization. Each characteristic or quality
describing a particular entity is called an attribute. For example, employee name, address, age, gender,
date employed is an attribute each of the entity personnel. The specific values that these attributes can
have can be found in the field of the record describing the entity. Every record in the file contains at
least one field that uniquely identifies that record so that the record can be retrieved, changed,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Data Organization and Management: Files and Data Structures and more Lecture notes Computer Science in PDF only on Docsity!

CSC 223 LECTURE NOTES

FILES ORGANIZATION, DATA STRUCTURE, DECISION TABLES, SORTING AND

MERGING

THE DATA HIERARCHY

A computer system organizes data in a hierarchy that starts with bits and bytes and progresses to fields, records, files, and databases.

1. Bit: This represents the smallest unit of data a computer can handle. A group of bits, called a byte, represents a single character, which can be a letter, number or other symbol. 2. Field: A field is a particular place in a record where an item of information can be held or a grouping of characters into a word, group of words or a complete number (e.g. a person's first name or age), is called a field. 3. Record: A group of related fields, such as a student's name, class, date admitted, age or record is a collection of related items of data treated as a unit. 4. File: A file is organized collection of related records which are processed together. It is also referred to as a data set. The files is a collection of records relating to some class of object e.g. records of all insurance policies issue by an insurance company, records of all employees of firm, student records etc. A group of records of the same type (e.g. the records of all students in the class) is called a file. 5. Database: A group of related files (e.g. the personal history, examinations records and payments history files) make up a database. A record describes an entity. An entity is a person, place, thing, or event on which we maintain information. An employee record is an entity in a personnel records file and maintains information on the employees in that organization. Each characteristic or quality describing a particular entity is called an attribute. For example, employee name, address, age, gender, date employed is an attribute each of the entity personnel. The specific values that these attributes can have can be found in the field of the record describing the entity. Every record in the file contains at least one field that uniquely identifies that record so that the record can be retrieved, changed,

modified or sorted. This identifier is called the key field. An example of a key field is the employee number for a personnel record containing employee data such as name, address, age, job title etc.

COMPUTER FILE A computer file is a collection of related records / information that is stored in a computer system and can be identified by its full path name. File can also be defined as a group of records pertaining to a specific item e.g. payroll file. This contains all the payroll records within the organization’s records. Computer files are so called because they are the computer equivalent of card, paper, or microfiche files in the traditional office environment. Computer files provide a way to organize the resources used to permanently store information inside a computer.

A file has got a layout which show, for each different type of record in each file, the name of each file, its length and its locations within the record. Files are created when need for a particular collection of records is recognized. However, the creation and maintenance of files are major factor in the work load of a computer information processing system.

Purpose: A file holds data which is required for providing information. Some files are processed at regular intervals to provide this information (e.g. payroll file) and others which is required at regular intervals (e.g. file containing prices of items).

Ways of viewing file There are two common ways of viewing files:

1. Logical Files A logical file is a file viewed in terms of what data items its records, contain and what processing operations may be performed upon the file. The user of the file will normally adopt such a view. 2. Physical Files A physical file is a file viewed in terms of how the data are stored on a storage device such as a magnetic disk and how the processing operations are made possible. A logical file usually gives rise to a number of alternative physical file implementation

Types of file

1. Master file These are files of a fairly permanent nature e.g. customer ledger, payroll, inventory, etc. A feature to note is the regular updating of these files to show a current position. For example customer’ order will be processed by increasing the “balance owing” figure on a customer ledger record. It is seen therefore that master records will contain both data of a static nature, e.g. a customer name and address, and data which by its nature will change each time a transaction occurs, e.g. the “balance” personal file. 2. Movement file/Transaction file This is made up of the various transactions created from the source documents. In a sales ledger application, the file will contain all the orders received at a particular time. This file will be used to update the master file. As soon as it has been used for this purpose, it is no longer required. It will therefore have a very short life; because it will be replaced by a file containing the next batch addresses E.g. Sales Invoicing file, purchase order file and payroll file.

  1. Reference file This is a file with a reasonable amount of permanency. Example of data used for reference purposes are price lists, tables of rates of pay, names and addresses. 4. Working file: Working file: A file that is used to support computer procedures. Its content could be same with the transaction and or master file. It is usually of temporary nature and derived by interrogating the master/transaction files. An example is a file containing the list of debtors to an organization.

Processing activities on a file We will need to have access to particular records in the files in order to process them. The major processing activities are given below:

  1. Updating: This is when data on the master record is changed to reflect a current position e.g. updating a customer ledger record with new orders. Note that the old data on the record is replaced by the new data.
  1. Referencing: When access is made to a particular record to ascertain therein e.g. reference is made to a “price” file during an invoicing run. Note that this does not involve any alteration to the record itself.
  2. Sort file: This can be defined as a working file or record to be sequenced. This may be the original or a copy of the transaction file, master file or report file.
  3. File maintenance: New records must be added to a file and records need to be deleted. Prices change, and the file must be altered. Customer’s addresses also change and new addresses have to be inserted to bring the file up to date. These particular activities come under the heading of “maintaining” the file. File maintenance can be carried out as a separate run but the insertion and deletion of records is sometimes combined with Updating.
  4. File enquiry or interrogation: This is similar in concept to referencing. It involves the need to ascertain a piece of information from, say, a master record. For example, a customer may query a statement sent to him. A “file enquiry” will get the data in dispute from the record so that the query may be settled.

File organization Organization of a file on tape is simply a matter of placing the records one after the other on to the tape. There are four basic methods of organizing files on disk:

  1. Serial: Exactly as for tape. Records are placed onto the disk one after the other with no regard for sequence.
  2. Sequential: Again as for tape; records are written onto the disk but in a defined sequence according to the record keys.
  3. Indexed sequential: Records are stored in sequence as for 20b but with one important difference – an index is provided to enable individual records to be located.
  4. Random: Records are actually placed onto the disk “at random”, that is to say there is no obvious relationship between the records.

Record: Record can be defined as the collection of various data items, for example, if we talk about the student entity, then its name, address, course and marks can be grouped together to form the record for the student.

File: A File is a collection of various records of one type of entity, for example, if there are 60 employees in the class, then there will be 20 records in the related file where each record contains the data about each employee.

Attribute and Entity: An entity represents the class of certain objects. it contains various attributes. Each attribute represents the particular property of that entity.

Field: Field is a single elementary unit of information representing the attribute of an entity.

Need of Data Structures As applications are getting complexed and amount of data is increasing day by day, there may arrise the following problems:

1. Processor speed: To handle very large amout of data, high speed processing is required, but as the data is growing day by day to the billions of files per entity, processor may fail to deal with that much amount of data. 2. Data Search: Consider an inventory size of 106 items in a store, If our application needs to search for a particular item, it needs to traverse 106 items every time, results in slowing down the search process. 3. Multiple requests: If thousands of users are searching the data simultaneously on a web server, then there are the chances that a very large server can be failed during that process in order to solve the above problems, data structures are used. Data is organized to form a data structure in such a way that all items are not required to be searched and required data can be searched instantly.

Advantages of Data Structures Efficiency: Efficiency of a program depends upon the choice of data structures. For example: suppose, we have some data and we need to perform the search for a perticular record. In that case, if we

organize our data in an array, we will have to search sequentially element by element. hence, using array may not be very efficient here. There are better data structures which can make the search process efficient like ordered array, binary search tree or hash tables. Reusability: Data structures are reusable, i.e. once we have implemented a particular data structure, we can use it at any other place. Implementation of data structures can be compiled into libraries which can be used by different clients. Abstraction: Data structure is specified by the ADT which provides a level of abstraction. The client program uses the data structure through interface only, without getting into the implementation details.

Types of Data Structures

There are two types of data structures:

o Primitive data structure o Non-primitive data structure

Primitive Data structure

The primitive data structures are primitive data types. The int, char, float, double, and pointer are the primitive data structures that can hold a single value.

Non-Primitive Data structure

The non-primitive data structure is divided into two types:

o Linear data structure o Non-linear data structure

Linear Data Structure

Linked List: Linked list is a linear data structure which is used to maintain a list in the memory. It can be seen as the collection of nodes stored at non-contiguous memory locations. Each node of the list contains a pointer to its adjacent node.

Stack: Stack is a linear list in which insertion and deletions are allowed only at one end, called top.

A stack is an abstract data type (ADT), can be implemented in most of the programming languages. It is named as stack because it behaves like a real-world stack, for example: - piles of plates or deck of cards etc.

Queue: Queue is a linear list in which elements can be inserted only at one end called rear and deleted only at the other end called front.

It is an abstract data structure, similar to stack. Queue is opened at both end therefore it follows First- In-First-Out (FIFO) methodology for storing the data items.

Non Linear Data Structures: This data structure does not form a sequence i.e. each item or element is connected with two or more other items in a non-linear arrangement. The data elements are not arranged in sequential structure.

Types of Non Linear Data Structures are given below:

Trees: Trees are multilevel data structures with a hierarchical relationship among its elements known as nodes. The bottommost nodes in the herierchy are called leaf node while the topmost node is called root node. Each node contains pointers to point adjacent nodes.

Tree data structure is based on the parent-child relationship among the nodes. Each node in the tree can have more than one children except the leaf nodes whereas each node can have atmost one parent except the root node. Trees can be classfied into many categories which will be discussed later in this tutorial.

Graphs: Graphs can be defined as the pictorial representation of the set of elements (represented by vertices) connected by the links known as edges. A graph is different from tree in the sense that a graph can have cycle while the tree can not have the one.

Operations on data structure

  1. Traversing: Every data structure contains the set of data elements. Traversing the data structure means visiting each element of the data structure in order to perform some specific operation like searching or sorting.

Example: If we need to calculate the average of the marks obtained by a student in 6 different subject, we need to traverse the complete array of marks and calculate the total sum, then we will devide that sum by the number of subjects i.e. 6, in order to find the average.

  1. Insertion: Insertion can be defined as the process of adding the elements to the data structure at any location.

If the size of data structure is n then we can only insert n- 1 data elements into it.

  1. Deletion: The process of removing an element from the data structure is called Deletion. We can delete an element from the data structure at any random location.

If we try to delete an element from an empty data structure then underflow occurs.

  1. Searching: The process of finding the location of an element within the data structure is called Searching. There are two algorithms to perform searching, Linear Search and Binary Search. We will discuss each one of them later in this tutorial.

  2. Sorting: The process of arranging the data structure in a specific order is known as Sorting. There are many algorithms that can be used to perform sorting, for example, insertion sort, selection sort, bubble sort, etc.

  3. Merging: When two lists List A and List B of size M and N respectively, of similar type of elements, clubbed or joined to produce the third list, List C of size (M+N), then this process is called merging

To make them more concise, many decision tables include in their condition alternatives a don't care symbol. This can be a hyphen[1][2][3]^ or blank,[4]^ although using a blank is discouraged as it may merely indicate that the decision table has not been finished.[ citation needed ]^ One of the uses of decision tables is to reveal conditions under which certain input factors are irrelevant on the actions to be taken, allowing these input tests to be skipped and thereby streamlining decision-making procedures.[5]

Aside from the basic four quadrant structure, decision tables vary widely in the way the condition alternatives and action entries are represented.[6][7]^ Some decision tables use simple true/false values to represent the alternatives to a condition (similar to if-then-else), other tables may use numbered alternatives (similar to switch-case), and some tables even use fuzzy logic or probabilistic representations for condition alternatives.[8]^ In a similar way, action entries can simply represent whether an action is to be performed (check the actions to perform), or in more advanced decision tables, the sequencing of actions to perform (number the actions to perform).

A decision table is considered balanced or complete if it includes every possible combination of input variables. In other words, balanced decision tables prescribe an action in every situation where the input variables are provided.[4]

While recognizing these advantages, many will point out that tables are merely a systematic way to present static data. Do they have a worthwhile function in a more dynamic situation - that of decision making?

Decision tables may take one of three forms: (1) Limited entry table (2) Extended entry table (3) Mixed entry table

The limited-entry decision table is the simplest to describe. The condition alternatives are simple Boolean values, and the action entries are check-marks, representing which of the actions in a given column are to be performed.

A technical support company writes a decision table to diagnose printer problems based upon symptoms described to them over the phone from their clients.

The following is a balanced decision table.

Sorting Algorithms

Sorting is the process of arranging the elements of an array so that they can be placed either in ascending or descending order. For example, consider an array A = {A1, A2, A3, A4, ?? An }, the array is called to be in ascending order if element of A are arranged like A1 > A2 > A3 > A4 > A5 >?

An.

Consider an array;

int A[10] = { 5, 4, 10, 2, 30, 45, 34, 14, 18, 9 )

The Array sorted in ascending order will be given as;

A[] = { 2, 4, 5, 9, 10, 14, 18, 30, 34, 45 }

Bubble Sort

In Bubble sort, each element of the array is compared with its adjacent element. The algorithm processes the list in passes. A list with n elements requires n-1 passes for sorting. Consider an array A of n elements whose elements are to be sorted by using Bubble sort. The algorithm processes like following.

  1. In Pass 1, A[0] is compared with A[1], A[1] is compared with A[2], A[2] is compared with A[3] and so on. At the end of pass 1, the largest element of the list is placed at the highest index of the list.
  2. In Pass 2, A[0] is compared with A[1], A[1] is compared with A[2] and so on. At the end of Pass 2 the second largest element of the list is placed at the second highest index of the list.
  3. In pass n-1, A[0] is compared with A[1], A[1] is compared with A[2] and so on. At the end of this pass. The smallest element of the list is placed at the first index of the list.

Algorithm:

o Step 1 : Repeat Step 2 For i = 0 to N- 1 o Step 2 : Repeat For J = i + 1 to N - I o Step 3 : IF A[J] > A[i] SWAP A[J] and A[i] [END OF INNER LOOP] [END OF OUTER LOOP o Step 4 : EXIT