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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started