Re: [algogeeks] Re: wrong output of C program
@naveen :read the his doubt properly...he was expecting 5 10 15 but was getting 8 32 96...and dats the correction required which i made On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar algorithm.i...@gmail.comwrote: @Mahendra: for ur above code with t=(a2)+a o/p will be 5,10, 15 as i explained above. without bracket answer will be 8 , 32 and 96 because + precedence is higher than . On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar sengar.m...@gmail.comwrote: Cracked it...i guess precedence of + is more than so use t=(a2)+a; I checked, its giving proper output now !!! On Friday, June 8, 2012 5:46:09 AM UTC+5:30, algo lover wrote: The following is a simple C program which tries to multiply an integer by 5 using the bitwise operations. But it doesn't do so. Explain the reason for the wrong behavior of the program. #include stdio.h #define PrintInt(expr) printf(%s : %d\n,#expr,(expr)) *int* FiveTimes(*int* a) { *int* t; t *=* a**2 *+* a; *return* t; } *int* main() { *int* a *=* 1, b *=* 2,c *=* 3; PrintInt(FiveTimes(a)); PrintInt(FiveTimes(b)); PrintInt(FiveTimes(c)); *return* 0; } -- 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/-/7CNEyeGuUzEJ. 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] Re: Power(n^n)
You don't need to use BigNum or long int for this program. Both n k should be less than 1000. Since there is no restriction on k,you don't need Bignum Since both n,k are restricted,you don't need bignum. if n5, simply reject the input and return false On Fri, Jun 8, 2012 at 11:01 AM, Dave dave_and_da...@juno.com wrote: @victor: But if K = 1000, then the largest N you have to deal with is 4, since 4^4 1000 but 5^5 1000. So your code looks like this: int IsNtoNEqualK( int N, int K) { return (N==1)(K==1) || (N==2)(K==4) || (N==3){K==27) || (N==4)(K==256); } On Thursday, June 7, 2012 5:14:00 PM UTC-5, Victor Manuel Grijalva Altamirano wrote: Hi, everybody!!! I have the follow quest... I have two numbers N and K, i need to check that N^N = K. for example: if N=2 and K=4 , 2^2 = 4 so return true; if N=3 and K=26 , 3^3 != 26 so return false But 0=N , K=1000 so N^N could be have 1000 digits. I program in C++, and i can use Bignum (array manipulation) + fast power(binary power) but i want to know if exist a mathematical property. -- Victor Manuel Grijalva Altamirano Universidad Tecnologica de La Mixteca -- 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/-/s6ahKx0Sxe8J. 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- 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] Re: Power(n^n)
Ignore the last post. Updated: You don't need to use BigNum or long int for this program. Both n k should be less than 1000. you need bignum only if there would be no restriction on k. Since both n,k are restricted, you don't need bignum. if n5( 5^5 1000), simply reject the input and return false On Fri, Jun 8, 2012 at 11:49 AM, Abhishek Sharma abhi120...@gmail.comwrote: You don't need to use BigNum or long int for this program. Both n k should be less than 1000. Since there is no restriction on k,you don't need Bignum Since both n,k are restricted,you don't need bignum. if n5, simply reject the input and return false On Fri, Jun 8, 2012 at 11:01 AM, Dave dave_and_da...@juno.com wrote: @victor: But if K = 1000, then the largest N you have to deal with is 4, since 4^4 1000 but 5^5 1000. So your code looks like this: int IsNtoNEqualK( int N, int K) { return (N==1)(K==1) || (N==2)(K==4) || (N==3){K==27) || (N==4)(K==256); } On Thursday, June 7, 2012 5:14:00 PM UTC-5, Victor Manuel Grijalva Altamirano wrote: Hi, everybody!!! I have the follow quest... I have two numbers N and K, i need to check that N^N = K. for example: if N=2 and K=4 , 2^2 = 4 so return true; if N=3 and K=26 , 3^3 != 26 so return false But 0=N , K=1000 so N^N could be have 1000 digits. I program in C++, and i can use Bignum (array manipulation) + fast power(binary power) but i want to know if exist a mathematical property. -- Victor Manuel Grijalva Altamirano Universidad Tecnologica de La Mixteca -- 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/-/s6ahKx0Sxe8J. 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- 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] MS Q: how to test a driverless car?
Things like sensor data coming from CAN/MoST from the car is collected and analysed in real time to avoid collisions, off-lane movement, distance maintenance, auto parking(including parallel), slippage on road/snow, GPS integration for perfect location and location specific data (like traffic,school/hospital/potholes etc), capability to act on instructions from telematics agents for SoS(accidents, profile based paths/alterations,speed control as per laws), action on maintenance reminders, fuel auto-filling/auto-charging should drive the testing, . Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Jun 7, 2012 at 1:07 PM, Umer Farooq the.um...@gmail.com wrote: What are the specs of the car. Can you please give the answer to the following clarifying questions: - How much distance is it suppose to travel without the driver? - Is it suppose to run on smooth roads only or can it also run on roads with jumps on it? On what type of road is the car most suitable? - Is it suppose to slow down at speed brakers? - Is it suppose to run on a two-way street as well or can it run on one way roads only? - Is it suppose to auto-park the car, or do we need to have a driver to park the car? On Wed, Jun 6, 2012 at 8:34 PM, Ashish Goel ashg...@gmail.com wrote: Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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. -- Umer -- 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] Re: MS question : string compression
#include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr, int length, char* pNew) { if (!pStr) return -1; if (length 3) return -1; int i = 0; int k = 0; char p1 = pStr[i++]; char p2 = pStr[i++]; char p3 = pStr[i++]; int pos=0; int cCount = 0; bool verbatim = false; while ((p3) (ilength)) { if (p1==p2) { if (p2==p3) { if (i == k+3) //no vRun verbatim = false;//no vRun befor this cRun if (verbatim) { int vEnd = (i-3)-k;; pNew[pos++] = vEnd; for (int t=k;tvEnd;t++) { pNew[pos++]=pStr[t]; } } cCount++; p1 = p2; p2 = p3;/*not required*/ p3 = pStr[i++]; continue; } else { //run end or no run at all if (cCount 0) { //a run pNew[pos++] = -cCount; /// pNew[pos++] = p2; p1 = p3; k = i-1; //p3's position p2 = pStr[i++]; if (!p2) break; p3 = pStr[i++]; cCount = 0; } else { /*aab */ verbatim = true; p1 = p2; p2 = p3; p3 =pStr[i++]; } } } else { //no run verbatim = true; p1 = p2; p2 = p3; p3 =pStr[i++]; } } //possible run or no run here if (cCount0) { pNew[pos++] = -cCount; pNew[pos++] = p2; } else { if (klength) { pNew[pos++] = length-k-1; for (int t=k;tlength;t++) { pNew[pos++]=pStr[t]; } } } pNew[pos]='\0'; return 1; } void rleDecode(char *pEnc, char *pDec, char *pOrig) { int i = 0; int pos =0; int count ; char character ; do { count = pEnc[i++]; if (count 0) { count = 2-count; character = pEnc[i++]; for (int j=0;jcount;j++) pDec[pos++] = character; } else { //pNew[pos++]=character; for (int j=0;jcount;j++) { pDec[pos++]=pEnc[i++]; } } }while (pEnc[i]); pDec[pos]='\0'; for(int i=0;ilen;i++) if (pOrig[i]!=pDec[i]) cout JERK, do it again!! (: endl; } int _tmain(int argc, _TCHAR* argv[]) { char *pStr = (char *)malloc(sizeof(char)*len); pStr = abccdddijkk; //TRY more examples char *pNew = (char *)malloc(sizeof(char)*len); char *pDec = (char *)malloc(sizeof(char)*len); //rleSimple(pStr,pNew); rle(pStr,len,pNew); rleDecode(pNew, pDec, pStr); return 0; } Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 9:04 AM, Ashish Goel ashg...@gmail.com wrote: The idea here is that there will be parts of the stream which actually should not be compressed. For example abcdef as well as aa do not need any compression. We need to compress only if 3 characters match because for compressing two chars we will take up 2 chars so no compression benefit (: So we need to keep a pos as a reference to say that here is the position in the string i am processing now and do the compress(either verbatim or real compress) when 3 same chars are found eg abcfdgffg: pos is 0 and at index 8 we get to know that there is a run, so we should say 8-3+1=6 need to go verbatim so we write 6abcfdg and update pos to index 6, and count to 1. Since now run flag is on, we continue till we find a triplet mismatch(f==f but f!=g) which happens at g (index 12)implying an end to a run, therefore now count is 4, we would write 4f implying 2+4 times of next char should be expanded. now again pos will be set to 12, count to 0 and three same char check should re-begin. This will for sure have 2 while loops and a bit comex, and i donot think this is what the interviewer should expect one to code. Kindly note that if run is more than max length, we need to tweak the writing part too. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Jun 7, 2012 at 7:05 PM, Navin Gupta navin.nit...@gmail.comwrote: If abcdef is changed to a1b1c1d1e1f1, then we need to allocate memory dynamically. Because length is increased,I think this has no practical implementation.As abcdef serves the same purpose. On Sunday, 3 June 2012 09:36:25 UTC+5:30, utsav sharma wrote: @ashish:-algo given in link wiil fail for abcdef @navin:- output of abcdef should be 1a1b1c1d1e1f On Sun, May 27, 2012 at 3:24 PM, Ashish Goel ashg...@gmail.com wrote: Will fail for the sing having say 257characters all same Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, May 26, 2012 at 12:26 PM, Navin Gupta navin.nit...@gmail.comwrote: This is called Run-Length-Encoding (RLE) of a string. Its purpose is to save space.So in case of abcdef,I think the output needed is abcdef (1 is implicit). The added benefit is it makes the solution in-place. Approach:- (In-place and Linear Time) Start from the left of string and PREVIOUS_CHAR = str[0] move forward till u match the CURRENT_CHAR with PREVIOUS_CHAR and keep count of PREVIOUS_CHAR At any point if (PREVIOUS_CHAR!=CURRENT_CHAR) put the count of prev_char next to the start position of the previous character. Below is the working code :- void torle(char *str) { int i=0,j=0,k=0,cnt=1; char cur_char=str[0],num[100]; while(str[j+1]) { cnt=1; while(str[j+1]==cur_char str[j]!='\0'){
Re: [algogeeks] Re: wrong output of C program
@sengar: sorry dude...i got his doubt.Though my explanation was correct. I think now everybody's doubt is clear.By the way thanx for correcting me. On Fri, Jun 8, 2012 at 11:48 AM, sengar.mahi sengar.m...@gmail.com wrote: @naveen :read the his doubt properly...he was expecting 5 10 15 but was getting 8 32 96...and dats the correction required which i made On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar algorithm.i...@gmail.comwrote: @Mahendra: for ur above code with t=(a2)+a o/p will be 5,10, 15 as i explained above. without bracket answer will be 8 , 32 and 96 because + precedence is higher than . On Fri, Jun 8, 2012 at 7:31 AM, Mahendra Sengar sengar.m...@gmail.comwrote: Cracked it...i guess precedence of + is more than so use t=(a2)+a; I checked, its giving proper output now !!! On Friday, June 8, 2012 5:46:09 AM UTC+5:30, algo lover wrote: The following is a simple C program which tries to multiply an integer by 5 using the bitwise operations. But it doesn't do so. Explain the reason for the wrong behavior of the program. #include stdio.h #define PrintInt(expr) printf(%s : %d\n,#expr,(expr)) *int* FiveTimes(*int* a) { *int* t; t *=* a**2 *+* a; *return* t; } *int* main() { *int* a *=* 1, b *=* 2,c *=* 3; PrintInt(FiveTimes(a)); PrintInt(FiveTimes(b)); PrintInt(FiveTimes(c)); *return* 0; } -- 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/-/7CNEyeGuUzEJ. 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.
[algogeeks] Book Feedback needed for book from Narasimha Karumanchi
Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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] Book Feedback needed for book from Narasimha Karumanchi
Its a book worth have. On Fri, Jun 8, 2012 at 1:44 PM, Ashish Goel ashg...@gmail.com wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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] first Repeating character in a string
how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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] first Repeating character in a string
you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Regards Anika Jain -- 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] first Repeating character in a string
howcome hashing will result in wrong output..?? if(isHashed(str[i]) { character found. break. } else hash(str[i]); On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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] Re: Book Feedback needed for book from Narasimha Karumanchi
anybody having the ebook ? On Friday, 8 June 2012 13:44:18 UTC+5:30, ashgoel wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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/-/CaiO2BXclWEJ. 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] first Repeating character in a string
This is MS Q and hasing will give the right answer. walk over the string, if it is present in hashTable, it is first repeated character. This is single pass. However, if you do another pass, your answer would be a which is first char that is repeated whereas b is first character to occur first again in the string. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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] Re: MS question : string compression
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 12:54 PM, Ashish Goel ashg...@gmail.com wrote: #include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr, int length, char* pNew) { if (!pStr) return -1; if (length 3) return -1; int i = 0; int k = 0; char p1 = pStr[i++]; char p2 = pStr[i++]; char p3 = pStr[i++]; int pos=0; int cCount = 0; bool verbatim = false; while ((p3) (ilength)) { if (p1==p2) { if (p2==p3) { if (i == k+3) //no vRun verbatim = false;//no vRun befor this cRun if (verbatim) { int vEnd = (i-3)-k;; pNew[pos++] = vEnd; for (int t=k;tvEnd;t++) { pNew[pos++]=pStr[t]; } } cCount++; if (cCount == maxCount) { pNew[pos++] = -cCount; /// pNew[pos++] = p3; p1 = pStr[i++]; if (!p1) break; k = 0; p2 = pStr[i++]; if (!p2) break; p3 = pStr[i++]; cCount = 0; continue; } else { /*p1 = p2; p2 = p3; //not required*/ p3 = pStr[i++]; } } else { //run end or no run at all if (cCount 0) { //a run pNew[pos++] = -cCount; /// pNew[pos++] = p2; p1 = p3; k = i-1; //p3's position p2 = pStr[i++]; if (!p2) break; p3 = pStr[i++]; cCount = 0; } else { /*aab */ verbatim = true; p1 = p2; p2 = p3; p3 =pStr[i++]; } } } else { //no run verbatim = true; p1 = p2; p2 = p3; p3 =pStr[i++]; } } //possible run or no run here if (cCount0) { pNew[pos++] = -cCount; pNew[pos++] = p2; } else { if (klength) { pNew[pos++] = length-k-1; for (int t=k;tlength;t++) { pNew[pos++]=pStr[t]; } } } pNew[pos]='\0'; return 1; } void rleDecode(char *pEnc, char *pDec, char *pOrig) { int i = 0; int pos =0; int count ; char character ; do { count = pEnc[i++]; if (count 0) { count = 2-count; character = pEnc[i++]; for (int j=0;jcount;j++) pDec[pos++] = character; } else { //pNew[pos++]=character; for (int j=0;jcount;j++) { pDec[pos++]=pEnc[i++]; } } }while (pEnc[i]); pDec[pos]='\0'; for(int i=0;ilen;i++) if (pOrig[i]!=pDec[i]) cout JERK, do it again!! (: endl; } int _tmain(int argc, _TCHAR* argv[]) { char *pStr = (char *)malloc(sizeof(char)*len); pStr = abccdddijkk; //TRY more examples char *pNew = (char *)malloc(sizeof(char)*len); char *pDec = (char *)malloc(sizeof(char)*len); //rleSimple(pStr,pNew); rle(pStr,len,pNew); rleDecode(pNew, pDec, pStr); return 0; } Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 9:04 AM, Ashish Goel ashg...@gmail.com wrote: The idea here is that there will be parts of the stream which actually should not be compressed. For example abcdef as well as aa do not need any compression. We need to compress only if 3 characters match because for compressing two chars we will take up 2 chars so no compression benefit (: So we need to keep a pos as a reference to say that here is the position in the string i am processing now and do the compress(either verbatim or real compress) when 3 same chars are found eg abcfdgffg: pos is 0 and at index 8 we get to know that there is a run, so we should say 8-3+1=6 need to go verbatim so we write 6abcfdg and update pos to index 6, and count to 1. Since now run flag is on, we continue till we find a triplet mismatch(f==f but f!=g) which happens at g (index 12)implying an end to a run, therefore now count is 4, we would write 4f implying 2+4 times of next char should be expanded. now again pos will be set to 12, count to 0 and three same char check should re-begin. This will for sure have 2 while loops and a bit comex, and i donot think this is what the interviewer should expect one to code. Kindly note that if run is more than max length, we need to tweak the writing part too. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Jun 7, 2012 at 7:05 PM, Navin Gupta navin.nit...@gmail.comwrote: If abcdef is changed to a1b1c1d1e1f1, then we need to allocate memory dynamically. Because length is increased,I think this has no practical implementation.As abcdef serves the same purpose. On Sunday, 3 June 2012 09:36:25 UTC+5:30, utsav sharma wrote: @ashish:-algo given in link wiil fail for abcdef @navin:- output of abcdef should be 1a1b1c1d1e1f On Sun, May 27, 2012 at 3:24 PM, Ashish Goel ashg...@gmail.com wrote: Will fail for the sing having say 257characters all same Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, May 26, 2012 at 12:26 PM, Navin Gupta navin.nit...@gmail.comwrote: This is called Run-Length-Encoding (RLE) of a string. Its purpose is to save space.So in case of abcdef,I think the output needed is abcdef (1 is implicit). The added benefit is it makes the solution in-place. Approach:- (In-place and Linear
Re: [algogeeks] first Repeating character in a string
But you can use unordered map something like what boost does .. http://boost.cowic.de/rc/pdf/unordered.pdf Cheers. On Friday, June 8, 2012 5:38:56 PM UTC+8, ashgoel wrote: This is MS Q and hasing will give the right answer. walk over the string, if it is present in hashTable, it is first repeated character. This is single pass. However, if you do another pass, your answer would be a which is first char that is repeated whereas b is first character to occur first again in the string. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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 view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/KV8auOcBZ9kJ. 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] Re: Differentiate the following declarations.
Using Spiral-Anderson rule, 1:- const char * a - a is a pointer to char const (character which is constant , the value pointed by the pointer is constant) 2:- char * const a - a is a const pointer to char (pointer is constant, it always point to same memory location) 3:- char const * a - a is a pointer to const char (again character is constant , the value pointed by the pointer is constant) *a='F' a =Hi From above 1 2 3 *a= 'F' Legal Illegal Legal a=Hi Illegal Legal Illegal -- 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/-/AKf8Zszo-IoJ. 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] Re: Book Feedback needed for book from Narasimha Karumanchi
Its one of the best book. If u r planning for some big jobs thn u should read this book SDE 1 Amazon India development Center On Fri, Jun 8, 2012 at 2:45 PM, Ramindar Singh ramin...@gmail.com wrote: anybody having the ebook ? On Friday, 8 June 2012 13:44:18 UTC+5:30, ashgoel wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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/-/CaiO2BXclWEJ. 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. -- *Abhishek Prajapati Final Year, B.Tech(Hons) Department of Computer Science Engg. NIT Jamshedpur* -- 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] Re: wrong output of C program
@mehender exactly bro. program -- #include stdio.h #define PrintInt(expr) printf(%s : %d\n,#expr,(expr)) int FiveTimes(int a) { int t; t = (a2) + a; // change - added parenthesis. return t; } int main() { int a = 1, b = 2,c = 3; PrintInt(FiveTimes(a)); PrintInt(FiveTimes(b)); PrintInt(FiveTimes(c)); return 0; } o/p-- FiveTimes(a) : 5 FiveTimes(b) : 10 FiveTimes(c) : 15 -- 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] first Repeating character in a string
In a string try to loop through all character and count the occurances (incrementing by 1 whenever that character occurs)... store it in hash (initialize the hash to 0)... when the count of any char equals 2 break from the loop that char is first repeating char. -- RK :) On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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] first Repeating character in a string
Use the below function, that will return first repeated character of string or null; Note: blank space is also consider as character... you can add exception to avoid such case char firstRepeatChar(char *str) { int arr[256] = {0}; for(int i = 0; str[i] != '\0'; i++) { arr[str[i]] +=1; if(arr[str[i]] 1) { return str[i]; } } return 0; } On Fri, Jun 8, 2012 at 2:38 PM, atul anand atul.87fri...@gmail.com wrote: howcome hashing will result in wrong output..?? if(isHashed(str[i]) { character found. break. } else hash(str[i]); On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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] first Repeating character in a string
the output will be correct it will not be incorrect in hashing case . On Fri, Jun 8, 2012 at 2:38 PM, atul anand atul.87fri...@gmail.com wrote: howcome hashing will result in wrong output..?? if(isHashed(str[i]) { character found. break. } else hash(str[i]); On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Cheers, Nishant Pandey |Specialist Tools Development | npan...@google.comgvib...@google.com | +91-9911258345 -- 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] first Repeating character in a string
lets say we have an array COUNT[256] which is initialized to zero. 1) traverse the string S from 0 to length-1 2) if COUNT[S[i] - '0'] == 0 , increment COUNT[S[i] - '0'] = 1; 3) else print the first repeating character. -Mahesh On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote: you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Regards Anika Jain -- 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] Book Feedback needed for book from Narasimha Karumanchi
Hi, I have been reading this book these days Book have very nice collection of problems which are very much needed for interview preparation. This is for not for those who is expecting to learn basics. On Fri, Jun 8, 2012 at 1:46 PM, rajesh singarapu rajesh0...@gmail.comwrote: Its a book worth have. On Fri, Jun 8, 2012 at 1:44 PM, Ashish Goel ashg...@gmail.com wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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] first Repeating character in a string
you may use look up table for each character like this : int table[255]={0}; for(int i=0;str[i];i++) { if( table[str[i]] ) return true; else { table[str[i]]=1; } } return false; On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote: you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Regards Anika Jain -- 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. -- Cheers, Nishant Pandey |Specialist Tools Development | npan...@google.comgvib...@google.com | +91-9911258345 -- 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] Finding largest zigzag subsequence
Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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] first Repeating character in a string
The key doesn't lies in the way it will be solved.It is how efficiently you implement the hash table.do we really need an integer array ( 4*256 bytes) just to record the first occurrence of a character? Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 8, 2012 at 2:36 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: you may use look up table for each character like this : int table[255]={0}; for(int i=0;str[i];i++) { if( table[str[i]] ) return true; else { table[str[i]]=1; } } return false; On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote: you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Regards Anika Jain -- 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. -- Cheers, Nishant Pandey |Specialist Tools Development | npan...@google.comgvib...@google.com | +91-9911258345 -- 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] first Repeating character in a string
no hashtable needed , a bitmap is sufficient Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:04 PM, saurabh singh saurab...@gmail.com wrote: The key doesn't lies in the way it will be solved.It is how efficiently you implement the hash table.do we really need an integer array ( 4*256 bytes) just to record the first occurrence of a character? Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 8, 2012 at 2:36 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: you may use look up table for each character like this : int table[255]={0}; for(int i=0;str[i];i++) { if( table[str[i]] ) return true; else { table[str[i]]=1; } } return false; On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.comwrote: you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- 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. -- Regards Anika Jain -- 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. -- Cheers, Nishant Pandey |Specialist Tools Development | npan...@google.comgvib...@google.com | +91-9911258345 -- 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] Finding largest zigzag subsequence
O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to conceptualize it this way (:. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 3:47 PM, Ratan success.rata...@gmail.com wrote: Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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 largest zigzag subsequence
Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21 23; but the correct optimized o/p should have been with length 7 as 4,12,1,43,21,23,9 On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel ashg...@gmail.com wrote: my solution will not provide the largest eg 2,4,6,5 should have largest as 2,6,5 not 2,4.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel ashg...@gmail.com wrote: O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to conceptualize it this way (:. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 3:47 PM, Ratan success.rata...@gmail.com wrote: Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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. -- -- Ratan | 3rd Year | Information Technology | 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 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 largest zigzag subsequence
we should use dp On Fri, Jun 8, 2012 at 5:39 PM, Ratan success.rata...@gmail.com wrote: Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21 23; but the correct optimized o/p should have been with length 7 as 4,12,1,43,21,23,9 On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel ashg...@gmail.com wrote: my solution will not provide the largest eg 2,4,6,5 should have largest as 2,6,5 not 2,4.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel ashg...@gmail.com wrote: O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to conceptualize it this way (:. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 3:47 PM, Ratan success.rata...@gmail.com wrote: Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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. -- -- Ratan | 3rd Year | Information Technology | 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 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. -- Srikanth Reddy M (M.Sc Tech.) Information Systems BITS-PILANI -- 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 largest zigzag subsequence
#includestdio.h int main() { int Seq[100],i,j,n,Max,tmp; int zzlen[100][2]; scanf(%d,n); for(i = 0 ; i n ; i++) { scanf(%d,Seq[i]); zzlen[i][0] = 1;zzlen[i][1] = 0;} Max = 1; for(i = 1 ; i n ; i++) { for(j = i-1 ; j = 0 ; j--) { if(Seq[i] = Seq[j]) { tmp = 1; if(zzlen[j][1] == -1 || zzlen[j][1] == 0) { if(zzlen[i][0] zzlen[j][0]+1) { zzlen[i][0] = zzlen[j][0]+1; zzlen[i][1] = tmp; } } } if(Seq[i] Seq[j]) { tmp = -1; if(zzlen[j][1] == 1 || zzlen[j][1] == 0) { if(zzlen[i][0] zzlen[j][0]+1) { zzlen[i][0] = zzlen[j][0]+1; zzlen[i][1] = tmp;} } } } if(zzlen[i][0] Max) Max = zzlen[i][0]; } printf(Length of longest zig-zag subsequence is : %d\n,Max); return 0; } On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel srikk...@gmail.com wrote: we should use dp On Fri, Jun 8, 2012 at 5:39 PM, Ratan success.rata...@gmail.com wrote: Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21 23; but the correct optimized o/p should have been with length 7 as 4,12,1,43,21,23,9 On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel ashg...@gmail.com wrote: my solution will not provide the largest eg 2,4,6,5 should have largest as 2,6,5 not 2,4.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel ashg...@gmail.com wrote: O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to conceptualize it this way (:. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 3:47 PM, Ratan success.rata...@gmail.com wrote: Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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. -- -- Ratan | 3rd Year | Information Technology | 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 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. -- Srikanth Reddy M (M.Sc Tech.) Information Systems BITS-PILANI -- Srikanth Reddy M (M.Sc Tech.) Information Systems BITS-PILANI -- 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] first Repeating character in a string
order of hashing and counting is important eg. abba if we do hashing by characters 'a' is stored before 'b' and count of both is 2 at the end and when we process this we give result 'a' (because 'a' comes before 'b' )which is wrong because 'b' is the first repeated character. Thanks Regards Saurabh -- 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 largest zigzag subsequence
@srikanth: can u frame out the recursive function for the solution proposed in DP . i was actually finding difficulty in this.. On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel srikk...@gmail.com wrote: #includestdio.h int main() { int Seq[100],i,j,n,Max,tmp; int zzlen[100][2]; scanf(%d,n); for(i = 0 ; i n ; i++) { scanf(%d,Seq[i]); zzlen[i][0] = 1;zzlen[i][1] = 0;} Max = 1; for(i = 1 ; i n ; i++) { for(j = i-1 ; j = 0 ; j--) { if(Seq[i] = Seq[j]) { tmp = 1; if(zzlen[j][1] == -1 || zzlen[j][1] == 0) { if(zzlen[i][0] zzlen[j][0]+1) { zzlen[i][0] = zzlen[j][0]+1; zzlen[i][1] = tmp; } } } if(Seq[i] Seq[j]) { tmp = -1; if(zzlen[j][1] == 1 || zzlen[j][1] == 0) { if(zzlen[i][0] zzlen[j][0]+1) { zzlen[i][0] = zzlen[j][0]+1; zzlen[i][1] = tmp;} } } } if(zzlen[i][0] Max) Max = zzlen[i][0]; } printf(Length of longest zig-zag subsequence is : %d\n,Max); return 0; } On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel srikk...@gmail.com wrote: we should use dp On Fri, Jun 8, 2012 at 5:39 PM, Ratan success.rata...@gmail.com wrote: Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21 23; but the correct optimized o/p should have been with length 7 as 4,12,1,43,21,23,9 On Fri, Jun 8, 2012 at 5:26 PM, Ashish Goel ashg...@gmail.com wrote: my solution will not provide the largest eg 2,4,6,5 should have largest as 2,6,5 not 2,4.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:15 PM, Ashish Goel ashg...@gmail.com wrote: O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase = true; } } } What i was thinking is to find the number of peaks and valleys through binary search thereby using log(n) solution not able to conceptualize it this way (:. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 3:47 PM, Ratan success.rata...@gmail.com wrote: Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag subsequence will be : {1,10,5,9,8,12} or {1,10,5,9,8,20} and length will be=6; -- -- -- 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. -- -- Ratan | 3rd Year | Information Technology | 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 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. -- Srikanth Reddy M (M.Sc Tech.) Information Systems BITS-PILANI -- Srikanth Reddy M (M.Sc Tech.) Information Systems BITS-PILANI -- 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. -- -- Ratan | 3rd Year | Information Technology | NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to
Re: [algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi
Does anybody has its ebook ? Please upload it -- 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/-/AETPnqJps7AJ. 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] search in O(logn)
A sorted array of integers is rotated unknown times. find an item in O(logn) time and O(1) space complexity. for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3 find 2 in O(logn) time in O(1) space complexity Regards Hassan H. Monfared -- 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] Re: search in O(logn)
@Hassan: This is not possible without additional conditions. E.g., you cannot find the 1 in the array {0,0,0,...,0,1,0,0,...,0} in less than O(n) time. But with the condition that the elements of the array are pairwise distinct, you can use a binary search to find k such that a[k-1] a[0] and a[k] a[0]. Then if x a[k], do a binary search to find x in {a[k] ... a[n-1]}; otherwise do a binary search to find x in {a[0] ... a[k]}. Dave On Friday, June 8, 2012 8:41:47 AM UTC-5, Hassan Monfared wrote: A sorted array of integers is rotated unknown times. find an item in O(logn) time and O(1) space complexity. for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3 find 2 in O(logn) time in O(1) space complexity Regards Hassan H. Monfared -- 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/-/KD9Hz01ZIJ8J. 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] Re: search in O(logn)
Yes, Thanks Dave. for non-distinct items It's not possible. On Fri, Jun 8, 2012 at 6:44 PM, Dave dave_and_da...@juno.com wrote: @Hassan: This is not possible without additional conditions. E.g., you cannot find the 1 in the array {0,0,0,...,0,1,0,0,...,0} in less than O(n) time. But with the condition that the elements of the array are pairwise distinct, you can use a binary search to find k such that a[k-1] a[0] and a[k] a[0]. Then if x a[k], do a binary search to find x in {a[k] ... a[n-1]}; otherwise do a binary search to find x in {a[0] ... a[k]}. Dave On Friday, June 8, 2012 8:41:47 AM UTC-5, Hassan Monfared wrote: A sorted array of integers is rotated unknown times. find an item in O(logn) time and O(1) space complexity. for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3 find 2 in O(logn) time in O(1) space complexity Regards Hassan H. Monfared -- 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/-/KD9Hz01ZIJ8J. 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] first Repeating character in a string
@all: my bad...i ws confused while posting the ques. hashing can gv either a or bonly thing tht matters is hw u implement hashing and counting thanx i hv got the soln On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote: order of hashing and counting is important eg. abba if we do hashing by characters 'a' is stored before 'b' and count of both is 2 at the end and when we process this we give result 'a' (because 'a' comes before 'b' )which is wrong because 'b' is the first repeated character. Thanks Regards Saurabh -- 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. -- Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- 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] override struct definition in c ????
is it possible to override struct definition in c in header.h header file i have eg typedef struct a { int ab ; } nw in .c file i have included header.h typedef struct a { char c ; int b; } and giving following def i m getting an error ... *'struct type redefinition'* So anyways in c anyways to override this error , like in c++ or c# we use virtual keyword -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- 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] Re: Algorithm page
More post: http://marathoncode.blogspot.com.br/2012/06/qual-e-o-melhor-comentario-no-codigo.html http://marathoncode.blogspot.com.br/2012/06/importancia-de-algoritmos-eficientes.html http://marathoncode.blogspot.com.br/2012/06/um-professor-em-minha-vida.html http://marathoncode.blogspot.com.br/2012/06/o-amor-e-uma-falacia-ou-nao-ensine.html http://marathoncode.blogspot.com.br/2012/05/algoritmos-gulosos.html http://marathoncode.blogspot.com.br/2012/05/algoritmos-de-tentativa-e-erro.html http://marathoncode.blogspot.com.br/2012/05/introducao-ao-haskell.html http://marathoncode.blogspot.com.br/2012/05/metodos-de-ordenacao.html Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Sat, May 26, 2012 at 1:09 PM, Wladimir Tavares wladimir...@gmail.comwrote: More posts: http://marathoncode.blogspot.com.br/2012/04/list-comprehension-and-generator.html http://marathoncode.blogspot.com.br/2012/04/floating-point-arithmetic-with.html http://marathoncode.blogspot.com.br/2012/05/algoritmos-gulosos.html http://marathoncode.blogspot.com.br/2012/05/algoritmos-de-tentativa-e-erro.html http://marathoncode.blogspot.com.br/2012/05/introducao-ao-haskell.html http://marathoncode.blogspot.com.br/2012/04/paralelismo-de-bits.html http://marathoncode.blogspot.com.br/2012/04/inverso-multiplicativo.html http://marathoncode.blogspot.com.br/2012/04/usando-pthread.html Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Mon, Apr 16, 2012 at 7:34 PM, Wladimir Tavares wladimir...@gmail.comwrote: Great Job!! Wladimir Araujo Tavares *Federal University of Ceará http://lia.ufc.br/%7Ewladimir/ Homepage http://lia.ufc.br/%7Ewladimir/ | Maratonahttps://sites.google.com/site/quixadamaratona/| * On Mon, Apr 16, 2012 at 2:34 PM, Praveen Kumar praveen97...@gmail.comwrote: Here[0] is one of the post( http://marathoncode.blogspot.com.br/2012/03/alguns-truques-da-linguagem-c.html) by Wladimir in english [0]http://codewar.in/c-tricks-vectors-and-algorithm-in-stl/ -- Cheers -- 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] Re: override struct definition in c ????
No. In C++ you can't either. You can declare a new class that _extends_ a previous one, but you can't change a declaration once it's complete. On Jun 8, 11:38 am, HARSHIT PAHUJA hpahuja.mn...@gmail.com wrote: is it possible to override struct definition in c in header.h header file i have eg typedef struct a { int ab ; } nw in .c file i have included header.h typedef struct a { char c ; int b; } and giving following def i m getting an error ... *'struct type redefinition'* So anyways in c anyways to override this error , like in c++ or c# we use virtual keyword -- HARSHIT PAHUJA M.N.N.I.T. ALLAHABAD -- 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] first Repeating character in a string
@saurabh: why would u count all??? just see while counting if the bitmap is set.. then return the char. On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote: order of hashing and counting is important eg. abba if we do hashing by characters 'a' is stored before 'b' and count of both is 2 at the end and when we process this we give result 'a' (because 'a' comes before 'b' )which is wrong because 'b' is the first repeated character. Thanks Regards Saurabh -- 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] Re: search in O(logn)
It is easy.. find the point where it is rotated to get 14-1 O(log(n)) since 214 that means u have to find it in subarray [123].. do a binary search here o(long(n)) final 2*O(log(n))... On Fri, Jun 8, 2012 at 7:44 PM, Dave dave_and_da...@juno.com wrote: @Hassan: This is not possible without additional conditions. E.g., you cannot find the 1 in the array {0,0,0,...,0,1,0,0,...,0} in less than O(n) time. But with the condition that the elements of the array are pairwise distinct, you can use a binary search to find k such that a[k-1] a[0] and a[k] a[0]. Then if x a[k], do a binary search to find x in {a[k] ... a[n-1]}; otherwise do a binary search to find x in {a[0] ... a[k]}. Dave On Friday, June 8, 2012 8:41:47 AM UTC-5, Hassan Monfared wrote: A sorted array of integers is rotated unknown times. find an item in O(logn) time and O(1) space complexity. for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3 find 2 in O(logn) time in O(1) space complexity Regards Hassan H. Monfared -- 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/-/KD9Hz01ZIJ8J. 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] first Repeating character in a string
ya...hashing is rt method but, we have to implement it by using self referential structure i think ..stilll we can solve this problem by using arrayslike int arr[256]={0}; int main() { char str[]=abba; . . for(i=0;str[i]!=NULL;i++) { if(arr[(str[i]-'0')]==1) { printf(first repeated is%c,str[i]); break; } else arr[(str[i]-'0')]==1; } } On Fri, Jun 8, 2012 at 7:15 AM, himanshu kansal himanshukansal...@gmail.com wrote: @all: my bad...i ws confused while posting the ques. hashing can gv either a or bonly thing tht matters is hw u implement hashing and counting thanx i hv got the soln On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.comwrote: order of hashing and counting is important eg. abba if we do hashing by characters 'a' is stored before 'b' and count of both is 2 at the end and when we process this we give result 'a' (because 'a' comes before 'b' )which is wrong because 'b' is the first repeated character. Thanks Regards Saurabh -- 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. -- Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- 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] Re: interview HARD problem
is it like this : Ex: rose open send end this is a rectangle having valid words.and available in dictionary tooo... On Wed, Jun 6, 2012 at 11:46 AM, Ashish Goel ashg...@gmail.com wrote: Gene, you are right, the rectangle is valid if rotated by 90 degrees too. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Jun 5, 2012 at 7:45 PM, Gene gene.ress...@gmail.com wrote: Does this sufficae? Suppose you were using a dictionary from the frapplewonk language, which has only 5 words: tab oma to am ba Then the biggest rectangle is clearly tab oma On Jun 4, 10:39 pm, Ashish Goel ashg...@gmail.com wrote: preparing a sample itself is a great problem here, that is why i called it hard all words in the rectangle horizontally as well as vertically needs to be valid dictionary words Ashish Hassan say this rectangle AH,SA,HS,IS,SA,HN should also be valid dictonary words, indeed they are not.. definitely we will need a multimap to have words of same length forming a bucket..not able to think beyond this Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Jun 4, 2012 at 6:38 PM, Hassan Monfared hmonfa...@gmail.com wrote: Give a sample please On Mon, Jun 4, 2012 at 5:34 PM, Ashish Goel ashg...@gmail.com wrote: Given a dictionary of millions of words, give an algorithm to find the largest possible rectangle of letter that every row forms a word(reading left to right) and every column forms a word(reading from top to bottom). Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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] first Repeating character in a string
i was explaining the general idea which we generally use with hashing i.e. hashing and counting the all the char and then find which is the repeated character yes u r correct , for the correct solution we should return when we found bitmap set , which is the actual solution :) On Fri, Jun 8, 2012 at 7:58 PM, partha sarathi Mohanty partha.mohanty2...@gmail.com wrote: @saurabh: why would u count all??? just see while counting if the bitmap is set.. then return the char. On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.comwrote: order of hashing and counting is important eg. abba if we do hashing by characters 'a' is stored before 'b' and count of both is 2 at the end and when we process this we give result 'a' (because 'a' comes before 'b' )which is wrong because 'b' is the first repeated character. Thanks Regards Saurabh -- 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. -- Thanks Regards Saurabh Yadav -- 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] Basics--- Advanced
If one wants to start with basics of Data Structures and Algorithms and then move to advanced, how should one start with. I mean, which books to read first so that one gets basics clear. And then to move to advanced level, what more to do(like books to read,training in USACO, practice in Codechef,spoj,codeforces etc.). Also, where can one practice problems to get a firm hold of DS Algo. eg. USACO, UVa will do or more has to done to be a good programmer. Thanx in advance. -- 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/-/6wWs7Opr2IgJ. 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.