SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxEllenGrace9
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy TutorialAfzal Badshah
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its FundamentalsHitesh Mohapatra
 
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
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structuresDurgaDeviCbit
 

Mais procurados (20)

Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its Fundamentals
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Priority queues
Priority queuesPriority queues
Priority queues
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 

Destaque

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
 

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

Semelhante a Fundamentals of Data Structures - Arrays, Linked Lists, Binary Trees

Semelhante a Fundamentals of Data Structures - Arrays, Linked Lists, Binary Trees (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
 

Mais 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
 

Mais 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

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Fundamentals of Data Structures - Arrays, Linked Lists, Binary Trees

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