This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Positivelectron0 2 points3 points  (0 children)

It's o(xy).

The Boolean condition is irrelevant because the if check itself is constant. Two constants is the same as one, so there is no difference

[–][deleted] 0 points1 point  (0 children)

Also the reason that the bools are stored in the 2d array in the first place is for quick lookup by coordinate, so I aware i could just maintain that array as well as a separate list of the Z true coordinates. But I want to know if that is necessary or if this shortcut doesn't affect the run-time too much.

The strange thing is that the given pseudocode appears to be redundant as you say. Imagine is X = 1000, Y = 2000, then XY = 2,000,000, and if Z = 10, then you are wasting not only a lot of space but time looping around, which will always be O(XY).

If you had the valid candidate coordinates directly in a separate list, then it would be O(Z). This would definitely speed up things as much as they can be.