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
0 votes
1 answer
25 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
1 vote
2 answers
93 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/...
2 votes
3 answers
186 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
189 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
99 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
385 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
1 answer
78 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 ...
-4 votes
3 answers
160 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
98 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
47 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
84 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
111 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
157 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 ...
  • 147
2 votes
2 answers
84 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
237 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
901 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
419 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
2k 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 ...
  • 121
0 votes
1 answer
55 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
76 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
151 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
78 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
121 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
0 votes
2 answers
106 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
81 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
74 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
67 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
517 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 ...
0 votes
1 answer
157 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. ...
  • 111
0 votes
1 answer
56 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 ...
  • 57
0 votes
2 answers
373 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 ...
  • 145
0 votes
3 answers
197 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
536 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
766 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
196 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:...
3 votes
1 answer
476 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 ...
  • 89
2 votes
2 answers
89 views

Optimal sequence of recipes

I assume the following is/reduces to a known problem, but I haven't been able to find it. I have a sequence of recipes with associated costs. Each recipe converts a set of resources to another set of ...
0 votes
1 answer
547 views

Counting primitive operations on recursive functions

I'm reading Algorithm Design and Applications, by Michael T. Goodrich and Roberto Tamassia, published by Wiley. They teach the concept of primitive operations and how to count then in a given ...
2 votes
1 answer
192 views

Algorithm to find efficient swaps between nodes

I have the following problem: There is an amount of nodes each containing elements of different kinds. Each node has a max amount of elements it can hold. I want to sort the elements between the nodes ...
  • 29
-1 votes
1 answer
89 views

How would I detect a physical attack in video form? [closed]

I hope this question isn't too vague because it's more a discussion than a question. I want to write a code which can detect physical violence in a scene (with the end result being the prediction of ...
1 vote
4 answers
130 views

How to find all combinations of all items in a set? [closed]

Let's say, there's a Product data-model. Product has the attribute - colour, which can, in this case, be red, black, yellow, white, orange. And which in total amounts to 5 different Products. Now I ...
-1 votes
1 answer
158 views

search message in a conversation like messenger

I want to implement a search feature in my chat application like a messenger, skype, whatsapp has done. What they have done is when we search a word then it would not only show the message with that ...
  • 141
0 votes
1 answer
82 views

Understand implementation of exponential moving average (in case of unix load average)

The UNIX load average gives 3 numbers over 1/5/15 minute time intervals. It's supposed to be an indicator of how busy a UNIX machine is. The global load average is an exponentially decaying average of ...
  • 337
-1 votes
1 answer
223 views

Binary search is not fast

I am trying to put in practice an algorithm for binary searching and compare it with linear searching: linear search: public static int linearSearch(ArrayList<Book> books, int searchedId) { ...
  • 128
-3 votes
3 answers
316 views

Find the longest sequence of words where first 2 letters of a word are same as last 2 letters of previous word, sequence ends if word ends with "xx"

This is example of the problem (sequence ends if last 2 letters are "te") lasagna nato top operation online nervous usable levitate -> end word ended with "te" There are around &...
  • 105
4 votes
5 answers
1k views

How can you ensure order of execution in concurrent tasks?

Here is what I am specifically doing: I have a thread-safe queue One 'write' thread constantly writes to the queue with data that comes from another service Multiple 'read' threads take from the ...
0 votes
0 answers
398 views

Calculating time complexity of a code snippet

I am trying to calculate the time complexity of the below code snippet def func() { for(i=1; i<=n; i++) { for(j=1; j<=n; j=j+i) { print("hello") } }...

1
2 3 4 5
44