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,529
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
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 -...
-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
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 ...
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
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 ...
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 ...
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
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 ...
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
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 ...
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 ...
-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
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 ...
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 ...
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 ...
-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) ...
-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
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 ...
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 ...
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
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 ...
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 ...
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
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 ...
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 ...
0
votes
0
answers
26
views
Are there techniques to mathematically compute the amount of searching in greedy graph searching? [closed]
I have developed a greedy graph search algorithm and made some optimizations. However, its performance varies depending on the parameters I use. I am keen to create a module that can compute the ...
-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(...
-4
votes
0
answers
68
views
Why does the map size change? [closed]
class Solution {
public:
bool checkInclusion(string s1, string s2) {
int m = s1.size();
int n = s2.size();
unordered_map<char, int> s1_freq;
unordered_map<char, int> ...
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
0
answers
39
views
Checking if Hamiltonian path exists
I am trying so solve interesting algorithmic problem, I would say, and after unsuccessfully trying bunch of various stuff, I am looking for help here.
So here is the assignment:
Suppose we have ...
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 ...
-1
votes
0
answers
27
views
Weighted Graphs [closed]
I was wondering what is the problem in the code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#define MAX_ROOMS 100 // Maximum number of ...
-3
votes
0
answers
31
views
find best distance in given points [closed]
I have a sequence of azimuth angles ranging from 0 to 180, then from -170 to -10, totaling 36 angles. In some cases, certain azimuth angles may be unavailable. I aim to choose N points from the ...
0
votes
0
answers
21
views
How to set weight of enpoints durin laod balancing in wso2 manager [closed]
enter image description hereI have set up weighted round robin as algorithm but i can't seem to set weight to different endpoints in apim publisher, default weight of 1 is implemented how can i set ...
0
votes
1
answer
37
views
How to find big o of dependent loops and recursive functions?
I want to be able to measure any code snippet time complexity. Is there a general rule or step by step approach to measure any big o (besides dominant term, removing constants and factors)? What math ...
-1
votes
0
answers
36
views
Time Limit Exceeded, Leetcode problem, 3Sum, 308 / 313 testcases passed, Why is it slow? Python
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not ...
0
votes
1
answer
70
views
How do I find all non-overlapping combinations
Given a straight line of length N, the index position starts from 1 not 0.
Points are marked on this line using startIndex and endIndex pair.
Calculate the total number of non-intersecting pairs
...
-2
votes
0
answers
28
views
How can I efficiently find two numbers in an array that sum up to a given target without using the same element twice? [closed]
You are given a list of integers representing the height of people standing in a queue. Each person wears a hat with a unique color. However, due to a recent gust of wind, the hats have been blown ...
-1
votes
3
answers
87
views
How to test that a specific sorting algorithm was actually implemented?
I'm looking for an automated test to validate that merge sort was actually implemented. I know how to validate that a sorting algorithm actually sorts, but how do I validate that merge sort was used ...
0
votes
0
answers
14
views
Understanding Unary PCP Reduction to a Matching Problem (UPCP)
this the question
I'm trying to understand the relationship between the Post Correspondence Problem (PCP) and a related problem called Unary PCP (UPCP). In UPCP, we are given dominoes of the form (d_i ...
1
vote
1
answer
33
views
Is there any efficient algorithm for updating ordered data in DRF?
I had a problem with algorithm which updates ordered data.
For example, I have one model called Route.
class Route(models.Model):
order = models.IntegerField(null=False, blank=False)
memo = ...
-3
votes
1
answer
52
views
Sliding window python [closed]
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
A subarray is a contiguous non-empty sequence of elements within an array. I would like to ...
-4
votes
0
answers
38
views
Total combinations to reach 100 Step, taking either 1 step at a time OR 2 steps at a time , starting from step 1 [closed]
There are 100 steps, in which i can either take 1 step at a time or 2 steps at a time,
so in total, how many combinations are possible to reach step 100 , if starting from step 1
1
vote
3
answers
86
views
Creating a more efficient algorithm for taking the third largest difference an element has with another element in the list in python
This is a programming problem activity from my university. I am going to modify the problem to avoid plagiarism.
Let's say you have n people in a group. For each person, we number them from 0 to n−1. ...
-3
votes
0
answers
20
views
how to think to write algorithm steps to write the code [closed]
How to think to write algorithm steps to write the code?
Can anyone suggest how to think and better approach good steps to solve the particular problem and what are steps we will need to follow to ...
-3
votes
0
answers
32
views
Making a private key encryption algorithm and getting the error, "IndexError: list index out of range." [closed]
I am attempting to make an algorithm to decrypt PKE and I have hit a wall. My IDE keeps giving the error, "IndexError: list index out of range."
I tried looking that error up, and it pointed ...
0
votes
3
answers
60
views
Efficient shift and roll in numpy without pd.Series
Consider the code below which gives the wanted output:
import numpy as np
import pandas as pd
sumvalues = 2
touchdown = 3
arr = np.array([1, 2, 3, 4, 5, 6, 7])
series = pd.Series(arr)
shifted = pd....