3 ms·
An algorithm might be: Take an array of integers as input and return their sum. Returning or adding integers does not require allocating memory.
by aliceryhl 6y ago
An algorithm might be: Take an array of integers as input and return their sum. Returning or adding integers does not require allocating memory.
- Frost1x 6y agoI presume you mean allocating new memory. You could sum an array and keep track of state/store cumulative sum in the existing array i.e. in-place algorithmic approaches: https://en.m.wikipedia.org/wiki/In-place_algorithm https://en.m.wikipedia.org/wiki/In-place_algorithm You still have to have memory and use it though, somewhere.
- aliceryhl 6y agoYes of course. If the algorithm operates on existing allocations, then it doesn't allocate any memory. Similarly the algorithm might operate on a fixed set of integers, which would not require allocations at all, even in Java.