tag:blogger.com,1999:blog-71781410774677155.post8565787980680851113..comments2023-10-26T14:09:25.963+05:30Comments on Sachith's Matrix: Binary Search Tree with In Order Traversal implementation in JavaSachith Withanahttp://www.blogger.com/profile/14680370493467240706noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-71781410774677155.post-69447793740614913152015-08-09T10:33:39.401+05:302015-08-09T10:33:39.401+05:30Thanks .. Great work..:D
Thanks .. Great work..:D<br />Piyum Ranganahttps://www.blogger.com/profile/13320851746783225899noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-7314924189463446492014-10-20T04:57:37.957+05:302014-10-20T04:57:37.957+05:30Great Job !
Just a small change you might wanna ma...Great Job !<br />Just a small change you might wanna make to the above code as even for the non-existing values, binarySearch() still returns a 'true' value.<br />One more verification step to verify<br />if(root.getData() == n.getData())<br />return true;Anonymoushttps://www.blogger.com/profile/15673394882228036000noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-73664744423169360552014-10-20T04:50:01.564+05:302014-10-20T04:50:01.564+05:30This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/15673394882228036000noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-65026515000857529752014-05-28T03:34:33.519+05:302014-05-28T03:34:33.519+05:30Hi.. can you show how a delete would work as well ...Hi.. can you show how a delete would work as well please?Harryhttps://www.blogger.com/profile/13828613862545338073noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-28509268060014838692014-03-27T07:56:59.340+05:302014-03-27T07:56:59.340+05:30No Man...
code of binarySearch(...) is correct and...No Man...<br />code of binarySearch(...) is correct and work well...<br /><br />ThanksAli Mehrpourhttps://www.blogger.com/profile/18060055301549713715noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-22438044319588501392014-02-14T02:24:27.286+05:302014-02-14T02:24:27.286+05:30//binary search
public boolean binarySearch(No...//binary search<br /> public boolean binarySearch(Node root,Node n){<br /> if(root == null || n == null) {<br /> return false;<br /> }<br /> System.out.println(" Testing out "+root.getData()+" for value "+n.getData());<br /> if(root.getData() > n.getData()){<br /> return binarySearch(root.getLeft(),n);<br /> }else if(root.getData() < n.getData()){<br /> return binarySearch(root.getRight(),n);<br /> }<br /> return true;<br /> }<br /><br />I think this particular code is incorrect and will always return true even for the values not present in the BST. The correct implement should have either "false" or "true" be returned something like this<br /><br />private boolean binarySearch(Node root, Node node) { <br /> <br /> if(root == null || node == null)<br /> return false;<br /> else{<br /> if(root.getData() == node.getData())<br /> return true;<br /> else if(root.getData() > node.getData())<br /> return binarySearch(root.left, node);<br /> else<br /> return binarySearch(root.right, node);<br /> } <br /> }<br />CuriousToLearnhttps://www.blogger.com/profile/15637779403555719103noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-40203018166173601542014-02-13T12:32:49.141+05:302014-02-13T12:32:49.141+05:30This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/12233431415069674743noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-77435208079996806842013-12-18T10:28:20.544+05:302013-12-18T10:28:20.544+05:30great workgreat workAasif Alihttps://www.blogger.com/profile/12555687285240201369noreply@blogger.comtag:blogger.com,1999:blog-71781410774677155.post-29069672586717641622013-12-07T14:55:45.910+05:302013-12-07T14:55:45.910+05:30You're welcome.You're welcome. Sachith Withanahttps://www.blogger.com/profile/14680370493467240706noreply@blogger.com