×

# Second largest element in a binary search tree.

 0 How to find out the second largest largest element in a binary search tree? asked 12 Nov '16, 07:54 1★rashedcs 487●4●19 accept rate: 4%

 4 void print2ndLargest ( node * root) { if(root==NULL||(root->Rchild==NULL&&root->Lchild==NULL)) { cout<<"2nd Largest Not possible \n"; return; } if(root->Rchild==NULL) { node * temp; temp=root->Lchild; while(temp->Rchild!=NULL) { temp=temp->Rchild; } cout<<"2nd Largest : "<< temp->info; return; } node * parentt; node * temp; parentt=root; temp=root->Rchild; while(temp->Rchild!=NULL) { parentt=temp; temp=temp->Rchild; } cout<< "2nd Largest : " << parentt->info; //Largest is : temp->info } ^ Hope this helps. answered 12 Nov '16, 17:26 127●3 accept rate: 37%
 2 If a BST have atleast 2 nodes then... Second largest Element in a BST is the parent of Largest Element of BST. ie its the parent of rightmost node. If a BST don't have right subtree Second largest element is the rightmost child of left subtree. answered 12 Nov '16, 09:19 238●8 accept rate: 20%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×761

question asked: 12 Nov '16, 07:54

question was seen: 902 times

last updated: 18 Nov '16, 21:53