Graph & Heap in Data Structure (Basic Information)

Post on 16-Jan-2017

206 views 1 download

Transcript of Graph & Heap in Data Structure (Basic Information)

Title Layout• Subtitle

Course: CSE134 (Data Structure)Course Teacher: Mr. A. S. M. Farhan Al Haque (ASMFH)Section: P Group: A Depertment: CSE(43 Batch)Group Members: 01. Md. Ashaf Uddaula (161-15-7473)02. Alamin Hossain (161-15-7483)03. Md. Khasrur Rahman (161-15-7214)04. Md. Eram Talukder (161-15-7485)05. Ijaz Ahmed Utsa (161-15-7180)

Going to tell about……. Graph• Definition of Graph

• Adjacent Node

• Degree of Graph

• Isolated Node

• Path

• Closed Path

• Simple Path

• Connected Graph

• Labelled Graph

• Multiple Edges & Loop

• Multi Graph

• Graph Types

• Directed Graph

• Complete Graph

• Null Graph

• Sub-Graph

Heap

• Definition of Heap

• Type of heap

• Min Heap

• Max Heap

• Representation of Heap

• Determine Child

• Heapify Process

What is Graph?• A collection of Nodes(v1,v2,v3,v4,v5,v6) & connected by

Edges(e1,e2,e3,e4,e5,e6).

• Abstract Data Type.

• In Mathematically, A graph G is composed by a set V of vertices or node connected through a set E of edges or links.

Here, V={v1,v2,v3,v4,v5,v6}

& E={e1,e2,e3,e4,e5,e6}

Then , Graph G will be the sets of V & E,

Graph, G = {V,E}

Adjacent Node

• Two Nodes are adjacent if they are connected via only one edge.

• Here, (1,7),(7,6),(6,5),(5,4),(4,3),

(3,2),(2,1) every node of every

pair is an adjacent node.

Degree of Graph

• The number of edges of a node

Here, the degree of

Node Number , 1 is 2(5,2)

Node Number , 2 is 4(2,5,4,14)

Node Number , 3 is 2(14,34)

Node Number , 4 is 3(5,5,58)

Node Number , 5 is 3(4,34,58)

Isolated Node

• If the degree of a node is 0, that means , a node which has no connection with other other nodes is called Isolated Node.

Here, f is an isolated node.

Path

• A sequence of vertices that connected two nodes in a graph

Here, p=n-1

;p=the length of a path which is called the length of number of edges.

;n=Number of Nodes

Closed Path• The path said to be closed if the

starting point of path from a node & finishing point of that path will same , that type of path can called closed path.

Here, H->D->G->H is a closed path

B->D->C->B is a closed path

F->D->E->F is a closed path

Simple Path

• A path where is no repeatation of any node which is involved in that path previously.

Here, bec is a simple path

but, acda is not a simple path, that

type of path is called cycle.

Connected Graph

• A graph is connected when there is a path between every pair of vertices.

Labelled Graph

• A graph is to be labeled if its edges & vertices are assigned data.

Multiple Edges & Loop

• MULTIPLE EDGES: Edges have the same pair of end points.

• LOOP: An edge whose end points are equal.

Multiple Graph

• A graph consisting of

Multiple Edges &

Loop

Graph Types

• There are two type of graph:

Directed Graph Undirected Graph

Directed Graph

• A graph where every node has a direction by using edges of that node.

Here , A -> B , A->C & B->C are directed .

Complete Graph

A graph where every Node is interconnected with all nodes in a graph.

Null Graph

• A graph which has no edges between nodes

Sub-Graph• All the edges and vertices of (a) might not

be present in M1,M2,M3,M4; but if a vertex is present in M1,M2,M3,M4, it has a corresponding vertex in (a) and any edge that connects two vertices in M1,M2,M3,M4 will also connect the corresponding vertices in (a).

What is Heap?

• Heap is a tree with some special properties.

• The basic requirement of a heap is that the value of a node must be >=(or,<=) to the values of its children.

• Tree must be made an almost binary tree(ABT).

Type of heap

• Heap is two type basically.

1. Min Heap

2. Max Heap

Min Heap

• A min-heap is a binary tree such that. - the data contained in each node is less than (or equal to) the data in that node's children. - the binary tree is complete.

Max Heap• ● A max-heap is a binary tree

such that. - the data contained in each node is greater than (or equal to) the data in that node's children

Representation of Heap• Heap can be represent by using

arrays Data of Node from Almost Binary

Tree(ALT) will serially input in a declare array with the sequence of

Root Left Right

Determine Child

Process of Determine Child of a Heap from an array

Heapify Process

Process of Determine Parent of a Heap from an array