{"id":480,"date":"2021-07-13T11:24:08","date_gmt":"2021-07-13T11:24:08","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=480"},"modified":"2021-09-13T07:23:23","modified_gmt":"2021-09-13T07:23:23","slug":"how-to-find-second-largest-element-in-bst","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/","title":{"rendered":"How to find Second largest element in BST ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"how-to-find-second-largest-element-in-bst\" class=\"color-pink\" style=\"text-align: justify;\">How to find Second largest element in BST ?<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>In an N-ary\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/r-programming\/r-decision-tree\" target=\"_blank\" rel=\"noopener\">tree<\/a>, the second largest value in the given tree to find and return the node. Return NULL if no node with required value is present.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>For example, in the given tree<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"ImageContent\" style=\"text-align: justify;\">\n<div class=\"hddn\"><img decoding=\"async\" class=\"img-responsive center-block aligncenter\" src=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png\" alt=\"Second largest element in a BST\" \/><\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h3 id=\"second-largest-node-is-20\">Second largest node is 20.<\/h3>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul style=\"text-align: justify;\">\n<li>A simple solution is to traverse the\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/c++\/passing-2d-array-to-function-c++\" target=\"_blank\" rel=\"noopener\">array<\/a>\u00a0twice. In the first traversal the maximum value node to be find.<\/li>\n<li>In the second traversal find the greatest element node less than the element obtained in first traversal.<\/li>\n<li>This solution O(n) is the\u00a0<a href=\"https:\/\/www.wikitechy.com\/interview-questions\/programming\/what-is-the-time-complexity-of-adding-three-matrices\" target=\"_blank\" rel=\"noopener\">time complexity<\/a>.<\/li>\n<li>To find the second largest element in a single traversal to be efficient solution.<\/li>\n<\/ul>\n<h2 id=\"algorithm\" class=\"color-green\" style=\"text-align: justify;\">Algorithm<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markdown code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markdown code-embed-code\">Initialize two nodes first and second to NULL as,<br\/>first = second = NULL<br\/><br\/>Start traversing the tree,<br\/>If the current node data say root->key is greater<br\/>than first->key then update first and second as,<br\/>second = first<br\/>first = root<br\/>If the current node data is in between first and<br\/>second, then update second to store the value<br\/>of current node as<br\/>second = root<br\/><br\/>Return the node stored in second.<\/code><\/pre> <\/div>\n<h2 id=\"sample-code-in-java\" class=\"color-blue\" style=\"text-align: justify;\">Sample Code in Java<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-javascript code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-javascript code-embed-code\">\/\/ Java code to find second largest element in BST <br\/>  <br\/>\/\/ A binary tree node <br\/>class Node { <br\/>  <br\/>    int data; <br\/>    Node left, right; <br\/>  <br\/>    Node(int d) <br\/>    { <br\/>        data = d; <br\/>        left = right = null; <br\/>    } <br\/>} <br\/>  <br\/>class BinarySearchTree { <br\/>  <br\/>    \/\/ Root of BST <br\/>    Node root; <br\/>  <br\/>    \/\/ Constructor <br\/>    BinarySearchTree() <br\/>    { <br\/>        root = null; <br\/>    } <br\/>  <br\/>    \/\/ function to insert new nodes <br\/>    public void insert(int data) <br\/>    { <br\/>        this.root = this.insertRec(this.root, data); <br\/>    } <br\/>      <br\/>    \/* A utility function to insert a new node with given  <br\/>    key in BST *\/<br\/>    Node insertRec(Node node, int data) <br\/>    { <br\/>        \/* If the tree is empty, return a new node *\/<br\/>        if (node == null) { <br\/>            this.root = new Node(data); <br\/>            return this.root; <br\/>        } <br\/>  <br\/>        \/* Otherwise, recur down the tree *\/<br\/>        if (data < node.data) { <br\/>            node.left = this.insertRec(node.left, data); <br\/>        } else { <br\/>            node.right = this.insertRec(node.right, data); <br\/>        } <br\/>        return node; <br\/>    } <br\/>  <br\/>    \/\/ class that stores the value of count <br\/>    public class count { <br\/>        int c = 0; <br\/>    } <br\/>  <br\/>    \/\/ Function to find 2nd largest element <br\/>    void secondLargestUtil(Node node, count C) <br\/>    {    <br\/>        \/\/ Base cases, the second condition is important to <br\/>        \/\/ avoid unnecessary recursive calls <br\/>        if (node == null || C.c >= 2) <br\/>            return; <br\/>              <br\/>        \/\/ Follow reverse inorder traversal so that the <br\/>        \/\/ largest element is visited first <br\/>        this.secondLargestUtil(node.right, C);  <br\/>          <br\/>         \/\/ Increment count of visited nodes <br\/>        C.c++; <br\/>          <br\/>        \/\/ If c becomes k now, then this is the 2nd largest <br\/>        if (C.c == 2) { <br\/>            System.out.print(&quot;2nd largest element is &quot;+ <br\/>                                              node.data); <br\/>            return; <br\/>        } <br\/>          <br\/>         \/\/ Recur for left subtree <br\/>        this.secondLargestUtil(node.left, C);  <br\/>    } <br\/>  <br\/>    \/\/ Function to find 2nd largest element <br\/>    void secondLargest(Node node) <br\/>    {    <br\/>        \/\/ object of class count <br\/>        count C = new count();  <br\/>        this.secondLargestUtil(this.root, C); <br\/>    } <br\/>  <br\/>    \/\/ Driver function <br\/>    public static void main(String[] args) <br\/>    { <br\/>        BinarySearchTree tree = new BinarySearchTree(); <br\/>          <br\/>        \/* Let us create following BST <br\/>              50 <br\/>           \/     \\ <br\/>          30      70 <br\/>         \/  \\    \/  \\ <br\/>       20   40  60   80 *\/<br\/>         <br\/>        tree.insert(50); <br\/>        tree.insert(30); <br\/>        tree.insert(20); <br\/>        tree.insert(40); <br\/>        tree.insert(70); <br\/>        tree.insert(60); <br\/>        tree.insert(80); <br\/>  <br\/>        tree.secondLargest(tree.root); <br\/>    } <br\/>} <\/code><\/pre> <\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"output\" class=\"color-blue\">Output<\/h2>\n<\/div>\n<\/div>\n<div class=\"Output\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\">\n<pre><code class=\"hljs\" data-lang=\"\"><span class=\"nt\">2nd largest element is 70\r\n<\/span><\/code><\/pre>\n<\/figure>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"time-complexity\" class=\"color-purple\">Time Complexity<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\">\n<div class=\"hddn\">\n<ul>\n<li style=\"text-align: justify;\">Time Complexity: The above solution is O(h) where h is height of\u00a0<a href=\"https:\/\/www.wikitechy.com\/technology\/java-program-check-binary-tree-bst-not\/\" target=\"_blank\" rel=\"noopener\">BST<\/a>.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : In an N-ary tree, the second largest value in the given tree to find and return the node&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3028],"tags":[195,971,491,221,368,203,199,214,198,363,3057,205,3256,3251,3249,3252,3254,3250,3247,3237,222,15934,484,3054,196,212,3257,3240,3248,3245,3244,3243,3253,207,366,204,206,972,3255,3246,3236,3239,3238,3258,3260,3241,3259,3242,200,3055,197,968,3056,285,969],"class_list":["post-480","post","type-post","status-publish","format-standard","hentry","category-data-structure","tag-accenture-interview-questions-and-answers","tag-altimetrik-india-pvt-ltd-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-bharti-airtel-interview-questions-and-answers","tag-bmc-software-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-te-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-find-kth-largest-element-in-a-binary-search-tree-java","tag-find-max-value-in-binary-search-tree-c","tag-find-maximum-in-binary-search-tree","tag-find-min-and-max-in-binary-search-tree-in-c","tag-find-the-2nd-largest-node-in-a-binary-tree","tag-find-the-node-with-maximum-value-in-a-binary-search-tree","tag-find-the-second-largest-element-in-a-binary-search-tree-java","tag-find-the-second-largest-element-in-a-binary-search-tree-python","tag-flipkart-interview-questions-and-answers","tag-geekyants-interview-questions-and-answers","tag-genpact-interview-questions-and-answers","tag-globallogic-india-pvt-ltd-interview-questions-and-answers","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-kth-largest-element-in-a-stream-bst","tag-kth-largest-element-in-bst","tag-kth-smallest-element-in-a-bst-leetcode","tag-kth-smallest-element-in-a-bst-python","tag-kth-smallest-element-in-a-bst-recursive","tag-largest-node-in-bst","tag-largest-number-in-bst-which-is-less-than-or-equal-to-n-java","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-sapient-consulting-pvt-ltd-interview-questions-and-answers","tag-second-largest-element-in-bst","tag-second-largest-element-in-bst-java","tag-second-largest-element-in-bst-leetcode","tag-second-largest-element-in-bst-python","tag-second-largest-element-in-generic-tree","tag-second-largest-element-in-generic-tree-java","tag-second-largest-element-in-n-ary-tree-java","tag-second-largest-element-in-tree-java","tag-second-largest-in-tree","tag-second-minimum-node-in-a-binary-tree","tag-tech-mahindra-interview-questions-and-answers","tag-tracxn-technologies-pvt-ltd-interview-questions-and-answers","tag-unitedhealth-group-interview-questions-and-answers","tag-wipro-infotech-interview-questions-and-answers","tag-wm-global-technology-services-india-pvt-ltd-limited-wmgts-interview-questions-and-answers","tag-xoriant-solutions-pvt-ltd-interview-questions-and-answers","tag-yodlee-infotech-pvt-ltd-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to find Second largest element in BST ? - Data Structure<\/title>\n<meta name=\"description\" content=\"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to find Second largest element in BST ? - Data Structure\" \/>\n<meta property=\"og:description\" content=\"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-13T11:24:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-13T07:23:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/\"},\"author\":{\"name\":\"Editor\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"headline\":\"How to find Second largest element in BST ?\",\"datePublished\":\"2021-07-13T11:24:08+00:00\",\"dateModified\":\"2021-09-13T07:23:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/\"},\"wordCount\":765,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-a-bst.png\",\"keywords\":[\"Accenture interview questions and answers\",\"Altimetrik India Pvt Ltd interview questions and answers\",\"Applied Materials interview questions and answers\",\"Bharti Airtel interview questions and answers\",\"BMC Software interview questions and answers\",\"Capgemini interview questions and answers\",\"CASTING NETWORKS INDIA PVT LIMITED interview questions and answers\",\"CGI Group Inc interview questions and answers\",\"Chetu interview questions and answers\",\"Ciena Corporation interview questions and answers\",\"Collabera Te interview questions and answers\",\"Dell International Services India Pvt Ltd interview questions and answers\",\"find kth largest element in a binary search tree java\",\"find max value in binary search tree c++\",\"find maximum in binary search tree\",\"find min and max in binary search tree in c\",\"find the 2nd-largest node in a binary tree\",\"find the node with maximum value in a binary search tree\",\"find the second largest element in a binary search tree java\",\"find the second largest element in a binary search tree python\",\"Flipkart interview questions and answers\",\"geekyants interview questions and answers\",\"Genpact interview questions and answers\",\"Globallogic India Pvt Ltd interview questions and answers\",\"IBM interview questions and answers\",\"Indecomm Global Services interview questions and answers\",\"kth largest element in a stream bst\",\"kth largest element in bst\",\"kth smallest element in a bst leetcode\",\"kth smallest element in a bst python\",\"kth smallest element in a bst recursive\",\"largest node in bst\",\"largest number in bst which is less than or equal to n java\",\"Mphasis interview questions and answers\",\"NetApp interview questions and answers\",\"Oracle Corporation interview questions and answers\",\"SAP Labs India Pvt Ltd interview questions and answers\",\"Sapient Consulting Pvt Ltd interview questions and answers\",\"second largest element in bst\",\"second largest element in bst java\",\"second largest element in bst leetcode\",\"second largest element in bst python\",\"second largest element in generic tree\",\"second largest element in generic tree java\",\"second largest element in n ary tree java\",\"second largest element in tree java\",\"second largest in tree\",\"second minimum node in a binary tree\",\"Tech Mahindra interview questions and answers\",\"Tracxn Technologies Pvt Ltd interview questions and answers\",\"UnitedHealth Group interview questions and answers\",\"Wipro Infotech interview questions and answers\",\"WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers\",\"Xoriant Solutions Pvt Ltd interview questions and answers\",\"Yodlee Infotech Pvt Ltd interview questions and answers\"],\"articleSection\":[\"Data Structure\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/\",\"name\":\"How to find Second largest element in BST ? - Data Structure\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-a-bst.png\",\"datePublished\":\"2021-07-13T11:24:08+00:00\",\"dateModified\":\"2021-09-13T07:23:23+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-bst\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-a-bst.png\",\"contentUrl\":\"https:\\\/\\\/cdn.wikitechy.com\\\/interview-questions\\\/data-structure\\\/how-to-find-second-largest-element-in-a-bst.png\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/editor\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to find Second largest element in BST ? - Data Structure","description":"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/","og_locale":"en_US","og_type":"article","og_title":"How to find Second largest element in BST ? - Data Structure","og_description":"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/","og_site_name":"Wikitechy","article_published_time":"2021-07-13T11:24:08+00:00","article_modified_time":"2021-09-13T07:23:23+00:00","og_image":[{"url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png","type":"","width":"","height":""}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/"},"author":{"name":"Editor","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"headline":"How to find Second largest element in BST ?","datePublished":"2021-07-13T11:24:08+00:00","dateModified":"2021-09-13T07:23:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/"},"wordCount":765,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png","keywords":["Accenture interview questions and answers","Altimetrik India Pvt Ltd interview questions and answers","Applied Materials interview questions and answers","Bharti Airtel interview questions and answers","BMC Software interview questions and answers","Capgemini interview questions and answers","CASTING NETWORKS INDIA PVT LIMITED interview questions and answers","CGI Group Inc interview questions and answers","Chetu interview questions and answers","Ciena Corporation interview questions and answers","Collabera Te interview questions and answers","Dell International Services India Pvt Ltd interview questions and answers","find kth largest element in a binary search tree java","find max value in binary search tree c++","find maximum in binary search tree","find min and max in binary search tree in c","find the 2nd-largest node in a binary tree","find the node with maximum value in a binary search tree","find the second largest element in a binary search tree java","find the second largest element in a binary search tree python","Flipkart interview questions and answers","geekyants interview questions and answers","Genpact interview questions and answers","Globallogic India Pvt Ltd interview questions and answers","IBM interview questions and answers","Indecomm Global Services interview questions and answers","kth largest element in a stream bst","kth largest element in bst","kth smallest element in a bst leetcode","kth smallest element in a bst python","kth smallest element in a bst recursive","largest node in bst","largest number in bst which is less than or equal to n java","Mphasis interview questions and answers","NetApp interview questions and answers","Oracle Corporation interview questions and answers","SAP Labs India Pvt Ltd interview questions and answers","Sapient Consulting Pvt Ltd interview questions and answers","second largest element in bst","second largest element in bst java","second largest element in bst leetcode","second largest element in bst python","second largest element in generic tree","second largest element in generic tree java","second largest element in n ary tree java","second largest element in tree java","second largest in tree","second minimum node in a binary tree","Tech Mahindra interview questions and answers","Tracxn Technologies Pvt Ltd interview questions and answers","UnitedHealth Group interview questions and answers","Wipro Infotech interview questions and answers","WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers","Xoriant Solutions Pvt Ltd interview questions and answers","Yodlee Infotech Pvt Ltd interview questions and answers"],"articleSection":["Data Structure"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/","name":"How to find Second largest element in BST ? - Data Structure","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png","datePublished":"2021-07-13T11:24:08+00:00","dateModified":"2021-09-13T07:23:23+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"How to find Second largest element in BST ? - In an N-ary tree, the second largest value in the given tree to find and return the node.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-bst\/#primaryimage","url":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png","contentUrl":"https:\/\/cdn.wikitechy.com\/interview-questions\/data-structure\/how-to-find-second-largest-element-in-a-bst.png"},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=480"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/480\/revisions"}],"predecessor-version":[{"id":3525,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/480\/revisions\/3525"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}