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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started