Questions tagged [algorithms]

In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

Filter by
Sorted by
Tagged with
2 votes
2 answers
145 views

Efficient way to Decouple classes in class design

I am working on a class design question - design a simple grocery store with a self-checkout system I am a beginner After briefly jotting down requirements, I started with the Product class as follows ...
1 vote
1 answer
135 views

How do I narrow down a search space if symmetries are equivalent?

I have an algorithm that runs a search through every combination of a 5x5 grid where each cell can have 3 values, looking to see which combinations meet certain conditions. This gives 3^25 naive ...
  • 391
2 votes
2 answers
129 views

Scheduling Algorithm that Maximizes Gaps Between Participants’ Appearances

I’m currently tackling a programming challenge to schedule a series of “performances” (a set of dancers together on a stage for a period of time, concretely) that each involve a set of “participants” (...
29 votes
7 answers
15k views

How can lossless compression ever exist?

If all data is essentially just a bit string, then all data can be represented as a number. Because a compression algorithm, c(x), must reduce or keep the same length of the input, then the compressed ...
  • 465
0 votes
1 answer
51 views

Generating grid shell coordinates

I need to generate grid shells for a given level. For example, the 2d grid "shell" at level 0 is just the cell (0,0). The level 1 shell would be every cell surrounding (0,0), the level 2 ...
  • 111
2 votes
1 answer
154 views

can partial optimized Bozosort improve speed of sorting?

First of all, I am serious :) You have array of N elements and we can compare them (e.g. operator > works). Let's try to (unstable) sort it using following brand new sorting algorithm. First, ...
  • 295
1 vote
4 answers
231 views

Most efficient way to represent a random ordering of the numbers 0-10

I am currently looking for a way to encode a list of random numbers most efficently (as in length). To be specific, I have an array of 11 numbers containing each number from 0 to 10. The order will be ...
  • 29
0 votes
1 answer
145 views

Many if conditions

I have the code but I want to be pseudo as possible so I learn from other ways as much as possible. So what I am building is web based tool and in one section we have a table. This table renders lines ...
1 vote
1 answer
70 views

Some questions about shortest-path algorithms

I'm trying to understand why anyone would prefer Floyd-Warshal over Dijkstra: Dijkstra gives a correct result, using an understandable system, combined with backtracking. Floyd-Warshal makes an ...
  • 1,701
1 vote
1 answer
107 views

How to implement converters without needing to implement every permutation

I've got this class: [UsedImplicitly] public class ClassicalKeplerian { public ClassicalKeplerian(Angle argumentOfPeriapsis, Angle inclination, UnitFraction eccentricity, Angle ...
2 votes
3 answers
171 views

How can I mix this grid to guarantee it being solvable in X minimum steps?

Note: This question is not about this particular instance of this grid with these exact words, but about any combination of words. I am programming a puzzle game where you have to arrange a grid of ...
0 votes
1 answer
33 views

How to generate a status time duration matrix from Status event log?

I am trying to create a duration matrix, that is, time spent in each status based on the status transition event logs. I have the following event log where status transition time along with old and ...
  • 3
3 votes
4 answers
270 views

Iterating through stacks and queues?

Are stacks and queues allowed to be iterated over, conceptually? It “feels wrong” for some reason but I can't come up with a reason why it would be bad to see through the whole thing that's stacked/...
3 votes
3 answers
192 views

Eliminating combinations based on user input

I am stuck with this particular problem. To give context to the problem, I am developing a mobile app which helps with loading dangerous goods onto a truck. Ignore the size and weight of the dangerous ...
-2 votes
1 answer
200 views

What does the 4th line of this pseudocode mean? [closed]

https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/untangle.html Untangle is a game where you must "untangle" the line so they don't cross. It requires a planar graph, meaning a graph ...
  • 2,266
-4 votes
1 answer
105 views

What is the big O of this algorithm? [duplicate]

I think it's O(m*n) but someone said it's O(n). If you think it's O(n) could you provide an explanation? def convert(self, s: str, numRows: int) -> str: if numRows == 1: return ...
  • 103
0 votes
3 answers
525 views

Why isn't a counter used to avoid nested for loops for index based operations?

Let's assume we have a method that we want to run as fast as possible and it needs to loop on a 2D array, naturally we would do a nested for loop as such: int[][] arr = new int[3][3]; for(int ...
  • 51
1 vote
2 answers
101 views

Dependency resolution of tasks which have crontab information

I want to illustrate my problem statement with a use case. I am building a trading system that acts as a container for deploying trading strategies. The trading strategy comprises dependent tasks. Let'...
0 votes
3 answers
187 views

Prove that an expression can create duplicate

Let's suppose we have this expression: (i % 1000000) * 1000 + ms where i is an always increasing number, and ms is the millisecond part of the current time ( ranging 0..999). So each time we are ...
-3 votes
3 answers
166 views

How to identify whether or not 2 pieces of text are identical? [closed]

Let's say I was to create a scraper. At some point I'll need to come up with algorithm of identifing whether or not a piece of a newly scraped text matches the one that's already in the DB. How would ...
-1 votes
2 answers
111 views

More efficient FIFO inventory calculation?

I am implementing a basic ledger system for which I want to calculate costs based on the FIFO system. Is there a more clever method than an O(n) search? Example Suppose I have two lists of ...
0 votes
1 answer
50 views

I need to choose records from a database to feed to a model for training, but would like to weigh records beforehand. What's a good strategy for this?

I am currently responsible for feeding data to an STT model. My backend is written in Python/Django and is primarily responsible for managing a Postgress database. The database has a table that saves ...
0 votes
0 answers
94 views

Is there a known algorithm for reducing a tree based on a list of its leaves?

For a given, tree-like data structure: - Alan - Barbara - Charlie - Cecil - Brian - Chris - Candice - Cohen - Boromir - Corcoran -...
  • 6,123
-2 votes
2 answers
113 views

Is there a name for a function that outputs more data than was put into it? [closed]

Is there a name for a function that outputs more data than was put into it? For example: let's say I input a one byte value into the function and it returns a three byte value, is there a name for ...
2 votes
2 answers
205 views

Are there typo-tolerance algorithms (as opposed to string similarity)? [closed]

I want to build a search with basic typo tolerance. There are quite a few string similarity algorithms (and implementations for almost all languages I guess). However, humans tend to make some typos ...
  • 157
2 votes
2 answers
89 views

Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?

I work in a production company where my colleagues calculate costprices based on 3D models and their respective operations. Apart from workactivities where a user has to insert an operation time and ...
0 votes
4 answers
265 views

QR order - how to prevent customers from placing an order when they're not on premise [closed]

From my understanding, a QR code is just a static link which get opened up when I scan the code with my phone's camera. Once opened, a customer can keep the browser tab even after he leaves the ...
  • 245
-1 votes
2 answers
1k views

Loop pattern for batch data processing

When processing data sets in batches I usually can think of the following three implementations. Which one do you consider better than the other and why? Notes: The implementation is in C# but the ...
5 votes
1 answer
641 views

Algorithm for floor tiling

I'm looking for an algorithm for placing tiles of different sizes within a complex area (all 2D) as randomly but efficiently as possible. I know the different dimensions of the tiles provided and the ...
0 votes
0 answers
94 views

O(nlogn) + O(logn) =? [duplicate]

So I came upon this time complexity result and I was confused about it, it said that : O(nlogn) + O(logn) =O(log(n+1)) Why is that the case? Shouldn't the result be O(nlogn)?
  • 27
1 vote
3 answers
3k views

Efficient way to merge two similar objects (where only a few fields are different)

I am being challenged (or confused) by this problem: I have a List<CustomObject> in which each element has around 20 fields/attributes. In this list I might have sort of duplicate items. Four ...
  • 159
0 votes
1 answer
56 views

Design a non replayable endpoint for a service

I am trying something out in Springboot and stuck with a weird issue where I want to send some data from my frontend (react app) to backend (SpringBoot) and make that request non replay able by users (...
-2 votes
1 answer
77 views

What does it mean if an algorithm converges?

I’m considering following sentence in a document: Lastly, a xxx algorithm is performed to improve the convergence speed (speed it takes for the individuals in the population to get closer to the ...
1 vote
2 answers
175 views

Algorithm: Given an array inside an array of arrays, how to find subsets of elements that make that array unique or with the smallest match count?

Given [ ["hahaha", "hehehe", "hihihi", "huhuhu"], ["hehe","hehehe","hihi","hihihi"], ["huhuhu","juju"...
  • 159
1 vote
0 answers
81 views

Is there an optimal strategy for placing rectangles inside a window without overlapping?

My specific problem is that I have a vertically scrollable window into which I need to place rectangular <div> elements that are locked horizontally and have different widths and heights. ...
  • 111
-1 votes
2 answers
124 views

How to measure how "changy" something is? [closed]

I need to think of a way to model how one thing is more "changy" than another. Say I need to index a news website's different news sections with some web crawler. I want to prioritise ...
user avatar
1 vote
2 answers
113 views

How to convert vehicle schedule time window calculation algorithm to FP

I am working on an algorithm that optimizes utilitization of a vehicle. What I have is a list of paths the vehicle is planned to take and between which times (time windows) it has to be at a certain ...
0 votes
0 answers
82 views

Designing algorithm to use available space in signup form in most efficient manner

The case is that I have a signup form for students where they can choose between different lessons in multiple rounds. Each lesson in each round has a defined available space. The total amount of ...
1 vote
1 answer
75 views

Algorithm for multi-dimensional maximisation

I would like to devise an algorithm that given: An array of dishes with macronutrient information (proteins, fats and carbohydrates, in grams), constrained to a maximum of around 200 items. A desired ...
  • 119
0 votes
1 answer
68 views

Ranking results from a Question and Answer game

I have a question and answer trivia game app which randomly picks questions from a database and prompts the user to answer the question correctly. The total number of correct answers, the total number ...
3 votes
3 answers
574 views

What algorithm should I use for this game problem?

I have a grid-based puzzle game, that is based on states. I need an algorithm that can find a solution for each game level. A game level starts in a specific state and ends in a unique, well-known ...
1 vote
1 answer
298 views

Efficient way to separate text file to header, tail lines and the leftover in between

I'm looking for a more efficient algorithm for the following problem: The input of the algorithm is a text file and two non-negative integer numbers - the number of headers and the number of tails. ...
  • 121
0 votes
1 answer
57 views

The correct relationship between unit and end to end tests

I am writing tests for an algorithm that is built up of several consecutive stages. Each such stage has its own set of unit tests. I want to check that the whole algorithm performs as expected, but am ...
  • 77
1 vote
2 answers
487 views

Finding similar objects in a large data set

I have a large collection of (C#) objects and these objects have a large number of properties, mostly strings and numbers. This collection is stored in a database. When a new object is about to be ...
  • 163
0 votes
3 answers
216 views

How to deal with forward references in a compiler?

I'm creating a very simple compiler PoC that only has Procedures Calls to procedures. The syntax of the language is really simple: Main { Call("Proc1"); } Proc1 { // Empty } I ...
  • 403
7 votes
2 answers
599 views

Why are sort() and reverse() JavaScript methods in-place?

Which are the technical reasons/considerations for the sort() and reverse() JavaScript array methods to be in-place operations instead of returning a new array without modifying the original one, like ...
2 votes
1 answer
1k views

Multiple if condition optimization

Often I find conditional statements such as: if (life_max < max): if (expand): do life_max = max else: if (life_max > max) and not (expand): do life_max = max; Although readable, ...
2 votes
2 answers
2k views

How can the size of a heap be less than its length?

I am studying the heap sort algorithm from the book Introduction to Algorithms by Thomas H. Corman. It differentiates between the length of the array, A.length, as "the number of elements in the ...
1 vote
2 answers
239 views

Is there a simple algorithm for generating unit tests given a function's code? [closed]

Given the abstract syntax tree (AST) of each line of a function's code, I am asked to generate code for that function's corresponding unit tests, similar to what Microsoft's IntelliTest tool does here:...
4 votes
1 answer
562 views

What is the most suitable data structure for IPv4 addresses with intersecting ranges?

Mostly in all routers and operating systems the Longest Prefix Match algorithm is used for searching the trie of IPv4 addresses. Packet filters like Iptables don't need some special data structure for ...
  • 99

1
2 3 4 5
44