{"id":113,"date":"2018-02-14T02:19:41","date_gmt":"2018-02-14T02:19:41","guid":{"rendered":"http:\/\/www.datastructure.org\/?p=113"},"modified":"2025-04-21T13:49:11","modified_gmt":"2025-04-21T13:49:11","slug":"find-whether-binary-tree-is-a-binary-search-tree","status":"publish","type":"post","link":"https:\/\/www.bhargaviurs.com\/index.php\/2018\/02\/14\/find-whether-binary-tree-is-a-binary-search-tree\/","title":{"rendered":"Find whether Binary tree is a Binary Search Tree"},"content":{"rendered":"<p><strong>Property:<\/strong>\u00a0A binary tree is a Binary Search Tree when all elements to the left is lesser than the current node and the ones to the right are greater than that node.<\/p>\n<ul>\n<li>Simplest way to understand is when you print a left node, root and right node, you should get a sorted list based on property of BST.<\/li>\n<li>In other words, traversing in the order Left, Root, Right is called Inorder traversal.<\/li>\n<li>Inorder traversal visits each element in a tree exactly once and hence takes <strong>O(n)<\/strong> time, where \u2019<strong>n\u2019<\/strong> is the number of elements.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-111 size-full\" src=\"http:\/\/www.datastructure.org\/wp-content\/uploads\/2018\/02\/main-qimg-fea9a9a8e6f7c1a03d8720d2b762d1f8.png\" alt=\"\" width=\"602\" height=\"442\" srcset=\"https:\/\/www.bhargaviurs.com\/wp-content\/uploads\/2018\/02\/main-qimg-fea9a9a8e6f7c1a03d8720d2b762d1f8.png 602w, https:\/\/www.bhargaviurs.com\/wp-content\/uploads\/2018\/02\/main-qimg-fea9a9a8e6f7c1a03d8720d2b762d1f8-300x220.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/p>\n<ul>\n<li>Hence, if Inorder traversal of a Binary tree produces a sorted list, the tree is said to be a Binary Search Tree.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Property:\u00a0A binary tree is a Binary Search Tree when all elements to the left is lesser than the current node and the ones to the right are greater than that node. Simplest way to understand is when you print a left node, root and right node, you should get a sorted list based on property &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8,9,10,11,12,14,17],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-trees","tag-binary-trees","tag-bst","tag-complexity","tag-datastructures","tag-delete","tag-interview","tag-trees","entry"],"_links":{"self":[{"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":1,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":491,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions\/491"}],"wp:attachment":[{"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhargaviurs.com\/index.php\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}