Questions tagged [in-place]

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place sorting, in-place merge, etc.

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place , in-place , etc.

379 questions
0
votes
2 answers

Looking for an optimal in-place sorting algorithm

I'm working on an avionics OS (thread layer) and I'm looking for an optimal solution regarding the following (simplified) requirement: "Threads waiting for [various objects] are queued in priority order. For the same priority, threads are also…
0
votes
1 answer

in-place Merge Sort | C#

I have written a program for merge sort and The program works fine until at a point of merging that it doesn't merge properly such as Example: mergesort.in: // all number is one array and not use temp array for sorting 2 //-->This is Array…
mail temp
  • 11
  • 2
0
votes
0 answers

How does Fortran handle augmented assignment of arrays?

I've been working on some code lately that requires me to shift elements in an array left, right, up, and down (depending on an index i). My first thought was to try something like this: subroutine shift(f) real, intent(inout) :: f(0:8, rDim,…
0
votes
1 answer

builtins.permissionerror, but no file is there?

I'm trying to do inplace editing of a file using the fileinput module, but it doesn't seem to want to work. The code I'm using: for line in fileinput.FileInput(complaint_db, inplace=True, backup=(complaint_db + ".backup")): …
Cody Dostal
  • 311
  • 1
  • 3
  • 13
0
votes
1 answer

Trying to Do Quicksort in Place

Seems like it should be pretty straightforward, I've done quick sort before, but I've got some bug in my code, and I can't quite find it. Here's my code: public static void quickSortInPlace(ArrayList numbers, int left, int right) { …
Chris Fretz
  • 387
  • 1
  • 2
  • 10
0
votes
1 answer

Are there any compilers/interpreters that optimize operations not in-place to in-place?

I observe errors like this pretty often when I grade papers (and definitely make them myself on occasion): % any vectorized language, such as MATLAB/Octave/R that supports logical indexing Y = rand(1,10); % random numbers drawn uniformly from the…
0
votes
1 answer

implementing add and iadd for custom class in python?

I am writing a Queue class that wraps list for most of its operations. But I do not sublcass from list, since I do not want to provide all the list API's. I have my code pasted below. The add method seems to work fine, but iadd seems to go wrong,…
brain storm
  • 30,124
  • 69
  • 225
  • 393
0
votes
1 answer

How would I compute a summed area table in Python?

I'm having trouble calculating a summed area table (https://en.wikipedia.org/wiki/Summed_area_table) in Python. The most obvious algorithm involves updating list elements in place while referencing already written elements...but something about the…
Mike S
  • 531
  • 4
  • 14
0
votes
1 answer

What is In-place Algorithm?

Suppose I want remove duplicates from a string. I decided to use a boolean array of length 256 which stores whether a particular character has already occurred or not. I can traverse the string and can remove all duplicate with the help of this…
Abhishek Gupta
  • 1,173
  • 4
  • 12
  • 26
0
votes
2 answers

(Mass) text processing in place (in bash)

How do I process a file or multiple files in place with bash? So: read from file x, do some processing (e.g. search-replace) and write to file x. I know that with sed you can do: sed -i "" "s/original/replacement/g", but sometimes sed doesn't cut it…
pancake
  • 1,923
  • 2
  • 21
  • 42
0
votes
1 answer

Rearranging the contents of a file in place

I'm trying to optimize an archive format which stores data in nodes. As time goes on the container becomes messy (small unusable "free" space nodes accumulate etc). What I'm doing is similar to defragmenting. I already have a list of all the data…
mcu17818
  • 35
  • 1
  • 5
0
votes
2 answers

Detect Non-Mutating Call Statements to Pure Functions in D

I believe D has the potential to add yet another cool feature to its suite of compilers, namely the power to disallow non-side-effect calls to pure functions. For example auto s = "a"; toStringz(a); should error just like a == ""; currently errors…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
0
votes
2 answers

quicksort in place performance (python)

I was asked to write an 'in place' Quicksort version. Created two internal functions - a recursive one and an 'in place sorting' one that chooses random pivot (Question required so), sorts the list in place and returns the pivot's index after…
jizanthapus
  • 121
  • 1
  • 9
0
votes
1 answer

jquery issue copying data from div to input text

I am working on inplace edit for a form. I am having two divs one of them holds display elements and the other holds input form. When you click edit data moves from display div to input form. I see the change when I use val(text), however when I…
Irfan Mulic
  • 1,186
  • 3
  • 14
  • 28
-1
votes
1 answer

Merge Sort - This Recursive Implementation Code Works But I Have A Question About "In-Place"

1 def merge_sort(arr): 2 3 if len(arr) > 1: 4 # Divide the array into two halves 5 mid = len(arr) // 2 6 left_half = arr[:mid] 7 right_half = arr[mid:] 8 9 # Recursively sort the left and right…
rustlecho
  • 33
  • 1
  • 7