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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:48:31+00:00 2026-05-25T13:48:31+00:00

Need help with an efficient algorithm to gather data that will be displayed in

  • 0

Need help with an efficient algorithm to gather data that will be displayed in a chart. I am using c# but you can use pseudo code as a solution.

To explain I am using below sample.
Starting with zero create 10 bins on either side (positive bins and negative bins). A bin is just a container. (counter)

  • bin10 (numbers 91 to 100 go in this bin)
  • bin9 (numbers 81 to 90 go in this bin)
  • bin8 (numbers 71 to 80 go in this bin)

and so on until

  • bin2 (numbers 11 to 20 go in this bin)
  • bin1 (numbers 1 to 10 go in this bin)
  • bin0 (number zero goes in this bin – the set point. Any number can be set point. I have taken zero to illustrate)

  • bin-1 (numbers -1 to -10 go in this bin)

  • bin-2

and so on until

  • bin-10 (numbers -91 to -100 go in this bin)

Need help for an efficient algorith for below.

int[] bins = CreateBins(bin range, number of bins on each side, setpoint)

CreateBins(10, 10, 0) 
{
   //??
}

FindTheRightBinAndInsertInFoundBin(value, bin[])
{
  //??
}

FindTheRightBinAndInsertInFoundBin(77, bin[])
//that should basically do a bin8++ where bin8 is an index into the bin array

Update : A 2D array is fine if it does the job. (or any data structure for that matter like dictionary etc).

thank you

  • 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-25T13:48:31+00:00Added an answer on May 25, 2026 at 1:48 pm

    I don’t know what range is supposed to mean – it should measure size, either of a single bin or all bins, because the actual “range” is determined by the set point, the number of bins and the size. I’m going to assume it’s bin size.

    class Bins
    {    
        private int setPoint;
        private int binSize;
        private int numberOfBins;
        private Dictionary<int, int> bins; // bins are just counters, right?
    
        CreateBins(int range, int numberOfBins, int setPoint)
        {
            this.setPoint = setPoint;
            this.binSize = range
            this.numberOfBins = numberOfBins;
            bins = new Dictionary<int, int>();
        }  
    
        PutInRightBin(int value) 
        {
            var binIndex = (value - setPoint) / binSize 
            // add or substract a 1 here because your 'first' bin is index 1, not 0.
                + Math.Sign((value - setPoint)/binSize);
            if (!bins.ContainsKey(binIndex))
            {
                bins.Add(binIndex, 0);
            }
    
            bins[binIndex] = bins[binIndex] + 1;
        }
    }
    

    edit

    I think the key element here is the bin determing algorithm:

    var binIndex = (value - setPoint) / binSize          
    + Math.Sign((value - setPoint)/binSize); 
    
    • subtract the set point from the value, so you can determine whether it is on the set point, or to the positive or negative side of it.
    • divide by the bin size to determine which bin you want to place in. so 0-9 will result in 0, 10-19 will result in 1, and -20 to -29 will result in -2.
    • add or substract 1 using Math.Sign to fix the indexing, because you effectively want 1-based indexing rather than 0 based indexing (relative to your set point).

    I have the edge case of the bin size elements wrong here (i.e. 10 will end up in bin 2 rather than bin 1). The fix is probably

    var binIndex = (value - Math.Sign(value) - setPoint) / binSize 
        + Math.Sign((value - setPoint)/binSize);
    

    which will ‘move’ the value one closer to 0. However you will need to test to prove this.

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

Sidebar

Related Questions

I need help writing a T-SQL query that will generate 52 rows of data
Need help writing a script downloads data from google insight using c# this is
I need help on regex or preg_match because I am not that experienced yet
I need some help working out how to make my query more efficient. I'm
I need a help with tuning parameters in my.cnf for efficient work of my
I'm trying to create a function that i can use over and over. I
I need some help to store some data efficiently. I have a large list
Hello I am trying to get the efficiency for Strassen's algorithm but need some
Need a little help with a regex I'm trying to match a string that
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card

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.