Question

2. Sometimes you want to sort lots of data, but you only need the smallest (or largest) K items instead of all items. For example, maybe you want to give awards to the ten students with the best GPAs. If you have thousands of students, you could waste time sorting all of them just to find the top ten. Perhaps we can adapt an existing sorting algorithm so that it works faster if we just want to find and sort the smallest (or largest) K items Suppose we can start with either insertion sort or selection sort. Part A: Which one is easier to modify so that it efficiently gives us only the smallest K items (in sorted order) instead of all items? Part B: Describe the changes needed to make this happen. Part C: Briefly explain why the other algorithm cannot be modified to do what we want efficiently
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer)

The selection sort is an advantage over the insertion sort as the number of writes is in O(n) whereas the insertion sort is in O (n^2).

The insertion sort performs less comparison than the selection sort which depends on the degree of sortness of the mentioned array. During the selection sort one must scan the left out part of the array while placing an element. Insertion refers to scanning as many elements are needed which means that when an array is sorted almost or already then the insertion sort performs in O (n) times.

Usually, insertion sort will perform less comparisons than selection sort, depending on the degree of "sortedness" of the array. While selection sort must scan the remaining parts of the array when placing an element, insertion sort only scans as many elements as necessary. That means that when the array is already sorted or almost sorted, insertion sort performs in O(n) time.

The other algorithms will not help as Selection Sort has a way to always performs in quadratic time and also selection sort is always a better alternative when one uses an array, while an insertion sort might perform better when one uses a linked list.

Hope this answer helps. :) Happy to help.

Add a comment
Know the answer?
Add Answer to:
2. Sometimes you want to sort lots of data, but you only need the smallest (or...
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
  • Shell sort works by Group of answer choices using insertion sort on subarrays of equally spaced...

    Shell sort works by Group of answer choices using insertion sort on subarrays of equally spaced entries using insertion sort on subarrays of equal size consecutive entries iteratively searching for the smallest entry in subarrays of equally spaced entries iteratively searching for the smallest entry in subarrays of equal size consecutive entries Chapter 15:  Shell sort can be improved by Group of answer choices you cannot improve the algorithm’s time efficiency using selection sort instead of insertion sort as the final...

  • Data Structures: For each of the following situations, name the best sorting algorithm we studied. (For...

    Data Structures: For each of the following situations, name the best sorting algorithm we studied. (For one or two questions, there may be more than one answer deserving full credit, but you only need to give one answer for each.) (a) The array is mostly sorted already (a few elements are in the wrong place). (b) You need an O(n log n) sort even in the worst case and you cannot use any extra space except for a few local...

  • c++ data structures please Pick any inefficient sorting algorithm you want, selection, bubble, insertion, etc., and...

    c++ data structures please Pick any inefficient sorting algorithm you want, selection, bubble, insertion, etc., and implement it as a function. Using the system clock as a timer, determine when the efficiency of the algorithm breaks down. For example, does it become slow after 1000 elements, 10000 elements, 100000 elements? Write some code to figure this out. Then use the sort() algorithm that is part of the STL <algorithm> library. How does this function compare to the function you implemented?...

  • Algorithms and Basic Data Structures

    This part involves writing and testing code. You are to make an experiment with 3 sorting algorithms partially given on Blackboard: Insertion sort, Mergesort, Quicksort. First, create a positive integer array of 10000 (ten thousand) elements with random values in it. Then, run the algorithms on this array by recording their running times. That is, take note of the time just before the sorting starts, and just after the sorting finishes, and record the difference. For a complete experiment, do...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

  • this is the page no. 255 .. can some one please help me with please. just...

    this is the page no. 255 .. can some one please help me with please. just give a way to do it assuming that we have add algs4.jar. thank you!! As a general r libraries provided by the authors of our text in algs4.jar. However, java.util.Arrays.sort(), should be used as indicated below ule for programming assignments for this class, you should feel free to use the Exercise Comparing Sorting Methods . The purpose of this exercise is to get a...

  • please answer all parts and code thanks . - PART 1-Introduction to Sorting, 21 points Use...

    please answer all parts and code thanks . - PART 1-Introduction to Sorting, 21 points Use this array of integer for the problems 1A, 1B, and 1c: 9 57 8324761 Each of these problems is worth 3 points A. Show the contents of the array each time a selection sort changes it while sorting the array into B. Show the contents of the array each time an insertion sort changes it while sorting C. Show the contents of the array...

  • Data Structures using C BuildHeap and Heap Sort In preparation: If you have not done so...

    Data Structures using C BuildHeap and Heap Sort In preparation: If you have not done so already, you should complete Worksheet 33 to leam more about the heap data structure. In some applications it is useful to void buildHeap (struct dyArray heap) { initialize a Heap with an existing vector int max = dy Array Size(heap); int i; of values. The values are not assumed for (i = max/2-1; i >= 0; i--) to be organized into a heap, and...

  • You will create a dimple Bubble Sort program to sort a string of random integers or...

    You will create a dimple Bubble Sort program to sort a string of random integers or text. Please read instructions and examples Please show screenshot of proof that the code works in the C program ECE 216 Programming Project 2 The Bubble Sort You will create a simple Bubble Sort program to sort a string of random integers or text or whatever you can punch in from the keyboard. For the input data, you will input a string of single...

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

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