DEV Community

loading...

Discussion on: 📌How to reverse an array?📌

Collapse
mallockey profile image
Josh Melo

Nice post! Question though, wouldn't the time complexity be O(n / 2 ) since it only goes through half the length of the array?

Collapse
kaiwalyakoparkar profile image
Kaiwalya Koparkar Author

That's true but if you simplify (n/2) so it becomes (n^-2). As power is negative we neglect it. and hence the total complexity becomes O(n). What are your views?