Ayush ThakurforInterview Bitsinterviewbits.hashnode.dev·Jul 15, 2024Constructing a Binary Tree from Preorder and Inorder TraversalOne of the fascinating challenges in binary tree problems is reconstructing the tree from its traversal data. In this post, we will discuss how to construct a binary tree given the preorder and inorder traversal arrays. Problem Statement Given two in...DiscussPython
Anower Hossainanower77.hashnode.dev·Jul 14, 2024Segment Tree-1Segment Tree Basic Node Divide With Segment Tree Node Numbering (Segment Tree) // build (node, begin, end) build (1, 1, N) { L = 2xN, R = (2xN) + 1 // Node Number Calculate mid = (begin + end) / 2 left = (L, begin, mid) left = (R, ...Discuss·91 readssegment-tree
Akshaya Biswalakshaya-biswal.hashnode.dev·Jun 27, 2024Binary TreeA binary tree is a tree data structure where each parent node can have up to two children. All the nodes in the left subtree of a node have values smaller than the node's value. All the nodes in the right subtree of a node have values greater than...DiscussData StructureDSA
Akshaya Biswalakshaya-biswal.hashnode.dev·Jun 27, 2024Tree TraversalTraversing a tree means visiting every node in the tree. Types Breadth First Search (BFS) is when you visit all the nodes on one level before moving to the next level. This means you explore the tree sideways. Depth First Search (DFS) is when you g...DiscussData StructureDSA
Akshaya Biswalakshaya-biswal.hashnode.dev·Jun 27, 2024Tree Data StructureThe data structure is called a "tree" because it looks like a tree, only upside down. A tree is a nonlinear hierarchical data structure that consists of nodes connected by edges. Tree Terminologies Height and depth of each node Types of Trees Binar...DiscussData StructureDSA
Abhilietcode.hashnode.dev·Jun 23, 2024Binary Tree Maximum Path Sum (Hard)A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum...DiscussTreesTree
Abhilietcode.hashnode.dev·Jun 23, 2024Kth Smallest Element in a BST (Medium)Given the root of a binary search tree, and an integer k, return the k<sup>th</sup> smallest value (1-indexed) of all the values of the nodes in the tree. Example 1: Input: root = [3,1,4,null,2], k = 1 Output: 1 Example 2: Input: root = [5,3,6,2,4...DiscussTreesTree
Abhilietcode.hashnode.dev·Jun 23, 2024Sum of Nodes with Even-Valued Grandparent (Medium)Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. A grandparent of a node is the parent of its parent if it exists. Example 1: Input: ...DiscussTreesTree
Abhilietcode.hashnode.dev·Jun 23, 2024Sum Root to Leaf Numbers (Medium)You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf n...DiscussTreesTree
Abhilietcode.hashnode.dev·Jun 23, 2024Validate Binary Search TreeGiven the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only no...DiscussTreesTree