Which algorithm is better for sorting short lists?

Assignment Help Data Structure & Algorithms
Reference no: EM13943881

1.

Write a recursive "Merge" method meeting this specification:

Inputs: a sorted list L1 and a sorted list L2.

Outputs: a sorted list that is the merging of L1 and L2, and, the number of times two list elements were compared during the merging process (call it C).

The recursive Merge method returns the merging of L1 and L2 as its result. Thus, after executing L1 = Merge(L1,L2,Nc,Njs), L1 contains the result of the merge and the 'other' list has been destroyed. In other words, at this point, (1) either L2 has been destroyed,or (2) the old L1 has been destroyed and now L1==L2.

(Note: Nc is the total number of times two list elements were compared during the merging process. Njs is the total number of join and split operations that were performed during the merging process. Nc and Njs are output values but not input values. 2005-11-16 12:45:32)

2.

Write a method "General_Sort" that meets this specification:

Inputs: a list L, and a method "Cut_In_Two" that meets the specification below

Outputs: L is sorted in increasing order, and the integer C defined as follows:

C is the total number of times two list elements were compared during the sorting process, including the comparisons made by the Merge and Cut_In_Two methods.

General_Sort must use the "general sorting strategy" (described in detail in class):

1. Use the procedure Cut_In_Two to divide L into two pieces

2. Recursively sort the two pieces

3. Merge the results (use the function written in Question 1a).

The function Cut_In_Two meets this specification:

Input: a list L1 containing at least two elements.

Outputs: non-empty lists L2 and L3 such that L1 = L2+L3 (concatenation), and the integer C (the number of times two list elements were compared during the cut_in_two process)

The method Cut_In_Two should "RANDOMLY" cut the list L1 in two pieces. Thus L1 can be split at "ANY" position (between 1 and lenght(L1)-1), not necessarily in the middle position.

3.

Write a method Merge_Sort that implements the "merge sort algorithm" simply by calling GeneralSort with an appropriate Cut_In_Two method (which you must also write). Merge_Sort should return the sorted list and the integer C returned by
GeneralSort.

4.

Write a method Insertion_Sort that implements the "insertion sort algorithm" simply by calling GeneralSort with an appropriate Cut_In_Two method (which you must also write). Insertion_Sort should return the sorted list and the integer C returned by
GeneralSort.

5.

Choose five different lengths of lists ranging from small (e.g. 10) to large (as large as you can and still finish executing in a few minutes), with reasonably-spaced intermediatevalues. For instance: 10, 100, 1000, 10000, 100000. The lists must be randomly generated.

For each of these list lengths, run the program written for question 1 five times using a different random number seed each time. Average the results.

Plot the average number of comparisons (C) for the two sorting algorithms (merge sort and insertion sort) as a function of the length of the list.

Which algorithm is better for sorting short lists?

Which will be better for sorting extremely long lists?

Justify your answers.

6.

How would you modify the methods above in order to implements the "quick sort algorithm" by simply calling General_Sort?


Attachment:- Sorting_-1 (2).zip

Reference no: EM13943881

Questions Cloud

Demonstrate application of process costing of a manufactur : Demonstrate application of Process Costing of a manufacturing company including the following: Determine Department WIP inventory, Calculation of Equivalent Units, Determine Finished Goods Inventory, Calculation of COGS, Determination of Gross Profit
Richard promised to have darlene''s deck : Richard promised to have Darlene's deck awning constructed by July 10. On June 20, Darlene called him and asked if he could get the job done by July 3, in time for Independence Day. Richard said he could, but he failed to do so, and Darlene hd to ren..
Cash available to complete this purchase : Buyer contracted to buy Seller's house for $290,000; the contract included a representation by Buyer "that he has sufficient cash available to complete this purchase." Buyer was a physician who practiced with his uncle. He had received assurances fro..
Theory of constraints lab points description : Theory of Constraints L A B O V E R V I E W This lab looks at bottlenecks and the calculations necessary to determine which process is the source of a bottleneck condition. Use MS Word to copy your answers. Theory of Constraints Lab Points Descrip..
Which algorithm is better for sorting short lists? : Write a method Insertion_Sort that implements the "insertion sort algorithm" simply by calling GeneralSort with an appropriate Cut_In_Two method (which you must also write). Insertion_Sort should return the sorted list and the integer C returned b..
The birmingham board of education to transport : Yellow Cab contracted with the Birmingham Board of Education to transport physically handicapped students. The contract provided, "Yellow Cab will transport the physically handicapped students of the School System...and furnish all necessary vehicles..
How many shares of common stock are authorized and issued : How many shares of common stock are authorized, issued, and outstanding? Why didn't Priceline.com pay dividends to common stockholders in any of the three years shown?
Discuss the overall quality of customer service : Provide a general overview of the nursing home (e.g., name, location, bed size, ownership, etc.), Discuss the overall quality of customer service offered at the nursing home (as evident by customer complaint inspection results)
Developed an ethical perspective of the problems : Developed an ethical perspective of the problems involved in Ken Johnson's case using the Hedonistic or Kant theories of ethical philosophies. Fully address the questions and rely upon scholarly resources or adequately rely upon Kantian or Hedonist..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Data structures and algorithm design

Data Structures and Algorithm Design

  Supposing that the set of possible list values abcd sort

assuming that the set of possible list values abcd sort the following list in alphabetical order by the distribution

  Give a recursive definition of a singly linked list

Give a C++ code fragment that, given an×n matrix M of type float, replaces M with its transpose. Try to do this without the use of a temporary matrix.

  Question about damaged database

Suppose if you were one of the users of a damaged database, discuss how would you be affected by such a failure and what measures could you take to prevent it?

  Write the code to implement the method

The "linked list" has a integer "position". In an array, the position is very easy to implement as it is related to the "index" of the array. In the "linked list", the position is much more difficult.

  Write algorithm to decide which commute is cheaper

Write working algorithm in pseudo code to decide which commute is cheaper: You wish to decide whether you must drive your car to work or take train. You know one-way distance

  Choose a combination of meaningful data structures

Describe a mechanism to access the telephone customer records by telephone #. Assume that we have a huge data in hand, say a million records or so.

  Describe and implement fft algorithm cooley-tukey

Describe and implement in C++ FFT algorithm "Cooley-Tukey". Also, implement naive DFT and compare naive DFT with FFT using: a sample of the signal x(t) = t

  Order statistic tree to count number of inversions in array

Demonstrate how to use an order-statistic tree to count the number of inversions in an array of size n in time O(n lg n).

  What is the new time complexity in the array

What is the time complexity of running the below bubblesort on an array of random integers?

  Create the algorithm to read information through file

Create the algorithm which will read through file and compute numbers of married men, single men, married women and single women.

  Measure the execution time of the three sorting algorithms

The program should display the array values before sorting and then after invoking each sorting method. For this case, consider SIZE value 100 and MAXRNG value 9999.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd