Questions tagged [algorithm]
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
algorithm
120,581
questions
0
votes
0
answers
5
views
Connect random point with non self intersection right angle polylines
I've found some posts and known that radom points could be sorted using a ciecle. Then a non self intersection polyline could be drawn follwoing the sorted point order.
However, in my case, I need ...
0
votes
3
answers
45
views
Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
The code below was taught in my Data Structures and Algorithms class. I am currently reviewing it in preparation for exams. The code, by the lecturer, works well.
#include<iostream>
#define size ...
3
votes
2
answers
93
views
Fastest algorithm for finding first k elements in ordered cross sums of two sorted array
I have two sorted arrays x[] and y[] of floats. The array sizes are n and m respectively.
I need to find the ordered k-th, k << min(m, n), element in the array of cross sums, i.e. s = {x[0] + y[...
0
votes
4
answers
308
views
Maintaining a list in a particular order per user, in Java
I have a list of items and set of users. Users can re-order list items. Each user has his own view for the list, he can arrange the items in his own way. One item can be placed in different locations ...
0
votes
0
answers
12
views
MCNP 6 - Doubts about cells
I'm trying to insert a cylinder in the MCNP 6 code. I believe I defined the surfaces and planes correctly. What could be wrong?
Surfaces:
520 cz 435 1
5020 px 435
6020 px 450
Cells:
81 5 -...
17
votes
19
answers
19k
views
finding common prefix of array of strings
I have an array like this:
$sports = array(
'Softball - Counties',
'Softball - Eastern',
'Softball - North Harbour',
'Softball - South',
'Softball - Western'
);
I would like to find the longest ...
0
votes
1
answer
24
views
Given partially sorted array of type x<y => first apperance of x comes before first of y, sort in average O(n)
i was given an assignment to find an algorithm that takes an array A such that for every x<y we have the first appearance of x coming before the first appearance of y
and sorts it in average time ...
-6
votes
0
answers
43
views
Is there any case in which this code (for a code forces question) does not holdup? [closed]
This is the question I am talking about - 1948 C : Arrow Path
I have written the following code with the logic in mind that when two << sets overlap, we cant reach our destination like
">...
0
votes
1
answer
48
views
Building a School Schedule Generator
I'm trying to develop a school schedule generator in JavaScript for a high school with various subjects, teachers, and classes. The goal is to create a balanced and efficient schedule that minimizes ...
0
votes
3
answers
77
views
Check if Array Is Sorted and Rotated on LeetCode
I am trying to solve LeetCode problem 1752. Check if Array Is Sorted and Rotated:
Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number ...
1
vote
0
answers
37
views
Identify the checksum algorithm
I am trying to reverse-engineering a device (an 8 bit microcontroller) that comunicates with the PC. Each microcontroller has a Serial number of two digits (in decimal) that is used to calculated a ...
0
votes
1
answer
61
views
Processing inputs and report success or error
I have a program that gets requests (an array of strings of size n) from different domains (each input value is called as a domain) for each second i.
Within 5 seconds for a given domain the program ...
0
votes
0
answers
89
views
Champions League Structure Algorithm - how to?
I am trying to understand an issue that arose following the news regarding the new format of the Champions League.
As some of you may know, the new format consists of n=36 teams, divided into p=4 pots....
2
votes
1
answer
50
views
What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
Tests shows that Python's math.gcd is one order faster than naive Euclidean algorithm implementation:
import math
from timeit import default_timer as timer
def gcd(a,b):
while b != 0:
...
0
votes
2
answers
52
views
Minimum window substring not sliding correctly
Problem
Minimum Window Substring
Given two strings s and t of lengths m and n respectively, return the minimum window
substring
of s such that every character in t (including duplicates) is included ...
0
votes
0
answers
15
views
Dots and Boxes with apha-beta pruning
I have a problem with writing a dots and boxes game with alpha-beta pruning. The whole program works, but the algorithm makes some stupid moves sometimes and I think it generates wrong evaluation of ...
1
vote
1
answer
50
views
What is the average and worst-case time complexity of my string searching algorithm?
I created this algorithm to return the index of the first occurrence of a needle in a haystack, or -1 if the needle is not part of the haystack. It passed on LeetCode with a lower-bound of one and an ...
-2
votes
0
answers
68
views
How lambda function in set algorithms in C++ really works?
I am curious about how std algorithms interpret lambda expressions. In below example I am using std::set_difference algorithm for two maps. But the question is common for all algorithms vs comparison ...
0
votes
1
answer
62
views
Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
I want to create a python script, where I have a list of 14 digits and have to find the integer formed by a specific combination of all digits, with the requirement that the number of such ...
3
votes
3
answers
3k
views
General formula to generate a cubic bezier elliptical arc?
How could I implement in C a simple way to generate the 2 missing control points for an elliptic arc given a start and end point? I don't need fancy error estimation, just something that can take ...
1
vote
0
answers
51
views
Algorithm to find neighbours of point by distance with no repeats
I have an array of points formatted like this: [point(0,0), point(0,0), point(0,0)], where 0,0 is replaced with the location of the point. I would like to interconnect them all by distance, for ...
1
vote
5
answers
2k
views
Find longest palindrome by reversing substring
I'm trying to find the longest palindrome. I have two pointers starting at the first letter of the string. For each letter in the outer loop, I go through all the other letters in the inner loop and ...
251
votes
24
answers
244k
views
HSL to RGB color conversion
I am looking for an algorithm to convert between HSL color to RGB.
It seems to me that HSL is not very widely used so I am not having much luck searching for a converter.
0
votes
0
answers
18
views
TC problem 5-2:how to calculate the probability of the indicator random variable?
Here is the original problem:
Now consider a deterministic linear search algorithm, which we refer to as
DETERMINISTIC-SEARCH. Specifically, the algorithm searches 𝐴 for 𝑥 in order,
considering 𝐴[...
0
votes
1
answer
35
views
LCA of a binary tree implemented in Python
I have implemented LCA of a binary tree problem on Leetcode using Python: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
But I got error: TypeError: list indices must be ...
0
votes
0
answers
20
views
Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
I was given a problem that in a connected, weighted graph G = (N, A), find a connected subgraph G_s = (N_s, A_s), where |N_s| <= l and A_s = {(i, j): i \in N_s, j \in N_s, (i, j) \in A}, such that ...
-4
votes
0
answers
32
views
algorithm to solve availability problem base on time line [closed]
I am looking for an algorithm to solve the following problem :
company have fixed number of product x.
the company can rent product x to their customers.
customers can order product x from date time ...
1
vote
1
answer
88
views
Heap sort with multithreading
I need to improve general heap sort using C# multithreading.
I don't have a clear idea about implementation of improvements.
One of the suggestions I got is to separate arrays for N parts and heapsort ...
3
votes
3
answers
2k
views
Most efficient way to find the common prefix of many strings
I need to identify the common prefix among a set of strings. I'm looking for the most efficient method, avoiding character-by-character comparisons.
For example, consider the following set of strings:
...
0
votes
1
answer
21
views
Complexity in Union of disjointed sets with lists
I can't understand why the complexity of a weighted-union of disjointed sets with lists has complexity O(log n) for one Union and O(nlogn) for n unions.
I know that the complexity is based uppon the ...
0
votes
0
answers
35
views
Distribute items evenly into buckets
I’m trying to figure out an algorithm to distribute a set of 20 to 5000 items into a variable number of boxes (2 to 50). Items are identified by a number of properties, and we need to distribute them ...
8
votes
7
answers
6k
views
Finding element nearest to clicked point
Need some help here. I'm a UI designer who isn't good at numbers doing an experimental web form design and I need to know which input element is closest to a clicked point on a web page. I know how to ...
0
votes
0
answers
34
views
Asking code suggestions about data structure and algorithm [closed]
I recently posted an entry here in stackoverflow for a specific problem I've encountered after run and did asked a few. It's a similar one but this time I need your thoughts and comments to atleast ...
-4
votes
0
answers
31
views
Find the largest numer for array after operation [closed]
Tom wants to find the maximum value after doubling each element in an array. He defines f(i) as: the maximum value of the array after doubling the i-th element. Tom expects to find the values of f(1) ...
7
votes
6
answers
172
views
Generating a pseudorandom binary sequence where the same number does not occur more than twice in a row
I want to be able to generate a (pseudo)random binary sequence (for example, a sequence of Rs and Ls like RLLRRLR) which is counterbalanced such that the same item does not occur more than twice in a ...
6
votes
0
answers
195
views
Fast BCD addition
[I do not desire the review of any of the code in this question. Code present is purely for illustration purposes to demonstrate what I have come up with on my own. I am looking for a performance ...
4
votes
2
answers
4k
views
Find the nth count-and-say sequence element
Given a problem, the count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, ...
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is ...
1
vote
2
answers
229
views
Count Subarrays Where Max Element Appears at Least K Times sliding window
Problem
Count Subarrays Where Max Element Appears at Least K Times
You are given an integer array nums and a positive integer k. Return the number of subarrays where the maximum element of nums ...
7
votes
3
answers
1k
views
What is the complexity of HashMap#replace java?
I was wondering what was the complexity of the replace(Key , Value) for a HashMap is.
My initial thoughts are O(1) since it's O(1) to get the value and I can simply replace the value assigned to the ...
0
votes
1
answer
85
views
C++ : Is there an objective universal way to compare the speed of iterative algorithms?
I have a couple of iterative algorithms written in C++ to solve the same problem. When running these algorithms on my machine for very large input sets, it is quite easy to classify them based on the ...
1
vote
1
answer
23
views
Partitions in co-lexicographic order (PARI/GP algorithm without recursion)
It is likely that many of you are familiar with partitions and the ways they are represented (I mean the lexicographic order and its variations).
Here are some partitions in co-lexicographic order:
[1]...
0
votes
0
answers
45
views
Difficulty updating Neo4j LPA community detection to GDS version with graph projections
I'm trying to migrate and upgrade my graph to the latest version of Neo4j and make use of new features and GDS algorithms. The old LPA community detection query was as follows:
CALL algo....
248
votes
18
answers
833k
views
Finding the max/min value in an array of primitives using Java
It's trivial to write a function to determine the min/max value in an array, such as:
/**
*
* @param chars
* @return the max value in the array of chars
*/
private static int maxValue(char[] ...
94
votes
12
answers
105k
views
How do I check if a directed graph is acyclic?
How do I check if a directed graph is acyclic? And how is the algorithm called? I would appreciate a reference.
0
votes
0
answers
16
views
I run Micromouse simulation (mms by Mackorone) using BFS algorithm but it not going well
When I run simulation the mouse (the simulate I use it make by Mackorone) did mark the wall I sure about that but after every loop the maze still not update. First I think the mouse not update the ...
10
votes
3
answers
16k
views
Simple/Basic steganography algorithms and methods
What are the basic and simpliest steganography algorithms and methods?
I mean the steganography applied to images.
How does a simple program that hides data to images work? What are the main ...
0
votes
0
answers
22
views
How to Accurately Count and Time Movement Events in Sensor Data with Python? [closed]
I'm working on a Python project involving sensor data analysis, specifically using accelerometer and gyroscope readings (2 sensors) from a CSV file (3gb).
The goal is to identify movement events based ...
4
votes
3
answers
9k
views
Is there any red black tree or avl tree implementation in c++ standard library?
Just like multiset is a Binary Search Tree implementation in STL, is there any RB tree or AVL tree implementation available?
-2
votes
0
answers
29
views
AVL tree Nth largest operation - How to have all my tests pass? JAVA [closed]
I'm working a school lab assignment and I'm a bit frustrated with AVL trees and I'm a bit lost at how to make all my tests pass for the assignment.I'm supposed to implement ExtendedAVLTree's getNthKey(...
461
votes
14
answers
405k
views
Which cycle detection within a directed graph are more efficient than O(n^2)? [closed]
Is there an algorithm that is more time efficient than O(n^2) for detecting cycles within a directed graph?
I have a directed graph representing a schedule of jobs that need to be executed, a job ...