Re: [algogeeks] Re: searching all matching words in a Trie with a given filter.

2013-06-08 Thread avinesh saini
@Rahul,  The problem is to get all the words matching to a given filter
like *...n..p  *from already built trie.

@Don, I'm storing words at the ending node, now I'm trying to modify this
function so that it returns only one random word from all words matching
that filter with equal probability for each word, I'm trying like this

char* randomWord(trie *root, char *k)
{
int m;
if(!root || flag) return;

if(*k == '\0') {
if(root-word) {
strcpy(mWord,root-word);   // storing the random word
in mWord.
flag = 1;
}
return;
}
else if(*k == '.') {
for(m=0;m26;m++) {
if(root-children[mark[m]]){//
 where mark[26] is an array containing numbers [0,1,2,.,25] on random
indices.
randomWord(root-children[mark[m]],k+1);
}
}
randomize();   //
 randomize function shuffles mark[].
}
else
randomWord(root-children[*k-'a'],k+1);
}

But this is not giving words with equal probability. It is returning words
more frequently which are having consecutive same letters.


On Thu, May 30, 2013 at 2:34 AM, rahul sharma rahul23111...@gmail.comwrote:

 wat exaclty the question is.
 We have to make a tire with filter or we have a trie(whole dictionary) and
 we have to check filter out the elements.

 plz explain question


 On Wed, May 29, 2013 at 7:55 PM, Don dondod...@gmail.com wrote:

 There has to be some way to know that a node is the end of a word, and
 to know what that word is. This might be done by using a parent
 pointer which lets you traverse the trie back to the root, rebuilding
 the word, or you could keep track of the word as you traverse down the
 trie. Putting the whole word in the node where the word ends would be
 the most simple and time-efficient approach, if you have the memory to
 support it.

 Here is a different way to do it, if the trie has a wordEnd flag and
 does not store the word in the node.

 void findWords(trie *root, char *filter, String word=)
 {
 if (!root) return;

 if (*filter == 0)  // When you reach the end of the filter at the
 end of a valid word, add the word.
 {
 if (root-wordEnd) words.add(word);
 }
 else if (*filter == '.')   // Search for words with any letter
 {
 for(int i = 'a'; i = 'z' ; ++i)
 findWords(root-link[i], filter+1, word+i);
 }
 else  // Search for words with the required letter
 {
  findWords(root-link[*filter], filter+1, word+*filter);
 }
 }

 On May 28, 11:36 pm, avinesh saini avinesh.sa...@gmail.com wrote:
  Thank you Don, I was also trying in similar way. But here I'm confused
 how
  you are storing the traversed words. Are you adding whole words at the
 node
  on which word is ending during insertion.
 
 
 
 
 
 
 
 
 
  On Wed, May 29, 2013 at 12:36 AM, Don dondod...@gmail.com wrote:
   void findWords(trie *root, char *filter)
   {
   if (!root) return;
 
   if (*filter == 0)  // When you reach the end of the filter at the
   end of a valid word, add the word.
   {
   if (root-words) words.add(root-word);
   }
   else if (*filter == '.')   // Search for words with any letter
   {
   for(int i = 'a'; i = 'z' ; ++i)
   findWords(root-link[i], filter+1);
   }
   else  // Search for words with the required letter
   {
findWords(root-link[*filter], filter+1);
   }
   }
 
   On May 28, 4:47 am, avinesh saini avinesh.sa...@gmail.com wrote:
How to search all the matching words for a filter in a trie.
e.g.
searching by filter  ...r..m will find all the words(of length =
 7) in
trie in which 4th character is 'r' and 7th character is 'm'.
 
--
*
*
*thanks  regards,*
*Avinesh
*
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To unsubscribe from this group and stop receiving emails from it,
 send an
   email to algogeeks+unsubscr...@googlegroups.com.
 
  --
  *
  *
  *thanks  regards,*
  *Avinesh
  *

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.






-- 
*
*
*regards,*
*Avinesh Kumar
National Institute of Technology, Calicut.*
*Kerala- 673601*
*+91 7849080702*
*http://www.facebook.com/avinesh.saini*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email

Re: [algogeeks] Re: Array Problem

2013-06-01 Thread avinesh saini
I was going through this problem on stackoverflow, and I found this classic
article on this very topic

http://www.americanscientist.org/issues/pub/2002/3/the-easiest-hard-problem

Definitely, worth a read.




-- 
*
*
*thanks  regards,*
*Avinesh Kumar
National Institute of Technology, Calicut.*
*Kerala- 673601*
*+91 7849080702*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] searching all matching words in a Trie with a given filter.

2013-05-30 Thread avinesh saini
Don, I'm trying to get all the words from trie iteratively, because I'm
creating trie of whole dictionary (more than 200k words) and searching
recursively will consume a lot of stack space.
 Thanks for your help!

On Wed, May 29, 2013 at 9:44 AM, rahul sharma rahul23111...@gmail.comwrote:


 @don u r searching in a previously built trie with the given filter...then
 wat is this add fxn doing?correct me if m getting u wrng

 On Wednesday, May 29, 2013, avinesh saini avinesh.sa...@gmail.com wrote:
  Thank you Don, I was also trying in similar way. But here I'm confused
 how you are storing the traversed words. Are you adding whole words at the
 node on which word is ending during insertion.
 
 
  On Wed, May 29, 2013 at 12:36 AM, Don dondod...@gmail.com wrote:
 
  void findWords(trie *root, char *filter)
  {
  if (!root) return;
 
  if (*filter == 0)  // When you reach the end of the filter at the
  end of a valid word, add the word.
  {
  if (root-words) words.add(root-word);
  }
  else if (*filter == '.')   // Search for words with any letter
  {
  for(int i = 'a'; i = 'z' ; ++i)
  findWords(root-link[i], filter+1);
  }
  else  // Search for words with the required letter
  {
   findWords(root-link[*filter], filter+1);
  }
  }
 
  On May 28, 4:47 am, avinesh saini avinesh.sa...@gmail.com wrote:
   How to search all the matching words for a filter in a trie.
   e.g.
   searching by filter  ...r..m will find all the words(of length = 7)
 in
   trie in which 4th character is 'r' and 7th character is 'm'.
  
   --
   *
   *
   *thanks  regards,*
   *Avinesh
   *
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To unsubscribe from this group and stop receiving emails from it, send
 an email to algogeeks+unsubscr...@googlegroups.com.
 
 
 
 
 
  --
 
  thanks  regards,
  Avinesh
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To unsubscribe from this group and stop receiving emails from it, send
 an email to algogeeks+unsubscr...@googlegroups.com.
 
 
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.






-- 
*
*
*regards,*
*Avinesh Kumar
National Institute of Technology, Calicut.*
*Kerala- 673601*
*+91 7849080702*
*http://www.facebook.com/avinesh.saini*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] searching all matching words in a Trie with a given filter.

2013-05-28 Thread avinesh saini
How to search all the matching words for a filter in a trie.
e.g.
searching by filter  ...r..m will find all the words(of length = 7) in
trie in which 4th character is 'r' and 7th character is 'm'.


-- 
*
*
*thanks  regards,*
*Avinesh
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Re: searching all matching words in a Trie with a given filter.

2013-05-28 Thread avinesh saini
Thank you Don, I was also trying in similar way. But here I'm confused how
you are storing the traversed words. Are you adding whole words at the node
on which word is ending during insertion.


On Wed, May 29, 2013 at 12:36 AM, Don dondod...@gmail.com wrote:

 void findWords(trie *root, char *filter)
 {
 if (!root) return;

 if (*filter == 0)  // When you reach the end of the filter at the
 end of a valid word, add the word.
 {
 if (root-words) words.add(root-word);
 }
 else if (*filter == '.')   // Search for words with any letter
 {
 for(int i = 'a'; i = 'z' ; ++i)
 findWords(root-link[i], filter+1);
 }
 else  // Search for words with the required letter
 {
  findWords(root-link[*filter], filter+1);
 }
 }

 On May 28, 4:47 am, avinesh saini avinesh.sa...@gmail.com wrote:
  How to search all the matching words for a filter in a trie.
  e.g.
  searching by filter  ...r..m will find all the words(of length = 7) in
  trie in which 4th character is 'r' and 7th character is 'm'.
 
  --
  *
  *
  *thanks  regards,*
  *Avinesh
  *

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.





-- 
*
*
*thanks  regards,*
*Avinesh
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] least common ancestore bst

2013-05-16 Thread avinesh saini
If one node is parent of other then Parent Node is lowest common ancestor.
Source- http://en.wikipedia.org/wiki/Lowest_common_ancestor (just read it)

On Mon, May 13, 2013 at 1:42 AM, rahul sharma rahul23111...@gmail.comwrote:

 [image: BST_LCA]
 what should be ancestor of 12 and 14.it should be 12 or
 14...if 12 then for 20 and 22 also it is 20...if 12 ans 14 has
 ancestor as 8 then for 20 and 22 it is NULL.

 @allplz give me clear one line definition in case if one node is
 parent of other then what is LCA


 On Sun, Apr 21, 2013 at 10:32 PM, Tushar Patil tushar01pa...@gmail.comwrote:

 @rahul : It's fine solution, but can we check  the root-data == n1 || n2
 before calling function recursively, I think if we check this condition 1st
 it will reduce unnecessary function calls.
Correct me if i am wrong?
 Thanks,
 Tushar Patil.



 On Sun, Apr 21, 2013 at 10:26 PM, rahul sharma 
 rahul23111...@gmail.comwrote:

 int leastCommanAncestor(struct node* root, int n1, int n2)
 {
  if(root==NULL)
  return -1;
  if(root-datan1  root-datan2)
  return leastCommanAncestor(root-left,n1,n2);
  else if(root-datan1  root-datan2)
  return leastCommanAncestor(root-right,n1,n2);
  return root-data;

 }

 Does this code miss any case?N suppose if we have to find LCA of n1 and
 n2 and suppose n1 is parent of n2 ..then this will return n1..is this fyn
 or if n1 is parent of n2 then we should return -1??

 Plz. comment

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to algogeeks+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.






-- 
*
*
*regards,*
*Avinesh Kumar
National Institute of Technology, Calicut.*
*Kerala- 673601*
*+91 7849080702*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] No of nodes in B-Tree

2011-11-25 Thread avinesh saini
 *Suppose that we insert the keys  (**1,2,...,n)  **into an empty
B-tree with minimum **degree **2.  How many nodes does the final B-tree
have?*
explain your answer.!

-- 
*Avinesh Kumar,
*

-- 
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] Hello World

2011-09-26 Thread avinesh saini
Explain this code-
It is supposed to print-  Hello World


#include iostream
using namespace std;
int main()
{
long long int
l1l[]={72,-11037827,917043223,-47519989,1450408591,-194718605,2037206149,-8912843,279667,-26713,-3617,1571,-79};

longlongintll1[]={1,9240,277200,13440,725760,290304,14515200,483840,193536,483840,14515200,15966720,31933440};
long double lll=1;
long long int l1='\0'+1, ll='\0'+1;
for (int i='\0'; i'\r'; i=i+1)
{
for (int j='\r'-1; j='\0'; j=j-1)
{
for (int k='\0'; kj; k=k+1)
{
ll=l1=l1*(!!i);
for (int l='\0'; li-1; l=l+1)
{
l1=l1+ll;
}
}
lll+=(long double)l1/(*(ll1+j))*(*(l1l+j));
l1='\0'+1;
}
std::cout(char)(lll+0.5);
lll=!lll;
}
std::coutstd::endl;
return 0;
}

-- 
*Avinesh Kumar,
MCA
NIT Calicut.
*

-- 
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] Reverse the string word by word . Can someone tell what is wrong in my code ?

2011-09-25 Thread avinesh saini
Try this one...

#includestdio.h
#includestring.h
void reverse(char *p,char*q)
{
char c;
while(pq)
 {
c=*p;*p=*q;*q=c;
p++;
q--;

 }
}

int main()
{
char A[50];
printf(\n Enter a String:\n\n);
gets(A);
int len=strlen(A);
reverse(A,A[len-1]);
printf(%s\n,A);
return 0;
}

On Sun, Sep 25, 2011 at 10:51 AM, Dheeraj Sharma 
dheerajsharma1...@gmail.com wrote:

 u shud do TWO things in..your reverseword function..
 first is str[i]=='\0' and not str[i]='\0'
 second is while(i=len) and not while(ilen)


 On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan deok...@gmail.com wrote:

 //Reverse String word by word
 // if string is :- I am a good boy
 //output string should be :- boy good a am I
 #includestdio.h
 #includestring.h
 void reverse(char *p,char*q)
 {
 int i;char c;
 while(pq)
 {
 c=*p;*p=*q;*q=c;
 p++;
 q--;
 }
 }

 void reverseWordByWord(char str[],int len)
 {
 int i=0,j=0;

  while(ilen)
  {

 if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0'))
 {
 reverse(str[j],str[i-1]);
 j=i+1;
 }
 i++;
  }
 }

 int main()
 {
 char A[]=Ram is a good person;
 int i;
 int len=strlen(A);
 reverse(A[0],A[len-1]);
 printf(%s\n,A);
 reverseWordByWord(A,len);
 printf(%s\n,A);
 return 0;
 }


 --
 **With Regards
 Deoki Nandan Vishwakarma

 *
 *

  --
 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.




 --
 *Dheeraj Sharma*
 Comp Engg.
 NIT Kurukshetra



  --
 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.




-- 
*Avinesh Kumar,
MCA
NIT Calicut.
*

-- 
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.