Skip to content

Commit 769be52

Browse files
committed
Edited scriped for isomorphism sc video
1 parent 1119c27 commit 769be52

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

slides/graphtheory/trees.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,7 @@ you've given the previous video a watch if you haven't done so. There should be
772772
a link in the description below.
773773

774774
All the source code you see today can be found on Github at github dot com slash
775-
william fiset slash algorithms. Alright, buckle up because even though we'll
776-
only be looking at around 150 lines of code there's a lot going on,
777-
let's jump in.
775+
william fiset slash algorithms.
778776

779777
So here we are in the source code for identifying isomorphic trees written
780778
in Java. Let's start by taking a look at an example of what this code does in
@@ -791,31 +789,29 @@ fundamentally different trees.
791789

792790
---
793791

794-
treesAreIsomorphic
795-
796-
The first interesting method is the treesAreIsomorphic method which takes as
792+
Going back up to the treesAreIsomorphic method, you'll see that it takes as
797793
input two undirected trees stored as adjacency lists: tree1 and tree2.
798794

799-
Just so that we don't have to worry about it, I check if either trees are empty
800-
and throw an exception.
795+
Just so that we don't have to worry about it, the first thing I do is check if
796+
either trees are empty and throw an exception.
801797

802-
After that, we begin the whole tree serialzation process, it's pretty simple,
798+
After that, we begin the whole tree serialization process, it's pretty simple,
803799
start by finding the center or centers of both trees.
804800

805801
Then encode the first tree into a string. The encode method takes as input a
806-
rooted tree instead of an undirected tree so make sure you root the tree first.
807-
After the encode method has finished processing it will return a unique string
802+
rooted tree instead of an undirected tree, so make sure you root the tree first.
803+
After the encode method has finished processing, it will return a unique string
808804
for tree1.
809805

810806
Now the next thing we want to do is encode the second tree so that we can
811807
compare it to the first one. However, if the second tree has 2 centers we
812808
don't know which center node in the second tree is the correct one, so we need
813809
to try both.
814810
For this, iterate over both centers and root the tree comparing the
815-
encoded result with the first tree . If there's any match then we
811+
encoded result with the first tree. If there's any match then we
816812
know that the trees are isomorphic.
817-
Awesome so that's the algorithm from a bird's eye view, now let's dig into the
818-
details and figure out what the heck is going on inside the findTreeCenters,
813+
Awesome, so that's the algorithm from a bird's eye view, now let's dig into the
814+
details and figure out what is going on inside the findTreeCenters,
819815
rootTree and encode methods.
820816

821817
---

0 commit comments

Comments
 (0)