Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.3, Problem 9.3CP
Program Plan Intro
Sorting:
When contents of the array being arranged in the particular order is called as sorting. The order of arranging the contents can be ascending or descending order.
Types of sorting:
- Bubble sort
- Selection sort
- Insertion sort
- Merge sort
- Quick sort
- Shell sort
- Heap sort
These sort have the possibility of sorting the array in both ascending and descending order.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
A sort algorithm that finds the smallest element of the array and interchanges it with the
element in the first position of the array. Then it finds the second smallest element from the
remaining elements in the array and places it in the second position of the array and so on
Sort the array (D, G, J, F, A, C) using selection sort (show the array after each step).
Write a program that reads the numbers and sorts them by using the Counting
Sort algorithm and finally search a number from that array using Linear
Search Algorithm.
Input: 3 6 5 4 789
Search Item: 7
Output: Sorted Array: 3 4 5 6 789
Search item 7 is found.
Chapter 9 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Ch. 9.3 - Which of the sorting algorithms discussed makes...Ch. 9.3 - Prob. 9.2CPCh. 9.3 - Prob. 9.3CPCh. 9.4 - Prob. 9.4CPCh. 9.4 - On average, with an array of 1,000 elements, how...Ch. 9.4 - Prob. 9.6CPCh. 9 - Prob. 1MCCh. 9 - Prob. 2MCCh. 9 - Prob. 3MCCh. 9 - Prob. 4MC
Ch. 9 - Prob. 5MCCh. 9 - Prob. 6MCCh. 9 - Prob. 7MCCh. 9 - Prob. 8MCCh. 9 - Prob. 9MCCh. 9 - Prob. 10MCCh. 9 - Prob. 1TFCh. 9 - Prob. 2TFCh. 9 - Prob. 3TFCh. 9 - Prob. 4TFCh. 9 - Prob. 5TFCh. 9 - Prob. 1AWCh. 9 - Prob. 2AWCh. 9 - Prob. 3AWCh. 9 - What algorithm does the following pseudocode...Ch. 9 - Prob. 1SACh. 9 - Prob. 2SACh. 9 - Prob. 3SACh. 9 - Prob. 4SACh. 9 - Prob. 5SACh. 9 - Why is the selection sort more efficient than the...Ch. 9 - Prob. 7SACh. 9 - Prob. 8SACh. 9 - Assume the following main module is in a program...Ch. 9 - Prob. 1PECh. 9 - Sorted Names Design a program that allows the user...Ch. 9 - Rainfall Program Modification Recall that...Ch. 9 - Name Search Modify the Sorted Names program that...Ch. 9 - Charge Account Validation Recall that Programming...Ch. 9 - Prob. 7PECh. 9 - Sorting Benchmarks Modify the modules presented in...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Mina always wants things to be sorted. She loves perfection in work and doesn't worry about time. Her brother gifted her some boxes with different sizes. Now she needs your help to sort it. You're given n boxes with different sizes and your task is to sort the boxes in ascending order of size. You should recursively partition the array with a number p so that all the elements greater than p are to its right and all the elements lower than p to its left to sort the boxes. Make sure you are giving a solution that doesn't exceed the time complexity of O(n^2), but on average has complexity of O(nlogn) a. Which algorithm will you suggest to Mina? Explain if your algorithm is stable or unstable with appropriate example b. Show the step by step simulation of your algorithm on the boxes of size 5, 9, 10, 3, 15, 12, 6, 20, 9, 13, 3, 10, 1, 2. c. Give an example of box sizes when it will be worst case and when it will be the best case for this algorithm.arrow_forwardDouble Insertion Sort is a variation on Insertion Sort that works from the middle of the array out. At each iteration, some middle portion of the array is sorted. On the next iteration, take the two adjacent elements to the sorted portion of the array. If they are out of order with respect to each other, then swap them. Now, push the left element toward the right in the array so long as it is greater than the element to its right. And push the right element toward the left in the array so long as it is less than the element to its left. The algorithm begins by processing the middle two elements of the array if the array is even. If the array is odd, then skip processing the middle item and begin with processing the elements to its immediate left and right. Implement Double Insertion Sort, being careful to properly handle both when the array is odd and when it is even. By using java, Implement the Double Insertion sort algorithm on a randomly generated list of N integer numbers. Your…arrow_forwardDouble Insertion Sort is a variation on Insertion Sort that works from the middle of the array out. At each iteration, some middle portion of the array is sorted. On the next iteration, take the two adjacent elements to the sorted portion of the array. If they are out of order with respect to each other, then swap them. Now, push the left element toward the right in the array so long as it is greater than the element to its right. And push the right element toward the left in the array so long as it is less than the element to its left. The algorithm begins by processing the middle two elements of the array if the array is even. If the array is odd, then skip processing the middle item and begin with processing the elements to its immediate left and right. Implement Double Insertion Sort, being careful to properly handle both when the array is odd and when it is even. Implement the Double Insertion sort algorithm by using JAVA on a randomly generated list of N integer Your program…arrow_forward
- Double Insertion Sort is a variation on Insertion Sort that works from the middle of the array out. At each iteration, some middle portion of the array is sorted. On the next iteration, take the two adjacent elements to the sorted portion of the array. If they are out of order with respect to each other, then swap them. Now, push the left element toward the right in the array so long as it is greater than the element to its right. And push the right element toward the left in the array so long as it is less than the element to its left. The algorithm begins by processing the middle two elements of the array if the array is even. If the array is odd, then skip processing the middle item and begin with processing the elements to its immediate left and right. Implement Double Insertion Sort, being careful to properly handle both when the array is odd and when it is even. Improved Bubble Sort: One possible improvement for Bubble Sort would be to add a flag variable and a test that…arrow_forwardWrite a modified version of the selection sort algorithm that selects the largest element each time and moves it to the end of the array, rather than selecting the smallest element and moving it to the beginning. Will this algorithm be faster than the standard selection sort? What will its complexity class (big-Oh) be?arrow_forwardCompute the distance between the positions of the first and last zero element in the given array. For example, if the array is 3 0 1 0 4 9 5 0 6 your algorithm should yield 7 - 1 = 6. If the array contains a single zero, return 0. If it doesn't contain any zeroes, return a negative value.arrow_forward
- The binary search algorithm that follows may be used to search an array when the elements are in order. This algorithm is analogous to the following approach to finding a name in a telephone book. a. Open the book in the middle and look at the middle name on the page. b. b. If the middle name isn't the one, you're looking for, decide whether it comes before or after the name you want. c. Take the appropriate half of the section of the book you were looking in and repeat these steps until you land on the name. 1. Let the bottom be the subscript of the initial array element. 2. Let the top be the subscript of the last array element. 3. Let found be false. 4. Repeat as long as the bottom isn't greater than the top and the target has not been found. 5. Let middle be the subscript of the element halfway between bottom and top. 6. If the element in the middle is the target 7. Set found to true and index to middle. else if the element in the middle is larger than the target 8. Let the top be…arrow_forwardusing selection sort algorithm, the intermediate sorting results of sorting the array (1,3,24,19,5,2} in Descending order are: starting: {12,4,25,20,6,3,100} Result of the first iteration: Result of the second iteration: Result of the third iteration: Result of the fourth iteration: { Result of the fifth iteration:arrow_forwardMake a programme that compares the four advanced sorting algorithms covered in this chapter. Create a 1,000-element randomly generated array for the tests. What is the algorithm's ranking? What happens when the array size is increased to 10,000, then 100,000 elements?arrow_forward
- There are many algorithms that are used to solve a variety of problems. In this part, you should write an algorithm that shuffles a given array, the shuffled array should be completely different than the given array, explain your chosen algorithm, describe the algorithm step in pseudo code.arrow_forward1. Write a program that compares all four advanced sorting algorithms . To perform the tests, create a randomly generated array of 1,000 elements. What is the ranking of the algorithms? What happens when you increase the array size to 10,000 elements and then 100,000 elements?arrow_forwardWrite an algorithm to sort elements in an array with selection sort in pseudocode. You will be given an array, and you need to sort the elements in ascending order. ps: Some things to keep in mind: sorting is not required if the given array has a length of 0 or 1. You should take care to ensure that you start with the smallest element, and swap it to the front of the array. From there, compare each successive element with all previous elements and place them correctly, repeating the process until it's all sorted. ======================================================================================= Write an algorithm to sort elements in an array with insertion sort in pseudocode. You will be given an array, and you need to sort the elements in ascending order. ======================================================================================= Write an algorithm to sort elements in an array with merge sort in pseudocode. You will be given an array, and you need to sort the elements…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage