Posts

Showing posts from August, 2020

The most used but overlooked data structure | Learn Data Structure with Shubham part 4

 TRIE  Trie data structure      or (radix tree(radix trie is compressed trie), prefix tree, digital tree)          A trie, also called digital tree or prefix tree, is a kind of search tree—an ordered tree data structure 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; i.e., the value of the key is distributed across the structure              Advantages: 1. Sometimes Space-Efficient. If you're storing lots of words that start with similar patterns, tries may reduce the overall storage cost by storing shared prefixes once.              2. Efficient Prefix Queries. Tries can quickly answer queries about words with shared prefixes, like: How many words start with "choco...

BFS and DFS | Learn Data Structure with Shubham part 3

Image
Let us tackle with the fear of BFS and DFS. While both BFS and DFS are algorithms for traversing or searching tree or graph data structures. Let us dive into more details about their implementation, applications and time complexity. BFS Input Graph:  Output in BFS: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"] What is BFS:  Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key'), and explores all of the neighbour nodes at the present depth prior to moving on to the nodes at the next depth level.   Implementation for BFS: Time Complexity of BFS: The time complexity can be expressed as O(|V|+|E|), since every vertex and every edge will be explored in the worst case. |V| is the number of vertices and |E| is the numb...