8000 Added example case. · jerrytdev/swift-algorithm-club@8bc6ab7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bc6ab7

Browse files
kelvinlauKLremlostime
authored andcommitted
Added example case.
1 parent e159902 commit 8bc6ab7

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

Encode and Decode Tree/readme.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,47 @@ Here's a high level overview of the above code:
12 8000 5125

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

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

129-
130-
130+
```
131+
Original Tree
132+
133+
┌──8423
134+
┌──8391
135+
│ └──nil
136+
┌──7838
137+
│ │ ┌──4936
138+
│ └──3924
139+
│ └──2506
140+
830
141+
│ ┌──701
142+
└──202
143+
└──169
144+
145+
Encoded tree: 830,202,169,X,X,701,X,X,7838,3924,2506,X,X,4936,X,X,8391,X,8423,X,X,
146+
147+
Decoded tree
148+
149+
┌──8423
150+
┌──8391
151+
│ └──nil
152+
┌──7838
153+
│ │ ┌──4936
154+
│ └──3924
155+
│ └──2506
156+
830
157+
│ ┌──701
158+
└──202
159+
└──169
160+
```
161+
162+
Notice the original tree and decoded tree are identical.
163+
164+
## Further Reading & References
165+
166+
- [LeetCode](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/description/)
167+
168+
*Written for the Swift Algorithm Club by Kai Chen & Kelvin Lau*
131169

132170

133171

0 commit comments

Comments
 (0)
0