Re:A Google Interviewing Story
by huhtenberg on Friday November 19, 2010 @08:18PM
(#1923501)
It would depend on the hardware used.
Standard counter-intuitive example (from the game development domain) is how to check if an array of integers has a zero in it. The answer, when all things are considered, is to scan through an entire array making a simple arithmetic for each item and one comparison at the end rather than compare each element.
The same may happen with your example. Filling up 32-bit mask might be more expensive than to flip an element in a boolean array. That's not even considering that the array option allows for early termination of the second loop.
Re:A Google Interviewing Story
by Oxryly on Friday November 19, 2010 @08:40PM
(#1923558)
Early termination is the biggest advantage of the array version. The 32-bit mask is probably the fastest possibility since it will reside in a register.
Standard counter-intuitive example (from the game development domain) is how to check if an array of integers has a zero in it. The answer, when all things are considered, is to scan through an entire array making a simple arithmetic for each item and one comparison at the end rather than compare each element.
The same may happen with your example. Filling up 32-bit mask might be more expensive than to flip an element in a boolean array. That's not even considering that the array option allows for early termination of the second loop.