Re: [algogeeks] Linked List question
You said : Given a linked list of infinite length On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla naveenshuklasweetdrea...@gmail.com wrote: But suppose a random number generate a value 5 and your linked list has only four elements. In that case what would be the answer ??? On Thu, Dec 27, 2012 at 4:03 PM, Prem Krishna Chettri hprem...@gmail.com wrote: Well my algo will be Something like this 1 Get a Random number. Perhaps You can have the function like Randon(List *head, int Randomnumber) 2 Use the function argument Randomnumber to loop the list. i.e. for(int count=0;count=Randomnumber;count++ ){ head = head - next; } 3 print (head-value); 4 return ; Now as we are using byvalue when we return the value of head remains the same old head value. So everytime we call we are traversing the same old list. The Random variable can be taken inside the function itself if the user is not taking the random value. i.e. int Randomnumber = random(); and now the user can calll Simple Random(head); On Thu, Dec 27, 2012 at 3:31 PM, naveen shukla naveenshuklasweetdrea...@gmail.com wrote: random node -- -- With Best Wishes From: Naveen Shukla IIIT Allahabad B.Tech IT 4th year Mob No: 07860896972 E-mail naveenshuklasweetdrea...@gmail.com -- --
Re: [algogeeks] Regex tester
i was asked the same question in my Microsoft interview. I gave the solution using a naive method by comparing each letter and tracking the next character. If the next character is *, then set a flag and check the equality, and if it is a . ignore and move on. He was ok with the solution but said that, there is a better way. On Sun, Dec 23, 2012 at 11:14 PM, Prem Krishna Chettri hprem...@gmail.com wrote: Well I can tell you Something about design pattern to solve this case.. What I mean is by using The State Machine Design Pattern, Anyone can solve this. but Ofcourse it is complicated. On Sun, Dec 23, 2012 at 11:01 PM, shady sinv...@gmail.com wrote: that's the point, Have to implement it from scratch... otherwise java has regex and matcher, pattern to solve it... On Sun, Dec 23, 2012 at 10:28 PM, saurabh singh saurab...@gmail.com wrote: If you need to implement this for some project then python and java have a very nice library Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sun, Dec 23, 2012 at 7:48 PM, shady sinv...@gmail.com wrote: http://stackoverflow.com/questions/13144590/to-check-if-two-strings-match-with-alphabets-digits-and-special-characters any solution for this. we need to implement such regex tester some complex cases : string regex-status reesd re*.d - match re*eed reeed - match can some one help with this ? -- -- -- -- --
Re: [algogeeks] Re: reverse a string efficiently
i guess it should be swap(str[i++], str[j--]); because we already subtracted 1 On Tue, Nov 27, 2012 at 8:58 PM, Don dondod...@gmail.com wrote: swap(str[i++], str[--j]); --
Re: [algogeeks] Re: Repeated values
@Don : Shift all the numbers to the corresponding positions in the first iteration And in the second loop check whether the number and the position matches or not. O(N) space and O(1) time constraint : the number's range must be from 0 to N-1 Cheers, On Wed, Oct 31, 2012 at 3:16 AM, Don dondod...@gmail.com wrote: In addition, inputs such as {2,2,0} will fail because when you try to make zero negative, it doesn't work so well. Don On Oct 30, 5:36 pm, Don dondod...@gmail.com wrote: That solution is using the sign bit as extra storage, which is clever, but if you have an array of unsigned integers and N is more than half of the largest unsigned integer, it won't work. There is a way to do it without using the sign bit as extra storage. On Oct 30, 5:16 pm, rahul sharma rahul23111...@gmail.com wrote: i thnik this is the solution... http://www.geeksforgeeks.org/archives/9755 On Wed, Oct 31, 2012 at 2:20 AM, Don dondod...@gmail.com wrote: We can modify the array. The algorithm should work even if we use unsigned integers and N is the largest unsigned integer. Don On Oct 30, 4:42 pm, rahul sharma rahul23111...@gmail.com wrote: Can we modify the array???we can make index we visit as negative and then if any one already containing -ve..then its repeating On Wed, Oct 31, 2012 at 1:40 AM, Don dondod...@gmail.com wrote: Does your algorithm work if N=4 and the array is {1,1,2,2}. Don On Oct 30, 2:32 pm, arumuga abinesh arumugaabin...@gmail.com wrote: if sum of all elements = n(n-1)/2 , no elements are repeated else some numbers are repeated On Tue, Oct 30, 2012 at 11:57 PM, Don dondod...@gmail.com wrote: Given an array of N integers in the range 0..N-1, determine if any number is repeated in the array. Solution should execute in O(n) time and use constant space. Don -- 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. -- 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] Finite state automata accpt string of length 6
we need to find no. of permutations of abcxyz s.t abc and xyz. @Rahul : If you want to solve it as a PC problem, here is the approach : ignoring these conditions abc and xyz, no. of permutations using abcxyz = 6! Now let's handle abc case. in these 6 ! combinations, abc can come in any of these below orders 1) abc 2) acb 3) bac 4) bca 5) cab 6) cba But we need the abc case (abc) So we need 1 out of these 6 combinations - (1/6) So assuming all the permutations are uniform, total permutations are 6! X (1/6) --- here only this case is taken(abc) now similarly for xyz also 1/6 combinations are possible. so total is 6! X 1/6 X 1/6 so if the questions is a b or c and y x z Ans is : a b or c = abc acb - 2 cases out of 6 satisfy. yxz = yxz - 1 out 6 And the answer will be : 6! X (2/6) X (1/6) -Cheers On Sat, Oct 27, 2012 at 8:04 PM, rahul sharma rahul23111...@gmail.comwrote: ..i under stand with 6!/(3!*3!) method... plz explain from combination point of viewi didnt get ur last linei understand that we need to find no. of permutaions of abcxyz s.t abc and xyz.plz tell how to find thisi understand as someone explained above with VVVHHH method. please explain from thsi view that we need to find no. of permutaions of abcxyz s.t abc and xyz. On Sat, Oct 27, 2012 at 12:31 PM, Saurabh Kumar srbh.ku...@gmail.comwrote: Since this is a small grid you can count it manually but in general problem is to count no. of paths from bottom-left corner to top-right corner (provided all the transition alphabets in the automata are distinct in the respective dimensions e.g. here, xyz in one dimension and abc in other) You can view this problem as writing all permutations of strings of 3R's and 3U's (for RIGHT movement and UP movement) RRRUUU which will take you to the top right most corner. All possible arrangements = (3+3)! / (3! * 3!) In general: (m+n)! / (m! * n!) for a mxn grid. On 27 October 2012 11:05, rahul sharma rahul23111...@gmail.com wrote: should i take it how many ways are there to reach from start to the top right destination...x,y,z,a,b,c, are i/p statexyzabc one stringabc xyz is another...if m ryt then is dere any formulla to calute or we have to do it manuall On Sat, Oct 27, 2012 at 11:02 AM, rahul sharma rahul23111...@gmail.comwrote: can u please elaborate...i am not able to understand the figure..plz explainit would be of great help On Sat, Oct 27, 2012 at 5:57 AM, payal gupta gpt.pa...@gmail.comwrote: should be 6C3 or 20 perhaps. On Sat, Oct 27, 2012 at 3:29 AM, rahul sharma rahul23111...@gmail.com wrote: Finite state automata accpt string of length 6 what is total number of strings in set..please find the attahcment -- 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. -- 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] Why #! ??
First of all in shell script # means that the line is commented. This way shell intepretor dont consider that line for compilation. Also that is the syntax for shebang line - http://linuxshellaccount.blogspot.com/2007/12/shebang-line-introduction-to-porting.html Thanks Vineeth On Thu, Sep 2, 2010 at 9:57 PM, Raj N rajn...@gmail.com wrote: Why do we specifically use #! symbol at the beginning of your scripts? Why not %! or $! or some random symbol? -- 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 with Increment Operators in C!
it sud b 19 naaa x++ = 5 ++x = 7 x++ = 7 5+7+7 On Sat, Aug 28, 2010 at 4:35 PM, jagadish jagadish1...@gmail.com wrote: I ran this code.. int main() { int x=5; printf(%d,(x++ + ++x + x++)); } The output printed was 18 instead of 19.. Should it not be 19? -- 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] linked list
void display(Node *head) { cout\n; for( ; head ; head=head-next) cout\thead-name; cout\n; } when head reaches last node condition head is true , then head will become head-next which is null , and it will try to print the name field from of a null value which is error On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi raj.jagvan...@gmail.comwrote: wats d problem in my display() #includeiostream #includemalloc.h #include string.h using namespace std; struct node { char *name; struct node *next; }; typedef struct node Node; void createList(Node **head ) { char str[20]; char *p; coutEnter a String: ; gets (str) ; p = str; if((strlen(p))2) return; Node *temp=*head; Node *newnode=(Node*)malloc(sizeof(Node)); newnode-name=p; newnode-next=NULL; if(!temp) *head = newnode; else { while(temp-next) temp = temp-next; temp-next = newnode; } createList(head); } void display(Node *head) { cout\n; for( ; head ; head=head-next) cout\thead-name; cout\n; } int main() { Node *head=NULL; while(1) { cout\n\t\tMENU\n; cout0 : To exit.\n; cout1 : To create a linear link list.\n; cout2 : To display the list.\n; char choice; choice = getchar(); getchar(); if(choice=='0') break; switch(choice) { case '1': createList(head ); break; case '2': display(head); break; default: coutEnter valid choice.; } } system(pause); 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.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: graph theory
On Jun 24, 10:05 am, pramod [EMAIL PROTECTED] wrote: For DAGs I don't think there's a unique path from a start vertex to each vertex reachable from it. There could be many paths. One way to solve this problem is to topologically sort the DAG and start from the end and move backwards till the start vertex and keep track of the longest path. The last vertex has no paths from it to anywhere so the longest path is of zero length. The vertex before this will have longest path of 1 if it has an edge to the last vertex. So in general, when we encounter a vertex u then we check each edge from it (u, v) and if vertex v has a longest path of length l then the vertex u has a path of length l+1. We just need to find the longest of these. When we come to the start vertex, we get the required answer. The while thing is linear time work. Let me know if this is wrong. Well, we need to do this for each last vertex. There could be many nodes such that they dont lead to other nodes. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~--~~~~--~~--~--~---