Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER ALL PARTS OF THE QUESTION CORRECTLY, I WILL GIVE U A THUMBS UP IF U ARE ABLE TO SOLVE THANK U 1. Brute

image text in transcribedimage text in transcribed

PLEASE ANSWER ALL PARTS OF THE QUESTION CORRECTLY, I WILL GIVE U A THUMBS UP IF U ARE ABLE TO SOLVE THANK U

1. Brute Force. [15 marks total] Given an integer array A, A[i] and A[j] are inverted if i A[j]. Consider the following array with 10 elements. In it, 1 (A[2] = 4), so 5-4 is an inversion. In this array there are a total of 15 inversions: 4-2, 4-3, 5-2, 5-3,5-4, 8-2, 8-3, 8-6, 8-7, 9-2, 9-3, 9-6, 9-7, 9-8, and 10-7. 0 1 2 3 4 5 6 7 8 9 | 1 5 4 9 8 2 3 6 10 | 7 (a) Write an iterative algorithm in C/C++ to count the number of inversions in an array A of size n. (Your syntax doesn't have to be perfect.) (10 marks] (b) What input results in the most, and in the fewest inversions? Explain briefly. [2 marks] (c) Analyze the worst case run time of your algorithm as a function of n. Show your work. [3 marks] 1. Brute Force. [15 marks total] Given an integer array A, A[i] and A[j] are inverted if i A[j]. Consider the following array with 10 elements. In it, 1 (A[2] = 4), so 5-4 is an inversion. In this array there are a total of 15 inversions: 4-2, 4-3, 5-2, 5-3,5-4, 8-2, 8-3, 8-6, 8-7, 9-2, 9-3, 9-6, 9-7, 9-8, and 10-7. 0 1 2 3 4 5 6 7 8 9 | 1 5 4 9 8 2 3 6 10 | 7 (a) Write an iterative algorithm in C/C++ to count the number of inversions in an array A of size n. (Your syntax doesn't have to be perfect.) (10 marks] (b) What input results in the most, and in the fewest inversions? Explain briefly. [2 marks] (c) Analyze the worst case run time of your algorithm as a function of n. Show your work. [3 marks]

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

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions