Graph & Heap in Data Structure (Basic Information)

27
Title Layout Subtitle

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

Page 1: Graph & Heap in Data Structure (Basic Information)

Title Layout• Subtitle

Page 2: Graph & Heap in Data Structure (Basic Information)

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)

Page 3: Graph & Heap in Data Structure (Basic Information)

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

Page 4: Graph & Heap in Data Structure (Basic Information)

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}

Page 5: Graph & Heap in Data Structure (Basic Information)

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.

Page 6: Graph & Heap in Data Structure (Basic Information)

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)

Page 7: Graph & Heap in Data Structure (Basic Information)

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.

Page 8: Graph & Heap in Data Structure (Basic Information)

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

Page 9: Graph & Heap in Data Structure (Basic Information)

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

Page 10: Graph & Heap in Data Structure (Basic Information)

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.

Page 11: Graph & Heap in Data Structure (Basic Information)

Connected Graph

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

Page 12: Graph & Heap in Data Structure (Basic Information)

Labelled Graph

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

Page 13: Graph & Heap in Data Structure (Basic Information)

Multiple Edges & Loop

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

• LOOP: An edge whose end points are equal.

Page 14: Graph & Heap in Data Structure (Basic Information)

Multiple Graph

• A graph consisting of

Multiple Edges &

Loop

Page 15: Graph & Heap in Data Structure (Basic Information)

Graph Types

• There are two type of graph:

Directed Graph Undirected Graph

Page 16: Graph & Heap in Data Structure (Basic Information)

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 .

Page 17: Graph & Heap in Data Structure (Basic Information)

Complete Graph

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

Page 18: Graph & Heap in Data Structure (Basic Information)

Null Graph

• A graph which has no edges between nodes

Page 19: Graph & Heap in Data Structure (Basic Information)

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).

Page 20: Graph & Heap in Data Structure (Basic Information)

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).

Page 21: Graph & Heap in Data Structure (Basic Information)

Type of heap

• Heap is two type basically.

1. Min Heap

2. Max Heap

Page 22: Graph & Heap in Data Structure (Basic Information)

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.

Page 23: Graph & Heap in Data Structure (Basic Information)

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

Page 24: Graph & Heap in Data Structure (Basic Information)

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

Page 25: Graph & Heap in Data Structure (Basic Information)

Determine Child

Process of Determine Child of a Heap from an array

Page 26: Graph & Heap in Data Structure (Basic Information)

Heapify Process

Process of Determine Parent of a Heap from an array

Page 27: Graph & Heap in Data Structure (Basic Information)