Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the following pseudocode the only basic step is to print one . Show that the RT of this code is O ( n ^

In the following pseudocode the only basic step is to print one . Show that the RT of this code is O(n^2). for i =0 to n-1: j :=0 while j < i: print one * j := j +1
Question 2.
In an array A of n different numbers two numbers A[i] and A[j] form an inversion if i < j, but A[i]> A[j], i.e. the bigger comes before the smaller. (For example 15 and 3 form an inversion in 8,15,1,10,3 since the 15 comes before 3).(a) How many inversions are there in 2,5,1,10,3?(b) Design a brute-force algo for counting the inversions, the running time should be O(n2), if the array contains n different numbers. (c) Design a divide-and-conquer algo for counting the inversions, here the running time should be O(nlogn) if the size of the array is n.for the last part we can notice inversions while performing mergesort.) you can suppose that the size of the array is a power of 2.

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions