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

  Dbms and data mining to imporve customer service

Discuss how a database management system and data mining can help motor vehicle maintenance center improve its services, and what tables would be required in such a database.

  Write algorithms to perform the following operations on it

Write algorithms to perform the following operations on it - create, insertion, deletion, for testing overflow and empty conditions.

  Develop the flow diagram of the information

Develop the flow diagram of the information and any control elements needed to ensure proper access for the information. A diagram of the information flow and any elements controlling proper access to the information it uses

  Read in a height in feet and inches

Write a program that will read in a height in feet and inches (feet should be an integer, while inches should be a float) and will output the equivalent height in meters (as a float). Use at least three functions

  Your final project is a script which performs a fundamental

your final project will utilize many of the various skills that you have learned throughout this course. the final

  Linear search algorithm with scans

Consider the linear search algorithm with scans through an n-element array a to determine if element xis in a. We say that the algorithm require i steps if x is located at index i; i.e. a[i] = x, for i = 0, 1, . . . , n ?

  Create a binary search tree from an array

Create a binary search tree from an array

  Submit your programs by email the program should have as

submit your programs by email. the program should have as many comments as necessary. the top comments should explain

  Draw a defining diagram

Draw a defining diagram (IPO). Draw a structure chart. Write a program using pseudocode and modularization

  Discuss and define normalization

Discuss and define normalization and what are the basic steps of the normalization process?

  Describe a dynamic programming algorithm

Let Fi(x) = i * (1+log x). Describe a dynamic programming algorithm to input 2 integers x and m and determine how to break x into m integers x1, x2, ..., Xm such that f1(x1) + f2(x2)+----+fm(Xm) is the largest among all possible ways of breaking x..

  Compute result for receiver after error detection algorithm

If receiver A receives 101010010011100100011101 and another receiver, B, receives 101011111111100100011101 compute the result for each receiver after error detection algorithm is run?

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