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

  Create a presentation describing the data types

Create a 10-12 slide presentation describing the data types. Include the following in your presentation: Introductory slide AND Slide for each data type

  What is minimum number of nodes expanded for bfs and dfs

Consider the following graph representing the state space and operators of a navigation problem: What is the minimum number of nodes expanded and the storage needed for BFS and DFS?

  Complex routing algorithm are used to maintain routing table

Complex routing algorithms are used to maintain routing table

  Use process flow charts procedures and orpolicy statements

Draft a 2-4-page (350 words per page) section that will use process flow charts, procedures, orpolicy statements to articulate the business requirements in terms of specific process or business development needs

  Java program to make choice for a coffee cup size

Create an application that prompts the user to make a choice for a Coffee cup size, S for Small, T for Tall, G for Grande and V for Venti the rates of cup sizes will be stored in a parallel double array as $2, $2.50, $3.25, and $4.50 respectively.

  List the inputs any processes calculations and outputs

Your goal is to solve the following simple programming exercise. You have been contracted by a local antique store to design an algorithm determining the total purchases and sales tax. List the inputs, any processes, calculations, and outputs

  Graph in which every node is pivotal for at least two nodes

Give an example of a graph in which every node is pivotal for at least two di fferent pairs of nodes. Explain your answer.

  Process in which cpu must undertake to read a value from me

On the von Neumann, describe the process that the CPU must undertake to read a value from memory and to write a value from memory and to write a value to memory in terms of what is put into the MAR, MBR, address bus, data bus, and control bus

  Greedy strategy for finding a shortest path

Think about the given greedy strategy for finding a shortest path from vertex start to vertex goal in a connected graph.

  Lines of action- explain how you will use a search tree to

lines of action- explain how you will use a search tree to find the solutionbullabstractbullintroductionbullrelated

  Design a recursive linear-time algorithm

Design a recursive linear-time algorithm that tests whether a binary tree satisfies the search tree order property at every node.

  Portfolio website containing thumbnail imagery

Explain in general terms what you think the role of good design is. Next, recognize 3-characteristics of an effective gallery website. Then find an example of a portfolio website containing thumbnail imagery.

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