Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. An inversion in a sequence is a pair of entries that are out of order. For example, the characters F and D form an
4. An inversion in a sequence is a pair of entries that are out of order. For example, the characters F and D form an inversion in the string 'ABBFHDL'. The characters H and D are also an inversion in the string 'ABBFHDL'. The total number of inversions in a sequence, i.e. the number of pairs that are out of order, is a measure of how unsorted the sequence is. Using nested for loops, write a function inversions0 that takes as a parameter a sequence of uppercase characters (i.e. a string with only uppercase letters) and returns the number of inversions in the sequence. The following shows the function on several sample parameters:* >>> inversions('ABBFHDL') vesons(ABCD') 0+ >inversions('CDBA')*- >inversions(DCBA')*- 6+0 >>> inversions(")- 0+
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started