Re: [algogeeks] C doubt
ch=i++[s]; // in this value is assigned first and then increment will take place...bcozz you are using post increment. here i does not have any other option it has to do post increment before [] comes...but it will not assign value to 'i' ( i.e incremented 'i' value) so compiler will do something like this ch=*(i + s); i=i+1; ch=++i[s]; // in this case compiler will rewrite it to something like this , ch=++(*(i+s)); // this will increment the value at i[s], pre-increment is taking place ...so updated i[s] value will be assigned o ch if you do somthing like this :- ch=i[s]++; // here post increment is happening , so compiler will rewrite it somthing like this // ch will contain old value but if you print i[s] , it will print incremented value of i[s]; ch=*(i+s); i[s]=i[s] + 1; On 10/6/12, rahul sharma wrote: > char ch > ch=i++[s]; > > printf("%c",ch); this will print i[s],then i is incrementrd after > assigning to ch > > > ch=++i[s];// this will inccrement value at i[s] > > > My question is what is role of priority which is making them behaving > differentI am not getting y not first i is incremented then i[s] is > assigned > plz tell > > -- > 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+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 algogeeks@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] finding element in array with minimum of comparing
Well actually, I've just gone through Dave's code thoroughly and I believe that his code is most appropriate. Thanks viper11 for providing the explanation. As for my code, I'd like to replace while (i!=j) with while (i < j) because != won't work for middle element if the number of elements are odd ... and it also won't work if the number of elements are even. Anyway, thanks Dave for providing us with such a great solution. Please keep posting! :-) And others, thanks for pointing out the issue in my code. On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J wrote: > @umer - what if the element to be searched is at the middle of the array? > your code doesn't handles this. check out. > > > On Sat, Oct 6, 2012 at 3:38 AM, icy` wrote: > >> nice solution, Dave! >> >> @Umer -- if the sought ele is first, then Dave's code has it sitting in >> the variable temp for a little while. Loop will stop when size is 0, >> since arr[0]==elem. Now he throws temp back into arr[0], which will return >> index 0 from the last compare line. >> >> On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote: >>> >>> @Dave Thanks for pointing that out. >>> >>> But I still can't get what if elem is on first element or it is not >>> present in the array? How is your code going to handle that situation? >>> >>> @Atul, Well yes, In the given question, the number of iterations were >>> 2n. Which I have reduced to n+n/2. >>> >>> >>> >>> >>> >>> On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote: >>> @umer : how no. of comparison are reduced to half by moving both sidesyou have 2 if condition inside, so you are making 2 comparisons at each iteration + n/2 comparison for while loop so number of comparisons are n+n/2 On 10/2/12, Umer Farooq wrote: > why don't we try it from both ends ... something like this: > > int i = 0; j = size-1; > > while (i != j) > { > if (arr[i] == elem) > return arr[i]; > if (arr[j] == elem) >return arr[j]; > } > > this way, we have eliminated half of the comparisons in for loop? What do > you guys say? > > On Tue, Oct 2, 2012 at 12:18 PM, rafi wrote: > >> Vikas is right! >> while (n) is equal to (while n!=0) >> you have 2n compares! >> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas: >> >>> still there is no improvement, compiler will generate the code to >>> compare >>> with zero here. what you have accomplished is , hide it from human eyes >>> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote: @atul: still it won't compare 0 th element. Slight modification in your code: n=*sizeof(arr)*; do { if(elem==arr[*--n*]) print found; }while(n); On Mon, Oct 1, 2012 at 9:50 AM, atul anand wrote: > yes, but there no need of checking outside the loop > > n=sizeof(arr)-1; > do > { > if(elem==arr[n]) > print found; > n--; > > }while(n); > > > > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar > wrote: > >> @atul: keep one more checking outside loop for element at 0 th index. >> Because when n = 0 the your loop come out from the loop without >> comparing >> it. >> >> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand >> wrote: >> >>> n=sizeof(arr); >>> n--; >>> >>> while(n) >>> { >>> if(elem=arr[n]) >>> print found; >>> >>> n--; >>> >>> } >>> >>> On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר >>> wrote: >>> Hi i was in an interview and was given a simple function int arrExsits(int* arr,int size,int elem){ for (int i=0;i>>> if(elem==arr[i]) return i; return -1; } this function does 2n compares n- the if statment n-check that i is smaller then size i was suppose to give an optimal (less compares) solution so i gave int arrExsits(int* arr,int size,int elem){ if (arr[size-1]==elem) return size-1; arr[size-1]=elem] for (int i=0;;++i) if(elem==arr[i]){ if (i!=size-1) return i; return -1; } this solution works and it has n+2 compares the first one another n >
[algogeeks] C doubt
char ch ch=i++[s]; printf("%c",ch); this will print i[s],then i is incrementrd after assigning to ch ch=++i[s];// this will inccrement value at i[s] My question is what is role of priority which is making them behaving differentI am not getting y not first i is incremented then i[s] is assigned plz tell -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] finding element in array with minimum of comparing
@umer - what if the element to be searched is at the middle of the array? your code doesn't handles this. check out. On Sat, Oct 6, 2012 at 3:38 AM, icy` wrote: > nice solution, Dave! > > @Umer -- if the sought ele is first, then Dave's code has it sitting in > the variable temp for a little while. Loop will stop when size is 0, > since arr[0]==elem. Now he throws temp back into arr[0], which will return > index 0 from the last compare line. > > On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote: >> >> @Dave Thanks for pointing that out. >> >> But I still can't get what if elem is on first element or it is not >> present in the array? How is your code going to handle that situation? >> >> @Atul, Well yes, In the given question, the number of iterations were 2n. >> Which I have reduced to n+n/2. >> >> >> >> >> >> On Tue, Oct 2, 2012 at 11:13 PM, atul anand wrote: >> >>> @umer : how no. of comparison are reduced to half by moving both >>> sidesyou have 2 if condition inside, so you are making 2 >>> comparisons at each iteration + n/2 comparison for while loop so >>> number of comparisons are n+n/2 >>> >>> On 10/2/12, Umer Farooq wrote: >>> > why don't we try it from both ends ... something like this: >>> > >>> > int i = 0; j = size-1; >>> > >>> > while (i != j) >>> > { >>> > if (arr[i] == elem) >>> > return arr[i]; >>> > if (arr[j] == elem) >>> >return arr[j]; >>> > } >>> > >>> > this way, we have eliminated half of the comparisons in for loop? What >>> do >>> > you guys say? >>> > >>> > On Tue, Oct 2, 2012 at 12:18 PM, rafi wrote: >>> > >>> >> Vikas is right! >>> >> while (n) is equal to (while n!=0) >>> >> you have 2n compares! >>> >> >>> >> בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas: >>> >> >>> >>> still there is no improvement, compiler will generate the code to >>> >>> compare >>> >>> with zero here. what you have accomplished is , hide it from human >>> eyes >>> >>> >>> >>> On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote: >>> >>> @atul: >>> still it won't compare 0 th element. Slight modification in your >>> code: >>> >>> n=*sizeof(arr)*; >>> do >>> { >>> if(elem==arr[*--n*]) >>> print found; >>> >>> }while(n); >>> >>> On Mon, Oct 1, 2012 at 9:50 AM, atul anand >>> wrote: >>> >>> > yes, but there no need of checking outside the loop >>> > >>> > n=sizeof(arr)-1; >>> > do >>> > { >>> > if(elem==arr[n]) >>> > print found; >>> > n--; >>> > >>> > }while(n); >>> > >>> > >>> > >>> > On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar >>> > wrote: >>> > >>> >> @atul: keep one more checking outside loop for element at 0 th >>> index. >>> >> Because when n = 0 the your loop come out from the loop without >>> >> comparing >>> >> it. >>> >> >>> >> >>> >> On Mon, Oct 1, 2012 at 8:55 AM, atul anand >>> >> wrote: >>> >> >>> >>> n=sizeof(arr); >>> >>> n--; >>> >>> >>> >>> while(n) >>> >>> { >>> >>> if(elem=arr[n]) >>> >>> print found; >>> >>> >>> >>> n--; >>> >>> >>> >>> } >>> >>> >>> >>> On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר >>> >>> wrote: >>> >>> >>> Hi >>> i was in an interview and was given a simple function >>> int arrExsits(int* arr,int size,int elem){ >>> for (int i=0;i>> if(elem==arr[i]) >>> return i; >>> return -1; >>> } >>> this function does 2n compares >>> n- the if statment >>> n-check that i is smaller then size >>> i was suppose to give an optimal (less compares) solution so i >>> gave >>> >>> int arrExsits(int* arr,int size,int elem){ >>> if (arr[size-1]==elem) >>> return size-1; >>> arr[size-1]=elem] >>> for (int i=0;;++i) >>> if(elem==arr[i]){ >>> if (i!=size-1) >>> return i; >>> return -1; >>> } >>> this solution works and it has n+2 compares the first one >>> another n >>> and the second inner if. >>> they told me it's good (and I've passed) but they told just for >>> my >>> knowledge that there is a better N compare solution. >>> I've searched the web but couldn't find it. >>> anybody knows? >>> Thanks >>> >>> -- >>> You received this message because you are subscribed to the >>> Google >>> Groups "Algorithm Geeks" group. >>> To post to this group, send email to algo...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/** >>> group
Re: [algogeeks] C output
#include int main() { char str[10]={'g','k'}; char str1[10]="gh"; int i; for(i=0;str1[i]!=NULL;i++) printf("%c",str[i]); getchar(); } NUll is there in character array also...make clear me... On Sat, Oct 6, 2012 at 9:22 PM, rahul sharma wrote: > int main() > { > char str[10]={'g','k'}; > char str1[10]="gh"; > > > printf("%s",str); > printf("%s",str1); > getchar(); > } > then how does this work??? > str printing gk...then NULL is automatically appended in this also...plz > tell > > > On Sat, Oct 6, 2012 at 6:33 PM, Rathish Kannan wrote: > >> For string, C appends '\0' internally. hence sizeof(str) returned the >> value 3. >> str1 is char array with two character. hence sizeof(str1) returned the >> value 2. >> >> -- RK :) >> >> >> On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma wrote: >> >>> char str[]="ab"; >>> char str1[]={'a','b'}; >>> >>> sizeof(str) ...o/p is 3 >>> sizeof(str1)o/p is 2.. >>> >>> Why so >>> plz explain... >>> >>> -- >>> 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+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 algogeeks@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 algogeeks@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] C output
int main() { char str[10]={'g','k'}; char str1[10]="gh"; printf("%s",str); printf("%s",str1); getchar(); } then how does this work??? str printing gk...then NULL is automatically appended in this also...plz tell On Sat, Oct 6, 2012 at 6:33 PM, Rathish Kannan wrote: > For string, C appends '\0' internally. hence sizeof(str) returned the > value 3. > str1 is char array with two character. hence sizeof(str1) returned the > value 2. > > -- RK :) > > > On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma wrote: > >> char str[]="ab"; >> char str1[]={'a','b'}; >> >> sizeof(str) ...o/p is 3 >> sizeof(str1)o/p is 2.. >> >> Why so >> plz explain... >> >> -- >> 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+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 algogeeks@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 algogeeks@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]
i dint get the questions..someone has 2+ year exp ke questions.i dnt need that.. i need questions for freshers On Sat, Oct 6, 2012 at 2:20 PM, vaibhav shukla wrote: > then please post it here as others might also be in need for the same. > > > On Sat, Oct 6, 2012 at 2:09 PM, vindhya chhabra > wrote: >> >> m sorry for this ques:) i got to know about it. >> >> On Sat, Oct 6, 2012 at 1:42 PM, vindhya chhabra >> wrote: >> > any one has an idea of what is the recruitment procedure of amadeus >> > software lab and what kind of pattern do they have? >> > >> > -- >> > Vindhya Chhabra >> > >> > -- >> > 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+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/algogeeks?hl=en. >> > >> >> >> >> -- >> Vindhya Chhabra >> >> -- >> 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+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > best wishes!! > Vaibhav > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Min Edges to be added to DAG to make it Strongly connected?
find no. of cut vertex in the DAGthat will be the ans. On 6 Oct 2012 19:33, "KK" wrote: > Given a DAG(Directed Acyclic Graph). How to find out the minimum number of > edges that needs to be added so that the given graph becomes Strongly > Connected? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ. > To post to this group, send email to algogeeks@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 algogeeks@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] C output
because of null char in 1st On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma wrote: > char str[]="ab"; > char str1[]={'a','b'}; > > sizeof(str) ...o/p is 3 > sizeof(str1)o/p is 2.. > > Why so > plz explain...-- > 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+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 algogeeks@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] C output
For string, C appends '\0' internally. hence sizeof(str) returned the value 3. str1 is char array with two character. hence sizeof(str1) returned the value 2. -- RK :) On Sat, Oct 6, 2012 at 5:53 PM, rahul sharma wrote: > char str[]="ab"; > char str1[]={'a','b'}; > > sizeof(str) ...o/p is 3 > sizeof(str1)o/p is 2.. > > Why so > plz explain... > > -- > 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+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 algogeeks@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] Min Edges to be added to DAG to make it Strongly connected?
Given a DAG(Directed Acyclic Graph). How to find out the minimum number of edges that needs to be added so that the given graph becomes Strongly Connected? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/T6idnKJ0It0J. To post to this group, send email to algogeeks@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] Min Edges to be added to DAG to make it Strongly connected?
Given a DAG(Directed Acyclic Graph). How to find out the minimum number of edges that needs to be added so that the given graph becomes Strongly Connected? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/PbR3j9S5OXUJ. To post to this group, send email to algogeeks@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]
then please post it here as others might also be in need for the same. On Sat, Oct 6, 2012 at 2:09 PM, vindhya chhabra wrote: > m sorry for this ques:) i got to know about it. > > On Sat, Oct 6, 2012 at 1:42 PM, vindhya chhabra > wrote: > > any one has an idea of what is the recruitment procedure of amadeus > > software lab and what kind of pattern do they have? > > > > -- > > Vindhya Chhabra > > > > -- > > 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+unsubscr...@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > > > > > -- > Vindhya Chhabra > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- best wishes!! Vaibhav -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] C output
char str[]="ab"; char str1[]={'a','b'}; sizeof(str) ...o/p is 3 sizeof(str1)o/p is 2.. Why so plz explain... -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
m sorry for this ques:) i got to know about it. On Sat, Oct 6, 2012 at 1:42 PM, vindhya chhabra wrote: > any one has an idea of what is the recruitment procedure of amadeus > software lab and what kind of pattern do they have? > > -- > Vindhya Chhabra > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Vindhya Chhabra -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks]
any one has an idea of what is the recruitment procedure of amadeus software lab and what kind of pattern do they have? -- Vindhya Chhabra -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.