Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.2, Problem 4E
Program Plan Intro
To argue that the procedure INSERTION-SORT would beat the procedure QUICKSORT on this problem.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Professor JAson uses the following algorithm for merging k sorted lists, each having n/k elements. He takes the first list and merges it with the second list using a linear-time algorithm for merging two sorted lists, such as the merging algorithm used in mergesort. Then, he merges the resulting list of 2n/k elements with the third list, merges the list of 3n/k elements that results with the fourth list, and so forth, until he ends up with a single sorted list of all n elements. Analyze the worst-case running time of the professor’s algorithm in terms of n and k.
We talked about the trade-off between using sequential search on an unsorted list as opposed to sorting the list and then using binary search. If the list size is n = 9,000, about how many worst-case searches must be done before the second alternative is better in terms of number of comparisons? (Hint: Let p represent the number of searches done.) Use selection search to sort the binary search list.
In this problem, consider a non-standard sorting algorithm called the Slow Sort. Given anarray A[1 : n] of n integers, the algorithm is as follows:
Slow-Sort(A[1 : n]):1. If n < 100, run merge sort (or selection sort or insertion sort) on A.2. Otherwise, run Slow-Sort(A[1 : n −1]), Slow-Sort(A[2 : n]), and Slow-Sort(A[1 : n −1]) again.
Question: Prove the correctness of Slow-Sort.
Chapter 7 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- What is the time complexity of deleting an element from a sorted array? Does it have better time complexity than deleting a node from an unsorted array? Why? What is the time complexity of append operation of an unsorted array of size n? why? What is the time complexity (in big-O notation) of binary search in a sorted array containing m (m >0) numbers? Why is the insertion not supported for unsorted array? What are the fundamental operations of an unsorted array?arrow_forwardPlease explain What is the worse-case performance of quicksort? Select the correct answer with the correct justification. Group of answer choices a. O(n*n), because during the partitioning stage it is possible that we select a 'bad' random pivot point that only sorts one item at a time. If we continuously do this over and over again, we are effectively only sorting 1 item each time. We then need to perform this pivot step n more times to sort the remaining n-1 items, thus giving us an O(n*n) complexity. b. O(n*n), because quicksort is a comparison-based sorting algorithm in which we have to compare every possible element against every other element in order to swap each element into the correct position. c. O(n*log(n)), because each time we are selecting a pivot point, on the average-case we are able to split our problem into roughly two collections, and sort half of our elements at the pivot point.arrow_forwardConsider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general? (a) Insertion Sort (b) Quick Sort (c) Heap Sort (d) Selection Sort (e) Merge Sortarrow_forward
- solution should have O(l1.length + l2.length) time complexity, since this is what you will be asked to accomplish in an interview. Given two singly linked lists sorted in non-decreasing order, your task is to merge them. In other words, return a singly linked list, also sorted in non-decreasing order, that contains the elements from both original lists.arrow_forwardModify the FindBestPlan(S) function to create a function FindBestPlan(S, O),where O is a desired sort order for S, and which considers interesting sortorders. A null order indicates that the order is not relevant. Hints: An algorithmA may give the desired order O; if not a sort operation may need to be added to get the desired order. If A is a merge-join, FindBestPlan must be invoked on the two inputs with the desired orders for the inputs.arrow_forwardConsider the following problem:L is a sorted list containing n signed integers (n being big enough), for example [-5, -2, -1, 0, 1, 2, 4] (here, nhas a value of 7). If L is known to contain the integer 0, how can you find the index of 0 ?arrow_forward
- For this given code, please help me create a recursive case for transpose of matrix using the cache oblivious algorithm. for ( size_t i=0; i<n; i += block ) { for ( size_t j=0; j<n; j++ ) { for ( size_t b = 0; b < block && i + b < n; ++b){ b[ j*n + i ] = a[ i*n + j ]; } } else { recursMatTranspose ( n, n, a, 0, 0, b, 0, 0 ); //recursive case using cache-oblivious algo } }arrow_forwardQuestion 17. Sorting a data set is an important sub-problem in data science. Given the size n of a data set, which statements are correct? a) Bubble Sort has worst-case run-time complexity O(n).b) Bubble Sort has worst-case run-time complexity O(n log N).c) Bubble Sort has worst-case run-time complexity O(n2).d) Merge Sort has worst-case run-time complexity O(n).e) Merge Sort has worst-case run-time complexity O(n log N).f) Merge Sort has worst-case run-time complexity O(n2).g) Quick Sort has worst-case run-time complexity O(n).h) Quick Sort has worst-case run-time complexity O(n log N).i) Quick Sort has worst-case run-time complexity O(n2).arrow_forwardFor sorting a set of items, we can employ one of these famous algorithms, merge-sort, heapsort, quicksort, and shell-sort. We can program in both Java and Python, and we have the choice of using three different computers with different instruction set architectures: x86, ARM, and MIPs. Regarding microarchitecture, for x86 we have two choices, and for ARM and MIPS we have three choices for each of them. How many choices we have to run a sort algorithm? (Draw diagram).arrow_forward
- Consider sorting a list of items that are in reverse sorted order. If you were forced to pick between the three iterative sorting algorithms (bubble sort, selection sort, or insertion sort) to work through this set and place it into normal (ascending) sorted order, which would you pick and why?arrow_forwardConsider the following problem:L is a sorted list containing n signed integers (n being big enough), for example [-5, -2, -1, 0, 1, 2, 4] (here, n has a value of 7). If L is known to contain the integer 0, how can you find the index of 0 ?arrow_forwardIn the radix sort bucketPass debate, integer values were sorted depending on a digit of the number. It was critical that the sort be stable, meaning that items with comparable digits stayed in their original relative order. Sadly, our solution employed Vectors, and in order for bucketPass to function in O(n) time, it was necessary to add and delete values from the Vector's end. It was also essential to unload the buckets backwards. Is it feasible to make this code more readable by using a Stack or a Queue? One of these two will allow us to discharge the buckets in increasing order into the data array. Is this updated version as fast (in terms of big-O)?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning