
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
Question
![Write the following variant of insertion sort.
// The function gets an array of length n of ints,
// and applies the Insertion Sort algorithm on the array.
// The function returns the array of ints of length n
// where output [i] contains the number of swaps
// made by the algorithm in the i'th iteration of the outer loop
int* insertion_sort (int* array, int n);
For example: If the input is the array A=[4,3,6,1,2,5], Insertion Sort on A works as follows:
- Insert 4: [4,3,6,1,2,5]: 0 swaps
- Insert 3: [3,4,6,1,2,5]: 1 swaps
- Insert 6: [3,4,6,1,2,5]: 0 swaps
- Insert 1: [1,3,4,6,2,5]: 3 swaps
- Insert 2: [1,2,3,4,6,5]: 3 swaps
- Insert 5: [1,2,3,4,5,6]: 1 swaps
After the execution of the function
(1) A will become [1,2,3,4,5,6]
(2) the function returns [0,1,0,3,3,1].](https://content.bartleby.com/qna-images/question/d4d1350d-1c9d-4d27-bfd0-605ff64c4314/5211c7fc-cd90-4554-91b7-a20ae4192181/7023fvd_thumbnail.png)
Transcribed Image Text:Write the following variant of insertion sort.
// The function gets an array of length n of ints,
// and applies the Insertion Sort algorithm on the array.
// The function returns the array of ints of length n
// where output [i] contains the number of swaps
// made by the algorithm in the i'th iteration of the outer loop
int* insertion_sort (int* array, int n);
For example: If the input is the array A=[4,3,6,1,2,5], Insertion Sort on A works as follows:
- Insert 4: [4,3,6,1,2,5]: 0 swaps
- Insert 3: [3,4,6,1,2,5]: 1 swaps
- Insert 6: [3,4,6,1,2,5]: 0 swaps
- Insert 1: [1,3,4,6,2,5]: 3 swaps
- Insert 2: [1,2,3,4,6,5]: 3 swaps
- Insert 5: [1,2,3,4,5,6]: 1 swaps
After the execution of the function
(1) A will become [1,2,3,4,5,6]
(2) the function returns [0,1,0,3,3,1].
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 3 steps with 1 images

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
- Write a following functions to do the following operations on the int array b[20]: a. SetArr( ) to assign values for the array b[ ]. b. MaxArr( ) to find the maximum element of an array. c. SortArr( ) to sort any array in ascending order.arrow_forwardProgramming language : Swiftarrow_forward///////1/////. Given an array of integers, write a PHP function to find the maximum element in the array. PHP Function Signature: phpCopy code function findMaxElement($arr) { // Your code here } Example: Input: [10, 4, 56, 32, 7] Output: 56 You can now implement the findMaxElement function to solve this problem. Let me know answer. //. .arrow_forward
- //convert array of numbers from farenheit to celcius// example:// argument: [23, 32, 41, 50, 59]// return: [-5, 0, 5, 10, 15]// hint: use Array.mapfunction toCelcius(array){ } //write a function that takes an input array and returns an array of booleans (>=75) or fail (<75)// example:// argument: [20, 30, 50, 80, 90, 100]// return: [false, false, false, true, true, true]// hint: use Array.mapfunction passOrFail(array){ }arrow_forwardHow can solve this problem using for looparrow_forward
arrow_back_ios
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