Skip to content

doc: add leaf list documentation #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc: add leaf list documentation
  • Loading branch information
MoigeMatino committed May 3, 2023
commit 2fc5c59a3f6c8ad9ed4eb84b9ad9d4c946de48c5
104 changes: 104 additions & 0 deletions binary_tree/leaf_list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# leaf list

Write a function, leaf_list, that takes in the root of a binary tree and returns a list containing the values of all leaf nodes in left-to-right order.

## test_00:

```python
a = Node("a")
b = Node("b")
c = Node("c")
d = Node("d")
e = Node("e")
f = Node("f")

a.left = b
a.right = c
b.left = d
b.right = e
c.right = f

# a
# / \
# b c
# / \ \
# d e f

leaf_list(a) # -> [ 'd', 'e', 'f' ]
```

## test_01:

```python
a = Node("a")
b = Node("b")
c = Node("c")
d = Node("d")
e = Node("e")
f = Node("f")
g = Node("g")
h = Node("h")

a.left = b
a.right = c
b.left = d
b.right = e
c.right = f
e.left = g
f.right = h

# a
# / \
# b c
# / \ \
# d e f
# / \
# g h

leaf_list(a) # -> [ 'd', 'g', 'h' ]
```

## test_02:

```python
a = Node(5)
b = Node(11)
c = Node(54)
d = Node(20)
e = Node(15)
f = Node(1)
g = Node(3)

a.left = b
a.right = c
b.left = d
b.right = e
e.left = f
e.right = g

# 5
# / \
# 11 54
# / \
# 20 15
# / \
# 1 3

leaf_list(a) # -> [ 20, 1, 3, 54 ]
```

## test_03:

```python
x = Node('x')

# x

leaf_list(x) # -> [ 'x' ]
```

## test_04:

```python
leaf_list(None) # -> [ ]
```