# Data Structure – codewindow.in

## Related Topics ## Data Structure

#### For example, the following tree is a full binary tree:

``````        1
/   \
2     3
/ \   / \
4   5 6   7
``````

#### And the following tree is a complete binary tree:

``````        1
/   \
2     3
/ \   /
4   5 6
``````

#### Here is an example implementation of a Trie in Python:

``````class TrieNode:
def __init__(self):
self.children = [None]*26  # 26 is the number of letters in the English alphabet
self.is_end_of_word = False

class Trie:
def __init__(self):
self.root = TrieNode()

def _char_to_index(self, char):
return ord(char) - ord('a')

def insert(self, word):
node = self.root
for char in word:
index = self._char_to_index(char)
if not node.children[index]:
node.children[index] = TrieNode()
node = node.children[index]
node.is_end_of_word = True

def search(self, word):
node = self.root
for char in word:
index = self._char_to_index(char)
if not node.children[index]:
return False
node = node.children[index]
return node is not None and node.is_end_of_word

def starts_with(self, prefix):
node = self.root
for char in prefix:
index = self._char_to_index(char)
if not node.children[index]:
return False
node = node.children[index]
return True
``````

#### Both algorithms produce the same result: a tree that connects all the vertices in the graph with the minimum total weight. #### Questions on Chapter 7  #### Questions on Chapter 8  ## We Loveto Support you

Go through our study material. Your Job is awaiting.