I'm reading Cracking the Coding Interview, 6th Ed. and I stumbled upon the same problem 2 times across the book but with 2 different given solutions. Which is puzzling.
I'm referring to calculating the amortised time to insert X elements in an expanding array. First time on page 43. The solution says X insertions take O(2X) times. Second time on page 89 where it says it takes O(X) times.
The difference is that in the first occurrence the author is considering the following sequence of insertions:
X + X/2 + X/4 + X/8… + 1
Which sums up to 2X correctly.
The second time just
X/2 + X/4 + X/8... + 1
Which sums up to X.
Why is she considering X in the first case and not in the second?