subject

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. Write a function inversions() 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: def inversions(s):
count = 0
for i in range(len(s)): # for each index i
for j in range(len(s)): # for each index J
if s[j]>=s[i]: # compare string[i] and string[j]
count += 0
else:
count +=1
return count

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:00
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
question
Computers and Technology, 22.06.2019 14:10
Dean wants a quick way to look up staff members by their staff id. in cell q3, nest the existing vlookup function in an iferror function. if the vlookup function returns an error result, the text “invalid staff id” should be displayed by the formula. (hint: you can test that this formula is working by changing the value in cell q2 to 0, but remember to set the value of cell q2 back to 1036 when the testing is complete.)
Answers: 3
question
Computers and Technology, 23.06.2019 00:00
Suppose you have 9 coins and one of them is heavier than others. other 8 coins weight equally. you are also given a balance. develop and algorithm to determine the heavy coin using only two measurements with the of the balance. clearly write your algorithm in the form of a pseudocode using the similar notation that we have used in the class to represent sorting algorithms
Answers: 1
question
Computers and Technology, 23.06.2019 00:40
Consider the following statements: struct nametype{string first; string last; }; struct coursetype{string name; int callnum; int credits; char grade; }; struct studenttype{nametype name; double gpa; coursetype course; }; studenttype student; studenttype classlist[100]; coursetype course; nametype name; mark the following statements as valid or invalid. if a statement is invalid, explain why.a.) student.course.callnum = "csc230"; b.) cin > > student.name; c.) classlist[0] = name; d.) classlist[1].gpa = 3.45; e.) name = classlist[15].name; f.) student.name = name; g.) cout < < classlist[10] < < endl; h.) for (int j = 0; j < 100; j++)classlist[j].name = name; i.) classlist.course.credits = 3; j.) course = studenttype.course;
Answers: 1
You know the right answer?
An inversion in a sequence is a pair of entries that are out of order. For example, the characters F...
Questions
question
Business, 30.09.2019 19:10
Questions on the website: 13722367