spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Divide Huge Array of Numbers in Buckets


If non uniform, and you want equal # of buckets, simply make your own hashtable w/ your own lambda value.

If you have 1000 numbers from 1-1000, and you want 10 buckets, simply give a hashcode of 1-100 to be 0, and 101-200 to be 1. This is really easy to do - you can just do (maxNum (in first instance it's 100) -1)/100 (which is 1000/numOfBuckets) to find the index of the array inside of your hash table.

If you want to have even distribution - that's a little harder. You're going to have to first take in with the previous uneven distribution, and then rehash so each bucket has the same # of numbers.

To rehash, simply take the # of numbers (iterate through each bucket, finding size, and add) and then divide by # of buckets. Now you have the new lambda value. If you don't care about the range being not uniform(as in 1-10, 11-20, instead of 1-15, 15-20, etc), then iterate through your old hashtable and add into a new hashtable w/ the new lambda value, filling sequentially - that's the closest you'll get(sometimes you'll get -1 from lambda value).

If you don't care much about the original uneven distribution but equal range, simply just take the number of numbers you have, sort using some easy sort like quicksort, and then put (lambda value)# of numbers in each bucket.

Not sure if that's what you mean, but hope this helps.


Categories : Algorithm

Related to : Divide Huge Array of Numbers in Buckets
Find triplets in an array such that sum of two numbers is also a number in the given array
At first glance, I can't see an algorithm that is less than O(n²). (Unless it is an extra-ordinarily clever one) This problem is very similar to the infamous 3SUM question: Basically, the idea is that given a set of n elements, are there any triples that sum to zero? An algorithm solving 3SUM faster than O(n²) is not known - This is an open problem in computer science... (See here: http://en.

Categories : Arrays
How to write a paged, sorted query that also returns group buckets
Here's one attempt, I don't have sql-server (which I assume you are using) at hand so you may have to adjust the query slighly: select * from ( select ROW_NUMBER() over(ORDER BY NetWorth asc) as rn , Age, NetWorth, FirstName, LastName , count(*) over () as totalrows , max(networth) over () as max_value from names ) as t where rn between 1 and 10;

Categories : SQL
How can I reliably test/benchmark the size (including empty buckets) of a .Net HashSet object?
thst is interesting questionstrong text... i have a radical suggestion for you: start your application and get the size of memory before initializing the HashSet. you can do so by using Process.GetCurrentProcess().WorkingSet64 (on msdn: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.workingset64(v=vs.110).aspx) then populate your HashSet and print Process.GetCurrentProcess().

Categories : C#
How to add numbers between two string array in c
Edit This Answer does not allow carry overs but infinity long add operations. It does not solve the problem of the user. But it is an implementation example and the user asked for one. This is why I will let the answer stay here and not delete it. You can use atoi (ascii to int) Do you realy mean C or C++? This code can't calculate 8+3 = 11 but 5+3 = 8. There is no carry over. int temp; const

Categories : C
Selecting numbers into array and then looping over them
your code fails because you are using clause into. For filling collections use bulk collect into instead. declare type idArray is table of number index by pls_integer; theIdArray idArray; begin select id bulk collect into theIdArray from table_name_here where report_id = 3449; end;

Categories : SQL
Recently Add
Proving optimality for a new algorithm that finds minimum spanning tree
why this assembly piece of code do jmp forever
Find out if segment is fully inside of polygon
Algorithm for coloring a hexagon tile map with minimum distance (3) for reoccurring colors
Sort pairs to be more consecutive
To find three unique numbers whose number of occurrence is even
Dealing with duplication between unit and integration tests
reflection and symmetry in back tracking queens
Big O analysis for method with multiple parameters
Divide Huge Array of Numbers in Buckets
Algorithm to find adjacent cells in a matrix
Why this code gives WA for Petersen Graph(codechef)?
Complexity of this prime number search algorithm
How to detect if a file has changed?
Given string x,y and z. Determine if z is a shuffle
Basic decryption for simple encryption algorithm
An efficient way to assign user_ids to huge dataset under certain conditions
What's a more efficient implementation of this puzzle?
Generating prime numbers in poly-time
What if I do not use G transpose in calculating Strongly Connected Components?
Dividing an array into optimum no of equal sum sublists
Counting derangements
How to iterate through all cases when partitioning objects
Algorithm: How to find closest element, having coordinates and dimension
Developing player rankings with ELO
How to transform two set of discrete points ( vectors ) to help plotting them on a common scale
Heap Sort Space Complexity
complex root finding algorithm
Every possible combination algorithm
RSA Cryptosystem - Retrieve m
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.