Search code examples
algorithmmemory-managementtimesplitcomplexity-theory

What is the time complexity of splitting an array in 2


What is the time complexity of splitting an array in 2; Is it O(1) because it is down directly by manipulating memory or O(N) as it has to loop through the entire array. And if the last is correct, is there a way to manipulate directly to memory?


Solution

  • Depends how you split it.

    If you do it by copying the halves of the array its O(N)

    If you do it by using a pointer like int* x = &a[n/2]; then its O(1)