Click here to Skip to main content
14,667,494 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100