Thursday, November 3, 2016

Hierarchical, Network and Relational Database Model

Hierarchical Model in DBMS

Hierarchical model is a data model which uses the tree as its basic structure. So, lets define the basics of the tree.

Basics of Tree :

  • A tree is a data structure that consists of hierarchy of nodes with a single node, called the root at highest level.
  • A node may have any number of children, but each child node may have only one parent node on which it is dependent. Thus the parent to child relationship in a tree is one to many relationship whereas child to parent relationship in a tree is one to one.
herarchical model
Figure 1
  • In figure 1, the node at level 1 is called the root node and the nodes at that has no children are called leaves. For example, node 4, 5, 7, 8, 9, 10 and 11.
  • Nodes that are children of the same parent are called siblings. For example, nodes 2, 3, 4 are siblings.
  • For any node there is a single path called the hierarchical path from the root node. The nodes along this path are called that nodes ancestors.
  • Similarly for a given node, any node along a path from that node to leaf is called its descendent.
  • For example, suppose we have to find out the hierarchical path of node 10, then it will be 1→2→6→10 and the ancestors of node 10 are 1, 2 and 6.
  • The height of tree is the number of levels on the longest hierarchical path from the root to a leaf. The above tree has a height= 4.
  • tree is said to be balanced if every path from the root node to a leaf has the same length.
Figure 2 shows a balanced and an unbalanced tree.
balanced unbalanced(Hierarchical Model)
Figure 2
binary tree is one in which each node has not more than two children.
Figure 3 shows a binary tree

Binary tree(Hierarchical Model)
Figure 3

Example of Hierarchical Model :

  • Figure 4 shows a data structure diagram for a tree representing the STUDENT, FACULTY and CLASS.
  • The root node chosen is faculty, CLASS as a child of faculty and STUDENT as a child of class.
  • The cardinality between CLASS and FACULTY is one to many cardinality as a FACULTY teaches one or more CLASS.
  • The cardinality between a CLASS and a STUDENT is also one to many cardinality because a CLASS has many STUDENTS.
 HIERARCHICAL MODEL EXAMPLE
Figure 4
Figure 5 shows an occurrence of the FACULTY-CLASS-STUDENT.
 HIERARCHICAL MODEL EXAMPLE 2
Figure 5

Another Example :

Operations on Hierarchical Model

  1. Deletion- If CS02 is deleted, then all the students in CS02 class will be deleted. So deletion is very difficult. However deletion of leaf nodes that is students does not create difficulty in deletion.
  2. Insertion- A new class say, CS03 may not be introduced unless some faculty is available at root level. So insertion is also difficult.
  3. Updation- Suppose a student has changed his subject from Hindi to Sanskrit, then firstly a search is performed to find out Hindi subject and then an update is made. A search is a time consuming process here.
So  these problem occurs in all the three operations.

Advantages of Hierarchical Model 

  • Easy to understand
  • Performance is better than relational data model

Disadvantages of Hierarchical Model 

  • Difficult to access values at lower level
  • This model may not be flexible to accomodate the dynamic needs of an organisation
  • Deletion of parent node result in deletion of child node forcefully
  • Extra space is required for the storage of pointers

Network Database or Network Model in DBMS

The network database or network model uses the plex structure as its basic data structure. A network is a directed graph consisting of nodes connected by links or directed arcs. The nodes corresponds to record types and the links to pointers or relationships. All the relationship are hardwired or pre-computed and build into structure of database itself because they are very efficient in space utilization and query execution time.
The network data structure looks like a tree structure except that a dependent node which is  called a child or member, may have more than one parent or owner node.All figure shows the network model –
 Network Model
Figure 1
A diagram called as Bachman Diagram is used to represent a network data structure. The nodes in the network are replaced by rectangles that represent records and links are shown by lines connecting the rectangles.

A plex structure with two record types is shown / Example of Network Database :

 NETWORK MODEL EXAMPLE
Figure 2

Another Example of Network Database is :

Operations on Network Model/Network Database

  1. Insertion- In the above figure, it is clear that a new part or supplier can easily be inserted.
  2. Deletion- For deletion only link is to be removed and no information will be lost. For example, to remove  PART 2, we delete  the connector line between suppliers.
  3. Updation- Updation is also easy, for example, suppose SUPPLIER B supplies PART 1 in place of SUPPLIER 2, so, updation will be successfully done by changing the link of SUPPLIER B from PART 2 to PART 1.

Advantages of Network Model/ Network Database :

  • Easy access to data.
  • Flexible
  • Efficient
  • This model can be applied to real world problems, that require routine transactions.

Disadvantages of Network Model/ Network Database :

  • Complex to design and develop.
  • Extra memory is required for storage of pointers
  • Performance is infexible and difficult to use.
  • Operation and maintenance are time consuming and expensive for large databases.


Relational Model or Relational Database 

The relational model is a lower level model. It is based on the concept of a relation, which is physically represented as a table. A table is a collection of rows & columns . The relational model uses a collection of tables to represent both data and the relationships among those data.
The tables are used to hold information about the objects to be represented in the database. A relation or a table is represented as a two dimensional form in which the rows of the table corresponds to individual records and the columns corresponds to attributes.
Each row is called a tuple and each column is called an attribute.For example, a student relation is represented by the STUDENT table having columns for attributes SID, NAME and BRANCH.
Relational Database or Relational Model

SID : Key
 Number of Records = Cardinality
 Number of Fields = Arity
 Student (SID,Name,Branch) = Relational Schema (Table Abstraction)
The SID here is the primary key as it identifies a student record or tuple uniquely.(A primary key is the key applied on an attribute(SID) which recognize a tuple.
The Cardinality of the Relation or table is defined as the number of records in the STUDENT relation which is 4.
The Arity is defined as the number of fields or columns in the relation.

Domain of an Attribute –

Domain of an attribute is the set of allowable values for that attribute. It is a pool of values from which the actual values appearing in a given column are drawn. For example, the values appearing in the SID column are drawn from the domain of all SID. Domains may be distinct, or two or more attributes may have same domain.

Operations in Relational Model –

  1. Insertion – A new student record can be easily inserted in the table.
  2. Deletion – An existing student record or tuple can easily be deleted from the STUDENT relation.
  3. Updation – An existing student record can be update easily. For example, if a student S2 changes its BRANCH from CS to IT, then it can easily be changed

Advantages of Relational Model –

  • Easy to use an understand
  • Very flexible.
  • Widely used.
  • Provides excellent support for adhoc queries.
  • Users need not consider issues such as storage structure and access strategy.
  • Specify control and authorization can be implemented more easily.
  • Data independence is achieved more easily with normalisation structure used in a relational database.

Disadvantages of Relational Model –

  • For large databases, the performance in responding to queries is definitely degraded.
  • The processing requirements need to construct the indexes. So, the index position of the file must be created and maintained along with the file records themselves.
  • The file index must be searched sequentially before the actual file records are obtained. This wastes time.

1 comment: