Previous | Next --- Slide 26 of 63
Back to Lecture Thumbnails
yey1

So this algorithm requires n is power of 2, otherwise the result is not correct. Is it possible to make this algorithm able to handle all cases(n != 2^k)?

carnegieigenrac

@yey1 If n isn't a power of 2, the algorithm can still be used by extending the array to the next power of two and filling in the new spaces with the identity element. This would give the same result as before as the new elements in the array wouldn't affect any of the old results.