Question

Perform the following traces and submit your answer. Write the letters in your name as a...

Perform the following traces and submit your answer.

  • Write the letters in your name as a sequence without spaces (first name, middle name, last name). In my case the sequence is: CARLOSSILVA.submit a trace of how the 2 merge sorts algorithms will sort the letter in alphabetic order. In my example the sort result will be: AACILLORSSV . Be sure, that each step of the algorithm is clearly presented in the result table.
  • a tracing for Down Merge Sort
  • a tracing for Bottom Up Merge Sorts
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//java program

import java.util.Scanner;

public class Sortname {
public static void main(String args[]) {
   Scanner in = new Scanner(System.in);
  
   String input ;
   System.out.println("Enter name : ");
   input = in.nextLine();
   char[] name1 = input.toCharArray();
   char[] name2 = input.toCharArray();
   char[] name3 = input.toCharArray();
     
   selectionsort(name1 , name1.length);
   insertionsort(name2 , name2.length);
   shellsort(name3 , name3.length);
     
   System.out.println(name1);
   System.out.println(name2);
   System.out.println(name3);
  
   in.close();
}
public static void selectionsort(char a[],int n){int min;
   for(int i=0;i<n-1;i++){
       min=i;
       for(int j=i+1;j<n;j++)if(a[j]<a[min])min=j;
       if(min!=i){
           char temp=a[i];
           a[i]=a[min];
           a[min]=temp;
       }
   }
}

public static void insertionsort(char a[],int n){
   for(int i=1;i<n;i++){
       int j=i-1;
       char val=a[i];
       while(j>=0&&a[j]>val){
       a[j+1]=a[j];
       j--;}
       a[++j]=val;
   }
}

public static void shellsort(char arr[], int n)
{
for (int gap = n/2; gap > 0; gap /= 2)
{
for (int i = gap; i < n; i += 1)
{
char temp = arr[i];
  
int j;   
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
arr[j] = arr[j - gap];

arr[j] = temp;
}
}
  
}
}

//sample output

Add a comment
Know the answer?
Add Answer to:
Perform the following traces and submit your answer. Write the letters in your name as a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program to do the following with your name. This can all be done...

    Write a Java program to do the following with your name. This can all be done in the main() method. 1. Create a String variable called myName and assign your personal name to it. Use proper capitalization for a legal name. I.e. String myName = "Billy Bob"; 2. Load myName with the upper case version of itself and display the result. 3. Load myName with the lower case version of itself and display the result. 4. Capitalize the first letter...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

  • C++. Need some help getting started. We will also have the following two functions: 1. A...

    C++. Need some help getting started. We will also have the following two functions: 1. A mutate function that randomly modifies a chromosome. 2. A crossover function that takes two chromosomes and splits each one at the same spot, then combines them together. Our genetic algorithm works by iterating over generations of chromosomes via the following process: 1. Generate random population. 2. Until we get an answer that is good enough, do the next steps in a loop: (a) Do...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...

    Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while loop  Writing a for loop  Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT