Give a big-Oh characterization, in terms of n, of the running time of the following method.

icon
Related questions
Question

Give a big-Oh characterization, in terms of n, of the running time of the following
method. 

/** Insertion-sort of an array of characters into nondecreasing order +/
public static void insertionSort(char[] data) {
int n = data.length;
for (int k = 1; k<n; k++) {
char cur = data[k];
int j = k;
}
while (j> 0 && data[j-1] > cur) {
data[j] = data[j-1];
j--:
}
data[j] = cur;
// begin with second character
// time to insert cur=data[k]
// find correct index j for cur
// thus, data[j-1] must go after cur
// slide data[j-1] rightward
// and consider previous j for cur
// this is the proper place for cur
Transcribed Image Text:/** Insertion-sort of an array of characters into nondecreasing order +/ public static void insertionSort(char[] data) { int n = data.length; for (int k = 1; k<n; k++) { char cur = data[k]; int j = k; } while (j> 0 && data[j-1] > cur) { data[j] = data[j-1]; j--: } data[j] = cur; // begin with second character // time to insert cur=data[k] // find correct index j for cur // thus, data[j-1] must go after cur // slide data[j-1] rightward // and consider previous j for cur // this is the proper place for cur
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer