Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-15 Thread WgpShashank
@sunny why we look at all k number which are greater then x , correct ? Lets think in this way we wants to check if kth smallest element in heap thats =x isn't it ? so if root of mean heap is greater then x then none other elements will less then x so we terminate . else our algorithm will

Re: [algogeeks] Re: doubt in TSUM

2011-12-15 Thread WgpShashank
@anubhaw ..its like spoon feeding , never mind u could have googled it :D http://www.google.co.in/search?q=3+sumie=utf-8oe=utf-8aq=trls=org.mozilla:en-US:officialclient=firefox-a Thanks Shashank Mani CSE, BIT Mesra http://shashank7s.blogspot.com/ -- You received this message because you are

[algogeeks] Re: SPOJ . 10186.PUCMM025

2011-12-15 Thread anubhav raj
hey ,i got the bug and got AC ALSO..there was several bugs ...sry ,for silly dbt -- 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] Re: convert into palindrome

2011-12-15 Thread Mohit kumar lal
@Lucifer- thnks got ur logic...:) On Thu, Dec 15, 2011 at 12:07 PM, Lucifer sourabhd2...@gmail.com wrote: Correction: for NAN : N(IT)A + TI + N = NITATIN On Dec 15, 11:33 am, Lucifer sourabhd2...@gmail.com wrote: @topcoder.. String: NITAN RevStr: NATIN LCS ( NITAN, NATIN) =

[algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread Ankur Garg
Twisted linked list problem: Two linked lists merge at some node p,both the head pointers are given find the merging point under the following restrictions. 1. You should not traverse to the end any of the linked list. 2. Merge node p should be detected by the time you reach at most most k nodes

[algogeeks] Exclusively For You

2011-12-15 Thread divya raghavan
I like this offer http://www.chrisbeck.de/inf.php It could be interesting for you, too -- 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

Re: [algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread Ravi Ranjan
in the link list take another variable suppose toggle and initialize all with 0,,, at the time of declaring the link list( so no traversal of entire link list).. now starting from both head traverse a single element at a time but in alternating way... for one linklist the toggling value is set to

Re: [algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread atul anand
seem like very twisted problem :P :P . lot of restriction. On Thu, Dec 15, 2011 at 7:30 PM, Ankur Garg ankurga...@gmail.com wrote: Twisted linked list problem: Two linked lists merge at some node p,both the head pointers are given find the merging point under the following restrictions. 1.

Re: [algogeeks] Re: convert into palindrome

2011-12-15 Thread saurabh singh
Sorry for replying late...ya posted the reply in hurry.But it appears that finally it has been resolved what i meant to say in my original post. On Thu, Dec 15, 2011 at 6:38 PM, Mohit kumar lal kumarmohit...@gmail.comwrote: @Lucifer- thnks got ur logic...:) On Thu, Dec 15, 2011 at 12:07 PM,

Re: [algogeeks] Complexity

2011-12-15 Thread Durgesh Kumar
saurabh is right nd or U can also download lecture 2 of series Introduction to Algorithm mit lecture . It is jst awesome . On 12/15/11, saurabh singh saurab...@gmail.com wrote: Introduction to Algorithms Coreman On Wed, Dec 14, 2011 at 8:21 PM, Shashank Jain shashan...@gmail.com wrote: I

Re: [algogeeks] Re: Dynamic programming question

2011-12-15 Thread Dheeraj Jain
http://www.geeksforgeeks.org/archives/14943 is a very similar problem. On Thu, Dec 15, 2011 at 1:12 PM, WgpShashank shashank7andr...@gmail.comwrote: @Azhar , also for 1st question u r trying Array DS will suffices. Its Standard Coin Change Problem , u need to solve subproblem 1st , store it in

Re: [algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread atul anand
@Ravi : your solution will not work for all the cases because of the restriction * * *1)You should not traverse to the end any of the linked list.* * * now consider one linked list to be very large while other is very small say 1/5 of the large one. now because second linked list is short and it

[algogeeks] Re: Suggest Algo for this Question

2011-12-15 Thread Lucifer
@All I don't think the algo given above is entirely correct.. Or may be i didn't it properly... So basically say a preorder traversal of the heap is done based on whether the current root value X. As the algo says that at any point if k0 and we hit a node value which is =X , then we are done.

Re: [algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread atul anand
@Ravi : if your solution is acceptable then there is no need ok modifying data structure. we can use hashMap which table address and count as an input. then we can move in same fashion as you have mentioned , if count is of given address is 1 then it means that address is the intersection point.

Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-15 Thread atul anand
@Lucifer : yes even i found flaw in the above algo when i gave it a second thought but didnt get time to post it. bcoz min heap has property that the parent node is less than its both child(subtree to be more precise ) but it does not confirm that left child is always smaller than right child of

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

2011-12-15 Thread Ankur Garg
Hi Topcoder. First of all you posted the wrong array . The array should be 4, 5, 10, 7, 12, 13 a+b a+c a+d b+cb+d c+d Now first calculate a+b+c+d which will be (sumofarray)/N-1 So here a+b+c+d = 17 Now take a[1] is a+c and a[N-1] = b+c subtracting them

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

2011-12-15 Thread Ankur Garg
on above algo , there is no need to calculate sum of array so we can do it in O(N) and not O(n). On Fri, Dec 16, 2011 at 12:59 AM, Ankur Garg ankurga...@gmail.com wrote: Hi Topcoder. First of all you posted the wrong array . The array should be 4, 5, 10, 7, 12, 13

Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-15 Thread sunny agrawal
oops... wanted to write the same but yeah its meaning turns out to be totally different :( anyways very well explained by Lucifier @shashank i think now u will be able to get why there will be only 2k comparisons in the worst case On Thu, Dec 15, 2011 at 10:51 PM, atul anand

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

2011-12-15 Thread Ankur Garg
I saw this term non-decreasing order So we need to sort the numbers first..it will take nlogn . On Fri, Dec 16, 2011 at 1:12 AM, Ankur Garg ankurga...@gmail.com wrote: on above algo , there is no need to calculate sum of array so we can do it in O(N) and not O(n). On Fri, Dec 16, 2011 at

Re: [algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread Ravi Ranjan
i got my mistake.. den how to fulfill all the conditions?? -- 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: doubt in TSUM

2011-12-15 Thread anubhav raj
shashank.dude the algorithm whch u suggested in the morning for tsum ...hv u tried it wid urself bcoz wid the wiki link method if we wl sort the array den wat b the delimiter so that ,i wl get get all combination of 3 .in dat method dat wz given for sum of three

[algogeeks] doubt in spoj 8473 ways

2011-12-15 Thread anubhav raj
we have to submit it in 120 byte cn ne 1 tl me dat whr z the chances of further byte reduction in this code. #includestdio.h #define s(n) scanf(%d,n) #define I int I a[14][14];I d(I m,I n){I s=a[m][n];I k;if(!m||!n)k=1;else if(s)k=s;else{k=d(m-1,n)+d(m,n-1);s=k;}return k;}main(){I

Re: [algogeeks] doubt in spoj 8473 ways

2011-12-15 Thread saurabh singh
Post the formatted code too.(With proper indents)Then it would be easier for others to work on it, On Thu, Dec 15, 2011 at 11:47 PM, anubhav raj anubhaw@gmail.com wrote: we have to submit it in 120 byte cn ne 1 tl me dat whr z the chances of further byte reduction in this code.

[algogeeks] zig zag problem

2011-12-15 Thread Sangeeta
Problem Statement A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a

Re: [algogeeks] zig zag problem

2011-12-15 Thread Azhar Hussain
It is dynamic programming. Search in topcoder algo tutorials On Dec 16, 2011 10:33 AM, Sangeeta sangeeta15...@gmail.com wrote: Problem Statement A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative.

[algogeeks] Dynamic programming problem

2011-12-15 Thread Sangeeta
Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many coins of one type as we want), or report that it's not possible to select coins in such a way that they sum up to S. For a better understanding

Re: [algogeeks] Dynamic programming problem

2011-12-15 Thread atul anand
use dynamic programming to solve this problem :- here is the algo:- result[S]; result[0]=1; index; for i=0 to len(coins[]) c=coins[i]; for k=c to S index=k-c; result[k]= result[k] + result[index]; end end print result[S]; On Fri, Dec 16, 2011 at 10:52 AM,

Re: [algogeeks] Dynamic programming problem

2011-12-15 Thread sangeeta goyal
give explaination On Fri, Dec 16, 2011 at 11:14 AM, atul anand atul.87fri...@gmail.comwrote: use dynamic programming to solve this problem :- here is the algo:- result[S]; result[0]=1; index; for i=0 to len(coins[]) c=coins[i]; for k=c to S index=k-c;

[algogeeks] Re: zig zag problem

2011-12-15 Thread top coder
int LIDS ( vectorint a , int n ){ int s[51][2]; for(int i = 0 ; i n ; i++) for(int j = 0 ; j 2 ; j++) s[i][j] = 1; for(int i = 0 ; i n ; i++){ for(int j = 0 ; j i ; j++){ if( a[i] != a[j] ){ s[i][a[i]a[j]] =

[algogeeks] given a stream of numbers FIND MEDIAN

2011-12-15 Thread Sangeeta
You are given a stream of numbers which can be positive or negative. You are required to provide an operation FIND MEDIAN..which when invoked should be able return the median of the numbers in stream (in sorted order) in O(1) time. -- You received this message because you are subscribed to the