Skip to content

Commit

Permalink
Added example case.
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinlauKL authored and remlostime committed Jan 15, 2018
1 parent e159902 commit 8bc6ab7
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions Encode and Decode Tree/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,47 @@ Here's a high level overview of the above code:

2. Using an array as a stack, you recursively decode each node. The array keeps track of sequence of nodes and progress.

Here's an example output of a tree undergoing the encoding and decoding process:



```
Original Tree
┌──8423
┌──8391
│ └──nil
┌──7838
│ │ ┌──4936
│ └──3924
│ └──2506
830
│ ┌──701
└──202
└──169
Encoded tree: 830,202,169,X,X,701,X,X,7838,3924,2506,X,X,4936,X,X,8391,X,8423,X,X,
Decoded tree
┌──8423
┌──8391
│ └──nil
┌──7838
│ │ ┌──4936
│ └──3924
│ └──2506
830
│ ┌──701
└──202
└──169
```

Notice the original tree and decoded tree are identical.

## Further Reading & References

- [LeetCode](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/description/)

*Written for the Swift Algorithm Club by Kai Chen & Kelvin Lau*



0 comments on commit 8bc6ab7

Please sign in to comment.