SlideShare une entreprise Scribd logo
1  sur  176
Fundamentals of Data Structure - Niraj Agarwal
Data Structures   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Structure (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Structures (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Collections ,[object Object],[object Object],create Create a new collection add Add an item to a collection delete Delete an item from a collection find Find an item matching some criterion in the collection destroy Destroy the collection
Analyzing an Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A[0] 1 A[1] 2 A[2] 3 A[n-2] N-1 A[n-1] N
Arrays (Cont.) Multi-dimensional Array A  multi-dimensional array   of dimension  n  (i.e., an  n -dimensional array or simply  n -D array) is a collection of items which is accessed via  n  subscript expressions. For example, in a language that supports it, the  (i,j) th element of the two-dimensional array x is accessed by writing x[i,j].   m x i : : : : : : : : : : : : : : : 2 1 0 n j 10 9 8 7 6 5 4 3 2 1 0 C o l u m n R O W
Arrays (Cont.)
Array : Limitations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Linked Lists ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Data Next object
Linked Lists (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Head Collection node Tail The variable (or handle) which represents the list is simply a pointer to the node at the  head  of the list.  Data Next object
Linked Lists (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],Head Collection node node Data Next object Data Next object2
Linked Lists -  Add   implementation ,[object Object],struct t_node { void *item;   struct t_node *next;   } node; typedef struct t_node *Node; struct collection { Node head; …… }; int AddToCollection( Collection c, void *item ) { Node new = malloc( sizeof( struct t_node ) ); new->item = item; new->next = c->head;   c->head = new; return TRUE; }  Recursive type definition - C allows it! Error checking, asserts omitted for clarity!
Linked Lists -  Find   implementation ,[object Object],void *FindinCollection( Collection c, void *key ) { Node n = c->head; while ( n != NULL ) { if ( KeyCmp( ItemKey( n->item ), key ) == 0 ) { return n->item; n = n->next; } return NULL; }  Add time  Constant - independent of n Search time  Worst case - n ,[object Object]
Linked Lists -  Delete  implementation ,[object Object],void *DeleteFromCollection( Collection c, void *key ) { Node n, prev; n = prev = c->head; while ( n != NULL ) { if ( KeyCmp( ItemKey( n->item ), key ) == 0 ) { prev->next = n->next; return n; } prev = n;   n = n->next; } return NULL; }  head
Linked Lists - Variations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],struct t_node { void *item;   struct t_node *next;   } node; typedef struct t_node *Node; struct collection { Node head, tail; }; head tail By ensuring that the tail of the list is always pointing to the head, we can build a  circularly linked list head is  tail->next LIFO or FIFO using ONE pointer
Linked Lists - Doubly linked ,[object Object],[object Object],struct t_node { void *item;   struct t_node *prev, *next;   } node; typedef struct t_node *Node; struct collection { Node head, tail; }; head tail prev prev prev Applications requiring both way search Eg. Name search in telephone directory
Binary Tree ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Note the recursive definition! Each sub-tree is itself a binary tree ,[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Tree (Cont.) ,[object Object],A C D E F G ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Tree - Implementation struct t_node { void *item;   struct t_node *left; struct t_node *right;   }; typedef struct t_node *Node; struct t_collection {   Node root; …… };
Binary Tree -  Implementation ,[object Object],extern int KeyCmp( void *a, void *b ); /* Returns -1, 0, 1 for a < b, a == b, a > b */ void *FindInTree( Node t, void *key ) { if ( t == (Node)0 ) return NULL; switch( KeyCmp( key, ItemKey(t->item) ) ) { case -1 : return FindInTree( t->left, key );  case 0:  return t->item; case +1 : return FindInTree( t->right, key ); } } void *FindInCollection( collection c, void *key ) { return FindInTree( c->root, key ); } Less, search left Greater, search right
Binary Tree -  Performance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Tree -  Traversing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Tree -  Applications ,[object Object],[object Object],[object Object],[object Object],[object Object]
General Tree ,[object Object],[object Object],A Hierarchical Tree
Heaps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Heaps (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Heaps (Cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Heaps (Cont.) ,[object Object],To add an item to a heap, we follow the reverse procedure.  Place it in the next leaf position and move it up.  Again, we require  O( h ) or O(log n ) exchanges .
Comparisons Arrays Simple, fast Inflexible O(1) O(n)  inc sort O(n) O(n) O(logn) binary search Add Delete Find Linked List Simple Flexible O(1) sort -> no adv O(1) -  any O(n) -  specific O(n) (no bin search) Trees Still Simple Flexible O(log n) O(log n) O(log n)
Queues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stacks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stack  (Cont.) ,[object Object],[object Object],function f( int x, int y) {   int a;   if ( term_cond ) return …;   a = ….;   return g( a );   } function g( int z ) {   int p, q;   p = …. ; q = …. ;   return f(p,q);   } Context  for execution of  f
Searching ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Search ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Time complexity   O( log  n)
Binary Search Implementation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Search vs Sequential Search ,[object Object],[object Object],[object Object],[object Object],[object Object],Logs Base 2 is by far the most common in this course. Assume base 2 unless otherwise noted!  Small problems - we’re not interested!   Large problems - we’re interested in this gap!   n   log 2 n   ,[object Object],[object Object],[object Object]
Sorting ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Insertion Sort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9 A K 10 J 4 5  9   Q 2
Bubble Sort ,[object Object],[object Object],[object Object],[object Object],[object Object],/* Bubble sort for integers */ #define SWAP(a,b)  { int t; t=a; a=b; b=t; } void bubble( int a[], int n ) { int i, j;   for(i=0;i<n;i++) { /* n passes thru the array */ /* From start to the end of unsorted part */ for(j=1;j<(n-i);j++) { /* If adjacent items out of order, swap */     if( a[j-1]>a[j] ) SWAP(a[j-1],a[j]); }   } }  Overall  O(n 2 ) O( 1 )  statement Inner loop n -1,  n -2,  n -3, … , 1 iterations Outer loop  n  iterations
Partition Exchange or Quicksort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],< pivot > pivot pivot < pivot > pivot pivot < p’ p’ > p’ < p” p” > p”
Heap Sort ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Comparisons of Sorting ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hashing ,[object Object],[object Object],[object Object],[object Object]
Bucket Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Direct Access Table ,[object Object],[object Object],[object Object],[object Object]
Analysis of Bucket Arrays ,[object Object],[object Object],[object Object]
Hash Functions ,[object Object],[object Object],[object Object],[object Object],[object Object]
Handling the collisions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Chaining ,[object Object],[object Object]
Rehashing ,[object Object],[object Object]
Overflow ,[object Object],[object Object],[object Object],[object Object]
Comparisons
Graph ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Labeled Graphs:  We may give edges and vertices labels. Graphing applications often require the labeling of vertices Edges might also be numerically labeled. For instance if the vertices represent cities, the edges might be labeled to represent distances.
Graph Terminology ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Terminology ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Terminology ,[object Object],[object Object],[object Object]
Graph Terminology A E D C B F a c b d e f g h i j
Graph Terminology A E D C B F a c b d e f g h i j Vertices A and B are endpoints of edge a
Graph Terminology A E D C B F a c b d e f g h i j Vertex A is the origin of edge a
Graph Terminology A E D C B F a c b d e f g h i j Vertex B is the destination of edge a
Graph Terminology A E D C B F a c b d e f g h i j Vertices A and B are adjacent as they are endpoints of edge a
Graph Terminology ,[object Object],[object Object],[object Object]
Graph Terminology U Y X W V Z a c b d e f g h i j Edge 'a' is incident on vertex V Edge 'h' is incident on vertex Z Edge 'g' is incident on vertex Y
Graph Terminology U Y X W V Z a c b d e f g h i j The outgoing edges of vertex W are the edges with vertex W as origin {d, e, f}
Graph Terminology U Y X W V Z a c b d e f g h i j The incoming edges of vertex X are the edges with vertex X as destination {b, e, g, i}
Graph Terminology ,[object Object],[object Object],[object Object]
Graph Terminology U Y X W V Z a c b d e f g h i j The degree of vertex X is the number of incident  edges on X. deg(X) = ?
Graph Terminology U Y X W V Z a c b d e f g h i j The degree of vertex X is the number of incident  edges on X. deg(X) = 5
Graph Terminology U Y X W V Z a c b d e f g h i j The in-degree of vertex X is the number of edges that  have vertex X as a destination. indeg(X) = ?
Graph Terminology U Y X W V Z a c b d e f g h i j The in-degree of vertex X is the number of edges that  have vertex X as a destination. indeg(X) = 4
Graph Terminology U Y X W V Z a c b d e f g h i j The out-degree of vertex X is the number of edges that  have vertex X as an origin. outdeg(X) = ?
Graph Terminology U Y X W V Z a c b d e f g h i j The out-degree of vertex X is the number of edges that  have vertex X as an origin. outdeg(X) = 1
Graph Terminology ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Terminology U Y X W V Z a c b d e f g h i j We can see that P1 is  a simple path. P1 = {U, a, V, b, X, h, Z} P1
Graph Terminology U Y X W V Z a c b d e f g h i j P2 is not a simple path as not all its edges and  vertices are distinct. P2 = {U, c, W, e, X, g, Y, f, W, d, V}
Graph Terminology ,[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Terminology Simple cycle {U, a, V, b, X, g, Y, f, W, c} U Y X W V Z a c b d e f g h i j
Graph Terminology U Y X W V Z a c b d e f g h i j Non-Simple Cycle {U, c, W, e, X, g, Y, f, W, d, V, a}
Graph Properties
Graph Representation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graph Applications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reachability ,[object Object],[object Object],[object Object]
Graphs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Depth First Search Algorithim DFS() Input graph G Output labeling of the edges of G as discovery edges and back edges for all u in G.vertices() setLabel(u, Unexplored) for all e in G.incidentEdges() setLabel(e, Unexplored)  for all v in G.vertices() if getLabel(v) = Unexplored   DFS(G, v).
Algorithm DFS(G, v)  Input graph G and a start vertex v of G Output labeling of the edges of G as  discovery edges and back edges setLabel(v, Visited) for all e in G.incidentEdges(v) if getLabel(e) = Unexplored w <--- opposite(v, e) if getLabel(w) = Unexplored setLabel(e, Discovery) DFS(G, w) else setLabel(e, BackEdge)
Depth First Search A A Unexplored Vertex Visited Vertex Unexplored Edge Discovery Edge Back Edge
A E D C B Start At Vertex A
A E D C B Discovery Edge
A E D C B Visited Vertex B
A E D C B Discovery Edge
A E D C B Visited Vertex C
A E D C B Back Edge
A E D C B Discovery Edge
A E D C B Visited Vertex D
A E D C B Back Edge
A E D C B Discovery Edge
A E D C B Visited Vertex E
A E D C B Discovery Edge
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
P J I M L F E N H G K O D C B A
Breadth First Search   Algorithm BFS(G) Input graph G Output labeling of the edges and a partitioning of the vertices of G for all u in G.vertices() setLabel(u, Unexplored) for all e in G.edges() setLabel(e, Unexplored) for all v in G.vertices() if getLabel(v) = Unexplored BFS(G, v)
Algorithm BFS(G, v) L 0  <-- new empty list L0.insertLast (v) setLabel(v, Visited) i <-- 0 while( ¬L i.isEmpty()) L i+1  <-- new empty list for all v in G.vertices(v) for all e in G.incidentEdges(v) if getLabel(e) = Unexplored w <-- opposite(v) if getLabel(w) = Unexplored setLabel(e, Discovery) setLabel(w, Visited) Li+1.insertLast (w) else setLabel(e, Cross) i <-- i + 1
A E F B C D
A E F B C D Start Vertex A Create a sequence L 0 insert(A) into L 0
A E F B C D Start Vertex A while L 0  is not empty create a new empty list L 1 L 0
A E F B C D Start Vertex A for each v in L 0  do get incident edges of v L 0
A E F B C D Start Vertex A if first incident edge is unexplored get opposite of v, say w if w is unexplored set edge as discovery  L 0
A E F B C D Start Vertex A set vertex w as visited and insert(w) into L 1   L 0 L 1
A E F B C D Start Vertex A get next incident edge L 0 L 1
A E F B C D Start Vertex A if edge is unexplored we get vertex opposite v  say w, if w is unexplored L 0 L 1
A E F B C D Start Vertex A if w is unexplored set edge as discovery L 0 L 1
A E F B C D Start Vertex A set w as visited and add w to L 1 L 0 L 1
A E F B C D Start Vertex A continue in this fashion until we have visited all incident edge of v L 0 L 1
A E F B C D Start Vertex A continue in this fashion until we have visited all incident edge of v L 0 L 1
A E F B C D Start Vertex A as L 0  is now empty we continue with list L 1 L 0 L 1
A E F B C D Start Vertex A as L 0  is now empty we continue with list L 1 L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D Start Vertex A L 0 L 1 L 2
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
A E F B C D
Weighted Graphs ,[object Object],[object Object],[object Object]
Shortest Paths ,[object Object],[object Object]
Dijkstra's Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dijkstra's Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object]
Edge Relaxation ,[object Object],[object Object],[object Object],[object Object],[object Object]
A D C B F E 8 4 2 1 7 5 9 3 2
A(0) D C B F E 8 4 2 1 7 5 9 3 2 Add starting vertex to cloud.
A(0) D C B F E 8 4 2 1 7 5 9 3 2 We store with each vertex v a label d(v) representing  the distance of v from s in the subgraph consisting  of the cloud and its adjacent vertices.
A(0) D(4) C(2) B(8) F E 8 4 2 1 7 5 9 3 2 We store with each vertex v a label d(v) representing  the distance of v from s in the subgraph consisting  of the cloud and its adjacent vertices.
A(0) D(4) C(2) B(8) F E 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud  with the smallest distance label d(v).
A(0) D(3) C(2) B(8) F(11) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}
A(0) D(3) C(2) B(8) F(11) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud  with the smallest distance label d(v).
A(0) D(3) C(2) B(8) F(8) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}.
A(0) D(3) C(2) B(8) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud  with the smallest distance label d(v).
A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}.
A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud  with the smallest distance label d(v).
A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud  with the smallest distance label d(v).
2 2 1 6 7 7 4 2 3 3 2 2 E G B A D H C F
2 2 1 6 7 7 4 2 3 3 2 2 Insert E G B A(0) D H C F
2 2 1 6 7 7 4 2 3 3 2 2 Update E G(6) B(2) A(0) D H C F
2 2 1 6 7 7 4 2 3 3 2 2 Insert E G(6) B(2) A(0) D H C F
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(6) B(2) A(0) D H C(9) F
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(6) B(2) A(0) D H C(9) F
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H(9) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H(9) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H(8) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H(8) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
Thank You

Contenu connexe

Tendances

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure pptNalinNishant3
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Muhammad Hammad Waseem
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahniHitesh Wagle
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Circular linked list
Circular linked listCircular linked list
Circular linked listchauhankapil
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
data structure
data structuredata structure
data structurehashim102
 

Tendances (20)

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Linked lists
Linked listsLinked lists
Linked lists
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
data structure
data structuredata structure
data structure
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 

En vedette

DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structureeShikshak
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and AlgorithmsPierre Vigneras
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 
Dna recombinant technology
Dna recombinant technologyDna recombinant technology
Dna recombinant technologyHama Nabaz
 
Quality control circle presentation
Quality control circle presentationQuality control circle presentation
Quality control circle presentationGanesh Murugan
 
Society, Culture and Family Planning with Population Education
Society, Culture and Family Planning with Population EducationSociety, Culture and Family Planning with Population Education
Society, Culture and Family Planning with Population EducationMylene Almario
 
Deep Learning through Examples
Deep Learning through ExamplesDeep Learning through Examples
Deep Learning through ExamplesSri Ambati
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its typesRameesha Sadaqat
 
Mac OS(Operating System)
Mac OS(Operating System)Mac OS(Operating System)
Mac OS(Operating System)Faizan Shaikh
 
OTN for Beginners
OTN for BeginnersOTN for Beginners
OTN for BeginnersMapYourTech
 
Pharmaceuticals Solutions dosage form
Pharmaceuticals Solutions dosage formPharmaceuticals Solutions dosage form
Pharmaceuticals Solutions dosage formUmair hanif
 
Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4jNeo4j
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 

En vedette (20)

DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Data Structure
Data StructureData Structure
Data Structure
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
Dna recombinant technology
Dna recombinant technologyDna recombinant technology
Dna recombinant technology
 
Quality control circle presentation
Quality control circle presentationQuality control circle presentation
Quality control circle presentation
 
Society, Culture and Family Planning with Population Education
Society, Culture and Family Planning with Population EducationSociety, Culture and Family Planning with Population Education
Society, Culture and Family Planning with Population Education
 
Deep Learning through Examples
Deep Learning through ExamplesDeep Learning through Examples
Deep Learning through Examples
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Mac OS(Operating System)
Mac OS(Operating System)Mac OS(Operating System)
Mac OS(Operating System)
 
OTN for Beginners
OTN for BeginnersOTN for Beginners
OTN for Beginners
 
Pharmaceuticals Solutions dosage form
Pharmaceuticals Solutions dosage formPharmaceuticals Solutions dosage form
Pharmaceuticals Solutions dosage form
 
Data Modeling with Neo4j
Data Modeling with Neo4jData Modeling with Neo4j
Data Modeling with Neo4j
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 

Similaire à Fundamentals of data structures

Similaire à Fundamentals of data structures (20)

Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02Fundamentalsofdatastructures 110501104205-phpapp02
Fundamentalsofdatastructures 110501104205-phpapp02
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Data structure
 Data structure Data structure
Data structure
 
Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
List
ListList
List
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Data structure
Data  structureData  structure
Data structure
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
Data structure
Data structureData structure
Data structure
 
DS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docxDS UNIT5_BINARY TREES.docx
DS UNIT5_BINARY TREES.docx
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Ch02
Ch02Ch02
Ch02
 

Plus de Niraj Agarwal

Pmp refresher know the exam
Pmp refresher   know the examPmp refresher   know the exam
Pmp refresher know the examNiraj Agarwal
 
Pm deep dive time management
Pm deep dive   time managementPm deep dive   time management
Pm deep dive time managementNiraj Agarwal
 
Pm deep dive the processes
Pm deep dive   the processesPm deep dive   the processes
Pm deep dive the processesNiraj Agarwal
 
Pm deep dive the framework
Pm deep dive   the frameworkPm deep dive   the framework
Pm deep dive the frameworkNiraj Agarwal
 
Pm deep dive risk management
Pm deep dive   risk managementPm deep dive   risk management
Pm deep dive risk managementNiraj Agarwal
 
Pm deep dive quality management
Pm deep dive   quality managementPm deep dive   quality management
Pm deep dive quality managementNiraj Agarwal
 
Pm deep dive integration management
Pm deep dive   integration managementPm deep dive   integration management
Pm deep dive integration managementNiraj Agarwal
 
Pm deep dive hr - comm - procurement - pr
Pm deep dive   hr - comm - procurement - prPm deep dive   hr - comm - procurement - pr
Pm deep dive hr - comm - procurement - prNiraj Agarwal
 
Pm deep dive cost management
Pm deep dive   cost managementPm deep dive   cost management
Pm deep dive cost managementNiraj Agarwal
 
Pm deep dive scope management
Pm deep dive   scope managementPm deep dive   scope management
Pm deep dive scope managementNiraj Agarwal
 

Plus de Niraj Agarwal (11)

Pmp refresher know the exam
Pmp refresher   know the examPmp refresher   know the exam
Pmp refresher know the exam
 
Pm deep dive time management
Pm deep dive   time managementPm deep dive   time management
Pm deep dive time management
 
Pm deep dive the processes
Pm deep dive   the processesPm deep dive   the processes
Pm deep dive the processes
 
Pm deep dive the framework
Pm deep dive   the frameworkPm deep dive   the framework
Pm deep dive the framework
 
Pm deep dive risk management
Pm deep dive   risk managementPm deep dive   risk management
Pm deep dive risk management
 
Pm deep dive quality management
Pm deep dive   quality managementPm deep dive   quality management
Pm deep dive quality management
 
Pm deep dive integration management
Pm deep dive   integration managementPm deep dive   integration management
Pm deep dive integration management
 
Pm deep dive hr - comm - procurement - pr
Pm deep dive   hr - comm - procurement - prPm deep dive   hr - comm - procurement - pr
Pm deep dive hr - comm - procurement - pr
 
Pm deep dive cost management
Pm deep dive   cost managementPm deep dive   cost management
Pm deep dive cost management
 
Pm deep dive scope management
Pm deep dive   scope managementPm deep dive   scope management
Pm deep dive scope management
 
Corporate Etiquette
Corporate EtiquetteCorporate Etiquette
Corporate Etiquette
 

Dernier

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 

Dernier (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

Fundamentals of data structures

  • 1. Fundamentals of Data Structure - Niraj Agarwal
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Arrays (Cont.) Multi-dimensional Array A multi-dimensional array   of dimension n (i.e., an n -dimensional array or simply n -D array) is a collection of items which is accessed via n subscript expressions. For example, in a language that supports it, the (i,j) th element of the two-dimensional array x is accessed by writing x[i,j]. m x i : : : : : : : : : : : : : : : 2 1 0 n j 10 9 8 7 6 5 4 3 2 1 0 C o l u m n R O W
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Binary Tree - Implementation struct t_node { void *item; struct t_node *left; struct t_node *right; }; typedef struct t_node *Node; struct t_collection { Node root; …… };
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Comparisons Arrays Simple, fast Inflexible O(1) O(n) inc sort O(n) O(n) O(logn) binary search Add Delete Find Linked List Simple Flexible O(1) sort -> no adv O(1) - any O(n) - specific O(n) (no bin search) Trees Still Simple Flexible O(log n) O(log n) O(log n)
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59. Graph Terminology A E D C B F a c b d e f g h i j
  • 60. Graph Terminology A E D C B F a c b d e f g h i j Vertices A and B are endpoints of edge a
  • 61. Graph Terminology A E D C B F a c b d e f g h i j Vertex A is the origin of edge a
  • 62. Graph Terminology A E D C B F a c b d e f g h i j Vertex B is the destination of edge a
  • 63. Graph Terminology A E D C B F a c b d e f g h i j Vertices A and B are adjacent as they are endpoints of edge a
  • 64.
  • 65. Graph Terminology U Y X W V Z a c b d e f g h i j Edge 'a' is incident on vertex V Edge 'h' is incident on vertex Z Edge 'g' is incident on vertex Y
  • 66. Graph Terminology U Y X W V Z a c b d e f g h i j The outgoing edges of vertex W are the edges with vertex W as origin {d, e, f}
  • 67. Graph Terminology U Y X W V Z a c b d e f g h i j The incoming edges of vertex X are the edges with vertex X as destination {b, e, g, i}
  • 68.
  • 69. Graph Terminology U Y X W V Z a c b d e f g h i j The degree of vertex X is the number of incident edges on X. deg(X) = ?
  • 70. Graph Terminology U Y X W V Z a c b d e f g h i j The degree of vertex X is the number of incident edges on X. deg(X) = 5
  • 71. Graph Terminology U Y X W V Z a c b d e f g h i j The in-degree of vertex X is the number of edges that have vertex X as a destination. indeg(X) = ?
  • 72. Graph Terminology U Y X W V Z a c b d e f g h i j The in-degree of vertex X is the number of edges that have vertex X as a destination. indeg(X) = 4
  • 73. Graph Terminology U Y X W V Z a c b d e f g h i j The out-degree of vertex X is the number of edges that have vertex X as an origin. outdeg(X) = ?
  • 74. Graph Terminology U Y X W V Z a c b d e f g h i j The out-degree of vertex X is the number of edges that have vertex X as an origin. outdeg(X) = 1
  • 75.
  • 76. Graph Terminology U Y X W V Z a c b d e f g h i j We can see that P1 is a simple path. P1 = {U, a, V, b, X, h, Z} P1
  • 77. Graph Terminology U Y X W V Z a c b d e f g h i j P2 is not a simple path as not all its edges and vertices are distinct. P2 = {U, c, W, e, X, g, Y, f, W, d, V}
  • 78.
  • 79. Graph Terminology Simple cycle {U, a, V, b, X, g, Y, f, W, c} U Y X W V Z a c b d e f g h i j
  • 80. Graph Terminology U Y X W V Z a c b d e f g h i j Non-Simple Cycle {U, c, W, e, X, g, Y, f, W, d, V, a}
  • 82.
  • 83.
  • 84.
  • 85.
  • 86. Depth First Search Algorithim DFS() Input graph G Output labeling of the edges of G as discovery edges and back edges for all u in G.vertices() setLabel(u, Unexplored) for all e in G.incidentEdges() setLabel(e, Unexplored) for all v in G.vertices() if getLabel(v) = Unexplored DFS(G, v).
  • 87. Algorithm DFS(G, v) Input graph G and a start vertex v of G Output labeling of the edges of G as discovery edges and back edges setLabel(v, Visited) for all e in G.incidentEdges(v) if getLabel(e) = Unexplored w <--- opposite(v, e) if getLabel(w) = Unexplored setLabel(e, Discovery) DFS(G, w) else setLabel(e, BackEdge)
  • 88. Depth First Search A A Unexplored Vertex Visited Vertex Unexplored Edge Discovery Edge Back Edge
  • 89. A E D C B Start At Vertex A
  • 90. A E D C B Discovery Edge
  • 91. A E D C B Visited Vertex B
  • 92. A E D C B Discovery Edge
  • 93. A E D C B Visited Vertex C
  • 94. A E D C B Back Edge
  • 95. A E D C B Discovery Edge
  • 96. A E D C B Visited Vertex D
  • 97. A E D C B Back Edge
  • 98. A E D C B Discovery Edge
  • 99. A E D C B Visited Vertex E
  • 100. A E D C B Discovery Edge
  • 101. P J I M L F E N H G K O D C B A
  • 102. P J I M L F E N H G K O D C B A
  • 103. P J I M L F E N H G K O D C B A
  • 104. P J I M L F E N H G K O D C B A
  • 105. P J I M L F E N H G K O D C B A
  • 106. P J I M L F E N H G K O D C B A
  • 107. P J I M L F E N H G K O D C B A
  • 108. P J I M L F E N H G K O D C B A
  • 109. P J I M L F E N H G K O D C B A
  • 110. P J I M L F E N H G K O D C B A
  • 111. Breadth First Search Algorithm BFS(G) Input graph G Output labeling of the edges and a partitioning of the vertices of G for all u in G.vertices() setLabel(u, Unexplored) for all e in G.edges() setLabel(e, Unexplored) for all v in G.vertices() if getLabel(v) = Unexplored BFS(G, v)
  • 112. Algorithm BFS(G, v) L 0 <-- new empty list L0.insertLast (v) setLabel(v, Visited) i <-- 0 while( ¬L i.isEmpty()) L i+1 <-- new empty list for all v in G.vertices(v) for all e in G.incidentEdges(v) if getLabel(e) = Unexplored w <-- opposite(v) if getLabel(w) = Unexplored setLabel(e, Discovery) setLabel(w, Visited) Li+1.insertLast (w) else setLabel(e, Cross) i <-- i + 1
  • 113. A E F B C D
  • 114. A E F B C D Start Vertex A Create a sequence L 0 insert(A) into L 0
  • 115. A E F B C D Start Vertex A while L 0 is not empty create a new empty list L 1 L 0
  • 116. A E F B C D Start Vertex A for each v in L 0 do get incident edges of v L 0
  • 117. A E F B C D Start Vertex A if first incident edge is unexplored get opposite of v, say w if w is unexplored set edge as discovery L 0
  • 118. A E F B C D Start Vertex A set vertex w as visited and insert(w) into L 1 L 0 L 1
  • 119. A E F B C D Start Vertex A get next incident edge L 0 L 1
  • 120. A E F B C D Start Vertex A if edge is unexplored we get vertex opposite v say w, if w is unexplored L 0 L 1
  • 121. A E F B C D Start Vertex A if w is unexplored set edge as discovery L 0 L 1
  • 122. A E F B C D Start Vertex A set w as visited and add w to L 1 L 0 L 1
  • 123. A E F B C D Start Vertex A continue in this fashion until we have visited all incident edge of v L 0 L 1
  • 124. A E F B C D Start Vertex A continue in this fashion until we have visited all incident edge of v L 0 L 1
  • 125. A E F B C D Start Vertex A as L 0 is now empty we continue with list L 1 L 0 L 1
  • 126. A E F B C D Start Vertex A as L 0 is now empty we continue with list L 1 L 0 L 1 L 2
  • 127. A E F B C D Start Vertex A L 0 L 1 L 2
  • 128. A E F B C D Start Vertex A L 0 L 1 L 2
  • 129. A E F B C D Start Vertex A L 0 L 1 L 2
  • 130. A E F B C D Start Vertex A L 0 L 1 L 2
  • 131. A E F B C D Start Vertex A L 0 L 1 L 2
  • 132. A E F B C D Start Vertex A L 0 L 1 L 2
  • 133. A E F B C D
  • 134. A E F B C D
  • 135. A E F B C D
  • 136. A E F B C D
  • 137. A E F B C D
  • 138. A E F B C D
  • 139. A E F B C D
  • 140. A E F B C D
  • 141. A E F B C D
  • 142. A E F B C D
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148. A D C B F E 8 4 2 1 7 5 9 3 2
  • 149. A(0) D C B F E 8 4 2 1 7 5 9 3 2 Add starting vertex to cloud.
  • 150. A(0) D C B F E 8 4 2 1 7 5 9 3 2 We store with each vertex v a label d(v) representing the distance of v from s in the subgraph consisting of the cloud and its adjacent vertices.
  • 151. A(0) D(4) C(2) B(8) F E 8 4 2 1 7 5 9 3 2 We store with each vertex v a label d(v) representing the distance of v from s in the subgraph consisting of the cloud and its adjacent vertices.
  • 152. A(0) D(4) C(2) B(8) F E 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud with the smallest distance label d(v).
  • 153. A(0) D(3) C(2) B(8) F(11) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}
  • 154. A(0) D(3) C(2) B(8) F(11) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud with the smallest distance label d(v).
  • 155. A(0) D(3) C(2) B(8) F(8) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}.
  • 156. A(0) D(3) C(2) B(8) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud with the smallest distance label d(v).
  • 157. A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 We update the vertices adjacent to v. d(v) = min{d(z), d(v) + weight(e)}.
  • 158. A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud with the smallest distance label d(v).
  • 159. A(0) D(3) C(2) B(7) F(8) E(5) 8 4 2 1 7 5 9 3 2 At each step we add to the cloud the vertex outside the cloud with the smallest distance label d(v).
  • 160. 2 2 1 6 7 7 4 2 3 3 2 2 E G B A D H C F
  • 161. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E G B A(0) D H C F
  • 162. 2 2 1 6 7 7 4 2 3 3 2 2 Update E G(6) B(2) A(0) D H C F
  • 163. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E G(6) B(2) A(0) D H C F
  • 164. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(6) B(2) A(0) D H C(9) F
  • 165. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(6) B(2) A(0) D H C(9) F
  • 166. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H C(9) F(6)
  • 167. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H C(9) F(6)
  • 168. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H(9) C(9) F(6)
  • 169. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H(9) C(9) F(6)
  • 170. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D H(8) C(9) F(6)
  • 171. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D H(8) C(9) F(6)
  • 172. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
  • 173. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
  • 174. 2 2 1 6 7 7 4 2 3 3 2 2 Update E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)
  • 175. 2 2 1 6 7 7 4 2 3 3 2 2 Insert E(4) G(5) B(2) A(0) D(10) H(8) C(9) F(6)