Re: [algogeeks] Re: Find Largest number in log(n)

2011-12-13 Thread sagar pareek
Thanks Dave, Don and all others for this clarification. On Mon, Dec 12, 2011 at 11:23 PM, Prakash D cegprak...@gmail.com wrote: only the number of comparisons is log(n) On Mon, Dec 12, 2011 at 11:04 PM, Ankur Garg ankurga...@gmail.com wrote: Agree with dave..Its still O(n) On Mon, Dec

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread hary rathor
aal puzzle from techinterview. more then 50 % came from there . -- 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

[algogeeks] Suggest Algo for this Question

2011-12-13 Thread Ankur Garg
Given an array-based heap on n elements and a real number x, efficiently determine whether the kth smallest element in the heap is greater than or equal to x. Your algorithm should be O(k) in the worst-case, independent of the size of the heap. This question was also asked in Amazon -- You

[algogeeks] Dynamic programming question

2011-12-13 Thread Azhar Hussain
We have apples arranged in a mxn matrix. We start from the upper left corner and have to reach bottom right corner with maximum apples. We can only move either down or right. Now if we can start any where in the matrix and have to reach anywhere on the right(reach n column). We can either up,

Re: [algogeeks] Dynamic programming question

2011-12-13 Thread Dheeraj Sharma
i thnk it can be done using dynamic programming.. let the array b 25 3 25 1 10 2 5 now at at every point in the matrix..there can be two ways..to reach that point..either from left..or from right.. for example to reach at the center of the above matrix..we can come from 2-5-5 or

[algogeeks] Re: Dynamic programming question

2011-12-13 Thread vikas
Graph take up, right and bottom as nodes connected to current and do find max path. On Dec 13, 3:44 pm, Azhar Hussain azhar...@gmail.com wrote:   We have apples arranged in a mxn matrix. We start from the upper left corner and have to reach bottom right corner with maximum apples. We can only

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread rahul sharma
On Tue, Dec 13, 2011 at 3:21 PM, hary rathor harry.rat...@gmail.com wrote: aal puzzle from techinterview. more then 50 % came from there . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread sunny agrawal
@aayush Lots of member are here but that doesn't mean that you should start posting the things which are strictly banned on this group. I hope you will take care next time while posting anything in this group. On Tue, Dec 13, 2011 at 7:40 PM, rahul sharma rahul23111...@gmail.comwrote: On

Re: [algogeeks] Nice question

2011-12-13 Thread Amir hossein Shahriari
actually there are infinite number of sequences that match it for example if the absolute differences are 3 2 5 1 one possible sequence is 6 3 5 0 1 one other is 7 4 6 1 2 or 8 5 7 2 3 and you can add any integer value to all elements and the result will still be valid actually you can start with

Re: [algogeeks] simpel DP solution

2011-12-13 Thread Amir hossein Shahriari
1 is not a prime number! On Mon, Oct 31, 2011 at 4:07 PM, mc2 . qlearn...@gmail.com wrote: Hey guys , I am trying to solve this DP problem : http://community.topcoder.com/stat?c=problem_statementpm=10033rd=13513 SRM 422, DIV 2 ,level 2. Here is my DP solution. But it is not working.

[algogeeks] Re: Removing same character(s) in a group

2011-12-13 Thread top coder
After first iteration, adjacent similar characters are converted to get a single character After second iteration, similar adjacent strings of length 2 in the remaining string are replaced with single string of length 2 After third iteration, similar adjacent strings of length 3 in the remaining

[algogeeks] Re: Nice question

2011-12-13 Thread Dave
@Amir: Presumably, since these are digits in a number, they are bounded on the bottom by 0 and on the top by radix-1. So in decimal, if a digit is 7 and the absolute difference between it and the next digit is 3, there is only one possibility for the next digit, 7-3 = 4, since 7+3 is too large. So

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread tech coder
which other group u people are talking about, i would like to join that group. On Tue, Dec 13, 2011 at 9:21 PM, sunny agrawal sunny816.i...@gmail.comwrote: @aayush Lots of member are here but that doesn't mean that you should start posting the things which are strictly banned on this group. I

Re: [algogeeks] Suggest Algo for this Question

2011-12-13 Thread atul anand
O(k) in the worst-case , then i guess it would better to use median-of median algo to find element at rank k. and comparing with x. or we can us hashtable to solve this. On Tue, Dec 13, 2011 at 3:23 PM, Ankur Garg ankurga...@gmail.com wrote: Given an array-based heap on n elements and a real

[algogeeks] Re: Nice question

2011-12-13 Thread Don
The following is a dynamic programming solution to this problem. It builds up an array num[i][j] such that num[i][j] is the number of combinations of digits starting with digit j at position i. The answer is the sum of num[1][1]..num[9][1]. #include stdio.h int main(int argc, char* argv[]) {

[algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread top coder
If pairwise sums of 'n' numbers are given in non-decreasing order identify the individual numbers. If the sum is corrupted print -1 Example: i/p: 4 4 5 7 10 12 13 o/p: 1 3 4 9 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread sunny agrawal
http://groups.google.com/group/interview-street On Tue, Dec 13, 2011 at 10:19 PM, tech coder techcoderonw...@gmail.comwrote: which other group u people are talking about, i would like to join that group. On Tue, Dec 13, 2011 at 9:21 PM, sunny agrawal sunny816.i...@gmail.comwrote: @aayush

[algogeeks] Re: Nice question

2011-12-13 Thread Don
The following is a dynamic programming solution to this problem. It builds up an array num[i][j] such that num[i][j] is the number of combinations of digits starting with digit j at position i. The answer is the sum of num[1][1]..num[9][1]. #include stdio.h int main(int argc, char* argv[]) {

Re: [algogeeks] Re: Nice question

2011-12-13 Thread tech coder
I tried the problem and written the code for it . it is in java. it is printing all the possible numbers I am treating the differences ans an array of integers. here is the code public class Main { public static void main(String[] args) { int digit[]={3,2,5,1};// array of

[algogeeks] Re: Nice question

2011-12-13 Thread Don
One other observation: if any of the absolute differences was zero, it would print the same number more than once. Your algorithm is fine for n=5, but as n gets larger, the execution time increases exponentially. The dynamic programming algorithm is O(n). Don On Dec 13, 11:37 am, tech coder

Re: [algogeeks] Re: Nice question

2011-12-13 Thread tech coder
thanks don , i got it , it was due the condition in if expression . modified code i have highlighted the change public class Main { public static void main(String[] args) { int digit[]={3,2,5,1}; for(int num=1;num=9;num++) findNumber(digit,4,num,0,num); }

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Moheed Moheed Ahmad
To get a abs difference of 0 there are 10 ways similarly getting abs difference of 1 there are 9x2 ways(w1) for 2 its 8x2 (say w(2) for 3 its 7x2 . for 9 its 1x2(w9) let w(i) represents the number of ways to get abs diff of i. So total numbers that are possible from the given abs diff i j k

Re: [algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread atul anand
i am not sure , but this came to me when i first read it here is the idea:- given : 4 5 7 10 12 13 4 should be there boz it is the least. next is 5 , 5-4 =1 which is less that 4 , so 1 should be there next is 7 , 7-4 = 3 which is less than 4 , so 3 should be there next is 10 , 10-4 = 6 which

[algogeeks] Re: Nice question

2011-12-13 Thread Don
Moheed, If n=3 and absdiff = {0,0}, your program says that there are 100 possible numbers. Can you show me at least 10 of them? Don On Dec 13, 12:24 pm, Moheed Moheed Ahmad mohe...@gmail.com wrote: To get a abs difference of 0 there are 10 ways similarly getting abs difference of 1 there are

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Gaurav Kumar
When the difference is 0, the numbers will be repeated: 000, 111, 222, 333, 444, 555, 666, 777, 888, 999 but only these are possible. Gaurav On Tue, Dec 13, 2011 at 10:47 AM, Don dondod...@gmail.com wrote: Moheed, If n=3 and absdiff = {0,0}, your program says that there are 100 possible

Re: [algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread sayan nayak
@atul: Suppose the input is :(7,8,9) So output should be (3,4,5) then ur approach is not giving the answers.. Regards, Sayan On Tue, Dec 13, 2011 at 11:51 PM, atul anand atul.87fri...@gmail.comwrote: i am not sure , but this came to me when i first read it here is the idea:- given : 4 5 7

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Gaurav Kumar
I am just trying to understand the number of ways we can form this number, lets say d is the absolute difference between the numbers and the length of the numbers is n. Lets say we are considering base 10 numbers, so lets say radix r = 10. if you try to see all the comparisons, here is what

Re: [algogeeks] Suggest Algo for this Question

2011-12-13 Thread Gaurav Kumar
Why can't we keep removing the minimum element each time and compare it with x? This should take O(k) time since in a Min heap, the minimum element can be removed in O(1) time? Am I missing something? On Tue, Dec 13, 2011 at 8:43 AM, atul anand atul.87fri...@gmail.com wrote: O(k) in the

[algogeeks] Re: Nice question

2011-12-13 Thread Don
That gives an answer of 40,320, but the correct answer is 39. You can't multiply all of those values together and expect to get the right answer. There are not 14 possible values for the first digit, and if there were, for any particular value of the first digit there are not 16 possible values

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Gaurav Kumar
On Tue, Dec 13, 2011 at 12:40 PM, Don dondod...@gmail.com wrote: That gives an answer of 40,320, but the correct answer is 39. You can't multiply all of those values together and expect to get the right answer. There are not 14 possible values for the first digit, and if there were, for any

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Gaurav Kumar
Thanks for pointing out the issue with my logic. What I am wondering is what is the general solution to finding the number of possible numbers? Is the only way is to try these combinations? Please share if you know. Gaurav On Tue, Dec 13, 2011 at 1:56 PM, Gaurav Kumar gkuma...@gmail.com wrote:

[algogeeks] Re: Nice question

2011-12-13 Thread Don
Trying the combinations is not necessary. See my solution above. Don On Dec 13, 3:59 pm, Gaurav Kumar gkuma...@gmail.com wrote: Thanks for pointing out the issue with my logic. What I am wondering is what is the general solution to finding the number of possible numbers? Is the only way is to

Re: [algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread atul anand
hmmm i guess i screwed by taking least element as a part of the output set directly. On Wed, Dec 14, 2011 at 12:57 AM, sayan nayak sayanna...@gmail.com wrote: @atul: Suppose the input is :(7,8,9) So output should be (3,4,5) then ur approach is not giving the answers.. Regards, Sayan

Re: [algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread atul anand
in above case we need to do some checking like in case when next element is 10; next elements is 10 10-4 = 6 , 6 4 add(1,3,4 ) = 8 8 10(required_element) , so add 1 to 8 = 9 and do same as mentioned but if sum( number_found_so_far ) required_num then add 1 to difference of required_num -

Re: [algogeeks] Re: Cliched 'k' largest elements in billion numbers: Heaps or median-of-medians?

2011-12-13 Thread atul anand
@Gene : considering m-of-m algo , one thing that worries me is that using m-of-m for huge data is not good bcoz when practically implementing it constant would be very large so as to make it work for O(N) here is the reason why is not a good approach for huge data :- reccurence eqn for m-of-m is

Re: [algogeeks] Re: Nice question

2011-12-13 Thread Moheed Moheed Ahmad
Thanks Don for pointing it out. It will not work [the second and consecutive abs-diffs are not mutually exclusive]. However, here are the 10 possible numbers that will work for n=3 and absdiff={0,0}: 0 0 0 1 1 1 2 2 2 -- 8 8 8 9 9 9 -Moheed 'If a man neglects education, he walks lame to the

Re: [algogeeks] Suggest Algo for this Question

2011-12-13 Thread atul anand
@gaurav : you need to first build heap and then maintain heap property ever time you remove element.so this would take O(n logn ). On Wed, Dec 14, 2011 at 1:38 AM, Gaurav Kumar gkuma...@gmail.com wrote: Why can't we keep removing the minimum element each time and compare it with x? This

Re: [algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread Arun Vishwanathan
how is the case taken of when 2 pairs add to the same sum?... On Tue, Dec 13, 2011 at 11:35 AM, atul anand atul.87fri...@gmail.comwrote: hmmm i guess i screwed by taking least element as a part of the output set directly. On Wed, Dec 14, 2011 at 12:57 AM, sayan nayak

[algogeeks] Re: Suggest Algo for this Question

2011-12-13 Thread Dave
@Atul: The initial heap is given. You have to maintain the heap property as k elements are removed, which is O(k log n). This does not satisfy the original request for an algorithm that is O(k) in the worst-case, independent of the size of the heap. Dave On Dec 13, 10:31 pm, atul anand