DP with Trees

When you need to use the solution to the left and right subtree to find the answer to the root, dynamic programming with trees is often relevant. Path sum, tree diameter, and maximum path sum are some examples of DP on trees problems. All of these problems have one thing in common: we get the answers for the left and right subtrees, then apply some math to find answers for the root.

Basics of DP with Trees

By Saksham Gupta

● Published At Dec 2021

In this blog, we will discuss how we can apply dynamic programming on trees and will understand its implementation by taking various examples.
... Keep reading ..

Maximum sum path from the leaf to leaf(Extend it to any node to any node)

By Saksham Gupta

● Published At Dec 2021

In this blog, we will discuss how we can calculate the maximum sum path from leaf to leaf in a binary tree. Further, we’ll extend it to the maximum sum path from any node to any node in a binary tree.
... Keep reading ..

Sum of the Length of Paths from Every Node to All Other Nodes

By Soumya Agrawal

● Published At Mar 2022

This article will cover the approach and implementation of the problem- Sum of the Length of Paths from every Node to all other Nodes using the Tree Rerooting technique.... Keep reading ..

Unique Binary Search Trees

By Rubleen Kaur

● Published At Jan 2022

This article is based on the problem of finding the total number of unique binary search trees which could be generated using ‘N’ nodes, using various approaches.
... Keep reading ..

## Top Problems related to DP with Trees

Symmetric Tree

Is It A Tree?

Spiral Order Traversal of a Binary Tree

Count Special Nodes In Generic Tree

Leftmost & Rightmost Nodes of Binary Tree

Triplets in Binary Tree

Count Univalue Subtrees

Binary Tree Pruning

Deepest Right Leaf

Reverse Alternate Nodes

Right View

Diagonal Sum

LCA of three Nodes

Replace Node With Depth

Diagonal Anagram

Except Boundary

Deepest Leaves Sum

Partial BST

Convert Bst To The Greater Sum Tree

Distance between two nodes of a Tree

Height of the Binary Tree From Inorder and Level Order Traversal