SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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 Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its FundamentalsHitesh Mohapatra
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure pptNalinNishant3
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSAjunnubabu
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-SortTareq Hasan
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
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
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Anand Ingle
 

Was ist angesagt? (20)

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
 
Indexing Data Structure
Indexing Data StructureIndexing Data Structure
Indexing Data Structure
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its Fundamentals
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Linked lists
Linked listsLinked lists
Linked lists
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
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
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 

Andere mochten auch

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
 

Andere mochten auch (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++
 

Ähnlich wie Fundamentals of Data Structures - Arrays, Linked Lists, Binary Trees

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Kürzlich hochgeladen (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

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)