Computer Science, asked by tanmayeesawant, 11 months ago

Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the next permutation in lexicographic (dictionary) order? Write your answer without any blank spaces between letters.
eibjdhgfca

Answers

Answered by amitnrw
10

Answer:

eibjfacdgh

Explanation:

lexicographic order is increasing numerical order (or equivalently)

Given sequence is

eibjdhgfca

Next permutation in lexicographic (dictionary) order will be

eibjfacdgh

Rule is to find Largest in given sequence

j is the largest

then we can say we need to find next to  dhgfca after eibj

a is smallest in unit/last place

so a must be replaced by largest number digit

h is largest so   it must be placed at unit/last place

and d must be replaced by next digit / letter which is f

and all other letters digit should be in alphabetical order

f .........h        hence facdgh

eibjfacdgh

Hence the next permutation in lexicographic (dictionary) order

to the eibjfacdgh

Answered by poojan
1

The next word is eibjfacdgh

Finding the next word to the given one, in alphabetical order using a python program.

Language used : Python Programming

Program :

from itertools import permutations

st=['a','b','c','d','e','f','g','h','i','j']

y=tuple('eibjdhgfca')  

#you can take any word into 'y' using input function, dynamically to find the next word.

st=permutations(list(st))

st=sorted(st)

ind=st.index(y)

print(''.join(st[ind+1]))

Output :

eibjfacdgh

Explanation :

  • Assign the letters needed to form the words with, as a list, into a variable.

  • Take a word whose next word we need to find in dictionary order, as directly (statically) into another variable. You can take it as dynamically too from the user, using str(input()) fuction.

  • Using permutations function, list all the permutations of the givenn list of letters and store the permutations list into a variable.

  • Sort the permutations list using sorted() that sorts the values into dictionary order.

  • Now find the index of the word taken whose next value we need to find.

  • Then access that word's index+1 th value from the list which will be the word we are looking for. That's it!

Learn more :

  • Printing all the palindromes formed by a palindrome word.

        https://brainly.in/question/19151384

  • Indentation is must in python. Know more about it at :

       brainly.in/question/17731168

Attachments:
Similar questions