2022 Developer Survey is open! Take survey.

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.

2,161 questions
Filter by
Sorted by
Tagged with
88 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
1 vote
57 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 ...
51 views

Determing uniformity of (name, value) array [closed]

I have an array of objects that represent some type and its value. I'm looking for an algorithm to determine how random or uniform the array is. For example Item("name": "A", "...
15 views

Reordering algorithm for list in event streaming architecture

I have a specific use case where there are multiple lists which contains list items each having a line number. A user may want to rearrange the list and these changes are published through kafka. We ...
• 99
70 views

Utilizing OOP principles effectively to implement a graph algorithms demo application

I am currently working on writing a C++ app whose purpose it is to essentially "demo" various graph algorithms. At the moment, I have a very bare-bones Graph class working (which utilizes ...
178 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
140 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 ...
• 115
232 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 ...
• 203
90 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
197 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 ...
• 111
49 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 (...
69 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
123 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
73 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
118 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 ...
103 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 ...
• 440
79 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
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
60 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 ...
• 111
436 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 ...
• 141
61 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
50 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 ...
210 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 ...
• 137
174 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 ...
• 383
482 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 ...
331 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, ...
• 1,365
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
151 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:...
322 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 ...
• 113
38 views

Strategies for updating a database with multiple inserts and updates

I have experienced the issue of updating a database considering multiple sources a few times, each time I wonder if there isn't a better way of doing so. Brief example: An application needs to keep ...
• 101
641 views

Could H correctly decide that P never halts?

a practical, answerable problem that is unique to software development Could H be adapted to correctly decide that P never halts? #include <stdint.h> #include <stdio.h> typedef int (*ptr)...
• 85
85 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 ...
• 290
312 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 ...
184 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
88 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 ...
• 11
1 vote
117 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 ...
103 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
72 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
199 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
273 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
653 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 ...
• 457
254 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 vote
204 views

Full, 2-way table synchronization

I need to synchronize tables of data between two different systems. This is a multi-master setup; data can get changed in either system. After a synchronization runs I'd like the data in each table to ...
• 151
1 vote
69 views

Minimize volume of cylinder that covers a clusters, with constraints

A few hours ago I turned in my entrance exam, and i am very curious about this last problem. Given a cluster of stars each x, y, z range between -1000 to 1000. No four stars are coplanar. Find the ...
• 53
62 views

Calculate math function depend on N value [closed]

I have method with the following prototype : R[] = method(k,n) which : n = ordinal value 0 <n <10^9 k = math function depend on n value : i.e n^6 R = array of computed values For example : n = ...
3k views

Pros and cons of representing routes as legs or stops?

What are some pros and cons of representing routes as legs or as stops? A leg is a departure and arrival location, a departure time and a duration (or an arrival time and a duration). A stop is an ...
446 views

What's an edge case in email validation, and algorithms?

An edge case is usually defined as what Wikipedia would say, An edge case is a problem or situation that occurs only at an extreme (maximum or minimum) operating parameter. For example, a stereo ...
• 319
86 views

What design pattern / class / interface should I use for encapsulating a program? [closed]

I am building a chess - related application, and I want to use a pre-compiled program called Stockfish as my chess engine. I am wondering what is the best practice to encapsulate the usage of the ...
• 107
317 views

Possible trajectories with time travel

I'm trying to calculate a trajectory in the presence of time travel. In the following picture, there is a character traveling toward the right in a straight line (like a billiard ball). If the ...
• 127