Question: a) Implement the sorting algorithm (sorting by insertion) in Java. Generate an example list A with 10 elements. Use an array of integer numbers (int

a) Implement the sorting algorithm (sorting by insertion) in Java.

Generate an example list A with 10 elements. Use an array of integer numbers (int [] A = new int [10];) as the data structure.

Note: Write a helper method int to find the insertion point findInsertPoint(int [] arr, int n, ...).

b) Implement a search functionality that returns the position of a given element n from a sorted list if the element exists.

Otherwise, return the position where n would need to be. Use the following principle: 1. If list is empty, return the position of this empty list within the total list, otherwise consider A [m] at the middle position of the list. 2. If n = A [m] ? finished 3. If n A [m] ? search right part list using the same procedure

Note: So it's a recursive implementation needed.

c)Extend the algorithm (part a) so that finding the insertion position for inserting an element A [i] into the sorted part of the list is realized by the binary search designed in (part b).

d)Why is the improvement in part c) only marginal?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!