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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Red black tree
Red black treeRed black tree
Red black tree
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
FORESTS
FORESTSFORESTS
FORESTS
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Time complexity
Time complexityTime complexity
Time complexity
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 

Destaque

Ch2 3-informed (heuristic) search
Ch2 3-informed (heuristic) searchCh2 3-informed (heuristic) search
Ch2 3-informed (heuristic) search
chandsek666
 
Heuristic Search
Heuristic SearchHeuristic Search
Heuristic Search
butest
 
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
Alphorm
 

Destaque (19)

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
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
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
 

Semelhante a 17. Trees and Graphs

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 17
sajinsc
 

Semelhante a 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
 

Mais de Intro C# Book

Mais de 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
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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.

Notas do Editor

  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.* ##