<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>trie &#8211; JSAlgorithm</title>
	<atom:link href="https://jsalgorithm.com/tag/trie/feed/" rel="self" type="application/rss+xml" />
	<link>https://jsalgorithm.com</link>
	<description></description>
	<lastBuildDate>Thu, 14 May 2020 03:08:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>
<site xmlns="com-wordpress:feed-additions:1">177240629</site>	<item>
		<title>Search Suggestion System (Trie)</title>
		<link>https://jsalgorithm.com/2020/05/14/search-suggestion-system-trie/</link>
					<comments>https://jsalgorithm.com/2020/05/14/search-suggestion-system-trie/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Thu, 14 May 2020 03:08:02 +0000</pubDate>
				<category><![CDATA[Breadth First Search]]></category>
		<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Recursion]]></category>
		<category><![CDATA[Trie]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[breadth-first-search]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[trie]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=68</guid>

					<description><![CDATA[let suggestedProducts = function(products, searchWord) { const MAX_RESULT_COUNT = 3; let root = { children: {} }; function addToNode(word, index, node) { if (index &#62;= word.length) { node.end = true; return; } // const child = node.children[word[index]]; if (child) { addToNode(word, index + 1, child); } else { let child = {val: word[index], parent: node, [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let suggestedProducts = function(products, searchWord) {<br>    const MAX_RESULT_COUNT = 3;<br>    let root = {<br>        children: {}<br>    };<br><br>    function addToNode(word, index, node) {<br>        if (index &gt;= word.length) {<br>            node.end = true;<br>            return;<br>        }<br>        //<br>        const child = node.children[word[index]];<br>        if (child) {<br>            addToNode(word, index + 1, child);<br>        }<br>        else {<br>            let child = {val: word[index], parent: node, children: {}};<br>            node.children[word[index]] = child;<br>            addToNode(word, index + 1, child);<br>        }<br>    }<br><br>    function getWord(leaf) {<br>        let node = leaf;<br>        let str = '';<br>        while (node) {<br>            if (node.val) str = node.val + str; //?<br>            node = node.parent; //?<br>        }<br><br>        return str; //?<br>    }<br><br>    function searchProducts(searchString) {<br><br>        let words = [];<br>        let nodes = [...<strong><em>Object</em></strong>.entries(root.children)], len = searchString.length;<br>        while (nodes.length) {<br><br>            let currentNodeLength = nodes.length;<br>            while (currentNodeLength &gt; 0) {<br>                currentNodeLength--;<br><br>                const node = nodes.pop();<br>                const [key, val] = node;<br>                if (len &gt; 0 &amp;&amp; key === searchString[searchString.length - len]) {<br>                    nodes.unshift(...<strong><em>Object</em></strong>.entries(val.children));<br><br>                    if (len === 1 &amp;&amp; val.end) {<br>                        words.push(getWord(val));<br>                    }<br>                } else if (len &lt;= 0) {<br>                    if (val.end) words.push(getWord(val));<br>                    nodes.unshift(...<strong><em>Object</em></strong>.entries(val.children));<br>                }<br>            }<br>            len--;<br>        }<br><br>        return words.sort().slice(0, <strong><em>Math</em></strong>.min(MAX_RESULT_COUNT, words.length));<br>    }<br><br>    for(let product of products) {<br>        addToNode(product, 0, root);<br>    }<br><br><br>    let result = [];<br>    for (let i = 0; i &lt; searchWord.length; i++) {<br>        result.push(searchProducts(searchWord.substring(0, i + 1))); //?<br>    }<br><br>    return result; //?<br>};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/14/search-suggestion-system-trie/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">68</post-id>	</item>
	</channel>
</rss>
