+ 1
Challenge: Program to find rank of a word in dictionary order?
4 RĂ©ponses
+ 9
I don't quite understand the question. Can you give an example?
+ 1
Now to find the rank of any given word in dictionary (Without Repeating Alphabets) â
Example â âMOTHERâÂ
1) Arrange all the alphabets in alphabetical order like (E, H, M, O, R, T)
2) Now in dictionary words will appear in alphabetical order, so first words will appear starting alphabet âEâ. When E is fixed at first position, rest 5 alphabets can be arranged in 5! = 120 ways.
3) Next starting alphabet will be âHâ and again there will be 5! = 120 words starting with âHâ.
4) Now starting with âMâ, and next alphabet as âEâ we will have 4!=24 words.
5) Similarly starting with âMâ, and next alphabet as âHâ we will have 4!=24 words.
6) Next will be starting with âMâ, and next alphabet as âOâ and next as âEâ weâll have 3!=6 words.
7) Similarly starting with âMâ, and next alphabet as âOâ and next as (âHâ orâRâ) weâll have 3!*2=12 words.
8) Next will be starting with âMâ, and next alphabet as âOâ and next as âTâ and next as âEâ weâll have 2!=4 words.
9) Next will be starting with âMâ, and next alphabet as âOâ and next as âTâ and next as âHâ will have 2! = 4 words but the first word will be M>O>T>H>E>R which is the desired word.
So the rank of word MOTHER in dictionary will be 5! + 5! + 4! +4! + 3! + 3! + 3! + 2! +1 which equals 309.