# About remove algorithm in tries chapter 11

**URL:** <https://forums.kodeco.com/t/about-remove-algorithm-in-tries-chapter-11/201260>\
**Category:** Data Structures & Algorithms in Dart\
**Tags:** public-event, flutter\
**Created:** [January 5, 2024, 12:36pm UTC](https://forums.kodeco.com/t/about-remove-algorithm-in-tries-chapter-11/201260 "2024-01-05T12:36:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wesam\_amassi](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@wesam\_amassi](https://forums.kodeco.com/u/wesam_amassi)\
**Post date:** [January 5, 2024, 12:36pm UTC](https://forums.kodeco.com/t/about-remove-algorithm-in-tries-chapter-11/201260/1 "2024-01-05T12:36:58Z")

</div>

Hi  
In Chapter 11: Tries  
the remove algorithm remove only last node that has no children.  
for example remove **cute** after insert it remove only e node that has no children.  
I suggest edit the for loop like this:

```auto
 // 3
  while (current.parent != null &&
        current.children.isEmpty &&
        !current.isTerminating) {
    //current.parent!.children[current.key!] = null; //comment this and add the bottom line
    current.parent?.children.remove(current.key);
    current = current.parent!;
  }

```

---

<div class="post-metadata">

**Author:** ![suragch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/suragch/32/109020_2.png) [@suragch](https://forums.kodeco.com/u/suragch)\
**Post date:** [January 8, 2024, 1:42am UTC](https://forums.kodeco.com/t/about-remove-algorithm-in-tries-chapter-11/201260/2 "2024-01-08T01:42:36Z")

</div>

Thank you for commenting. I think you’re right. Since a `Map` in Dart can contain a key-value pair where the value is `null`, it would be better to simply remove the pair rather than set the value to `null`. We might be able to enforce this by making the value non-nullable for the child. That is, change this:

```auto
Map<T, TrieNode<T>?> children = {};

```

to this:

```auto
Map<T, TrieNode<T>> children = {};

```

in the `TrieNode` definition class. I recommend this change if we ever publish an updated version of the book.

Thanks again for your idea.
