Hello I want to ask something to make my case stronger, Can anyone please help m
ID: 3845925 • Letter: H
Question
Hello
I want to ask something to make my case stronger, Can anyone please help me in it to find the difference as I posted this question
on chegg and got this result
1. The Shell sort is a variation of the bubble sort. Instead of comparing adjacent
values, the Shell sort adapts a concept from the binary search to determine a
‘gap’ across which values are compared before any swap takes place. In the
first pass, the gap is half the size of the array. For each subsequent pass, the
gap size is cut in half. For the final pass(es), the gap size is 1, so it would be
the same as a bubble sort. The passes continue until no swaps occur.
Below is the same set of values as per the bubble sort example in Chapter 18
(p.681), showing the first pass:
9 6 8 12 3 1 7 size of array is 7, so gap would be 3
9 6 8 12 3 1 7 9 and 12 are already in order, so no
swap
^---------^
9 6 8 12 3 1 7 6 and 3 are not in order, so swap
^---------^
9 3 8 12 6 1 7 8 and 1 are not in order, so swap
^---------^
9 3 1 12 6 8 7 12 and 7 are not in order, so swap
^---------^
9 3 8 7 6 1 12 end of pass 1
A5-2 Module 6 – Assignment 5: Chapter 18…
TRU Open Learning
The pseudocode for the Shell sort is as follows:
gap = size / 2
do until gap <= 0
swapflag = true
do until swapflag is false
swapflag = false
for s = 0 to size – gap
if num[s] > num[s + gap]
swap num[s] with num[s + gap]
swapflag = true
endif
endfor
enddo
gap = gap / 2
enddo
Create a class called ShellArray. It should create and populate an array of
random integers based on a size supplied to the constructor. Implement the
Shell sort as a method of this class. Create a driver class to instantiate and sort
several different arrays of different sizes.
The answer given by chegg study is
// Include the required packages
import java.io.*;
import java.util.*;
// Class to perform the shell sorting
class ShellArray
{
int ary_values[] = null;
int n = 0;
Random rnd = new Random();
// Constructor
ShellArray(int n1)
{
n=n1;
random();
}
// Method to generate a random values between 0 to 100
void random()
{
ary_values = new int[n];
for(int it=0; it<n; it++)
{
this.ary_values[it] = rnd.nextInt(100);
}
}
// Method to perform the shell sorting
void shellsrt()
{
System.out.println(" Before Sorting :");
for(int it=0; it<n; it++)
{
System.out.print(ary_values[it] + " ");
}
// Required variables declaration
int inr, out, tmp;
int hh = 1;
// Loop code for shell sort
while (hh > 0)
{
for (out = hh; out < n; out++)
{
tmp = ary_values[out];
inr = out;
while (inr > hh - 1 && ary_values[inr - hh] >= tmp)
{
ary_values[inr] = ary_values[inr - hh];
inr -= hh;
}
ary_values[inr] = tmp;
}
hh = (hh - 1) / 3;
}
// Code to print the sorted values
System.out.println(" After Sorting");
for(int it=0; it<n; it++)
{
System.out.print(" " + ary_values[it]);
}
}
}
// Driver class to test the class ShellArray
import java.util.*;
public class DriverClass
{
// Main method
public static void main(String args[])
{
// Declare the required variables
int val,ary;
Scanner scan = new Scanner(System.in);
// Get the value to generate number of array
System.out.println("Enter the number of array to perform the shell sort:");
ary=Integer.parseInt(scan.nextLine());
for(int k=0;k<ary;k++)
{
// Get the size of the array
System.out.println("Enter the size of array"+(k+1)+":");
val=Integer.parseInt(scan.nextLine());
// Create object for the class
ShellArray obj = new ShellArray(val);
// Perform the shell sort by invoking the method
obj.shellsrt();
}
}
}
but my professor said it is matched with this link http://www.javacodex.com/Sorting/Shell-Sort , Can you please help me so that I do not get any academic integrity case. As everyone knows that java code can e found anywhere so it is common. But can you please tell me a brief description of it as professor gave me this comment The code you submitted does not follow the supplied pseudocode. The unusual gap calculation
hh = (hh - 1) / 3;
caused me to do a quick search and I found almost identical code to what you submitted at http://www.javacodex.com/Sorting/Shell-Sort
I really want to know how come it is matched with the link.
Can you please tell me how I can explain that this is not plagrized as it is completing the reqirements.
Explanation / Answer
import java.util.Arrays;
/**
*
* @author Sam
*/
public class ShellArray {
public static void shellSort(int[] num) {
int gap = num.length / 2;
while (gap > 0) {
boolean swapFlag = true;
while (swapFlag) {
swapFlag = false;
for (int s = 0; s < num.length - gap; s++) {
if (num[s] > num[s + gap]) {
int tmp = num[s];
num[s] = num[s + gap];
num[s + gap] = tmp;
swapFlag = true;
}
}
}
gap /= 2;
}
}
public static void main(String[] args) { //test driver
int[] exampleArr = {5,8,6,1,3,7,9,2,};
System.out.println(Arrays.toString(exampleArr));
shellSort(exampleArr);
System.out.println(Arrays.toString(exampleArr));
}
}
Well Champ, here you go. The code has been handcrafted only for you any you shall not face any plagerism issue. If you have any doubt, please feel free to comment below. I shall be glad to help you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.