(In Java) Do Shellsort twice, first using the suboptimal sequence for h which starts at half the length of the array and is halved for each pass. Then use Knuth’s interval sequence 1, 4, 13, 40 … for values of h.
For each sort, print the results in a table for:
a. How much time it took.
b. How many comparisons it made between two values.
am providing only sorting of elements code
public class ShellSort
{
private long[] item;
private int length;
public ShellSort(int max)
{
item = new long[max];
length = 0;
}
public void insert(long value)
{ item[length] = value;
length++;
}
public void display() {
System.out.print("Item:");
for (int j = 0; j < length; j++)
System.out.print(item[j] + " ");
System.out.println("");
}
public void shellSort() {
int inner, outer;
long temp;
int h = 1;
while (h <= length / 3)
h = h * 3 + 1;
while (h > 0)
{
for (outer = h; outer < length; outer++) {
temp = data[outer];
inner = outer;
while (inner > h - 1 && item[inner - h] >= temp)
{
item[inner] = item[inner - h];
inner -= h;
}
item[inner] = temp;
}
h = (h - 1) / 3;
}
}
public static void main(String[] args)
{
int maxSize = 10;
ShellSort arr = new ShellSort(maxSize);
for (int j = 0; j < maxSize; j++) {
long n = (int) (java.lang.Math.random() * 99);
arr.insert(n);
}
arr.display();
arr.shellSort();
arr.display();
}
}
(In Java) Do Shellsort twice, first using the suboptimal sequence for h which starts at half...
Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...
Someone help me with the following questions using java
Canvas x New Tab Help Center Submitted Dec 3 at T0:06pm This attempt took 3 minutes. Question 1 0/0.5 Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorit Index 0 Value 12 18 4, 9, 12.2.6,8.18 9, 4, 12, 2,6,18,8 2,4,9,12, 6, 8. 18 2. 4, 6, 8, 9,12,18 2. 4, 12,9.6,8,18 0/0.5 pts Question 2 the array after...
Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant of bubble sort. The rather severe constraints imposed by the singly-linked list organization presents special problems for implementing Shellsort. Your task is to overcome these constraints and develop a simple, elegant implementation that does not sacrifice efficiency or waste space. Step 1. First, implement a routine to build a list: read integers from standard input, and build a list node for each item consisting...
PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your solution. Readability of the program will be graded based on variable naming, indentation, commenting (not too little and not too much), spacing, consistency, and styling in general including choice of functions. [NOTE: the code at the end of this document does not completely meet requirements as it uses many single letter variables and has no internal documentation. You need to improve it.] 2. Compile...
-------------------------------------------------------------------- 1. How does Java support the concept of encapsulation? -------------------------------------------------------------------- 2. Describe the difference between an object and a class. -------------------------------------------------------------------- 3. What is the difference between the contents of a Java variable of a primitive type and a Java variable of a class type? -------------------------------------------------------------------- 4. (a) How is a 'static' class method different from a regular (non-static) class method? (b) How is a 'static' variable in a class different from a regular (instance) variable in a class?...
Molecular Bio lab. HELP!!
Here is the first part: the sequence traces and the entire
sequence. i just need the last 3 tasks. i color coded the ends so
you can see where it overlaps and connects
In the files section for your group there is a simulated output from an automated DNA sequencer using a variation of the classic Sanger method. (If you want to print it, it is formatted for legal sized paper.) This sequence encodes a protein...
JAVA Lab -Lottery Calculator IMPORTANT: This lab is best implemented using a loop structure. If you implement this without a loop, you would need to run your program once for each test item. Create a java program that will test for winning numbers on a lottery game. Each lottery ticket will have 5 integer numbers. Valid numbers must be integer numbers between 1 and 55 Assume that the winning Lottery ticket is 1 9 15 33 40 Your program is...
ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the...
Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...
Part 1 The function 'vbrf' (for very bad recursive function) is defined as follows: vbrf(0) = 2 vbrf(1) = 3 vbrf(2) = 4 vbrf(3) = 5 vbrf(n) = vbrf(n-1) - vbrf(n-2) + 3*vbrf(n-3) - 2*vbrf(n-4) if n > 3 Your job for this problem is to implement the function vbrf as a method in Java. Then write a program that uses this method to compute the function for various values of the argument and time how long it takes to...