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
1 answer

Modify an Array in-place with prototype

I have created a custom prototype with which to clean up an array so as to remove duplicates and sort it. It worked and looked like this: // given an example array such as this. var names = [ 'Lara', 'Lucy', 'Alexa', 'Vanessa', 'Lucy', 'Brianna',…
WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25
0
votes
1 answer

Filter only part of input using select

Given input like this: { "type": "collection", "foo": "bar", "children": [ { "properties": { "country": "GB" }, "data": "..." }, { "properties": { "country": "PL" }, "data":…
cmbuckley
  • 40,217
  • 9
  • 77
  • 91
0
votes
1 answer

Inplace file encoding

I'm trying to remove duplicates from a csv file with a lot of data. The removal works as intended but I can't seem to figure out how to change encoding on inplace removal. Googling for an answer didn't help. Any of you got a suggestion? This is my…
Rainoa
  • 491
  • 1
  • 4
  • 14
0
votes
0 answers

Assignment by reference and aggregation creates duplicates in data table R

I'm observing a weird behavior with data.table in R and I'm wondering whether this is a bug. Here is the code I use: num_req <- fread("number_requests.csv") num_req[, nrequests := sum(nrequests, na.rm=T), by = list(reqtype, server, timestamp)] The…
user5533186
0
votes
1 answer

Numpy array modification in-place

I have a file that looks like this: row column layer value1 value2 8 454 1 0.000e+0 1.002e+4 8 455 1 0.000e+0 1.001e+4 8 456 1 0.000e+0 1.016e+4 8 457 1 0.000e+0 1.016e+4 . . . I want to do some calculations on the last column…
Bob
  • 443
  • 7
  • 15
0
votes
1 answer

Inplace quick sort

Write a java program to sort a list of integers using ‘in place’ Quicksort algorithm. Generate the list randomly every time using the java.util.Random class. Allow the user to choose the size of the array. The program should display the result of…
theguy0994
  • 27
  • 5
0
votes
0 answers

Why can't we have a mergesort which is in-place? Why can't we have a quicksort which is stable?

I am asking first question because: As we know, we pass first and last index in quicksort which thereafter chooses a pivot, and then does partitioning. What if in mergesort also in Mergesort() method, we pass the first and last index and choose a…
0
votes
3 answers

In place sorting of a string to find out if there are non-unique characters

Recently I came across a problem that asks to find out the non-unique characters in a string without any additional buffer. I interpreted this problem to be an in-place sort of the characters in the string and then iterating through it in order to…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
0
votes
2 answers

In-place for loop to in-place list comprehension

I want to know if there is a way to do the code above as an in-place list comprehension or using a map() (just the for loop): s = [''] * n s[0:k] = ['X'] * k for i in range(k,m): s[i] = foo(s[i-k:i]) If I do: s = [''] * n s[0:k] = ['X'] * k s…
ViniciusArruda
  • 970
  • 12
  • 27
0
votes
0 answers

Why the "in-place constructors" for std::optional are explicit?

The C++17 standard says that the std::in_place constructors of std::optional must be explicit (the same was with boost::optional). But why?? What is the reason behind this? It forbids to have a nice code like this: struct Value { Value(int) {…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
0
votes
2 answers

C++ sort index file in-place (with heapsort)

Updated Question: Hi. I'm trying to sort a index file in-place. The file consits out of 14B data chunks and usually are too large to be loaded into the RAM. The first 8B are the bytes I want to sort after. I implemented a Heapsort algorithm which so…
BrainStone
  • 3,028
  • 6
  • 32
  • 59
0
votes
3 answers

In-place matrix transpose of an M*N matrix in Java not possible?

Is it possible to do in-place matrix transpose of an M*N matrix in Java? I don't think it's possible in Java because, in a 3*5 matrix, the element at 3*5 would ideally be swapped with the element at 5*3, but such a position does not exist. In say,…
saltandwater
  • 791
  • 2
  • 9
  • 25
0
votes
4 answers

Using perl one-liner in perl script

I embedded one perl one-liner in one perl script , the purpose of which is to in-place replace one string with another for each line of the files with name extension .ini, but I found that every file is backed up with .bak. Since in the one-liner, I…
Zii
  • 359
  • 4
  • 10
0
votes
2 answers

Algorithm to sort stack in place

Which sorting algorithms would be good to sort a Stack for space efficiency? I need to sort a stack 'in place.' Also my understanding of 'in place' algorithms was that they don't use any additional data structures - is this correct? I know this is…
user146303
  • 437
  • 1
  • 7
  • 20
0
votes
0 answers

In-place function with return value

I have a function that has a similar behavior of this: void process(const T& input,T& output){ if(&input==&output){ //Alter output directly } else{ output=input; //Deep Copy //Alter output } } Use case 1: T…
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160