Non Linear Data Structures
Non Linear Data Structures
1- Graphs :-
It is a set of points connected by lines, as shown in the
following figure:
The two vertices are called the edge endpoints. Graphs are ubiquitous in
computer science. The most important use of a graph is to show the relations
among entities. They are used to model real-world systems such as the
Internet (each node represents a router and each edge represents a
connection between routers); airline connections (each node is an airport
and each edge is a flight); or a city road network (each node represents
an intersection and each edge represents a block). The wireframe drawings
in computer graphics are another example of graphs.
Directed Undirected
Graph Graph
(digraph)
Applications of Graphs :-
Electronic circuits :-
Printed circuit board
Integrated circuit
Transportation networks :-
Highway network
Flight network
Computer networks :-
Local area network
Internet
Web
Databases :-
Entity-relationship diagram
Graph Algorithms :-
Graph Representation :-
One of the methods to represent the graphs is the Adjacency matrix method.
0 1 2 3
0 F T T F
2 T T F T
3 F F T F
If we remove (delete) the root of the tree we get a forest which is a set
of disjoint trees.
Important terms :-
1- The depth of a node is the length of the path (or the number of edges)
from the root to that node.
2- The height of a node is the longest path from that node to its leaves.
The height of a tree is the height of the root.
3- The degree of a node is the number of subtrees of the node.
4- The degree of a tree is the maximum degree of the nodes in the tree
5- The ancestors of the node are all the nodes along the path from the
root to that node.
6- The depth of a tree it also called height of a tree. It is the maximum
level of the tree.
1. General trees.
2. Binary trees.
EX2 :-
A
A
B
B F C F
C D D G
G J K
E J
E H I
H K
by level, from left to right and store nodes sequentially. (Very efficient
1. A preorder traversal visits the root of a subtree, then the left and right
subtrees recursively.
2. An inorder traversal visits the left subtree, the root of a subtree, and then
the right subtree recursively.
Applications of Trees :-
Family tree.
Company organization chart.
Table of contents in the books.
Biological classifications.
3. Many databases use a B- tree data structure that provides very fast keyed
access to records stored on disk.
directory or file.
5. In computer games where the current position is the root of the tree; the
branches lead to positions that might occur later in the game.
6. Language compilers (like C++) use tree data structures as part of the
parsing phase of translation to machine code. For example, arithmetic
expressions are represented using a binary expression tree that captures
the precedence of arithmetic operators.