Question: Write a program that calls stringSort with strings of various lengths where the characters of each string are in descending order. Include a counter in

Write a program that calls stringSort with strings of various lengths where the characters of each string are in descending order. Include a counter in your function right above the second if statement, to count the number of item comparisons for each input. Answer the questions below.

# of item comparisons for strings of length 1: 0

# of item comparisons for strings of length 2: 1

# of item comparisons for strings of length 3: 3

# of item comparisons for strings of length 4: 7

# of item comparisons for strings of length 5: 14

# of item comparisons for strings of length 6: 25

c) Find a polynomial f(n}, of lowest degree that fits your results from part b. In other words f(1) should equal the first number, f(2) should equal the second number and so on. Explain how you came up with your polynomial.

d) Based on your result from Part c, how does the efficiency of stringSort compare with other sorting algoritms like bubblesort, mergesort etc. ?




Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!