Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:11:28+00:00 2026-05-26T09:11:28+00:00

I had to write a merge sort function in Java. No problem. Well, a

  • 0

I had to write a merge sort function in Java. No problem. Well, a little, but I got through it. Then the follow up question I didn’t get.

Question: Given an array A[][] such that A[i][0] is a float and A[i][1] is a nonnegative int giving the multiplicity of the value A[i][0] (here think of a big vector that’s been collapsed down by combining repeated entries and recording how many got combined), write a version of merge sort that returns B[][] where B[i][0] < B[i+1][0] for all i.

Any ideas? The best I could do was merge sort and then group the equal ones, but apparently you can do it all in one step.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:11:28+00:00Added an answer on May 26, 2026 at 9:11 am

    Strage question… and using different types in these arrays is just ugly (personal point of view).

    However, the most useful thing to do, is to rewrite your merge function with a Comparator.
    This way you can sort using whatever property you want.
    You would end up with a signature like void merge(A[] arr, Comparator<? super A> comp).
    By the way, the Java implementation of sort is a lot like this.

    To solve your question you would call:

    A[][] a = ...;
    merge(a, new Comparator<A[]>() {
      int compare(A[] a, A[] b) {
        return ((Float)a[0]) - ((Float)b[0]);
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just had to write a string reverse function in C# 2.0 (i.e. LINQ
I have experience with OCaml. You had to write a stub for every function
My kiddo had a homework assignment to write Blackjack in Java. I helped him
Suppose I only had the regular J2SE http libraries but wanted to write a
Had to write the following program for an on line pre java class using,
recently I had to write a little script that parsed VMs in XenServer and
I have some code that I had to write to replace a function that
I'm a php developer, but recently had to write the same application twice, once
I had to write a linked list, then turn it into a dynamic Stack,
I thought this would work: if ($(this).attr('checked')) {} but I had to write it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.