Implement binary search tree with parent pointer

Binary search tree with parent feature

A binary search tree is a type of ordered binary tree, where the left child has a value smaller than its parent, and the right child has a value greater than or equal to its parent. In a binary search tree, a node has two references, the left child and …

Continue reading

Implement circular queue using an array

circular queue

A circular queue is a queue in which all elements are connected to form a circular. A circular queue can be implemented with an array or a linked list. In the array implementation, the index of the rear element wraps around to the beginning of the array. In this post, …

Continue reading

Permutation of multiple arrays and iterator – code

permutation

Permutation of multiple arrays and iterator has two tasks. First is the permutation of multiple arrays and output as an array of new combinations. The second is to implement the iterator of this new array. Permutation is an important topic in the fields of combinatorics. It is usually implemented using …

Continue reading

Implement trie using arrays

A trie is a tree-like data structure in which every node stores a character. A trie can store multiple words. After building a trie, strings or substrings can be retrieved by traversing down a path (a branch) of the trie. Tries are used to find substrings, autocomplete and many other …

Continue reading

Clean directories using recursion – code

delete files older than n days

Delete files older than n days and remove the empty directories after the files are deleted. This can be done using recursion. Recursion is a technique that a function calls itself.  When the base condition is met, the rest of call stacks return from the last call to the first. …

Continue reading

Sort squares of a sorted array in one pass

sort squares

To sort squares of a sorted array, you don’t want to use any sorting algorithms such as bubble sort. Because it takes O(nlogn) ~ O(n^2) time. Here we introduce a better way to sort in one pass. The solution is using two pointers. Initialize two pointers, one points to the …

Continue reading

Implement binary search tree

A binary search tree is an ordered binary tree. The left subtree contains nodes whose keys are less than the node’s key value, while the right subtree contains nodes whose keys are greater than or equal to the node’s key value. Moreover, both subtrees are also binary search trees. A binary search …

Continue reading

Implement trie using linked lists

trie feature list

A trie is a tree-like data structure in which every node stores a character. A trie can store multiple words. After building a trie, strings or substrings can be retrieved by traversing down a path (a branch) of the trie. Insert a word in a trie, search a word, or …

Continue reading

Implement trie using hashmaps

A trie is a tree-like data structure in which every node stores a character. A tire can store one or multiple words. After building a trie, strings or substrings can be retrieved by traversing down a path (a branch) of the trie. Tries are used to find substrings, autocomplete and …

Continue reading