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

  • SEARCH
  • Home
  • 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 209625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:55:56+00:00 2026-05-11T17:55:56+00:00

I would like to know if there’s an efficient algorithm to find the greatest

  • 0

I would like to know if there’s an efficient algorithm to find the greatest m elements in an N x N matrix, with a method header like this:

double[] greatestValues(double[][] matrix, int numberOfElements);

Any ideas?

  • 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-11T17:55:56+00:00Added an answer on May 11, 2026 at 5:55 pm

    If you treat the N x N matrix as an array of N x N items you can apply one of the following techniques:

    Direct application of the quick sort based selection algorithm The quick
    sort based selection algorithm can be
    used to find k smallest or k largest
    elements. To find k smallest elements
    find the kth smallest element using
    the median of medians quick sort based
    algorithm. After the partition that
    finds the kth smallest element, all
    the elements smaller than the kth
    smaller element will be present left
    to the kth element and all element
    larger will be present right to the
    kth smallest element. Thus all
    elements from 1st to kth element
    inclusive constitute the k smallest
    elements. The time complexity is
    linear in n, the total number of
    elements.

    Data structure based solutions Another simple method is to add each
    element of the list into an ordered
    set data structure, such as a heap or
    self-balancing binary search tree,
    with at most k elements. Whenever the
    data structure has more than k
    elements, we remove the largest
    element, which can be done in O(log k)
    time. Each insertion operation also
    takes O(log k) time, resulting in
    O(nlog k) time overall.

    It is possible to transform the list
    into a heap in Θ(n) time, and then
    traverse the heap using a modified
    Breadth-first search algorithm that
    places the elements in a Priority
    Queue (instead of the ordinary queue
    that is normally used in a BFS), and
    terminate the scan after traversing
    exactly k elements. As the queue size
    remains O(k) throughout the traversal,
    it would require O(klog k) time to
    complete, leading to a time bound of
    O(n + klog k) on this algorithm.

    From here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there is a simple algorithm (or jQuery plugin)
I would like to know whether there is any easy method to check whether
I would like to know if there is any way to add custom behaviour
I would like to know if there is some way to share a variable
I would like to know if there are general rules for creating an index
I would like to know if there is a way to disable automatic loading
I would like to know if there is an easy way to detect if
I would like to know if there is any easy way to print multiple
I would like to know if there are any tools that can help me
I would like to know if there is a simple way to parse HTML

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.