Category : optimization

So there’s an algorithm to find the minimum cash flow among people (ie: to find the minimum number of transactions among people ) (source :https://www.geeksforgeeks.org/minimize-cash-flow-among-given-set-friends-borrowed-money/) But the algorithm isn’t completely accurate Consider the following test case : enter image description here When you input this the output says that there must be 5 transactions however ..

Read more

Currently, I am working in C++ on a recursive function that to work, needs to be passed a large array and several constant variables. Here is the structure of the recursion: void recurse_objects(std::vector<Object> &objects, int i, int j, double merge_distance, double size_enclosure, double timestep){ //operations performed //recursion performed if(j+1 < objects.size()){ recurse_objects(objects, i, j+1, merge_distance, ..

Read more

I was thinking about this common situation in C++ code: std::string my_string { "I am just a demostration string" }; std::vector<string> my_vector_of_strings; split_by_delimiter(my_string, ‘ ‘, my_vector_of_strings); Now I can think on the split by delimiter signature in three ways. Way Nº 1: void split_by_delimiter(const std::string& input, char delimiter, std::vector<string>& output) { // construct a stream ..

Read more

I’m getting 98/100 points on the question, so I’m guessing you can do something faster here. The question: John decided to lose weight. He is after days of diet and intensive training, but his weight did not drop evenly, and sometimes it even increased. John wrote down his weight every day and now he wants ..

Read more