SlideShare a Scribd company logo
1 of 86
Trees and Graphs Trees, Binary Search Trees, Balanced Trees, Graphs ,[object Object],[object Object],[object Object]
Table of Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tree-like Data Structures Trees, Balanced Trees, Graphs, Networks
Tree-like Data Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tree-like Data Structures Tree Graph 2 3 6 1 4 5 5   (20) 5   (10) 15   (15) 15   (30) 5   (5) 20(20) 10   (40) Network Project Manager Team Leader De-signer QA Team Leader Developer  1 Developer 2 Tester 1 Developer 3 Tester 2 7 19 21 14 1 12 31 4 11
Trees and Related Terminology Node, Edge, Root, Children, Parent, Leaf , Binary Search Tree, Balanced Tree
Trees ,[object Object],[object Object],Height = 2 Depth 0 Depth 1 Depth 2 17 15 14 9 6 5 8
Binary Trees ,[object Object],[object Object],10 17 15 9 6 5 8 Root node Left subtree Right child Right child Left child
Binary Search Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Search Trees (2) ,[object Object],[object Object],17 19 9 6 12 25
Implementing Trees Recursive Tree Data Structure
Recursive Tree Definition ,[object Object],[object Object],[object Object],[object Object],public class TreeNode<T> { private T value; private List<TreeNode<T>> children; … } The value contained in the node List of child nodes, which are of the same type
TreeNode<int>  Structure TreeNode<int> int value List<TreeNode<int>> children 7 children 19 children 21 children 14 children 1 children 12 children 31 children 23 children 6 children
Implementing  TreeNode <T> public TreeNode(T value) { this.value = value; this.children = new List<TreeNode<T>>(); } public T Value { get { return this.value; } set { this.value = value; } } public void AddChild(TreeNode<T> child) { child.hasParent = true; this.children.Add(child); } public TreeNode<T> GetChild(int index) { return this.children[index]; }
[object Object],Implementing  Tree<T> public class Tree<T> { private TreeNode<T> root; public Tree(T value, params Tree<T>[] children): this(value) { foreach (Tree<T> child in children) { this.root.AddChild(child.root); } } public TreeNode<T> Root { get {  return this.root; } } } Flexible constructor for building trees
Building a Tree ,[object Object],Tree<int> tree = new Tree<int>(7, new Tree<int>(19, new Tree<int>(1), new Tree<int>(12), new Tree<int>(31)), new Tree<int>(21), new Tree<int>(14, new Tree<int>(23), new Tree<int>(6)) ); 7 14 19 23 6 21 31 1 12
Tree Traversals DFS and BFS Traversals
Tree Traversal Algorithms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],Depth-First  Search (DFS) DFS(node) { for each child  c  of node DFS( c ); print the current node; } 1 2 3 4 5 8 6 7 9 7 14 19 23 6 21 31 1 12
DFS in Action (Step  1 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  2 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  3 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  4 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  5 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  6 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  7 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  8 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  9 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  10 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  11 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  12 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  13 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  14 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  15 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  16 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  17 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
DFS in Action (Step  18 ) ,[object Object],[object Object],Traversal finished 7 14 19 23 6 21 31 1 12
[object Object],[object Object],Breadth-First  Search (BFS) BFS(node) { queue    node while queue not empty v     queue print v for each child  c  of  v queue     c } 5 6 7 2 3 4 8 9 1 7 14 19 23 6 21 31 1 12
BFS in Action (Step  1 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  2 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  3 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  4 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  5 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  6 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  7 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  8 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  9 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  10 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  11 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  12 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  13 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  14 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  15 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  16 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  16 ) ,[object Object],[object Object],7 14 19 23 6 21 31 1 12
BFS in Action (Step  17 ) ,[object Object],[object Object],The queue is empty    stop 7 14 19 23 6 21 31 1 12
Binary Trees   DFS Traversals ,[object Object],[object Object],[object Object],[object Object],17 19 9 6 12 25
Iterative DFS and BFS ,[object Object],[object Object],BFS(node) { queue    node while queue not empty v     queue print v for each child  c  of  v queue     c } DFS(node) { stack    node while stack not empty v     stack print v for each child  c  of  v stack     c }
Trees and Traversals Live Demo
Balanced Search Trees AVL Trees, B-Trees, Red-Black Trees, AA-Trees
Balanced Binary Search Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Balanced Binary Search Tree – Example 33 18 15 24 3 17 20 29 54 42 60 37 43 59 85
Balanced Binary Search Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
B-Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],B-Tree – Example 17 21 7 11 18 20 26 31 2 4 5 6 8 9 12 16 22 23 25 27 29 30 32 35
Balanced Trees in .NET ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Graphs Definitions, Representation, Traversal Algorithms
Graph Data Structure ,[object Object],[object Object],[object Object],Node with multiple predecessors Node with multiple successors 7 19 21 14 1 12 31 4 11
Graph Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A Node A Edge B
Graph Definitions (2) ,[object Object],[object Object],[object Object],[object Object],7 19 21 1 12 4 3 22 2 3 G J F D A E C H
Graph Definitions (3) ,[object Object],[object Object],3 G J F D A E C H Q K N 10 4 14 6 16 9 8 7 5 22
Graph Definitions (4) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],G C B A H N K
Graph Definitions (5) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],G C B A H N K
Graph Definitions (6) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],G C B A H N K
Graph Definitions (8) ,[object Object],[object Object],[object Object],[object Object],Unconnected graph with two connected components G J F D A Connected graph G J F D A E C H
Graphs and Their Applications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Representing Graphs ,[object Object],[object Object],[object Object],[object Object],[object Object],1 2 3 4 1 2 3 4 {1,2} {1,4} {2,3} {3,1} {4,2} 1    {2, 4} 2    {3} 3    {1} 4    {2} 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 0 2 4 1 3
Representing Graphs in C# public class Graph { int[][] childNodes; public Graph(int[][] nodes) { this.childNodes = nodes; } } Graph g = new Graph(new int[][] { new int[] {3, 6}, // successors of vertice 0 new int[] {2, 3, 4, 5, 6}, // successors of vertice 1 new int[] {1, 4, 5}, // successors of vertice 2 new int[] {0, 1, 5}, // successors of vertice 3 new int[] {1, 2, 6}, // successors of vertice 4 new int[] {1, 2, 3}, // successors of vertice 5 new int[] {0, 1, 4}  // successors of vertice 6 }); 0 6 4 1 5 2 3
Graph Traversal Algorithms ,[object Object],[object Object],BFS( node ) { queue     node visited[ node ] = true while queue not empty v     queue print  v for each child  c  of  v if not visited[ c ] queue     c visited[ c ] = true } DFS( node ) { stack     node visited[ node ] = true while stack not empty v     stack print  v for each child  c  of  v if not visited[ c ] stack     c visited[ c ] = true }
Recursive DFS Graph Traversal void TraverseDFSRecursive(node) { if (not visited[node]) { visited[node] = true print node foreach child node  c  of node { TraverseDFSRecursive( c ); } } } vois Main() { TraverseDFS(firstNode); }
Graphs and Traversals Live Demo
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Trees and Graphs ,[object Object],http://academy.telerik.com
Exercises ,[object Object],[object Object]
Exercises (2) ,[object Object],[object Object],[object Object],[object Object]
Exercises (3) ,[object Object],[object Object],[object Object]

More Related Content

What's hot (20)

Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Tree and graph
Tree and graphTree and graph
Tree and graph
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Topological Sort
Topological SortTopological Sort
Topological Sort
 
Dfs
DfsDfs
Dfs
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Data structure tries
Data structure triesData structure tries
Data structure tries
 
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
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Red black tree
Red black treeRed black tree
Red black tree
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 

Viewers also liked

14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course IntroductionIntro C# Book
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesKumar Avinash
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms masterHossam Hassan
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first searchHossain Md Shakhawat
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchchandsek666
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Searchbutest
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Shanawaz Ahamed
 
Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionMohamed Gad
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm
 

Viewers also liked (18)

14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
130210107039 2130702
130210107039 2130702130210107039 2130702
130210107039 2130702
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) search
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)Linear and Binary Search Algorithms.(Discrete Mathematics)
Linear and Binary Search Algorithms.(Discrete Mathematics)
 
Application of dfs
Application of dfsApplication of dfs
Application of dfs
 
Hillclimbing search algorthim #introduction
Hillclimbing search algorthim #introductionHillclimbing search algorthim #introduction
Hillclimbing search algorthim #introduction
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQL
 

Similar to 17. Trees and Graphs

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversalIntro C# Book
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphsmaznabili
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptxRedHeart11
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataAnalyticsWeek
 
RSX™ Best Practices
RSX™ Best PracticesRSX™ Best Practices
RSX™ Best PracticesSlide_N
 
Visualization of Supervised Learning with {arules} + {arulesViz}
Visualization of Supervised Learning with {arules} + {arulesViz}Visualization of Supervised Learning with {arules} + {arulesViz}
Visualization of Supervised Learning with {arules} + {arulesViz}Takashi J OZAKI
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like StructuresIntro C# Book
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharyaJash Acharya
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
bca data structure
bca data structurebca data structure
bca data structureshini
 
8. Recursion.pptx
8. Recursion.pptx8. Recursion.pptx
8. Recursion.pptxAbid523408
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraEric Normand
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...venkatapranaykumarGa
 
lecture 17
lecture 17lecture 17
lecture 17sajinsc
 

Similar to 17. Trees and Graphs (16)

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
Traversals | Data Structures
Traversals | Data StructuresTraversals | Data Structures
Traversals | Data Structures
 
Lecture_10 - Revised.pptx
Lecture_10 - Revised.pptxLecture_10 - Revised.pptx
Lecture_10 - Revised.pptx
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigData
 
RSX™ Best Practices
RSX™ Best PracticesRSX™ Best Practices
RSX™ Best Practices
 
Visualization of Supervised Learning with {arules} + {arulesViz}
Visualization of Supervised Learning with {arules} + {arulesViz}Visualization of Supervised Learning with {arules} + {arulesViz}
Visualization of Supervised Learning with {arules} + {arulesViz}
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
B tree by-jash acharya
B tree by-jash acharyaB tree by-jash acharya
B tree by-jash acharya
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
bca data structure
bca data structurebca data structure
bca data structure
 
Binary Trees
Binary TreesBinary Trees
Binary Trees
 
8. Recursion.pptx
8. Recursion.pptx8. Recursion.pptx
8. Recursion.pptx
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School Algebra
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
 
lecture 17
lecture 17lecture 17
lecture 17
 

More from Intro C# Book

Java Problem solving
Java Problem solving Java Problem solving
Java Problem solving Intro C# Book
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming CodeIntro C# Book
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism Intro C# Book
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstractionIntro C# Book
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritanceIntro C# Book
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexityIntro C# Book
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arraysIntro C# Book
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queuesIntro C# Book
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classesIntro C# Book
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processingIntro C# Book
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handlingIntro C# Book
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classesIntro C# Book
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variablesIntro C# Book
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with javaIntro C# Book
 

More from Intro C# Book (20)

Java Problem solving
Java Problem solving Java Problem solving
Java Problem solving
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming Code
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with java
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

17. Trees and Graphs

  • 1.
  • 2.
  • 3. Tree-like Data Structures Trees, Balanced Trees, Graphs, Networks
  • 4.
  • 5. Tree-like Data Structures Tree Graph 2 3 6 1 4 5 5 (20) 5 (10) 15 (15) 15 (30) 5 (5) 20(20) 10 (40) Network Project Manager Team Leader De-signer QA Team Leader Developer 1 Developer 2 Tester 1 Developer 3 Tester 2 7 19 21 14 1 12 31 4 11
  • 6. Trees and Related Terminology Node, Edge, Root, Children, Parent, Leaf , Binary Search Tree, Balanced Tree
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Implementing Trees Recursive Tree Data Structure
  • 12.
  • 13. TreeNode<int> Structure TreeNode<int> int value List<TreeNode<int>> children 7 children 19 children 21 children 14 children 1 children 12 children 31 children 23 children 6 children
  • 14. Implementing TreeNode <T> public TreeNode(T value) { this.value = value; this.children = new List<TreeNode<T>>(); } public T Value { get { return this.value; } set { this.value = value; } } public void AddChild(TreeNode<T> child) { child.hasParent = true; this.children.Add(child); } public TreeNode<T> GetChild(int index) { return this.children[index]; }
  • 15.
  • 16.
  • 17. Tree Traversals DFS and BFS Traversals
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59. Trees and Traversals Live Demo
  • 60. Balanced Search Trees AVL Trees, B-Trees, Red-Black Trees, AA-Trees
  • 61.
  • 62. Balanced Binary Search Tree – Example 33 18 15 24 3 17 20 29 54 42 60 37 43 59 85
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. Graphs Definitions, Representation, Traversal Algorithms
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. Representing Graphs in C# public class Graph { int[][] childNodes; public Graph(int[][] nodes) { this.childNodes = nodes; } } Graph g = new Graph(new int[][] { new int[] {3, 6}, // successors of vertice 0 new int[] {2, 3, 4, 5, 6}, // successors of vertice 1 new int[] {1, 4, 5}, // successors of vertice 2 new int[] {0, 1, 5}, // successors of vertice 3 new int[] {1, 2, 6}, // successors of vertice 4 new int[] {1, 2, 3}, // successors of vertice 5 new int[] {0, 1, 4} // successors of vertice 6 }); 0 6 4 1 5 2 3
  • 79.
  • 80. Recursive DFS Graph Traversal void TraverseDFSRecursive(node) { if (not visited[node]) { visited[node] = true print node foreach child node c of node { TraverseDFSRecursive( c ); } } } vois Main() { TraverseDFS(firstNode); }
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.

Editor's Notes

  1. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  2. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  3. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  4. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  5. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  6. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  7. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  8. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  9. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  10. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  11. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  12. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  13. * (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##