KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Given an array of values of length n, is there a way to count the number of swaps that would be performed by insertion sort to sort that array in time better than O(n 2 )? For example : arr[]={2 ,1, 3, 1, 2}; // Answer is 4. Algorithm: for i <- 2 to N j <- i while j > 1 and a[j] < a[j - 1] swap a[j] and a[j - 1] //I want to count this swaps? j <- j - 1
Tags (comma-separated)
Save Edits
Cancel