Question

An array contains the following characters in the sequence below: K N M O B Write...

An array contains the following characters in the sequence below:

K N M O B

Write down the characters for each round according to the specified sorting algorithms which sorts the character array into its ascending order.

First round always begins at the first location of the array.

• Bubble Sort

Round 1:      
Round 2:
Round 3:
Round 4:
Round 5:

• Selection Sort

Round 1:      
Round 2:
Round 3:
Round 4:
Round 5:

• Insertion Sort

Round 1:      
Round 2:
Round 3:
Round 4:
Round 5:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for asking!

1.Bubble Sort

Original Array: K N M O B

Adjacent elements will be swapped , starting from 1st to last element (say n i.e. size of array).

Round 1: K M N B O

Again adjacent elements will be swapped but only till n-1 element because last element is in its perfect place.

Round 2: K M B N O

Now, from first to (n-2)th element.

Round 3: K B M N O

Round 4: B K M N O

Round 5: B K M N O

2. Selection Sort

This sorting algorithm finds the smallest element and replace it with the first, then again finds the smallest element in the arrat except the first element, and replaces it with second element and so on.

Original Array: K N M O B

B is the smallest element, replaced by first element.

Round 1: B N M O K

Now from N to K, smallest element is K

Round 2: B K M O N

Now from M to N, smallest element is M. Already in its correct place

Round 3: B K M O N

Now from O to N, smallest element is N.

Round 4: B K M N O

Round 5: B K M N O

3. Insertion Sort

In this algorithm, each element (starting from 2nd element to last element) is compared to the elements present before it, and keep swapping if the previous element is larger than present element .

Original Array: K N M O B

Starting from N, comparing it with K. As K is less than N, No Swapping takes place

Round 1: K N M O B

Now, comparing M with N and K, it is swapped with N as it is less than M.

Round 2: K M N O B

Now, comparing O with its previous elements, it is already larger than all its previous.

Round 3: K M N O B

Now, comparing B with its previous elements, as it is smaller than O, N , M , K, it is swapped with all of them one by one.

Round 4: B K M N O

Sorted!

Round 5: B K M N O

I hope you like it!

Add a comment
Know the answer?
Add Answer to:
An array contains the following characters in the sequence below: K N M O B Write...
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
  • An array contains the following characters in the sequence below: V Z D H A Write...

    An array contains the following characters in the sequence below: V Z D H A Write down the characters for each round according to the specified sorting algorithms which sorts the character array into its ascending order. First round always begins at the first location of the array. Bubble Sort Round 1: Round 2: Round 3: Round 4: Round 5: Selection Sort Round 1: Round 2: Round 3: Round 4: Round 5: Insertion Sort Round 1: Round 2: Round 3:...

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

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

  • ?PLEASE READ CAREFULLY QUESTION #1 I’m doing a project which requires you to implement 4 sorting...

    ?PLEASE READ CAREFULLY QUESTION #1 I’m doing a project which requires you to implement 4 sorting algorithms. Bubble sort pair-wise, Bubble sort list-wise a.k.a selection sort, merge sort, and quick sort. These 4 sorting methods takes in an array of strings and sorts them alphabetically from a-z. I have all 4 sorting algorithms working fine, but I still need to fill out the table. There’s only one section I need help filling out. I basically need help filling out the...

  • does anyone know how to do this? C++ Your task for this assignment is to use...

    does anyone know how to do this? C++ Your task for this assignment is to use C++ language to implement an insertion sort algorithm. 1. Implement an insertion sort with an array to sort 10 arbitrary numbers using the C++ programming language. The program initializes an array with 10 random 3-digit positive integers. The program then sorts the numbers in the array using the insertion sort algorithm. 2. The program displays the original values in the array before the sort...

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

  • Suppose an array contains the sequence of values 8, 6, 10, 5, and 4. If the...

    Suppose an array contains the sequence of values 8, 6, 10, 5, and 4. If the selection sort algorithm is used to sort the values, what is the first pair of values to be swapped? Select one: a. 8 and 5 b. 10 and 5 c. 8 and 10 d. 8 and 4

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

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

  • The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements...

    The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

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