Implementation of mergesort

Requirements:

Write a program to read an input sequence and then produce an array of links giving the values in ascending order. The first line of the input file is the length of the sequence (n) and each of the remaining n lines is a non-negative integer. The first line of the output indicates the subscript of the smallest input value. Each of the remaining output lines is a triple consisting of a subscript along with the corresponding input sequence and link values.

Don't use plagiarized sources. Get Your Custom Essay on
Implementation of mergesort
Just from $13/Page
Order Essay

Getting Started:

  1. Your program should read the input files by using Unix shell redirection (e.g. a.out<lab1.dat) to read the input from

stdin (C). By using redirection, it is unnecessary to explicitly open and close the input file, nor should your program

prompt for a file name. You should dynamically allocate tables for storing the input keys and the table of links. Unlike

the mergesort in Notes 1 and CLRS, the table of keys is never modified.

  1. The link values are not initialized before the recursive mergesort begins. Each link will be initialized to -1 when its

sequence value is placed in a single-element list (at the bottom of the recursion’s “tree”).

  1. The input sequence array and the link array may be global. Under this assumption, the following prototype may be used:

int mergeSort(int start,int count) where start is the first subscript for a subarray of count elements. The returned int is the subscript of the first element in the resulting sorted sublist. The last element in the sublist will have a link value of -1.

  1. The critical part of the code is a linear-time merge of two subarrays that previously had their link values set for ordered

sublists. (Be sure to understand the merging concept from pp. 3-4 of Notes 1 before proceeding.) The merge will revise

the link values to give a single ordered list.

  1. If an input value appears more than once, those elements should be ordered by subscripts in the final list, i.e. your sort

code will be stable.

Consider the following input file:

8

5

5

2

4

3

1

0

1

The output (as subscript/value/link triples) will be:

First element is at subscript 6

0 5 1

1 5-1

2 2 4

3 4 0

4 3 3

5 1 7

6 0 5

7 1 2

Notice that the input sequence ordering has not changed.

The Homework Labs
Calculate your paper price
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

We ensure that all our papers are written from scratch. We deliver original plagiarism-free work. To guarantee this, we submit all work alongside a plagiarism report.

Free Revisions

All our papers are completed and submitted before the deadline. We ensure this to provide you with enough time to go through the work and point out any sections or topics that may need revision or polishing. We provide unlimited revision services for free.

Title-page

All papers have a title page providing your personal and institutional information. We do not charge you for this title page.

Bibliography

All papers have a bibliography or references page. This page is a requirement for academic and professional documents. We provide this page at no cost for all our papers.

Originality & Security

At Thehomeworklabs, we guarantee the confidentiality and security of your information. We value our clients and take confidentiality seriously. All personal information is treated with confidentiality and stored safely to ensure that no third parties gain access to it. We also provide original work and attach an originality/plagiarism report alongside all papers.

24/7 Customer Support

Our customer support team is available 24/7 to provide you with any necessary assistance when you need it. You can contact us at any time, day or night, via email or through the live chat button.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

We provide our customers with the best experience in the academic and business writing field.

Pricing

Flexible Pricing

We provide the best quality of service at affordable prices. We also allow our clients to make partial payments for their orders. You can also contact our customer support team in case you need to discuss a different payment plan.

Communication

Admission help & Client-Writer Contact

We realize that sometimes clarification is necessary to ensure that quality work is done. Therefore, we provide a button for clients and writers to communicate in case some clarification is needed.

Deadlines

Paper Submission

We ensure that we submit all papers ahead of their respective deadlines. This allows you to go through the documents and request any revision, corrections, or polishing before the paper is due.

Reviews

Customer Feedback

We encourage customer feedback, positive or negative. We can identify the various areas that we need to improve to provide even better services through your feedback. Please feel free to give us feedback.