Questions tagged [in-place]

When something happens with only a constant amount of extra space, it is said to happen in-place.

11 questions
Filter by
Sorted by
Tagged with
60 views

In-place matrix transposition using rotations

Some time ago I invented an algorithm for in-place matrix transposition using rotations. A matrix of size N×M is represented as a one-dimensional array of size N*M, which is also the future storage ...
33 views

In-place patching of diff between two sets?

For two ordered sets of keys Paul Heckel's diffing algorithm generates the necessary actions to transform, or patch, one set to the other. I am asking how you'd do the patching without keeping a copy ...
343 views

Interleaving first and second half of an array of even length in place

If A is an array with the following elements: $$a_1,a_2,...,a_n,b_1,b_2,...,b_n$$ How to shuffle A to form: $$a_1,b_1,a_2,b_2,...,a_n,b_n$$ with minimal swaps and using no additional space? I ...
589 views

Sorting in place & stable in linear time

Given an array with only 0 & 1. Can we have an algorithm which has all the following desirable characteristics- The algorithm runs in $O(n)$ time. The algorithm is stable. The algorithm sorts ...
154 views

Inplace sorting of variable length records

Is there an in-place algorithm for sorting variable length records? For example a vector of arbitrary length strings. Most provided in-place algorithms assume that you can switch two elements ...
4k views

What is the most efficient constant-space sorting algorithm?

I'm looking for a sorting algorithm for int arrays that doesn't allocate any byte other than the size of the array, and is limited to two instructions: SWAP: swap the next index with the current one; ...
5k views

Merge two sorted arrays without using additional memory

We have two sorted arrays of integers. Without using additional memory we need to merge these two arrays such that the smallest numbers are in the 1st array and the remaining numbers are in the ...
225 views

Shuffling a file on disk using $O(\log n)$ memory

How do you shuffle the bytes in a file (bytes for simplicity) on disk with a small, $O(\log n)$, amount of memory and preferably in-place? If the file had size $2^m$, then we can first split the file ...
365 views

Choosing an element from a set satisfying a predicate uniformly at random in $O(1)$ space

We are given a set of objects, say integers, $S$. In addition, we are given a predicate $P$, for example $P(i): \Leftrightarrow i \geq 0$. We don't know in advance how many elements of $S$ satisfy the ...
Worst case $O(n \ln n)$ in place stable sort?
I am having trouble finding good resources that give a worst case $O(n \ln n)$ in place stable sorting algorithm. Does anyone know of any good resources? Just a reminder, in place means it uses the ...
You are given an array of $2n$ elements $$a_1, a_2, \dots, a_n, b_1, b_2, \dots b_n$$ The task is to interleave the array, using an in-place algorithm such that the resulting array looks like ...
{"ft_lang_label":"__label__en","ft_lang_prob":0.86243576,"math_prob":0.98875225,"size":3229,"snap":"2019-43-2019-47","text_gpt3_token_len":812,"char_repetition_ratio":0.13643411,"word_repetition_ratio":0.010830325,"special_character_ratio":0.2573552,"punctuation_ratio":0.14732143,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9944083,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-17T01:26:28Z\",\"WARC-Record-ID\":\"<urn:uuid:d8f83dc6-50e4-4af2-8892-b93f598d3a9a>\",\"Content-Length\":\"144119\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:325aa168-4ad1-4f7d-a80f-cafc8ded1537>\",\"WARC-Concurrent-To\":\"<urn:uuid:8fae4ab1-c4f2-4bb3-bfbf-88174789829e>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/tagged/in-place\",\"WARC-Payload-Digest\":\"sha1:5MPK7FYGEQMCPXLY44IYGQM4I6FU4TUZ\",\"WARC-Block-Digest\":\"sha1:KN2PGVGX67KZWZDCVQOSOM544NYLCLDU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570986672431.45_warc_CC-MAIN-20191016235542-20191017023042-00417.warc.gz\"}"}