Re: [algogeeks] Re: Problem: Longest Increasing Seq code

2011-07-16 Thread surender sanke
p[i] maintains previous index from which b[i] has reached longest sequence till i. to get the actual list of non-decrease sequence, p has to be traversed through back indices for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v; surender On Sat, Jul 16, 2011 at 9:06 AM, Neeraj Gupta

[algogeeks] Re: Dynamic Programming Cormen

2011-07-16 Thread Nitish Garg
Someone please reply. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/vBP5ZdFV9HEJ. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] Re: Dynamic Programming Cormen

2011-07-16 Thread sagar pareek
Reply for what? On Sat, Jul 16, 2011 at 1:07 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Someone please reply. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread sukhmeet singh
for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2.

Re: [algogeeks] Image Based Problem (Google)

2011-07-16 Thread sagar pareek
OK :) On Sat, Jul 16, 2011 at 2:32 AM, Divye Kapoor divyekap...@gmail.com wrote: @Sagar: You misunderstand my concern. When I say hash collisions, I mean: Consider 2 very different images X and Y - both have the same hash value H. Such X and Y will always exist because you're mapping a

Re: [algogeeks] Printf ...

2011-07-16 Thread sagar pareek
@Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will be compiler dependent res1 is not defined .. as C don't allow to change the value of a variable more than

Re: [algogeeks] Printf ...

2011-07-16 Thread sagar pareek
and o/p is %#s Zi not %s Zi On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek sagarpar...@gmail.com wrote: @Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will

Re: [algogeeks] Printf ...

2011-07-16 Thread sagar pareek
tell me your output pls On Sat, Jul 16, 2011 at 2:19 PM, sagar pareek sagarpar...@gmail.com wrote: and o/p is %#s Zi not %s Zi On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek sagarpar...@gmail.comwrote: @Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :)

Re: [algogeeks] Printf ...

2011-07-16 Thread sagar pareek
@Antony res1=++a + ++a + ++a; Well it depends on the compiler but i know how gcc works :) from left to right it will first do addition of first two 'a' before addition it will increment the value of a by two cos of two pre increments. then resulting addition will then be added to the incremented

[algogeeks] Merge unsorted arrays

2011-07-16 Thread aseem garg
Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

[algogeeks] what would be the output of following code??

2011-07-16 Thread shiv narayan
Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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 group, send email to

Re: [algogeeks] Re: Dynamic Programming Cormen

2011-07-16 Thread sunny agrawal
Because here we can not reOrder words, Greedy seems to work fine to me too, i am not able to come up with an contradictory example..will post if will get one... or post if any one can. but here http://mitpress.mit.edu/algorithms/solutions/chap15-solutions.pdfis the DP solution to the

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread swetha rahul
2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: X-AmazoN

2011-07-16 Thread kaustubh
There is an infinitesimally small probability that it will continue to run forever. But I tested it for 10,000 runs and it ran in a flash on my archaic machine (5yrs old is archaic probably :) ) int generateRand() { int num = 1; for(int i=0;i10;i++) { int

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread Deoki Nandan
what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2));

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread saurabh singh
Well if there is a space btween the two %d's dn it should be 2 2 2 23 Otherwise fine. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul

[algogeeks] Re: A Tough Bit Manipulation

2011-07-16 Thread kaustubh
@Dave - Nice solution :) On Jul 10, 4:42 pm, Dave dave_and_da...@juno.com wrote: @Anurag: Seehttp://groups.google.com/group/algogeeks/msg/d90353c759125384?hl=en. Dave On Jul 10, 1:14 am, anurag anurag19aggar...@gmail.com wrote: You are given two integers n and k k signifies number of

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread Ankur Khurana
answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul

[algogeeks] Re: Printf ...

2011-07-16 Thread shiv narayan
according to me it processing is done from righ to left .first right most a would be incremented and then from righ to left for first question answer should be 8+7+6=21 and for 2nd it should be (8)+(7)*10+(6)*100=678 On Jul 15, 1:15 pm, Antony Kotre antonyko...@gmail.com wrote: can any tell and

Re: [algogeeks] Re: Printf ...

2011-07-16 Thread Ankur Khurana
I am using MinGW compiler (codeblocks , out put is 788 and not 678 . Its compiler dependent so , let us leave it that way only. On Sat, Jul 16, 2011 at 3:27 PM, shiv narayan narayan.shiv...@gmail.comwrote: according to me it processing is done from righ to left .first right most a would

Re: [algogeeks] Merge unsorted arrays

2011-07-16 Thread Ankur Khurana
Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else

[algogeeks] Re: Image based Problem (Google)

2011-07-16 Thread kaustubh
Divide the image into 1000x1000 grid. Compute and store hash of each individual cell. Now, compare hashes of cells instead. Assuming each hash is 16 bytes, it takes additional ~ 16 MB of memory, but the time required to localize the point of change is reduced by a factor of 10^6. To reduce the

Re: [algogeeks] MS:Linked list

2011-07-16 Thread sagar pareek
i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no encounter then traverse the remaining list with tmp pointer with start point ptr-next and match the numbers with iti hope it works :) On Sat, Jul 16, 2011 at 10:10 AM,

[algogeeks] Microsoft Interview Qn

2011-07-16 Thread Reynald
Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- 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

Re: [algogeeks] MS:Linked list

2011-07-16 Thread sagar pareek
yup :) On Sat, Jul 16, 2011 at 4:17 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: @sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.comwrote: i have solution with no extra space

Re: [algogeeks] MS:Linked list

2011-07-16 Thread Nishant Mittal
@sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.com wrote: i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no

Re: [algogeeks] Merge unsorted arrays

2011-07-16 Thread sagar pareek
sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) {

Re: [algogeeks] Merge unsorted arrays

2011-07-16 Thread Ankur Khurana
oops , didnt see the unsorted thing. complexity is mnlog(n) + mn log(m) On Sat, Jul 16, 2011 at 4:23 PM, sagar pareek sagarpar...@gmail.com wrote: sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use

Re: [algogeeks] MS:Linked list

2011-07-16 Thread shady
@sagar ya this is brute force On Sat, Jul 16, 2011 at 4:19 PM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sat, Jul 16, 2011 at 4:17 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On

Re: [algogeeks] Microsoft Interview Qn

2011-07-16 Thread shady
always state one input output while asking questions sample input-output ? On Sat, Jul 16, 2011 at 4:16 PM, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- You

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread shady
@ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread varun pahwa
the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread varun pahwa
please ignore my previous post. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote:

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread varun pahwa
ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2

[algogeeks] Re: Google interview question

2011-07-16 Thread Dumanshu
how about using voters algorithm? TC O(n) and SC O(1) On Jul 16, 6:28 am, Anand Shastri anand.shastr...@gmail.com wrote: Given a file containing 4,300,000,000  integers, how can you *find **one* that *appears* at *least **twice* -- You received this message because you are subscribed to the

[algogeeks] Re: Google interview question

2011-07-16 Thread XYZ
If the there are problems with hashing method, What about simply sorting the numbers then comparing the adjacent numbers ! Time complexity O(nlogn)+O(n)=O(nlogn) Cheers! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this

[algogeeks] Re: Merge unsorted arrays

2011-07-16 Thread noobcoder
how does ur algo produce sorted elements in final array? On Jul 16, 3:55 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: oops , didnt see the unsorted thing. complexity is mnlog(n) + mn log(m) On Sat, Jul 16, 2011 at 4:23 PM, sagar pareek sagarpar...@gmail.com wrote: sort all the

[algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread Reynald
Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- You received this

[algogeeks] Re: Google interview question

2011-07-16 Thread Dave
@Anand: Assuming that the file contains unsigned 32-bit integers. Set an integer array a[65536] to zero, read through the file and tally the numbers based on their low-order 16 bits: a[j0x]++. Since 4.3 billion exceeds 2^32, by the pigeonhole principle, there will be at least one tally, say

[algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread noobcoder
Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 group, send

[algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread noobcoder
Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 group, send

Re: [algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread saurabh singh
Check https://groups.google.com/group/algogeeks/browse_thread/thread/e8735bcdbf4c956/c49018d0eac8070b?hl=enlnk=gstq=saurabh8c#c49018d0eac8070b On Sat, Jul 16, 2011 at 7:50 PM, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that

Re: [algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sourabh jakhar
convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh singh saurab...@gmail.com wrote: Check

Re: [algogeeks] Re: Merge unsorted arrays

2011-07-16 Thread Ankur Khurana
you sort array before merging. and then use merge sort On Sat, Jul 16, 2011 at 6:53 PM, noobcoder ase.as...@gmail.com wrote: how does ur algo produce sorted elements in final array? On Jul 16, 3:55 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: oops , didnt see the unsorted thing.

Re: [algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread keyan karthi
can be done in NlogN take a node, say 'a' check if k-a exists in the tree(logN) On Sat, Jul 16, 2011 at 7:58 PM, sourabh jakhar sourabhjak...@gmail.comwrote: convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh

[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread Dave
@Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return

[algogeeks] Re: Merge unsorted arrays

2011-07-16 Thread Dave
@Aseem: Combine the arrays and sort the result. O(mn log mn). Dave On Jul 16, 4:13 am, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution.

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sagar pareek
@dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first)

[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread Dave
@Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at

[algogeeks] c++ probs

2011-07-16 Thread Anika Jain
Q.1 what is the output of following program? #include iostream using namespace std; class A { public: A() { coutConstructing Aendl; } ~A() { coutDestructing Aendl; } }; class B : public A { public: B()

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sagar pareek
ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal

Re: [algogeeks] c++ probs

2011-07-16 Thread Vipul Kumar
Output of 1st is constructing A constructing B destructing *A* * * as destructor is not virtual only the base class destructor is called and during object creation first base class constructor is called then derived class during the derived class object creation. output of 2nd : the object of

Re: [algogeeks] c++ probs

2011-07-16 Thread Sarvesh
HI, Q1: Destructor of B is not called because it doesn't have Run time type information as there is no virtual function. By have a declaration like A *b= new B(); Application only know that type of object b is A so when this object get destroyed, only Class A destructor is called. Q2:

[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread Dave
@Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sagar pareek
and so it must not be O(n) On Sat, Jul 16, 2011 at 10:54 PM, sagar pareek sagarpar...@gmail.comwrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM,

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sagar pareek
Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed

[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread Dave
@Sagar: The algorithm visits each node at most 3 times: Once when descending from its parent, once when ascending from its left child, and once when ascending from its right child. Furthermore, one node is eliminated from contention with every three comparisons of F with R. Thus, there are no more

[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread Dave
@Sagar: If you are not getting my logic, ask a question. Dave On Jul 16, 12:35 pm, sagar pareek sagarpar...@gmail.com wrote: Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread sagar pareek
You must take an example and then explain On Sat, Jul 16, 2011 at 11:59 PM, Dave dave_and_da...@juno.com wrote: @Sagar: If you are not getting my logic, ask a question. Dave On Jul 16, 12:35 pm, sagar pareek sagarpar...@gmail.com wrote: Ok may be i m not getting ur logic... On

Re: [algogeeks] Re: Printf ...

2011-07-16 Thread Kamakshii Aggarwal
@sagain:in dev c it is #s Zi On Sat, Jul 16, 2011 at 3:35 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: I am using MinGW compiler (codeblocks , out put is 788 and not 678 . Its compiler dependent so , let us leave it that way only. On Sat, Jul 16, 2011 at 3:27 PM, shiv narayan

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread Kamakshii Aggarwal
answer to the first should be 2 22 23 On Sat, Jul 16, 2011 at 5:44 PM, varun pahwa varunpahwa2...@gmail.comwrote: ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM,

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread Deoki Nandan
Give reason not answer . Answer can be found by compiler On Sun, Jul 17, 2011 at 12:38 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: answer to the first should be 2 22 23 On Sat, Jul 16, 2011 at 5:44 PM, varun pahwa varunpahwa2...@gmail.comwrote: ignore my previous result. the ans

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread sagar pareek
here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data;

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread Kamakshii Aggarwal
@gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread swetha rahul
@Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0;

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread Shubham Maheshwari
according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread sagar pareek
yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the

Re: [algogeeks] what would be the output of following code??

2011-07-16 Thread Kamakshii Aggarwal
printf returns no of characters printed..first of all the rightmost printf will print 2 2 .and since it is printing 3 characters(two 2's and 1 space) thereby its returning 3.same is with the other printf..now the outer most printf will print the value of(3 3) which is 3..and hence the answer. On

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread swetha rahul
Sagar , Shubam Maheshwari Thanks!! On Sun, Jul 17, 2011 at 1:11 AM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll

[algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread DK
void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root-left, root-right); convert(root-right, NULL); root-right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are

[algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread sagar pareek
I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a;

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.com wrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Kamakshii Aggarwal
u can always retrieve that value from the union that has been assigned last.therefore u get correct answer only for x.c in the case of union y y.a=100 and so the output but am not sure why y.b is printing character equivalent of 100. On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Shubham Maheshwari
@Kamakshii: thats probably becuz a union has a common memory location, accessed by all its members. so, the value '100' is treated as an int by 'a', as a char array by 'b' and as a float by 'c'. I thnk i read this read tis somewhere sometime back. ... so aint completely sure abt it. On Sun, Jul

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread Kamakshii Aggarwal
@shubham:yes u r right.thanks :) On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: @Kamakshii: thats probably becuz a union has a common memory location, accessed by all its members. so, the value '100' is treated as an int by 'a', as a char array by 'b'

Re: [algogeeks] What is the output of the following program? Why?

2011-07-16 Thread sagar pareek
Well shubham if you know about the unions very well then why u asked this question? On Sun, Jul 17, 2011 at 2:27 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: :D On Sun, Jul 17, 2011 at 2:24 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: @shubham:yes u r right.thanks :)

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread SkRiPt KiDdIe
A pre-order traversal which is used to index the (min,max) pair value at each level except the bottom-most level where all the entries are to be printed. O(n) time O(log n) memory. On 7/17/11, swetha rahul swetharahu...@gmail.com wrote: Sagar , Shubam Maheshwari

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread SkRiPt KiDdIe
Use O(2n) memory , list the in-order traversal of BST say A[0..n]. and K-A[0...n] say B . Now apply standard merge function(Merge sort) on A and B. keeping track of equal found elements during comparison to get the ans. On 7/17/11, sagar pareek sagarpar...@gmail.com wrote: You must take an

Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread saurabh singh
@sagar This is what Dave is suggesting in a more pseudocode way:- 1-Traverse a pointer right down to the leftmost element,i.e.the shortest,say small 2-traverse a pointer left down to the rightmost element i.e.the largest.say large while(small!=large) 3-Compare their sum.If sumk set large to its

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread Reynald Suz
Sagar;s Algo works, thank you so much guys. On Sun, Jul 17, 2011 at 3:41 AM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: A pre-order traversal which is used to index the (min,max) pair value at each level except the bottom-most level where all the entries are to be printed. O(n) time O(log n)

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread Reynald Suz
Yep! On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*);

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread sukhmeet singh
please explain the code a bit more.. unable to understand it..an example will be better.. On Sun, Jul 17, 2011 at 7:10 AM, Reynald Suz reynaldsus...@gmail.comwrote: Yep! On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75

Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread Nishant Mittal
value of b = 10 (in binary) and since b is a signed integer and also MSB is 1 so final value of b is 2's complement of 10 i.e. -2 On Sun, Jul 17, 2011 at 12:55 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: @gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh

Re: [algogeeks] Re: Merge unsorted arrays

2011-07-16 Thread sanjay ahuja
It depends upon problem if n m, apply insertion sort for sorting m arrays because for smaller sublists insertion sort perform better then merge sort and then merge them all in mnlog(m) otherwise simply combine and apply merge sort or any other standard sorting algorithm On Sat, Jul 16, 2011 at

Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree

2011-07-16 Thread sameer.mut...@gmail.com
@sagar: There is one flaw in the code. Trace ur code 15 and 250 get printed twice. otherwise it is fine. On Sat, Jul 16, 2011 at 7:59 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: please explain the code a bit more.. unable to understand it..an example will be better.. On Sun, Jul 17,

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread surender sanke
im a bit confused with child-sibling term, this expects output for A /\ B C / \ / \ DE F G 1 A / B C / / DE FG 2 A / B-- C / DEFG is output expected 1 or 2

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread naveen ms
in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- You received this message because you are