Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array A which is a permutation of [1,2,3,4,5], we observe the following inversions in A: [(5,4), (5,3), (2,1), (5,1), (3,1), (5,2)]. (i)

Given an array A which is a permutation of [1,2,3,4,5], we observe the following inversions in A: [(5,4),

Given an array A which is a permutation of [1,2,3,4,5], we observe the following inversions in A: [(5,4), (5,3), (2,1), (5,1), (3,1), (5,2)]. (i) Question: is array A unique (yes or no)? (ii) Justify your answer by listing out all possible A's. (b) (5) Given the sequence [23, 5, 33, 2, 17, 15, 29, 12], sort the sequence into ascending order using merge sort. (i) Plot a figure to show the result of each pass. (ii) Question: how many comparisons have you performed? (c) (8) Given an array with n elements to sort, what is the average and worst time complexity when using selection sort, merge sort, heap sort and quick sort in terms of Big-O notation. (d) (8) Now you have an array which consists only a, b and c to be sorted in alphabetical order from left to right. For example, the array can be [a, b, b, a, c, a, c]. Please give an algorithm which only traverses the array once with space complexity O(1) to sort the array in a non- descending order. (i) Use pseudo code or draw figures to show how you handle different cases and implement sorting; (ii) Explain why your algorithm is O(1) space complexity. (Hint: use double pointers) Activate Windows

Step by Step Solution

3.34 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

a Array Permutation i Is array A unique No the array A is not unique The given inversions do not uni... blur-text-image

Get Instant Access with AI-Powered 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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions