[algogeeks] Re: permuttaion
OK, On Thu, Feb 21, 2008 at 8:44 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi, can some one help me in writing an algorithm for finding permuttaion I will assume that you want all permutation : let's call: - S your set of number - pos your current position ** WARNING: Untested code follow: =) PERM(pos, S) if pos == len(S): print S for i = pos to len(S): swap(S[pos],S[i]) PERM(pos+1,S) swap(S[pos],S[i]) To find all permutation, just call PERM(0,S). Hope this help, Caio Valentim --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~--~~~~--~~--~--~---
[algogeeks] Re: factorial
Hi, On Feb 13, 2008 1:11 AM, Dave [EMAIL PROTECTED] wrote: Sum log 1 + log 2 + log 3 + ... + log n, where log represents the base-10 logarithm function. The ceiling of the sum gives the number of digits. Dave Yeh, that work fine. Only to explain a bit more to Hariharan: **let N your number I)- First, make cases by hand and convince yourself that the number of digits in a number is equals to exponent of the minor power of 10(ten) which is bigger then N. II)- Remember of the logarithm property learned at high school: - log(x.y) = log(x) + log(y) III)- N! = N.(N-1).(N-2)1 = log10(N!)= log10(N.(N-1).(N-2)1) = log10(N) + log10(N-1) + log(N-2)+...+1 Best regards, Caio Valentim --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~--~~~~--~~--~--~---
[algogeeks] Re: Graph problem
On 11/30/07, John [EMAIL PROTECTED] wrote: Given a DAG and two vertices s and t , give a linear time number of paths between s and t in G. How does topological sort help in finding the same ? Hi Joh, you can do a dynamic programming algorithm Your state is S[x] = number of path going from s to x, s is the initial vertex. It's easy to see that equation holds : S[x] = sum { S[v], for all v neighbor of x } Think about base cases and make a memorized function to get the answer. Hope this help, Caio --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~--~~~~--~~--~--~---