Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-26 Thread aswath G B
@Dave Slight change u have to do #includestdio.h main() { int a = 24; int b = (a | 7)+1; //This Line U have to change. not a || 7. printf(%d,b); return 0; } tats it btw it is nice one line easy soln... On Sat, Sep 25, 2010 at 10:17 PM, Dave dave_and_da...@juno.com wrote:

Re: [algogeeks] Print 1 to n one per each line on the standard output

2010-09-26 Thread aswath G B
@coolfrog$ I think this can match ur requirements not even indirect recursion #includeiostream using namespace std; static int i; class sample { public: sample() { i=i+1; couti\n; } }; main() { int n; coutEnter n\n; cinn; sample s[n]; return 0; } tats it On Thu, Sep 23, 2010 at 11:29 PM,

[algogeeks] Re: BST in BT

2010-09-26 Thread prodigy
BSTP : Root's right and left subtrees are BST and value at Root is (greater than largest of left) and (smaller than lowest of right). if BSTP is true, size of this BST is sum of (size of left subtree) and (size of right subtree) plus 1. Compare this value with global maximum. Do it recursively.

Re: [algogeeks] Re: BST in BT

2010-09-26 Thread Chonku
This can also be done if we do an inorder traversal of the binary tree and look for the longest continuous sequence of numbers in ascending order. On Sun, Sep 26, 2010 at 11:10 AM, mac adobe macatad...@gmail.com wrote: No parody .. that would be another doubt :( On Sat, Sep 25, 2010 at

Re: [algogeeks] Re: Microsoft interview question

2010-09-26 Thread ashita dadlani
@Mohit: I dont think it really matters here.We just have to validate the snapshot of the game board.Number of players should not have any relevance here. On Sat, Sep 25, 2010 at 2:46 PM, mohit ranjan shoonya.mo...@gmail.comwrote: @Ashita, Your logic is fine for one vs one game, but as per

[algogeeks] Re: Microsoft interview question

2010-09-26 Thread dreamer .....................
@ ashita and vrinda can u please write ur ms written and interview questions.. i ll be really thankful to both of u as ms is going to visit my campus soon.. so plz help... On Sep 26, 1:58 pm, ashita dadlani ash@gmail.com wrote: @Mohit: I dont think it really matters here.We just have to

Re: [algogeeks] Re: next multiple of 8

2010-09-26 Thread Mahendran MaheM
sry...i dnt get the qstn clearly. On Sat, Sep 25, 2010 at 10:18 PM, Dave dave_and_da...@juno.com wrote: Simpler: answer = (x || 7) + 1 Dave On Sep 25, 10:14 am, rajess rajess1...@yahoo.com wrote: scan last(left) 4 bits .if the bits are not 1000.make them 1000.else scan from left

[algogeeks] Re: next multiple of 8

2010-09-26 Thread Shravan
@Dave Your answer will be always 2 irrespective of the value of 'x'. BTW I too didn't the question. On Sep 26, 2:42 pm, Mahendran MaheM mehamind...@gmail.com wrote: sry...i dnt get the qstn clearly. On Sat, Sep 25, 2010 at 10:18 PM, Dave dave_and_da...@juno.com wrote: Simpler: answer

[algogeeks] Re: next multiple of 8

2010-09-26 Thread Dave
@Shrevan: I mistyped what I intended. Try answer = (x | 7) + 1; Dave On Sep 26, 5:51 am, Shravan shravann1...@gmail.com wrote: @Dave Your answer will be always 2 irrespective of the value of 'x'. BTW I too didn't the question. On Sep 26, 2:42 pm, Mahendran MaheM mehamind...@gmail.com wrote:

[algogeeks] Re: Bitwise operator - Adobe

2010-09-26 Thread Dave
@Ashwath: Thanks for the correction. Dave On Sep 26, 1:20 am, aswath G B aswat...@gmail.com wrote: @Dave  Slight change u have to do #includestdio.h main() {  int a = 24;  int b = (a | 7)+1;  //This Line U have to change. not  a || 7.  printf(%d,b);  return 0; } tats

Re: [algogeeks] search a 2d sorted array in less than O(n)

2010-09-26 Thread Nikhil Jindal
On Tue, Sep 21, 2010 at 6:05 PM, saurabh singh saurabh.n...@gmail.comwrote: solution 1: use concept of quad-tree and do binary search in that tree solution 2: do binary search on major diagonal. ultimately u will narrow down to search for element in 2 rows. in these two rows again do

Re: [algogeeks] search a 2d sorted array in less than O(n)

2010-09-26 Thread Nikhil Jindal
Here's an O(n) soln: Start from the bottom right corner. Move up within the last column until you reach an element such that the element before that is less than the value being searched and this is greater. Now move left and check for the same. Move one more left. The value can only be in the

Re: [algogeeks] search a 2d sorted array in less than O(n)

2010-09-26 Thread Nikhil Jindal
Sorry the last solution wont work. Here's the correct O(n) soln: Start from top-right element. If it is greater than the item, go left. Else go down. Keep on doing this until you find the element or can not go left or down (then the element is not in the array). void 2dsearch(int i, int j,

Re: [algogeeks] search a 2d sorted array in less than O(n)

2010-09-26 Thread saurabh singh
As you mentioned ultimately element to be searched should either be in row 'i' (ahead of [i,i] element) or in row i+1 (before [i+1,i+1] element). Since each row contain numbers in sorted order so u can do binary search on these two rows and ultimately the complexity will be O(logn) only On Sun,

[algogeeks] Re: BST in BT

2010-09-26 Thread prodigy
15 /\ 8 25 /\ 20 22 On Sep 26, 10:45 am, Chonku cho...@gmail.com wrote: This can also be done if we do an inorder traversal of the binary tree and look for the longest continuous

[algogeeks] Re: search a 2d sorted array in less than O(n)

2010-09-26 Thread Gene
If the array is m by n, pick the element a[m/2][n/2], i.e. the one in the middle. There are now 3 possibilities: 1) The middle element is the one you're looking for, so you're done. 2) The element you're looking for is smaller. In this case you can throw out about 1/4 of the array: everything