Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
can anyone give me a code to generate random names using breadth first search algorithm..

i was getting problem during implementation in BFS and one more thing i need a code in C# language.

See this example you can understand what i actually need to do.

A genetics professor Wants to name her new baby boy
Using only the letters D,N & A Search through possible strings (states)
D,DN,DNNA,NA,AND,DNAN, etc.
3 operators: add D, N or A onto end of string
Initial state is an empty string
Goal test Look up state in a book of boys’ names, e.g. DAN



here is the image showing random name is generating using breadth first search.
http://i42.tinypic.com/v9czk.png
Posted
Updated 22-Apr-12 11:26am
v2
Comments
Sergey Alexandrovich Kryukov 22-Apr-12 15:03pm    
Why do you think BFS can do anything with generation of anything random? :-)
--SA
[no name] 22-Apr-12 17:26pm    
Smells of.... homework
[no name] 22-Apr-12 17:27pm    
Removed "solution" that was really an example.

1 solution

If you need some code, you're supposed to create it. If you have a particular problem, please show some code sample and point out what exactly is your concern — we will gladly help you.

Now, I don't see how generation of random values can be related to search algorithm. These two things are completely different. Generation of any random values (names or not) can be done using the class System.Random, please see:
http://msdn.microsoft.com/en-us/library/system.random.aspx[^].

BFS (unrelated to random number generation) is fully explained here:
http://en.wikipedia.org/wiki/Breadth-first_search[^].

Good luck,
—SA
 
Share this answer
 
Comments
sohail charolia 22-Apr-12 17:23pm    
your assumption is write right, but see the example in solution 2
Sergey Alexandrovich Kryukov 23-Apr-12 23:27pm    
I got it. Well, then forget random generation, because it won't give him all the combinations. The process is very simple: add letter one by one to an empty string looping through 'D', 'N', 'A', performing dictionary lookup on every step: (D, N, A), ((DD, DN, DA), (ND, NN, NA), (AD, AN, AA)), etc.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900