• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 01, 2022 |2.8K Views
Find a pair with given sum in BST
Description
Discussion

Given a BST and a sum, find if there is a pair with given sum.


We have discussed different approaches to find a pair with given sum in below post.Find a pair with given sum in a Balanced BST
In this post, hashing based solution is discussed. We traverse binary search tree by inorder way and insert node’s value into a set. Also check for any node, difference between given sum and node’s value in set, if it is found then pair exists otherwise it doesn’t exist.

Find a pair with given sum in BST: https://www.geeksforgeeks.org/find-pair-given-sum-bst/