Click here to Skip to main content
15,885,914 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Algorithm to count how many "1" in binary o(1) PinPopular
Kornfeld Eliyahu Peter11-Nov-14 2:33
professionalKornfeld Eliyahu Peter11-Nov-14 2:33 
GeneralRe: Algorithm to count how many "1" in binary o(1) Pin
Member 1105509312-Nov-14 1:07
Member 1105509312-Nov-14 1:07 
AnswerRe: Algorithm to count how many "1" in binary o(1) Pin
Richard Deeming11-Nov-14 2:39
mveRichard Deeming11-Nov-14 2:39 
SuggestionRe: Algorithm to count how many "1" in binary o(1) Pin
Kornfeld Eliyahu Peter11-Nov-14 2:43
professionalKornfeld Eliyahu Peter11-Nov-14 2:43 
GeneralRe: Algorithm to count how many "1" in binary o(1) Pin
harold aptroot12-Nov-14 9:36
harold aptroot12-Nov-14 9:36 
AnswerRe: Algorithm to count how many "1" in binary o(1) Pin
Aurimas11-Nov-14 3:27
Aurimas11-Nov-14 3:27 
AnswerRe: Algorithm to count how many "1" in binary o(1) Pin
Joe DiNatale12-Nov-14 8:17
Joe DiNatale12-Nov-14 8:17 
AnswerRe: Algorithm to count how many "1" in binary o(1) Pin
harold aptroot12-Nov-14 10:04
harold aptroot12-Nov-14 10:04 
It depends on your abstract model. With the usual model, you can't do any better than O(n) (so o(n) is not happening, or did you write a lower case o by accident?) - obviously on a plain old Turing machine, you're going to have to read every bit.

But this problem is in NC. You could sum n/2 pairs of bits, then n/4 pairs of "2bit numbers", n/8 pairs of nibbles, etc, and you're done in log n steps, with each step taking logarithmic time too (adders) (sometimes not counted), all with a polynomial number of processing elements.

Similarly in "broadword computing", you would say that you could compute this in O(log n) broadword steps - using the same construction, but now every layer is a couple of steps (mask and add) (with the addition counted as 1 step, instead of as a circuit of depth O(log n))

Practically, on 32bit words but "pretending 32 is not a constant", you can still use the same construction for an O(log n) algorithm possibly with a multiplication trick to do several sums at once (already shown in answers) or lookup tables or (with as much space as you need, you could cheat terribly and compute any mapping from 32bit integers to anything in a single step), if available, the popcnt instruction.
For arrays you could use a pshufb-based trick[^] (pshufb is awesome).
QuestionPYTHON X-AXIS NEAREST POINT Pin
Member 112001292-Nov-14 6:01
Member 112001292-Nov-14 6:01 
AnswerRe: PYTHON X-AXIS NEAREST POINT Pin
Richard MacCutchan2-Nov-14 6:45
mveRichard MacCutchan2-Nov-14 6:45 
GeneralRe: PYTHON X-AXIS NEAREST POINT Pin
Member 112001292-Nov-14 7:14
Member 112001292-Nov-14 7:14 
GeneralRe: PYTHON X-AXIS NEAREST POINT Pin
Richard MacCutchan2-Nov-14 7:24
mveRichard MacCutchan2-Nov-14 7:24 
GeneralRe: PYTHON X-AXIS NEAREST POINT Pin
Albert Holguin5-Nov-14 10:43
professionalAlbert Holguin5-Nov-14 10:43 
GeneralRe: PYTHON X-AXIS NEAREST POINT Pin
CHill602-Nov-14 10:33
mveCHill602-Nov-14 10:33 
GeneralRe: PYTHON X-AXIS NEAREST POINT Pin
Alan Balkany12-Jan-15 9:03
Alan Balkany12-Jan-15 9:03 
Generalfinger search algorithm using data structure in c-program Pin
Member 111385018-Oct-14 5:31
Member 111385018-Oct-14 5:31 
GeneralRe: finger search algorithm using data structure in c-program Pin
Richard MacCutchan8-Oct-14 6:18
mveRichard MacCutchan8-Oct-14 6:18 
GeneralRe: finger search algorithm using data structure in c-program Pin
harold aptroot8-Oct-14 6:37
harold aptroot8-Oct-14 6:37 
GeneralRe: finger search algorithm using data structure in c-program Pin
Member 111385019-Oct-14 3:33
Member 111385019-Oct-14 3:33 
QuestionHow do I manipulate a series of data chart points against their Y-Axis so they are evenly distributed along the axis? Pin
Brady Kelly20-Sep-14 21:39
Brady Kelly20-Sep-14 21:39 
AnswerRe: How do I manipulate a series of data chart points against their Y-Axis so they are evenly distributed along the axis? Pin
Bernhard Hiller21-Sep-14 21:32
Bernhard Hiller21-Sep-14 21:32 
GeneralRe: How do I manipulate a series of data chart points against their Y-Axis so they are evenly distributed along the axis? Pin
Brady Kelly21-Sep-14 22:00
Brady Kelly21-Sep-14 22:00 
GeneralRe: How do I manipulate a series of data chart points against their Y-Axis so they are evenly distributed along the axis? Pin
Bernhard Hiller22-Sep-14 2:03
Bernhard Hiller22-Sep-14 2:03 
QuestionOptimizing memory usage Pin
CDP180214-Sep-14 2:14
CDP180214-Sep-14 2:14 
AnswerRe: Optimizing memory usage Pin
Daniel Pfeffer15-Sep-14 22:41
professionalDaniel Pfeffer15-Sep-14 22:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.