Hierarchical and Network Data Models

The hierarchical model arranges records in a tree with one parent each; the network model allows many parents through a graph of sets. Both used physical pointers, and that is exactly why the relational model replaced them.

Concept

These two models came before the relational model. They are still examined because their weaknesses explain, point by point, why the relational model was designed the way it was.

The hierarchical model

Data is organised as a tree. Every record type except the root has exactly one parent, and a parent may have many children. The relationship is strictly one to many, and it is represented by a physical pointer from parent to child.

                COLLEGE
                   |
        +----------+-----------+
        |                      |
    DEPARTMENT             DEPARTMENT
    (Computing)            (Commerce)
        |                      |
   +----+----+                 |
   |         |                 |
 STUDENT   STUDENT          STUDENT

 Navigation is by path: college -> department -> student.
 To reach a student you must walk from the root.

Problems with the hierarchical model

  • Many to many is not representable. A student taking many courses, and a course taken by many students, does not fit a tree. The workaround is duplicating records, which reintroduces redundancy.
  • A child cannot exist without a parent. Deleting a department deletes its students.
  • Access is navigational. The programmer must know and follow the path. There is no ad hoc query.
  • No data independence. Changing the tree shape rewrites the programs.

The network model

Data is organised as a graph. A record may have several parents. The relationship is expressed as a named set, which has one owner record type and one member record type, again implemented with pointers.

     STUDENT                     COURSE
        |                       /   |
        |     set: ENROLMENT   /    |
        |    +----> ENROLS <---+     |
        |            record          |
        |                            |
     owner of                     owner of
     set S_E                      set C_E

 A student owns many enrolment records.
 A course also owns many enrolment records.
 So many to many IS representable - by inserting a
 record type between the two, exactly the idea that
 becomes the junction table in the relational model.

Improvements over hierarchical

  • Many to many relationships are supported.
  • A record can be reached by more than one path.
  • Data retrieval is more flexible.

Problems that remain

  • Still navigational. The programmer walks pointers, one record at a time. There is no declarative query.
  • Structural complexity. A large network of sets is hard to draw, harder to change.
  • Still no data independence. Programs are written against the pointer structure, so changing it breaks them.
  • Design changes are expensive. Adding a relationship means adding sets and rewriting access code.

Comparison

PointHierarchicalNetworkRelational
StructureTreeGraph of setsTables
Parents per recordExactly oneManyNot applicable
Many to manyNot supported directlySupported through a linking recordSupported through a junction table
Relationships byPhysical pointersPhysical pointersMatching values in keys
AccessNavigational, from the rootNavigational, along setsDeclarative — state the result wanted
Data independenceVery lowLowHigh
Ad hoc queriesNoBarelyYes
Ease of changeVery hardHardComparatively easy
The one sentence that carries the whole comparison: the older models connect records with pointers, the relational model connects them with values. A pointer is a physical fact, so programs depend on physical layout. A value is a logical fact, so they do not. Every advantage in the right hand column follows from that.

Example

"Which students take Database Systems?"

 HIERARCHICAL
   start at the root, walk every department, walk every
   student, inspect their course children, collect matches.
   The programmer writes the walk. Adding a level of the
   tree means rewriting it.

 NETWORK
   find the COURSE record for Database Systems, then follow
   its enrolment set to each member, then follow each member
   back to its owning STUDENT record.
   Shorter, still a walk written by hand.

 RELATIONAL
   state the join between students, enrolments and courses
   and let the optimiser decide how to walk it.
   The access path is the DBMS decision, not yours.

Common mistakes

  • Saying the network model cannot do many to many. It can — that is its main improvement over hierarchical.
  • Saying the hierarchical model has no relationships. It has one to many relationships, expressed as parent to child.
  • Forgetting the real weakness. It is not the shape; it is that both are navigational and pointer based, which destroys data independence.
  • Assuming these models are extinct. Hierarchical thinking survives in file systems, XML and JSON documents, and directory services.

Exam and interview questions

  1. Explain the hierarchical model with a diagram and state two limitations.
  2. How does the network model represent a many to many relationship?
  3. Compare hierarchical, network and relational models on at least six points.
  4. Why did pointer based models fail to provide data independence?
  5. Give one modern structure that still uses hierarchical thinking.

Practice

  1. Draw a hospital as a hierarchical model and identify the fact it cannot represent.
  2. Redraw the same case as a network model and name the linking record type.
  3. Explain in three sentences why replacing pointers with key values improved data independence.

Conclusion

Hierarchical gives one parent and a tree; network gives many parents and a graph. Both link records with pointers, so both force programs to know the physical structure — and that single flaw is what the relational model was designed to remove.

Written by Lorens Mishra

Default administrator account created by the installer.

Continue reading

All DBMS notes →
DBMS

What a Data Model Is

A data model is the set of concepts used to describe data, relationships, semantics and constraints. Models are grouped as high level, representationa...

Read more

Discussion

0 comments
Sign in to join the discussion.

No comments yet. Be the first to say something.