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 7838325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:04:14+00:00 2026-06-02T15:04:14+00:00

There are 100 numbers present in an array and I need to find out

  • 0

There are 100 numbers present in an array and I need to find out the average of top 5 highest numbers among them.

Also in the same way the average of top 5 lowest numbers among them. How could I go about doing it?

  • 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-06-02T15:04:15+00:00Added an answer on June 2, 2026 at 3:04 pm

    Use Hoare’s select algorithm (or the median of medians, if you need to be absolutely certain of the computational complexity), then add the top partition (and divide by its size to get the average).

    This is somewhat faster than the obvious method of sorting instead of partitioning — partitioning is (O(N)) where sorting is O(N log(N) ).

    Edit: In C++, for real code (i.e., anything except homework where part of the requirement is to do the task entirely on your own) you can use std::nth_element to partition the input into the top 5 and everything else.

    Edit2: Here’s another quick demo to complement @Nils’, but this one in full C++11 regalia (so to speak):

    #include <numeric>  
    #include <algorithm>
    #include <iostream>
    #include <iterator>
    #include <vector>
    
    int main(){
        std::vector<int> x {1, 101, 2, 102, 3, 103, 4, 104, 5, 105, 6};
    
        auto pos = x.end() - 5;
    
        std::nth_element(x.begin(), pos, x.end());
    
        auto sum = std::accumulate(pos, x.end(), 0);
        auto mean = sum / std::distance(pos, x.end());
    
        std::cout << "sum = " << sum << '\n' << "mean = " << mean << "\n";
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any 100% Microsoft developers out there who have ventured out into learning
There is a string array myDownloadList containing 100 string URIs. I want to start
Is there a way to limit a textfield to only allow numbers 0-100, thereby
So, I have a file called 'dummy' which contains the string: There is 100%
There is a table with more than 100,000 records matching a particular criteria of
There is a table: doc_id(integer)-value(integer) Approximate 100.000 doc_id and 27.000.000 rows. Majority query on
Let's say there is a page with 100 different user photo's shown on the
Is there a way to format a decimal as following: 100 -> 100 100.1
Is there a way to limit a regular expression to 100 characters with a
I would like to know if there is any way I can apply 100%

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.