
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
The following is a pseudocode representation of an
+sort (in anArray[]: integer)
n: integer = length of anArray
temp: integer = 0;
for (i: integer = 0; i < n - 1; i++) {
for (j: integer = 0; j < n – i - 1; j++) {
if (anArray[j] > anArray[j + 1]) {
temp = anArray[j]
anArray[j] = anArray[j + 1]
anArray[j + 1] = temp
}
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

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
- We are going to create a poorly efficient sort which we will call Sort. This algorithm will arrange the elements in an array in descending order. Given some array A, we are going to start by finding the largest element in the array and then swapping it with the first element of the array A[O]. We will then find the next largest element of the array and swap it with A[1]. This procedure will be repeated until we reach A.length - 2. I am really struggling with the pseudo code for this algorithm. I figured out how to do it in descending order waiting confused by the part where it instructs us to find the largest element in the array and then swap it. I have included a picture of my work so far. If you could also help me with the loop invariant steps That would be much appreciated. These are practice questions for our upcoming quizarrow_forwardWrite a program that compares all four advanced sorting algorithms discussed in this chapter. To perform the tests, create a randomly generatedarray 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,000elements?arrow_forwardImproved Bubble Sort: One possible improvement for Bubble Sort would be to add a flag variable and a test that determines if an exchange was made during the current iteration. If no exchange was made, then the list is sorted and so the algorithm can stop early. This makes the best case performance become O(n) (because if the list is already sorted, then no iterations will take place on the first pass, and the sort will stop right there). Modify the Bubble Sort implementation to add this flag and test. by using java Implement both the Double Insertion sort and the Improved Bubble sort algorithm on a randomly generated list of N integer Your program should output only the running time. To measure the sorting time, call System.currentTimeMillis() just before and just after the sorting and take the difference. Submit a copy of your code.arrow_forward
- Consider the following algorithm, which may be called on an array that is not necessarily sorted. and returns the array in sorted form. GoofySort (A) : if (len (A) <= 3): SelectionSort(A) else: [len(A)/3] + GoofySort (A[1:2t]) GoofySort (A[t+1:n]) //sort the back 2/3rds + GoofySort (A[1:2t]) Let t + A[1:2t] //sort the front 2/3rds A[t+1:n] A[1:2t] //sort the front 2/3rds (a) Write a recurrence which captures the runtime of this algorithm. Your recurrence should be of the form T (n) =?. You can ignore any non-recursive operations (i.e. you only need to focus on operations in the last three lines). You do not need to handle base cases here. You can assumen is divisible by 3 for convenience. (b) Solve your recurrence using the substitution method. Show your work. You may assume a base case of T (1) = 1. State what the big-0 runtime is for this algorithm (hint: it should be a polynomial written in the form nº).arrow_forwardQuick sort the list L = {A, B, N, M, P, R}. What are your observations? How canthe observations help you in determining the worst-case complexity of quick sort?arrow_forwardWrite a Java program to sort an array of given integers using Stooge Sort non-negative Algorithm.arrow_forward
- One disadvantage of using a For-loop in sorting algorithms is that the body of theFor-loop is repeatedly executed even if it is no longer necessary. One example isBubble Sort:Input: Array A[1 . . . n]Output: Array A sortedfor i ←1 to (n −1) dofor j ←1 to (n −i) doif A[j] > A[j + 1] thenA[j] ↔A[j + 1]return AIn the array [2, 1, 3, 7, 9] we know that when 2 and 1 are interchanged, early on in theexecution of the algorithm, the array is now sorted, and all subsequent iterations ofthe outer loop are unnecessary. *Write a version of Bubble Sort that avoids unnecessary comparisons*arrow_forwardGiven an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7, -3,2,3,11] Output: [4.9,9,49,121]arrow_forwardPlease help me solve this problemarrow_forward
- Bubble Sort is a popular, but inefficient sorting algorithm. It works by repeatedly swapping adjacent elements that are out of order. Prove the correctness of following Bubble Sort algorithm based on Loop Invariant. Clearly state your loop invariant during your proof.arrow_forwardShell sort is an in-place comparison-based sorting algorithm which is based on insertion sort algorithm. It works as follow : It breaks the original list into a number of smaller sublists, each of which is sorted using an insertion sort. The unique way that these sublists are chosen is the key to the shell sort. Instead of breaking the list into sublists of contiguous items, the shell sort uses an increment i, sometimes called the gap, to create a sublist by choosing all items that are i items apart. n a) We say that the our initial gap is floor: when we divide our sequence into 2k n sublists where 2k k>0 be the number of passes that can be increment until the denominator not greater than n, n and then sorting the elements which are position away with insertion sort. We have three 2k passes for an array size of 8 to 15. Demonstrate the Shell algorithm on the input array A = [35,33,42,10,14,19,27,44] showing how even- %3D п tually the algorithm outputs the sorted array…arrow_forwardQuicksort is a powerful divide-and-conquer sorting algorithm that almost always runs in O(nlogn) time,though it can run in O(n^2) time for certain input arrays, depending on how we choose the pivot. For this question assume that the pivot isalwaysthe last (right-most) element of the input array.There are two main ways that we can code the PARTITION procedure: the Lomuto method and the Hoare method. Question: Clearly explain how the two partition methods work – the Lomuto method and the Hoare method, and how they are different. Finally apply both methods to partition the arrayA= [2, 8, 7, 1, 3, 5, 6, 4], using the pivot A[8] = 4.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education