Question

PROBLEM #11 What are the two algorithms used to sort an array? How do they work?...

PROBLEM #11

        What are the two algorithms used to sort an array? How do they work?
        --------------------------------------------------------------------
        */


        /*
        ---------------------------------------------------------------------------------------------------------------
        PROBLEM #12

        Given the following array 'jumbled', what will the array be after the first swap of a selection sort algorithm?
        (Assume the algorithm sorts in ascending order).
        ---------------------------------------------------------------------------------------------------------------
        */

        int jumbled[] = {12, 5, 3, 1, 9, 100, 45};


        /*
        ---------------------------------------------------------------------------------------------------------------
        PROBLEM #13

        Given the following array 'jumbled2', what will the array be after the third swap of a bubble sort algorithm?
        (Assume the algorithm sorts in ascending order).
        ---------------------------------------------------------------------------------------------------------------
        */

        int jumbled2[] = { 5, 9, 50, 6, 1, 70, 0 };


        return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

11. Sorting Algorithms
The two algorithms used to sort the array are:

  1. Bubble Sort: This is the simplest of the sorting algorithm that can be used in order to sort the elements and it basically uses the principle of bubbles. In this, the value of the array keeps on bubbling towards the right and we keep on pushing the value which is bigger of all to the right and smallest value would be the left.
  2. Merge Sort: This is the algorithm that works on the principle of divide and conquers. In this algorithm, we keep on dividing the problem into smaller sub-problems till the point we divide the array into the size of 1.
    Then we take them up merging all the divided subproblems and combine the smaller subarrays into a sorted array.

12. Selection sort will select the minimum element and will put it in the first position

So the output will be:

Array: {1, 5, 3, 12, 9, 100, 45}

According to Chegg Guidelines, I am obliged to do only one question at a time.
I will be happy to help, you can repost the remaining. I hope you understand.
Thanks

Add a comment
Know the answer?
Add Answer to:
PROBLEM #11 What are the two algorithms used to sort an array? How do they work?...
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
  • 8. (5 points) Trace merge sort algorithm as it sorts the following sequence of integer array into...

    8. (5 points) Trace merge sort algorithm as it sorts the following sequence of integer array into a descending order. 42 45 10 64 55 37 96 7 9. (5 points) Trace shell sort algorithm that halves the gap size at each iteration as it sorts the following sequence of integer array into an ascending order. 42 18 10 64 85 37 96 71 8. (5 points) Trace merge sort algorithm as it sorts the following sequence of integer array...

  •   Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first...

      Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first iteration? Given an insertion sort and the following array: [50,5,35,70,6] What does the array look like after the first insertion:    Fill in the missing code for InsertionSort method // Insertion Sort method //sorts an array of Auto objects public static void insertionSort(Auto [] arr) { Auto temp; int j; for (int i=1; i<arr.length; i++) {     j=i;     temp=arr[i];                while (j!=0 &&(temp.getModel().compareTo(arr[[j-1].getModel())<0)...

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    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....

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • Please come up with an array of 9 random integers then sort the array. Show the...

    Please come up with an array of 9 random integers then sort the array. Show the contents of the array each time a sorting algorithm changes it while sorting the array into ascending order. The 6 sorting algorithm we are using are: 1. Selection Sort 3 points 2. Insertion Sort 3 points 3. Shell Sort 6 points 4. Bubble Sort 3 points 5. Merge Sort 10 points 6. Quick Sort 10 points It is OK to do this assignment on...

  • 1. Which of the following algorithms requires the most extra space when implemented? A. Quicksort B....

    1. Which of the following algorithms requires the most extra space when implemented? A. Quicksort B. Mergesort C. Radix sort D. All use the same amount of extra space 2. Sort this array into ascending order: 80 90 70 85 60 40 50 95. Assume the pivot is 40. (SHOW WORK) A. (40) and (50 60 70 80 85 90 95) B. () and (80 90 70 85 60 50 95) C. () and (50 60 70 80 85 90...

  • This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort...

    This program should test the running time of these algorithms: Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort Heap Sort You have access to the implementation of all of these sorting algorithms, and you may use what is provided in your text directly. Be sure to cite the source of these implementations in the header of your program. Please maintain the property that these sorting algorithms sort arrays in ascending order. For this homework, you will write a...

  • After a single pass of selection sort algorithm (a single swap) what would be the state...

    After a single pass of selection sort algorithm (a single swap) what would be the state of the array? [7 ,6 , 12 , 13 , 6 , 17 , 0 , -2 , 31 , 1] After a single pass of bubble sort algorithm (could be zero/one/many swaps), what would be the state of the array? [7 , 6 , 12 , 13 , 6 , 17 , 0 , -2 , 31 , 1]

  • Write a program that compares the execution speed of two different sorting algorithms: bubble sort and...

    Write a program that compares the execution speed of two different sorting algorithms: bubble sort and selection sort. It should do this via functions you must write with the following prototypes: void setRandomValues(int[], int[], int length); This function sets two integer arrays with identical random values. The first two arguments are two integer arrays of the same length, and the third argument is the length of those arrays. The function then sets each element in the first and second argument...

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