Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a program to do Binary Search LCA #13

Closed
saurabhGr opened this issue Oct 7, 2023 · 3 comments
Closed

Write a program to do Binary Search LCA #13

saurabhGr opened this issue Oct 7, 2023 · 3 comments
Labels

Comments

@saurabhGr
Copy link
Owner

You are given pointer to the root of the binary search tree and two values and . You need to return the lowest common ancestor (LCA) of and in the binary search tree.

image
In the diagram above, the lowest common ancestor of the nodes and is the node . Node is the lowest node which has nodes and as descendants.

Function Description

Complete the function lca in the editor below. It should return a pointer to the lowest common ancestor node of the two values given.

lca has the following parameters:

  • root: a pointer to the root node of a binary search tree
  • v1: a node.data value
  • v2: a node.data value

Input Format

The first line contains an integer, , the number of nodes in the tree.
The second line contains space-separated integers representing values.
The third line contains two space-separated integers, and .

To use the test data, you will have to create the binary search tree yourself. Here on the platform, the tree will be created for you.

Constraints

The tree will contain nodes with data equal to and .

Output Format

Return the a pointer to the node that is the lowest common ancestor of and .

Sample Input

6
4 2 3 1 7 6
1 7
image

and .

Sample Output

[reference to node 4]

Explanation

LCA of and is , the root in this case.
Return a pointer to the node.

@nida242004
Copy link
Contributor

I'd like to contribute, please assign this to me @saurabhGr

@HacterCalling
Copy link
Contributor

Hi, As it is not assigned, I'm taking it up.

HacterCalling added a commit to HacterCalling/Programming-Data-Structure-using-C that referenced this issue Oct 8, 2023
@HacterCalling
Copy link
Contributor

Please review #17

saurabhGr added a commit that referenced this issue Oct 8, 2023
Added code for Binary search LCA check issue #13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants