Explore BrainMass
Share

Explore BrainMass

    Comparisons

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    A. You are given a list of n names (all of the names are distinct) with instructions to put them in alphabetical order. How many comparisons are necessary to accomplish your task?

    B. After you have accomplished the task to part a, you are given another name. How many comparisons are necessary to place this name in its place in the alphabetical list? What is the average or expected number of comparisons?

    C. After you have accomplished the task in part a, you are given k more names to put in the list. How many comparisons are necessary? What is the average number of comparisons actually needed?

    © BrainMass Inc. brainmass.com October 9, 2019, 10:26 pm ad1c9bdddf
    https://brainmass.com/math/discrete-math/comparisons-complete-tasks-220420

    Solution Preview

    A. We can use bubble sort to accomplich this task. First we find the smallest name from n names and it requires n-1 comparisons; Second in the rest n-1 names we find the smallest name and it requires n-2 comparisons. And so on. Finally the total number of comparison is:
    (n-1) + (n-2) + ... + 2 + 1 = n(n-1)/2

    B. After I have accomplished task of part a, for a ...

    Solution Summary

    The solution examples of determining how many comparisons are necessary to complete given tasks.

    $2.19