Trie Data Structure (EXPLAINED)
Get the full course on Algorithms & Data Structures:
in Javascript - https://www.udemy.com/algorithms-and-data-structures-in-javascript/?couponCode=YOUTUBE
in C++ - https://www.udemy.com/algorithms-and-data-structures-in-c-coding-interview/?couponCode=YOUTUBE
in Java - https://www.udemy.com/algorithms-data-structures-in-java-engineering-interview/?couponCode=ONLYFOR10
? GET 2 MONTHS OF SKILLSHARE PREMIUM FOR FREE HERE: ? https://www.skillshare.com/r/profile/Lukas-Vyhnalek/7845840
?SUPPORT ME BY ONE TIME DONATION?
https://paypal.me/support930
In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search tree—an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are not necessarily associated with every node. Rather, values tend only to be associated with leaves, and with some inner nodes that correspond to keys of interest. For the space-optimized presentation of prefix tree, see compact prefix tree.
In the example shown, keys are listed in the nodes and values below them. Each complete English word has an arbitrary integer value associated with it. A trie can be seen as a tree-shaped deterministic finite automaton. Each finite language is generated by a trie automaton, and each trie can be compressed into a deterministic acyclic finite state automaton.
Though tries are usually keyed by character strings,[not verified in body] they need not be. The same algorithms can be adapted to serve similar functions of ordered lists of any construct, e.g. permutations on a list of digits or shapes. In particular, a bitwise trie is keyed on the individual bits making up any fixed-length binary datum, such as an integer or memory address.
The complexity of creating a trie is O(W*L), where W is the number of words, and L is an average length of the word: you need to perform L lookups on the average for each of the W words in the set.
Same goes for looking up words later: you perform L steps for each of the W words.
Hash insertions and lookups have the same complexity: for each word you need to check equality, which takes O(L), for the overall complexity of O(W*L).
If you need to look up entire words, hash table is easier. However, you cannot look up words by their prefix using a hash table; If prefix-based lookups are of no interest to you, use a hash table; otherwise, use a trie.
class Node():
def __init__(self):
self.children = # mapping from character to Node
self.value = None
def find(node, key):
for char in key:
if char in node.children:
node = node.children[char]
else:
return None
return node.value
def insert(root, string, value):
node = root
i = 0
while i is-smaller len(string):
if string[i] in node.children:
node = node.children[string[i]]
i += 1
else:
break
# append new nodes for the remaining characters, if any
while i is-smaller len(string):
node.children[string[i]] = Node()
node = node.children[string[i]]
i += 1
# store value in the terminal node
node.value = value
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Trie Data Structure (EXPLAINED)», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.