See the Pen Distinct Shapes Leetcode by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Friday, June 11, 2021
Get Distinct Shapes
Sunday, April 25, 2021
BST insertion
See the Pen BST insertion by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Friday, April 23, 2021
Find corresponding Node of a second tree, given the node of a tree
See the Pen Corresponding DOM Node in 2nd DOM Tree by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Wednesday, April 14, 2021
Maximum Depth of Binary Tree
See the Pen Maximum Depth of Binary Tree by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Tuesday, April 13, 2021
Pangram
Monday, April 12, 2021
Subdomain visit count
See the Pen Subdomain Visit Count by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Intersecting clickstream data
See the Pen Intersecting Clickstream data by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Thursday, April 8, 2021
Most Frequent Subtree Sum
See the Pen Most Frequent Subtree Sum by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Monday, March 29, 2021
Two Sum
See the Pen Two-Sum by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Box Stacking - Dynamic Programming
See the Pen Box Stacking Problem - Dynamic Programming by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Sunday, March 21, 2021
Length of the longest substring
See the Pen Length of the longest substring by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Friday, March 19, 2021
String to Leet
See the Pen
String to Leet by Dhiviya Dhanasekar (@dhiviyadhanasekar)
on CodePen.
Lessons Learnt:
mapper = {'a': 0};
if(mapper['a']) ---> is false
0 || undefined ---> is undefined
undefined || 0 ---> is 0
Friday, March 12, 2021
Create a line on a graph given 2 coordinates that define the line
See the Pen Graph Line Plot by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Wednesday, March 3, 2021
Binary Heap properties
A Binary Heap is a Binary Tree with following properties.
1) It’s a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array.
2) A Binary Heap is either Min Heap or Max Heap. In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The same property must be recursively true for all nodes in Binary Tree. Max Binary Heap is similar to MinHeap.
Arr[(i-1)/2] Returns the parent node Arr[(2*i)+1] Returns the left child node Arr[(2*i)+2] Returns the right child node
Arr[(n/2) .... (n-1)] => will contain the leaf nodes, if n is the length of the array or total number of nodes.
The traversal method use to achieve Array representation is Level Order
Source: geeks for geeks
Tuesday, March 2, 2021
Binary Tree - DFS Preorder (Stacks)
See the Pen Binary Tree - DFS Preorder (Stacks) by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Binary Tree - DFS PostOrder (Recursion)
See the Pen DFS - Binary Tree PostOrder (Recursion) by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Monday, March 1, 2021
Binary Tree - DFS PreOrder (Recursive)
See the Pen Binary Tree DFS Pre-order traversal by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Binary Tree - DFS Inorder Traversal (Recursion)
See the Pen DFS - Binary Tree Inorder (Recursion) by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Sunday, February 28, 2021
Tree BFS in JS (Queue/Array)
1. The maximum number of nodes at level ‘l’ of a binary tree is 2^l
2. The Maximum number of nodes in a binary tree of height ‘h’ is 2^h – 1, Height of a tree with a single node is considered as 1.
BFS Complexity
Time Complexity - O(n)
Space Complexity - O(n)
Notes: BFS slower than DFS
From geeksforgeeks:
Extra space required for Level order traversal is likely to be more when tree is more balanced and extra space for Depth First Traversal is likely to be more when tree is less balanced.
How to Pick One?
- Extra Space can be one factor (Explained above)
- Depth First Traversals are typically recursive and recursive code requires function call overheads.
- The most important points is, BFS starts visiting nodes from root while DFS starts visiting nodes from leaves. So if our problem is to search something that is more likely to closer to root, we would prefer BFS. And if the target node is close to a leaf, we would prefer DFS.
Exercise:
Which traversal should be used to print leaves of Binary Tree and why? DFS
Which traversal should be used to print nodes at k’th level where k is much less than total number of levels? BFS
See the Pen Tree BFS in JS (Recursive & Non-recursive Queue versions) by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.
Friday, February 26, 2021
LinkedList functions in JS
See the Pen JS LinkedList by Dhiviya Dhanasekar (@dhiviyadhanasekar) on CodePen.