Re: [algogeeks] Check if a binary tree is Binary Search Tree or not.

2012-11-06 Thread atul anand
@vishal : as discussed in previous post , your solution wont work for certain test cases...and i dont think so , checking tree in inorder way is complex .It is simple to implement , you just need to call tree recursively in Inorder way and keep track of prev node and compare prev node with

[algogeeks] increment operator...

2012-11-06 Thread Anil Sharma
main() { int k = 5; if (++k 5 k++/5 || ++k = 8); printf(%d , k); } the output shud be 8 but it comes out to be 7.why??? as increment operator has higher precedence among them so increment shud be done throughout at first and after then other operators shud be

Re: [algogeeks] Check if a binary tree is Binary Search Tree or not.

2012-11-06 Thread Ankit Tripathi
I totally agree with atul007. And that's optimal because one must check every node for checking whether the tree is a BST or not, and this algorithm visits each node exactly once. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this

[algogeeks] Add and subtract with out using mathematical operator.......

2012-11-06 Thread DHARMENDRA KUMAR VERMA
how many ways are there to add or subtract two numbers with out addition or subtraction operator??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Check if a binary tree is Binary Search Tree or not.

2012-11-06 Thread vaibhav shukla
yes ofcourse... dats the easiest i suppose... but in one of my interviews, i told this approach, but was then asked not to use space (which i was ,to store inorder) So for such cases, you must try other approaches as well. (DO inorder,keep track of previously visited node and compare it with

Re: [algogeeks] Re: Repeated values

2012-11-06 Thread Saurabh Kumar
yes, that was an implementation mistake but what I meant to say was- Adding extra check of indirect xor'ing could have a pitfall too. Try the case: [0 1 1 1 4 4] http://ideone.com/3sreLZ On 4 November 2012 10:13, Vikram Pradhan vpradha...@gmail.com wrote: It should have caught in the first

Re: [algogeeks] increment operator...

2012-11-06 Thread Anil Arya
if (++k 5 k++/5 || ++k = 8); is same as if ++k 5) (k++/5)) || (++k = 8))); (++k 5) (k++/5) in this expression ++k5 returns false(0) ,so there is no need to evaluate right hand side(why?) 2012/11/6 Anil Sharma anilsharmau...@gmail.com main() { int k = 5; if (++k

Re: [algogeeks] increment operator...

2012-11-06 Thread vishal chaudhary
Hi anil first of all when the program starts k = 5 then compiler enters if region then k is incremented before it is compared with 5 ie k = 6 then condition is checked ie ++k 5 and it comes out to be false then as it was end operation compiler does not evaluate the second statement ie k++/5 then

Re: [algogeeks] Check if a binary tree is Binary Search Tree or not.

2012-11-06 Thread atul anand
@vaibhav : by not using extra space...i guess you mean that you were not allowed to use one extra pointer.bcozz space complexity will remain constant for inorder approch. On Tue, Nov 6, 2012 at 1:07 AM, vaibhav shukla vaibhav200...@gmail.comwrote: yes ofcourse... dats the easiest i suppose...