Skip to content

Commit 04bc089

Browse files
authored
Update trie.md
1 parent 1b0bd26 commit 04bc089

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

contrib/ds-algorithms/trie.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Node Class have mainly two components
2727

2828
Code Block of Node Class :
2929

30-
```
30+
```python
3131
class Node:
3232
def __init__(self):
3333
self.alphabets = [None] * 26
@@ -40,7 +40,7 @@ Now we need to implement Trie. We create another class named Trie with some meth
4040

4141
Code Implementation of Initialization:
4242

43-
```
43+
```python
4444
class Trie:
4545
def __init__(self):
4646
self.root = Node()
@@ -51,7 +51,7 @@ class Trie:
5151
1. **Insertion**: Inserts the word into the Trie. This method takes `word` as parameter. For each character in the word, it checks if there is a corresponding child node. If not, it creates a new `Node`. After processing all the characters in word, it increments the `end_of_word` value of the last node.
5252

5353
Code Implementation of Insertion:
54-
```
54+
```python
5555
def insert(self, word):
5656
node = self.root
5757
for char in word:
@@ -69,7 +69,7 @@ There are two cases in Searching:
6969
- *Word found*: It happens when the search word is present in the Trie. This case will occur, when the `end_of_word` value is greater than `0` of the node after traversing the whole word.
7070

7171
Code Implementation of Searching:
72-
```
72+
```python
7373
def Search(self, word):
7474
node = self.root
7575
for char in word:
@@ -84,7 +84,7 @@ Code Implementation of Searching:
8484

8585
Code Implementation of Deletion:
8686

87-
```
87+
```python
8888
def delete(self, word):
8989
node = self.root
9090
for char in word:
@@ -96,7 +96,7 @@ def delete(self, word):
9696

9797
Python Code to implement Trie:
9898

99-
```
99+
```python
100100
class Node:
101101
def __init__(self):
102102
self.alphabets = [None] * 26

0 commit comments

Comments
 (0)