Re: [algogeeks] help required...
if the possibilty of a person knowing other any1 based circular linked.. ie. 1/n.. then none becomes celebrity .. so wat to do in tat situation?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: do this: two numbers with min diff
can anyone post this answer pls?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: do this: two numbers with min diff
Modeling Expert 's code is greedyit won't work for the test cases in which the optimal answer is does not lie between first two numbers.. On 9/23/10, Srinivas lavudyasrinivas0...@gmail.com wrote: can anyone post this answer pls?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
isn't it supposed to be only O(n) questions.? On 9/23/10, santhosh santhos4...@gmail.com wrote: if the possibilty of a person knowing other any1 based circular linked.. ie. 1/n.. then none becomes celebrity .. so wat to do in tat situation?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
And what if more than one person in that set?...let it be c. so u must ask ac+1(n-1) questions right? On 9/23/10, Soundar soundha...@gmail.com wrote: isn't it supposed to be only O(n) questions.? On 9/23/10, santhosh santhos4...@gmail.com wrote: if the possibilty of a person knowing other any1 based circular linked.. ie. 1/n.. then none becomes celebrity .. so wat to do in tat situation?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Adobe Question
for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Anyone know optimized solution to bytelandian gold coins problem
It is a straight forward dp problem.Use a memoized version. it is pretty simple. #includeiostream #includemap using namespace std; map long long int,long long int p; main() { long long int a,f; long long int fun(long long int ); p.clear(); while(cina) { f=fun(a); coutfendl; } } long long int fun(long long int a) { long long int ch,q; if(a==0) return 0; if(p.find(a)!=p.end()) return p[a]; else { ch=fun(a/2)+fun(a/3)+fun(a/4); if(ch=a) p[a]=ch; else p[a]=a; } return p[a]; } -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Question
@Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1, where a^b is a to the power b. Dave On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Question
@ Dave can u explain ur answer...plz.. On Thu, Sep 23, 2010 at 8:55 AM, Dave dave_and_da...@juno.com wrote: @Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1, where a^b is a to the power b. Dave On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] do this: two numbers with min diff
int minDiff(int arr[], int arr_size) { int min_diff = arr[1] - arr[0]; int max_element = arr[0]; int i; for(i = 1; i arr_size; i++) { if(arr[i] - max_element min_diff) min_diff = arr[i] - max_element; if(arr[i] max_element) max_element = arr[i]; } return min_diff; } On Mon, Sep 20, 2010 at 10:38 AM, Srinivas lavudyasrinivas0...@gmail.comwrote: 2 nos with min diff given an array of size n. find 2 numbers from array whose difference is least in O(n) w/o using xtra space( i mean constant space) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: do this: two numbers with min diff
try for this {100,6,101,11} On Sep 23, 7:40 pm, Nishant Agarwal nishant.agarwa...@gmail.com wrote: int minDiff(int arr[], int arr_size) { int min_diff = arr[1] - arr[0]; int max_element = arr[0]; int i; for(i = 1; i arr_size; i++) { if(arr[i] - max_element min_diff) min_diff = arr[i] - max_element; if(arr[i] max_element) max_element = arr[i]; } return min_diff; } On Mon, Sep 20, 2010 at 10:38 AM, Srinivas lavudyasrinivas0...@gmail.comwrote: 2 nos with min diff given an array of size n. find 2 numbers from array whose difference is least in O(n) w/o using xtra space( i mean constant space) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
@kartheek i am getting. this prudent approach but what is add what remained to the remainder. suppose u have A,B,C,D and B is celebrity ... if( A knows B) { A is not celb. if( B knows C){} else{ C is not celb. if (C knows B ) { if( D knows B) { D is not celb. only B remain... hence it celeb... /* suppose if u have A,B,C,D,E and B is celeb. then again if (E knows B) {E is not celb only B remain... hence it celeb... } */ } } } } look in every if condition we are Asking Sequentially to A ,B,C,D,E... can these be correct solution correct me plz... if wrong.. On Thu, Sep 23, 2010 at 12:56 AM, kartheek muthyala kartheek0...@gmail.comwrote: Take 2 persons, suppose say A and B ask one of them the question about other if A Knows B, then A cannot be the celebrity, if A does not know B, then B cannot be the celebrity. add what remained to the remainder. repeat this process for the remaining n-1 until one or none remained. Then if it is none then there is no celebrity. If there is one ask the question whether this person is known by remaining n-1 and this person does n't know the remaining n-1. So a total of 3(n-1) questions is used to determine the celeb. Time complexity is O(n). Repeat this for the remaining n-1 persons, if the remainder contain one then On Wed, Sep 22, 2010 at 9:37 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Among n people, a celebrity is defined as someone who is known to everyone, but who knows no one. Design and analyze to identify the celebrity, if one exists, by asking only questions of the following form: Excuse me, do you know person x? You will get a binary answer for each such question asked. Find the celebrity by asking only O(n) questions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: do this: two numbers with min diff
I hope this will work. It finds the two minimum numbers and then prints the difference. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1=array[0], min2=array[1]; for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // int array[10]={99,12,45,33,88,9098,112,33455,678,3}; find_two_mins(array,10); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
is it not finding the articulation point in a graph ? = this has a linear time solution. if the edge exist TRUE otherwise FALSE, n x n adjacency matrix with 1/0 (TRUE/FALSE) Thanks, Sathaiah On Wed, Sep 22, 2010 at 9:37 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Among n people, a celebrity is defined as someone who is known to everyone, but who knows no one. Design and analyze to identify the celebrity, if one exists, by asking only questions of the following form: Excuse me, do you know person x? You will get a binary answer for each such question asked. Find the celebrity by asking only O(n) questions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
Use divide and conquer strategy of algorithm by diving in 2-2 group like merge sort make tree where every level we dropping people by using logic of above post so root will be celebrity On Thu, Sep 23, 2010 at 11:26 AM, kartheek muthyala kartheek0...@gmail.comwrote: Take 2 persons, suppose say A and B ask one of them the question about other if A Knows B, then A cannot be the celebrity, if A does not know B, then B cannot be the celebrity. add what remained to the remainder. repeat this process for the remaining n-1 until one or none remained. Then if it is none then there is no celebrity. If there is one ask the question whether this person is known by remaining n-1 and this person does n't know the remaining n-1. So a total of 3(n-1) questions is used to determine the celeb. Time complexity is O(n). Repeat this for the remaining n-1 persons, if the remainder contain one then On Wed, Sep 22, 2010 at 9:37 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Among n people, a celebrity is defined as someone who is known to everyone, but who knows no one. Design and analyze to identify the celebrity, if one exists, by asking only questions of the following form: Excuse me, do you know person x? You will get a binary answer for each such question asked. Find the celebrity by asking only O(n) questions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks Regards Umesh kewat -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adobe Question
what is the data type of 'j' ? On Thu, Sep 23, 2010 at 6:49 PM, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards Apoorve Mohan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Print 1 to n one per each line on the standard output
You can use setjmp ,longjmp or goto to get desired result. #includestdio.h #includesetjmp.h void print(int v) { int i=0; jmp_buf env; setjmp(env); if(i=v) { printf(%d\n,i); ++i; longjmp(env,1); } } int main() { int n; scanf(%d,n); print(n); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] sum of primes
How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Anyone know optimized solution to bytelandian gold coins problem
Recursion and Memoization. On Thu, Sep 23, 2010 at 2:12 AM, Dave dave_and_da...@juno.com wrote: @Venkatakrishna: What is the problem? I don's see a question. Dave On Sep 22, 2:36 pm, venkatakrishna bandla venkatakrishnabt...@gmail.com wrote: You are given a coin, which has an integer number written on it. A coin valued n can be exchanged with me for three coins valued n/2, n/3 and n/4. But these numbers are all rounded down to the integer value. You can sell these coins for American dollars. The exchange rate is 1:1. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Bharath -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: do this: two numbers with min diff
@Yellow: Change the 12 in a[1] in your test case to 35 and see what you get. Dave On Sep 23, 10:09 am, Yellow Sapphire pukhraj7...@gmail.com wrote: I hope this will work. It finds the two minimum numbers and then prints the difference. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1=array[0], min2=array[1]; for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // int array[10]={99,12,45,33,88,9098,112,33455,678,3}; find_two_mins(array,10); return 0; }- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
@ umesh kewat suppose A,B,C,D and D is celebrity A,B C,D how would u eliminate one form A,B even if u can ... it will be order of O(n logn) ... Regards ... Divesh On Thu, Sep 23, 2010 at 4:00 AM, umesh kewat umesh1...@gmail.com wrote: Use divide and conquer strategy of algorithm by diving in 2-2 group like merge sort make tree where every level we dropping people by using logic of above post so root will be celebrity On Thu, Sep 23, 2010 at 11:26 AM, kartheek muthyala kartheek0...@gmail.com wrote: Take 2 persons, suppose say A and B ask one of them the question about other if A Knows B, then A cannot be the celebrity, if A does not know B, then B cannot be the celebrity. add what remained to the remainder. repeat this process for the remaining n-1 until one or none remained. Then if it is none then there is no celebrity. If there is one ask the question whether this person is known by remaining n-1 and this person does n't know the remaining n-1. So a total of 3(n-1) questions is used to determine the celeb. Time complexity is O(n). Repeat this for the remaining n-1 persons, if the remainder contain one then On Wed, Sep 22, 2010 at 9:37 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Among n people, a celebrity is defined as someone who is known to everyone, but who knows no one. Design and analyze to identify the celebrity, if one exists, by asking only questions of the following form: Excuse me, do you know person x? You will get a binary answer for each such question asked. Find the celebrity by asking only O(n) questions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks Regards Umesh kewat -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] sum of primes
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes On Thu, Sep 23, 2010 at 5:45 PM, Debajyoti Sarma sarma.debajy...@gmail.comwrote: How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Print 1 to n one per each line on the standard output
@Greed in windows.. output is infinite loop and printing... 0 0 0 0 0 ... infinite loop.. On Thu, Sep 23, 2010 at 9:57 AM, Greed shrishkr...@gmail.com wrote: You can use setjmp ,longjmp or goto to get desired result. #includestdio.h #includesetjmp.h void print(int v) { int i=0; jmp_buf env; setjmp(env); if(i=v) { printf(%d\n,i); ++i; longjmp(env,1); } } int main() { int n; scanf(%d,n); print(n); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: sum of primes
@Debajyoti: Look at the 1 line of http://www.research.att.com/~njas/sequences/b007504.txt. Dave On Sep 23, 7:15 am, Debajyoti Sarma sarma.debajy...@gmail.com wrote: How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Print 1 to n one per each line on the standard output
try in linux.it is working fine On Thu, Sep 23, 2010 at 8:58 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: @Greed in windows.. output is infinite loop and printing... 0 0 0 0 0 ... infinite loop.. On Thu, Sep 23, 2010 at 9:57 AM, Greed shrishkr...@gmail.com wrote: You can use setjmp ,longjmp or goto to get desired result. #includestdio.h #includesetjmp.h void print(int v) { int i=0; jmp_buf env; setjmp(env); if(i=v) { printf(%d\n,i); ++i; longjmp(env,1); } } int main() { int n; scanf(%d,n); print(n); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: sum of primes
Following up to my own posting... Sorry. I answered the wrong question, What is the sum of the first 10,000 primes? For the given problem, first you have to look in http://www.research.att.com/~njas/sequences/b40.txt to find the number of primes up to 10,000, and then look in http://www.research.att.com/~njas/sequences/b007504.txt to find the sum of that number of primes. Dave On Sep 23, 10:32 am, Dave dave_and_da...@juno.com wrote: @Debajyoti: Look at the 1 line ofhttp://www.research.att.com/~njas/sequences/b007504.txt. Dave On Sep 23, 7:15 am, Debajyoti Sarma sarma.debajy...@gmail.com wrote: How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this .- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sum of primes
@Dave what is the complexity of this algorithm... it given *O*(*n*(log*n*)(loglog *n*)) but i think it should be O(n^2) On Thu, Sep 23, 2010 at 10:39 AM, Dave dave_and_da...@juno.com wrote: Following up to my own posting... Sorry. I answered the wrong question, What is the sum of the first 10,000 primes? For the given problem, first you have to look in http://www.research.att.com/~njas/sequences/b40.txthttp://www.research.att.com/%7Enjas/sequences/b40.txtto find the number of primes up to 10,000, and then look in http://www.research.att.com/~njas/sequences/b007504.txthttp://www.research.att.com/%7Enjas/sequences/b007504.txtto find the sum of that number of primes. Dave On Sep 23, 10:32 am, Dave dave_and_da...@juno.com wrote: @Debajyoti: Look at the 1 line ofhttp:// www.research.att.com/~njas/sequences/b007504.txthttp://www.research.att.com/%7Enjas/sequences/b007504.txt . Dave On Sep 23, 7:15 am, Debajyoti Sarma sarma.debajy...@gmail.com wrote: How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this .- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: sum of primes
@Coolfrog: I don't know the complexity, but, given a very high-level description of the algorithm, it takes less than a minute to implement the algorithm and produce the answer, which probably is faster than you can implement any other algorithm and find the answer. :-) Dave On Sep 23, 10:47 am, coolfrog$ dixit.coolfrog.div...@gmail.com wrote: @Dave what is the complexity of this algorithm... it given *O*(*n*(log*n*)(loglog *n*)) but i think it should be O(n^2) On Thu, Sep 23, 2010 at 10:39 AM, Dave dave_and_da...@juno.com wrote: Following up to my own posting... Sorry. I answered the wrong question, What is the sum of the first 10,000 primes? For the given problem, first you have to look in http://www.research.att.com/~njas/sequences/b40.txthttp://www.research.att.com/%7Enjas/sequences/b40.txtto find the number of primes up to 10,000, and then look in http://www.research.att.com/~njas/sequences/b007504.txthttp://www.research.att.com/%7Enjas/sequences/b007504.txtto find the sum of that number of primes. Dave On Sep 23, 10:32 am, Dave dave_and_da...@juno.com wrote: @Debajyoti: Look at the 1 line ofhttp:// www.research.att.com/~njas/sequences/b007504.txthttp://www.research.att.com/%7Enjas/sequences/b007504.txt . Dave On Sep 23, 7:15 am, Debajyoti Sarma sarma.debajy...@gmail.com wrote: How to find the sum of prime numbers between 1 and 1. I don't expected traversal of the whole range and find primes and sum uping Any other logic is there?? i think we need deep mathematics for this .- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: do this: two numbers with min diff
i dont think there exists a o(n) solution for this the best we can do is sort in o(nlogn) and then do a o(n) traversal On Thu, Sep 23, 2010 at 8:48 PM, Dave dave_and_da...@juno.com wrote: @Yellow: Change the 12 in a[1] in your test case to 35 and see what you get. Dave On Sep 23, 10:09 am, Yellow Sapphire pukhraj7...@gmail.com wrote: I hope this will work. It finds the two minimum numbers and then prints the difference. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1=array[0], min2=array[1]; for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // int array[10]={99,12,45,33,88,9098,112,33455,678,3}; find_two_mins(array,10); return 0; }- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adobe Question
@Davefor n=2 ur formulae would give 1 but the result is 3 On Thu, Sep 23, 2010 at 6:53 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: what is the data type of 'j' ? On Thu, Sep 23, 2010 at 6:49 PM, Krunal Modi krunalam...@gmail.comwrote: for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards Apoorve Mohan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adobe Question
@nishaanth for n=1 N=0 as k=1 and kn not k=n for n=2 N= 0+1 for n=3 N=0+1+3 so formula is correct .. i have checked twice @Dave : very nice but... how u approached while solving On Thu, Sep 23, 2010 at 12:29 PM, nishaanth nishaant...@gmail.com wrote: @Davefor n=2 ur formulae would give 1 but the result is 3 On Thu, Sep 23, 2010 at 6:53 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: what is the data type of 'j' ? On Thu, Sep 23, 2010 at 6:49 PM, Krunal Modi krunalam...@gmail.comwrote: for(k=1 ; kn ; k++){ j=k; while(j0){ j=j/2; } } How many times while loop gets executed (for any n) ? I don't want answer in terms of series (i.e, don't want any sigma, I have that) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards Apoorve Mohan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Question
@Apoorve : All are integer int. @Dave: Can you explain how u arrived at this equation ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Print 1 to n one per each line on the standard output
#includestdio.h void f1(int); void f2(int); int val; main() { printf(Enter number\n); scanf(%d,val); f1(1); return 0; } void f1(int m) { if(m = val) { printf(%d\n,m); m++; f2(m); } } void f2(int n) { if(n = val) { printf(%d\n,n); n++; f1(n); } } I think this prog is correct which satisfies ur requirements On Wed, Sep 22, 2010 at 9:19 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Write an algorithm that will print 1 to n, one per each line on the standard output, where n is a integer parameter to the algorithm. An algorithm should not use while, for, do-while loops, goto statement, recursion, and switch statement. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Print 1 to n one per each line on the standard output
@aswath : nice solution... very simple too. it gives the desired solution as required..though it is a case of indirect recursion... but still a nice aproach... keep it up thanks. Regards Divesh On Thu, Sep 23, 2010 at 12:45 PM, aswath G B aswat...@gmail.com wrote: #includestdio.h void f1(int); void f2(int); int val; main() { printf(Enter number\n); scanf(%d,val); f1(1); return 0; } void f1(int m) { if(m = val) { printf(%d\n,m); m++; f2(m); } } void f2(int n) { if(n = val) { printf(%d\n,n); n++; f1(n); } } I think this prog is correct which satisfies ur requirements On Wed, Sep 22, 2010 at 9:19 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Write an algorithm that will print 1 to n, one per each line on the standard output, where n is a integer parameter to the algorithm. An algorithm should not use while, for, do-while loops, goto statement, recursion, and switch statement. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] ReVerse a string using recursion
How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } But it is using two extra char pointer... is that allowed.?? On Thu, Sep 23, 2010 at 12:59 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
Sorry ...correction we have to bring temp2 to last char again... so char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ --temp2; *===* void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } On Thu, Sep 23, 2010 at 1:15 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } But it is using two extra char pointer... is that allowed.?? On Thu, Sep 23, 2010 at 12:59 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] decimal to binary and binary to decimal.....conversion algorithm
can some one suggest Algo a n-bit binary number to decimal; b n-bit decimal to binary. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
@nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
i am giving the full code #includestdio.h #includestdlib.h #includestring.h void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } int main() { char *s; s=(char *)malloc(sizeof(s)); gets(s); xstrrev(s,0,strlen(s)-1); puts(s); return 0; } On Fri, Sep 24, 2010 at 12:15 AM, coolfrog$ dixit.coolfrog.div...@gmail.com wrote: @nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
*...@nisanth : help me plz... to solve this finding largest and second largest elements from a set of n elements by means of Minimum comparison of n+celling(log n) +2* On Thu, Sep 23, 2010 at 1:50 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: i am giving the full code #includestdio.h #includestdlib.h #includestring.h void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } int main() { char *s; s=(char *)malloc(sizeof(s)); gets(s); xstrrev(s,0,strlen(s)-1); puts(s); return 0; } On Fri, Sep 24, 2010 at 12:15 AM, coolfrog$ dixit.coolfrog.div...@gmail.com wrote: @nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.comwrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
@Albert i think this should be right static int i=0; int j; void xstrrev(char *s) { char t; if(i==0) j=strlen(s)-1; if(ij) { t=s[i]; s[i++]=s[j]; s[j--]=t; xstrrev(s); } } On Fri, Sep 24, 2010 at 12:05 AM, albert theboss alberttheb...@gmail.comwrote: Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: do this: two numbers with min diff
Your comment brings to mind that we could do an O(n) sort such as a Radix Sort. Any ordinary implementation will be O(n) as a fixed number of passes will be required based on the word size. Dave On Sep 23, 11:21 am, nishaanth nishaant...@gmail.com wrote: i dont think there exists a o(n) solution for this the best we can do is sort in o(nlogn) and then do a o(n) traversal On Thu, Sep 23, 2010 at 8:48 PM, Dave dave_and_da...@juno.com wrote: @Yellow: Change the 12 in a[1] in your test case to 35 and see what you get. Dave On Sep 23, 10:09 am, Yellow Sapphire pukhraj7...@gmail.com wrote: I hope this will work. It finds the two minimum numbers and then prints the difference. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1=array[0], min2=array[1]; for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // int array[10]={99,12,45,33,88,9098,112,33455,678,3}; find_two_mins(array,10); return 0; }- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: finding largest and second largest elements
Do a single-elimination tournament of the numbers, where the larger wins each game. This will take n/2 + n/4 + ... + 1 = n-1 comparisons. The second largest will be among the numbers that lost to the largest in one of the games. As you conduct the tournament, keep track of the losers. Since there will be at most ceiling(log_2(n)) stages in the tournament, you can find the largest of the losers to the winner in ceiling(log_2(n))-1 comparisons. Dave On Sep 23, 1:36 pm, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: finding largest and second largest elements from a set of n elements by means of Minimum comparison of n+celling(log n) +2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Question
How did I arrive at this equation? I entered the first few terms of the sequence, 0,1,3,5,8,11,14,17, into the On-Line Encyclopedia of Integer Sequences, at http://www.research.att.com/~njas/sequences/, and read the Formula section of the result. It is amazing what you can find on the internet if you know where to look! Dave On Sep 23, 12:42 pm, Krunal Modi krunalam...@gmail.com wrote: @Apoorve : All are integer int. @Dave: Can you explain how u arrived at this equation ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: do this: two numbers with min diff
@Dave, I check for the values you suggested but the code worked fine. There were other errors in the code. I have rectified them now. The following code seems to be working fine and in O(n) time. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1, min2; if(array[0] = array[1]) { min1=array[0]; min2=array[1]; } else { min2=array[0]; min1=array[1]; } for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } if(t=min2) { min2=t; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d\n\n, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // //int array[10]={3,3,1,33,88,9098,112,33455,678,1}; //int array[10]={5,3,1,33,88,9098,112,33455,678,1}; //int array[10]={2,3,21,33,88,9098,112,33455,678,12}; int array[10]={3,2,21,33,88,9098,112,33455,678,12}; find_two_mins(array,10); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview
http://en.wikipedia.org/wiki/Run-length_encoding On Wed, Sep 15, 2010 at 5:51 PM, bittu shashank7andr...@gmail.com wrote: A file is given with many 0s stored in continuous way , store it in another file such that when you store try saving the space by using minimum amount of space. When you want to create the original file , you should be able to do so with the new file created -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sum of primes
Apart from 1, 2 and 3, all the prime numbers are either of the form (6*n - 1) or (6*n + 1). Can we use this property to generate the primes till we get 1 primes. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
void RevStr (char *str){ char ch = '\0'; if (*str){ ch = *str; RevStr (++str); } printf (%c, ch); } On Fri, Sep 24, 2010 at 12:37 AM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: @Albert i think this should be right static int i=0; int j; void xstrrev(char *s) { char t; if(i==0) j=strlen(s)-1; if(ij) { t=s[i]; s[i++]=s[j]; s[j--]=t; xstrrev(s); } } On Fri, Sep 24, 2010 at 12:05 AM, albert theboss alberttheb...@gmail.comwrote: Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: do this: two numbers with min diff
@Rishi: Try it on the original data with a[1] changed from 12 to 35: int array[10]={99,35,45,33,88,9098,112,33455,678,3}; What do you get as a result? Dave On Sep 23, 12:36 pm, Rishi Agrawal rishi.b.agra...@gmail.com wrote: @Dave, I check for the values you suggested but the code worked fine. There were other errors in the code. I have rectified them now. The following code seems to be working fine and in O(n) time. #include stdio.h #include stdlib.h void find_two_mins(int array[], int size) { int i,t; int min1, min2; if(array[0] = array[1]) { min1=array[0]; min2=array[1]; } else { min2=array[0]; min1=array[1]; } for (i=2; isize; i++){ t=array[i]; if(t=min1) { min2=min1; min1=t; continue; } if(t=min2) { min2=t; } } printf(\nMin elements are 1: %d 2: %d, min1,min2); printf(\n Absolute difference between two minimum elements are %d\n\n, abs(min1-min2)); } int main() { //int array[10]={ 9,2,3,4,1,7,5,6,8,0}; // //int array[10]={3,3,1,33,88,9098,112,33455,678,1}; //int array[10]={5,3,1,33,88,9098,112,33455,678,1}; //int array[10]={2,3,21,33,88,9098,112,33455,678,12}; int array[10]={3,2,21,33,88,9098,112,33455,678,12}; find_two_mins(array,10); return 0; }- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Question
But, how was it derived ? :( What is the intuition behind ? :( :( -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] help required...
@coolfrog, What I meant by remained is Considering your case of A,B,C,D and B is the celebrity, The sequence is First A,B ask the question to A, then remained=B Then B,C ask the question to B, then remained=B Then B,D ask the question to B, then remained= B Then ask A,C,D whether they know B Then ask B whether they know A,C,D So, that's how I said 3(n-1) questions... Correct me if I am wrong On Thu, Sep 23, 2010 at 8:32 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: @kartheek i am getting. this prudent approach but what is add what remained to the remainder. suppose u have A,B,C,D and B is celebrity ... if( A knows B) { A is not celb. if( B knows C){} else{ C is not celb. if (C knows B ) { if( D knows B) { D is not celb. only B remain... hence it celeb... /* suppose if u have A,B,C,D,E and B is celeb. then again if (E knows B) {E is not celb only B remain... hence it celeb... } */ } } } } look in every if condition we are Asking Sequentially to A ,B,C,D,E... can these be correct solution correct me plz... if wrong.. On Thu, Sep 23, 2010 at 12:56 AM, kartheek muthyala kartheek0...@gmail.com wrote: Take 2 persons, suppose say A and B ask one of them the question about other if A Knows B, then A cannot be the celebrity, if A does not know B, then B cannot be the celebrity. add what remained to the remainder. repeat this process for the remaining n-1 until one or none remained. Then if it is none then there is no celebrity. If there is one ask the question whether this person is known by remaining n-1 and this person does n't know the remaining n-1. So a total of 3(n-1) questions is used to determine the celeb. Time complexity is O(n). Repeat this for the remaining n-1 persons, if the remainder contain one then On Wed, Sep 22, 2010 at 9:37 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: Among n people, a celebrity is defined as someone who is known to everyone, but who knows no one. Design and analyze to identify the celebrity, if one exists, by asking only questions of the following form: Excuse me, do you know person x? You will get a binary answer for each such question asked. Find the celebrity by asking only O(n) questions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.