Design algorithm and program to work on the following data lists. Use at least 2 data structures/algorithms learnt in this course to get the following two outputs:
Output 1: Sort each data list.
Output 2: Pick the largest 3 numbers of each list to form a new list, and then sort the new list.
Data 1: 1, 5, 33, 57, 99, 26, 992
Data 2: 0, 33, 2234, 2, 902, 1, 5
Data 3: 5, 2, 22, 7, 99, 5, 17,92
Data 4: 100, 99876, 0, 899, 54, 88
(source code in java please with output ASAP)
Code Screenshots:

![dataSet[j] = dataSet [j+1]; dataSet[j+1] = temp; } } // Define the main() method. public static void main(String[] args) { //](http://img.homeworklib.com/questions/2e0e83a0-0097-11eb-8164-595e39537a66.png?x-oss-process=image/resize,w_560)

Sample Output:

Code to Copy:
Main.java:
// Import the
// required packages.
import java.util.*;
// Define the
// Main class.
class Main
{
// Define the method sortByInsertion().
public static void sortByInsertion(int dataSet[])
{
// Declare a variable to
// store the current value.
int currVal;
// Run the loop to
// perform the insertion sort.
for (int i = 1; i < dataSet.length; i++)
{
// Set the value at the index
// i as the current value.
currVal = dataSet[i];
// Set the value of j as i-1
// to check all the indices
// before i.
int j = i - 1;
// Run the loop till the value
// of the variable j is greater
// than 0 and the value at the
// index j is greater than
// the value present at the index i.
while (j >= 0 && dataSet[j] > currVal)
{
// Move the value at index j,
// ahead by one place.
dataSet[j + 1] = dataSet[j];
j = j - 1;
}
// Put the current value
// at the index j+1.
dataSet[j + 1] = currVal;
}
}
// Define the method sortByBubble()
public static void sortByBubble(int dataSet[])
{
// Run the loop to
// perform the bubble sort.
for(int i=0; i< dataSet.length - 1; i++)
{
// Run the loop
// to perform the swaps.
for(int j=0; j < dataSet.length - i - 1; j++)
{
// If the value at jth index
// is greater than the value
// present at the index j+1,
// swap the values.
if(dataSet[j] > dataSet[j+1])
{
int temp = dataSet[j];
dataSet[j] = dataSet[j+1];
dataSet[j+1] = temp;
}
}
}
}
// Define the main() method.
public static void main(String[] args)
{
// Define 4 arrays to store the data lists.
int data1[] = {1, 5, 33, 57, 99, 26, 992};
int data2[] = {0, 33, 2234, 2, 902, 1, 5};
int data3[] = {5, 2, 22, 7, 99, 5, 17,92};
int data4[] = {100, 99876, 0, 899, 54, 88};
// Sort the first two data
// lists using insertion sort.
sortByInsertion(data1);
sortByInsertion(data2);
// Sort the other two data
// sets using bubble sort.
sortByBubble(data3);
sortByBubble(data4);
//
// Display the four data lists
// after performing the sort.
//
System.out.print("Data 1: ");
for(int i=0; i<data1.length; i++)
{
System.out.print(data1[i] + " ");
}
System.out.println();
System.out.print("Data 2: ");
for(int i=0; i<data2.length; i++)
{
System.out.print(data2[i] + " ");
}
System.out.println();
System.out.print("Data 3: ");
for(int i=0; i<data3.length; i++)
{
System.out.print(data3[i] + " ");
}
System.out.println();
System.out.print("Data 4: ");
for(int i=0; i<data4.length; i++)
{
System.out.print(data4[i] + " ");
}
System.out.println();
// Define an array to
// store the new list.
int newDataSet[] = new int[12];
// Run the loop to store the
// last three elements from
// each list into the new list.
// Since the lists are sorted in
// ascending order, the last three
// elements are the greatest three
// elements in each list.
for(int i=0; i<12; i++)
{
if(i<3)
{
newDataSet[i] = data1[data1.length - (i + 1)];
}
else if(i < 6)
{
newDataSet[i] = data2[data2.length - ((i%3) + 1)];
}
else if(i < 9)
{
newDataSet[i] = data3[data3.length - ((i%3) + 1)];
}
else
{
newDataSet[i] = data4[data4.length - ((i%3) + 1)];
}
}
// Display the newly formed list.
System.out.print("New list: ");
for(int i=0; i<newDataSet.length; i++)
{
System.out.print(newDataSet[i] + " ");
}
System.out.println();
// Sort the new list.
sortByInsertion(newDataSet);
// Display the new list
// after performing the sort.
System.out.print("New list after Sorting: ");
for(int i=0; i<newDataSet.length; i++)
{
System.out.print(newDataSet[i] + " ");
}
System.out.println();
}
}
Design algorithm and program to work on the following data lists. Use at least 2 data...
Need help with program. I'm stuck
Objectives: In this assignment, we will
practice manipulating lists of data and arranging items in an
ascending/descending order. you will also explore storing
lists/arrays using different sorting algorithms including, the
selection sort, bubble sort, and insertion sort algorithm.
Comparison between the three algorithms are made based on the
number of comparisons and item assignments (basic operations) each
algorithms executes.
Background: Ordering the elements of a list is
a problem that occurs in many computer...
I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...
For [Select], there are three choices: worse than, the same as,
better than
Answer the following questions about the computational properties of divide-and-conquer sorting algorithms, based on tight big-Oh characterizations of the asymptotic growth rate of the functions for the running time or space size, depending on the question. Assume that the input sequence is given as a list, and the output sequence is also a list. Also assume a general implementation of the sorting algorithms, as opposed to an...
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...
ALGORITHM AND DATA STRUCTURES Question Question 1: Convert the following binary tree into a heap using the Heapify algorithm. Draw the diagrams of the tree step by step after every alteration. Question 2: Show the heap that results when the items are inserted into the heap one by one, starting with one that is empty. 7, 3, 8, 1, 4, 20, 11, 33, 45, 23, 6 Question 3. Draw the 2-3-4 tree that results when values are inserted in the...
Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....
Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...
The
language is python
thr language is python
I Expert Q&A Done The language is python. 10. The following is the algorithm for Merge Sort, one of the best sorting algorithms and one hat is recursive. Wine the merge sort function and draw the stack and heap dagrams for execution on the list |5, 8,9,1,4. 10 Algorithm: Mergesort Ingut an unsorted list b 1. If there is only one iten L. It is sorted, return L 2, Split L Sn...
Can this be solved in MATLAB language?
CSCI 251 Lab 6 File I/O Due Data: Nov 22, 2019 Problem Statement Given a text file with experiment data, implement a program that performs following operations: 1) Reads data from a text file. 2) Extract numerical data. 3) Sorts the data in a descending order (max to min). 4) Save the sorted result to a new text file. Algorithms: 1. Use the input_data.txt file as the input for your program. It can...
Do the following in C#
What different types of sorting algorithms you have learnt? Create a windows application with buttons to display at least 2 sorting methods in a step wise manner a sample prototype is displayed. Selection Sort cannot be used. There is something wrong in the Selection sort code because my output is shown as seen below: 1. 2. 3. File Edit iew Prcject Build DebugTeam Tecls Test RTocis Anslyze v 46 27E 2721 Selecton Sot Help me...