+ 1

Challenge: Program to find rank of a word in dictionary order?

19th Dec 2017, 2:48 AM
Benarjee Sambangi
Benarjee Sambangi - avatar
4 RĂ©ponses
+ 9
I don't quite understand the question. Can you give an example?
22nd Dec 2017, 2:08 AM
David Ashton
David Ashton - avatar
+ 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.
22nd Dec 2017, 2:47 AM
Benarjee Sambangi
Benarjee Sambangi - avatar