Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread Siddharth kumar
for long strings, the values will be larger. a simple approach could be to store occurrence of each char of both the strings in an integer array of size 26 and if both the arrays are same then the two strings are anagrams. -- You received this message because you are subscribed to the

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread Siddharth kumar
#includeiostream #includestring.h using namespace std; int main() { char str1[] = sdfgkirertyujvcheddirtyutrdfgrtyuigfkrertyuijhgfdshh; char str2[] = redirtyhgfdshhrtyrsujvcheierdutrdfgrtyuigfkdfgktyuij; int len1 = strlen(str1), len2 = strlen(str2); if(len1 != len2) {

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread saurabh singh
use a bitfield to optimize space On Fri, Jul 29, 2011 at 7:14 PM, Siddharth kumar siddhartha.baran...@gmail.com wrote: #includeiostream #includestring.h using namespace std; int main() { char str1[] = sdfgkirertyujvcheddirtyutrdfgrtyuigfkrertyuijhgfdshh; char str2[] =

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread snehi jain
thanks .. @siddhartha : i know the hashing technique ... and the problem of longer strings can be reduced by subtracting a large constant value from the ASCII value of all the characters .. and its not only with cubes even if u add squares of ascii values ... i think it will work . @saurabh : in

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread saurabh singh
ignore above status...i was looking at two problems simulataneously...posted on the wrong one... apologies...really its embarrasing. On Fri, Jul 29, 2011 at 8:11 PM, snehi jain snehijai...@gmail.com wrote: thanks .. @siddhartha : i know the hashing technique ... and the problem of longer

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread snehi jain
no problem .. but can u find a bug in this technique .. On Fri, Jul 29, 2011 at 8:17 PM, saurabh singh saurab...@gmail.com wrote: ignore above status...i was looking at two problems simulataneously...posted on the wrong one... apologies...really its embarrasing. On Fri, Jul 29, 2011 at 8:11

Re: [algogeeks] doubt in checking if 2 strings are anagrams

2011-07-29 Thread saurabh singh
Things can go very bad in case the string length is large and mostly of non priniting chars. and wat if there are chars with negative ascii value?does ur logic handles this situation?I doubt it does, On Fri, Jul 29, 2011 at 8:21 PM, snehi jain snehijai...@gmail.com wrote: no problem .. but can