Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve this code in python Task 03 [10 Points ]: Somewhere in the universe, the Biannual Regional Alien Competition is taking place. There are N

image text in transcribed

image text in transcribed

solve this code in python

Task 03 [10 Points ]: Somewhere in the universe, the Biannual Regional Alien Competition is taking place. There are N aliens standing in a line. You will be given a permutation of N, which denotes the height of each alien. A sequence of N numbers is called permutation if it contains all integers from 1 to N exactly once. For example, the sequences [3,1,4,2],[1] and [2,1] are permutations, but [1,2,1],[0,1] and [1,3,4] - are not. In the competition, for each alien, the judge wants to count how many aliens are standing on its right side with a strictly smaller height. The judge writes the following code to solve the problem. count =0 for i in range (n): for j in range (i+1,n): if H[i]>H[j]: count+=1 However, their algorithm wasn't efficient at all. Hence, the alien calls you to write a better solution for the program. More formally, you have to count how many pairs of aliens are standing in the line such that H[i]>H[j] and i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions