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
0 answers
19 views

Load files files among servers

Let's say there are N servers S1, S2.... SN They are keeping x1, x2, ... xn total data files on disk, and out of which writable files are y1, y2,...yn respectively. The task is to balance out the ...
Novice User's user avatar
-2 votes
4 answers
221 views

Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general

On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
jason's user avatar
  • 15
2 votes
3 answers
125 views

Please help with this maze of fencepost problems ( vector across window )

I'm trying to implement LOGO with a physical turtle. I got all the basics done, but I got completely sunk when implementing the "Window" mode. Original LOGO had 3 modes: "Border" - ...
SF.'s user avatar
  • 5,116
1 vote
0 answers
40 views

Why must a safe configuration be reached in `n^2 + n` rounds in Dijkstra's Self-stabilizing mutual exclusion algorithm? [migrated]

In the book Self-Stabilization (Dolev, 2000) the author provides a proof (p.19) of Dijkstra's self-stabilizing mutual exclusion algorithm. An excerpt of the book showing the proof is found below. At ...
KSI's user avatar
  • 11
1 vote
0 answers
120 views

Ideal Profits in companies in Perfect Binary Search tree

I'm trying to solve the following problems here: In the X world, companies have a hierarchical structure to form a large binary tree network (can be assumed to be a perfect binary tree). Thus every ...
driver's user avatar
  • 111
-1 votes
0 answers
20 views

Scheduling/clustering problem minimizing distances

I have a set of teams with corresponding locations (not nec. unique), and I want to group them into groups of four, assign one member of each group as host, and I want to do that for some number k (...
Amueller's user avatar
3 votes
1 answer
207 views

Simulated Annealing

In relation to another question I had, I have been researching Simulated Annealing. The general example used with this algorithm is the traveling salesman example. I have been testing the code ...
wforl's user avatar
  • 159
1 vote
3 answers
122 views

Graph layout positioning

Given a graph layout like the following image, where the layers/rows (y coordinate) and ordering of nodes within each layer have already been computed, what algorithm can I use to make it look "...
wforl's user avatar
  • 159
-1 votes
1 answer
126 views

Optimizing algorithm for categorizing pictures of Magic the Gathering Cards by type? [closed]

I'm making a piece of software that is able to recognize Magic the Gathering Cards from a picture or the actual camera. The codebase scans for rectangular shapes (cards) in an image and calculates ...
Martin's user avatar
  • 21
-3 votes
3 answers
138 views

NP-complete problem (subset sum) featured in Netflix series "Suits" S1 E8? [closed]

In the Netflix series Suits, Season 1, Episode 8 (Identity Crisis), the legal team, with the help of a hacker, is tasked with proving that a business magnate embezzled funds, splitting them and ...
Cade Bryant's user avatar
-3 votes
1 answer
113 views

How to find the shortest common superstring [closed]

Problem statement: You are given an array of strings. Each element (string) of array is of size 2. You are supposed to find the length of shortest possible string such that every element of the array ...
letitbesb's user avatar
6 votes
7 answers
7k views

How to avoid repeating "a==b" when comparing "condition a" and then "condition b" and then...?

For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int ...
wcminipgasker2023's user avatar
0 votes
3 answers
222 views

Mapping a range of values to a single value

So I have this problem where a specific ValuesA enum value is to be mapped to a respective ValuesB enum value, The trick is there can be multiple ValuesA mapping to a single ValuesB enum. So for the ...
xyf's user avatar
  • 109
0 votes
1 answer
77 views

Monte Carlo Tree Search with Cops and Robber Game

I recently started trying to implement a monte carlo tree search based algorithm for playing cops and robber. The game is based on the cops and robber game and is played on an arbitrary graph (not ...
Raoul Luqué's user avatar
0 votes
1 answer
103 views

Multi dimensional lookups

I am looking to see if there is a general design pattern or strategy to handle a use case I see often in our codebases. My best attempt to generalize this use case is "Map permutations of n ...
jason.zissman's user avatar
3 votes
1 answer
289 views

Algorithms: How do I sum O(n) and O(mlog(n)) together?

I'm doing a running time analysis using the aggregate method and I'm a bit confused about what would be the result in this case. I have some intuition in inferring that it would be O(mlog(n)) but I'm ...
neo's user avatar
  • 51
-1 votes
2 answers
266 views

what algorithm does the malloc function in the c language standard library use? And why it so fast?

Based on the data structure of the AVL tree, I implemented a memory manager that does the best matching according to the size. I originally thought that the speed would be fast and the length of the ...
CukiPid's user avatar
  • 11
3 votes
2 answers
215 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 ...
darklion's user avatar
1 vote
1 answer
156 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 ...
Jason C's user avatar
  • 453
2 votes
2 answers
235 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” (...
Daniel Rozeboom's user avatar
29 votes
7 answers
16k 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 ...
Mercury's user avatar
  • 465
0 votes
1 answer
65 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 ...
xytor's user avatar
  • 111
2 votes
1 answer
163 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, ...
Nick's user avatar
  • 295
1 vote
4 answers
250 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 ...
DK13's user avatar
  • 29
0 votes
1 answer
156 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 ...
Codemenot's user avatar
1 vote
1 answer
80 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 ...
Dominique's user avatar
  • 1,705
0 votes
1 answer
117 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 ...
ScottishTapWater's user avatar
1 vote
3 answers
179 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 ...
Florian Walther's user avatar
0 votes
1 answer
34 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 ...
Vivek's user avatar
  • 3
3 votes
4 answers
387 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/...
Lazar Ljubenović's user avatar
2 votes
3 answers
195 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 ...
Saul Goodman's user avatar
-4 votes
1 answer
111 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 ...
james pow's user avatar
  • 103
0 votes
3 answers
613 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 ...
Yoh's user avatar
  • 51
1 vote
2 answers
131 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'...
m0hithreddy's user avatar
0 votes
3 answers
188 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 ...
Felice Pollano's user avatar
-4 votes
3 answers
173 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 ...
Nicholas E. Harding's user avatar
-1 votes
2 answers
176 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 ...
poundifdef's user avatar
0 votes
1 answer
83 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 ...
John Lexus's user avatar
0 votes
0 answers
114 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 -...
StuperUser's user avatar
  • 6,133
-2 votes
2 answers
120 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 ...
SuperSim135's user avatar
2 votes
2 answers
370 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 ...
cis's user avatar
  • 255
2 votes
2 answers
107 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 ...
Jannick Breunis's user avatar
0 votes
4 answers
348 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 ...
JamesBoyZ's user avatar
  • 245
-1 votes
2 answers
3k 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 ...
Botond Botos's user avatar
6 votes
1 answer
1k 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 ...
Component 10's user avatar
0 votes
0 answers
96 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)?
blake 's user avatar
  • 27
1 vote
3 answers
5k 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 ...
kosa's user avatar
  • 159
0 votes
1 answer
61 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 (...
Abhijeet Shukla's user avatar
-1 votes
1 answer
81 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 ...
Msamericana1's user avatar
1 vote
2 answers
220 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"...
giorgio79's user avatar
  • 159

1
2 3 4 5
44