SlideShare una empresa de Scribd logo
1 de 176
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure NUPOORAWSARMOL
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 

La actualidad más candente (20)

Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Linked list
Linked list Linked list
Linked list
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
linked list
linked list linked list
linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Red black tree
Red black treeRed black tree
Red black tree
 
Linked list
Linked listLinked list
Linked list
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 

Destacado

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
 

Destacado (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++
 

Similar a Fundamentals of data structures

Similar a 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
 
Linked list
Linked listLinked list
Linked list
 
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
 

Más 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
 

Más 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
 

Último

EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlDr. Bruce A. Johnson
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustSavipriya Raghavendra
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxCapitolTechU
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17Celine George
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxraviapr7
 
3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptxmary850239
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...M56BOOKSTORE PRODUCT/SERVICE
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTDR. SNEHA NAIR
 
How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17Celine George
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 

Último (20)

Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting Bl
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptx
 
3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
 
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic SupportMarch 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
 
How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 

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)