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.
117,847
questions
0
votes
0
answers
6
views
Assign an ID to elemets of a python list to find a specific element later using that ID
I work on a project in which my laptop sends commands to a robot using a radio telemetry module and the robot does something according to the type of commands. After completing the task, the robot ...
2
votes
2
answers
48
views
Search is a string contains a substring in Javascript (partial search)
Yes I know we can use indexOf and includes or a regular expression to find weather a string is present in another string.
But we have a different requirement. We would like indexOf or includes ...
0
votes
0
answers
7
views
MILP - How to set variable to be absolute value of other variable
In a Milp, given an integer variable x, I would like to define a variable y which will be the absolute value of x.
y = |x|
x is bounded between [M, -M].
Is it even possible?
Thank you!
0
votes
1
answer
25
views
Solving Robozzle puzzle
I have a problem with solving the "Dispersion V2" puzzle on robozzle.com:
The puzzle has a robot that can be moved and turned with a program. The goal of the puzzle is to have the robot ...
-2
votes
1
answer
30
views
Recurrence Equation Simplification
Given a pseudocode like this:
int algorithm(int[] a, i, j)
if i > j
return 0
int n = j - i + 1
int d = n / 4
algorithm(a, i, i+3d-1)
algorithm(a, i+d, j)
return 1 ...
1
vote
0
answers
27
views
An undirected graph containing n (n<=100) nodes is divided into k complete graphs. Is there a solution to make the number of k as small as possible?
Input
The first line indicates that there will be m lines of input next, and each line indicates that node A is connected to node B.
Output
The minimum number of complete subgraphs k is output.
...
-1
votes
0
answers
32
views
How to make this program terminate to complete the algorithmix toolbox assignment?
I am working on coursera Algorithmic Toolbox course. I face a problem in the code, trying to run it and it doesn't terminate.
The main function as follows:
if __name__ == '__main__':
data = list(...
-8
votes
0
answers
48
views
Merge two arrays, with complicated order [closed]
How do I merge two arrays, in this order
const arr1 = [1,2,3,4,5]
const arr2 = [2,6,7,3,8,9]
To this:
const result = [1,2,6,7,3,8,9,4,5]
3
votes
1
answer
47
views
Algorithims for Selecting Unique Combinations
I'm looking for algorithims or methods that would be useful for solving this problem:
Say I have a dataframe:
x y Bin1 Bin2 Bin3
153.0303 -27.17894 10 6 5 ...
-1
votes
2
answers
90
views
What is the growth of this program? ChatGPT is wrong, right?
This is definitely a stupid, and simple question. But for some reason this is bugging me. This is not a homework question--insofar, as I am not solving a homework question for my own work. I am a ...
0
votes
0
answers
13
views
Seriability Test Algorithm in the R LANGUAGE
The specification is:
Create a node for each T of the S schedule
Edge Ti -> Tj for each r(x) in Tj after w(x) in Ti
Edge Ti -> Tj for each w(x) in Tj after r(x) in Ti
Edge Ti -> Tj for each ...
2
votes
0
answers
83
views
Is there an algorithm for choosing which unknown points to input based on maximising a function of a row/column?
Is there an efficient algorithm for a small sparse table which will fill up with values based on selecting the unknown data points that has greatest POTENTIAL maximum scalar value taken as a function ...
0
votes
1
answer
47
views
Most optimal way of writing sparse array not using any libraries nor hash table
You are given a large array where the vast majority of the elements are zero. Create a class that can store these elements more space efficiently. Your class must have the following methods:
...
0
votes
1
answer
48
views
How do I use if statement to return -1 if what I am searching for is not in my array?
I need to return the index place of my target and if my target is not present in my nums array I need to return -1. When I run my code it is like only my second return works?
function search(nums, ...
0
votes
0
answers
24
views
Weighted job scheduling in O(nlog(n), but with partial shifts allowed
If you are not familiar with the standard weighted job scheduling problem, here it is (along with a description of a solution with an asymptotic runtime of n*logn).
I’m wondering though, if you ...
0
votes
0
answers
22
views
Zmq pub-sub pattern does the publisher need to upload multiple times in n*O(m) messages to subscribers?
Hello all assuming that we have a pub-sub pattern in zmq with many subscribers, one publisher, and a message of 3GB. My question is does the publisher send n x O(m) where n is the number of ...
1
vote
1
answer
85
views
Find missing arrithmetic operations in arithmetic expression
I was given the following task:
Richard likes to ask his classmates questions like the following:
4 x 4 x 3 = 13
In order to solve this task, his classmates have to fill in the missing arithemtic ...
-2
votes
1
answer
45
views
Extract the sub elements >=2 into another list and delete them from the nested list
So I have a nested list
l = [[116, 125, 118], [119], [120, 121, 131, 123], [120, 121, 123, 111], [122, 117], [124, 125, 126, 127], [128, 115], [129, 115], [130], [133], [136, 139, 134, 131, 123], [...
2
votes
1
answer
49
views
Trying to remove obsolete points from a very long line in Python
Problem description:
I have a large array of 2D points (>150k) that represent an edge of a figure. The point coordinates are all integer (minimum distance between points = 1). Plotting the edge ...
0
votes
1
answer
28
views
Algorithm to find the optimal items to buy to reach certain criteria
We have n item types that we can buy (we have unlimited stock of each):
{ p:100.0f, a:10.0f, b:20.0f }
{ p:77.0f, a:20.0f, b:10.0f }
{ p:55.0f, a:0.0f, b:12.0f }
let a and b be some random properties ...
0
votes
2
answers
46
views
Java JSON tree structure creation from existing data
Need your help with creating a JSON tree structure from available data. This is what is available with me right now,
The same data in json format is as below,
{
"employees": [
{
"empId": 1,
...
-1
votes
0
answers
20
views
How to search efficiently an image location from a list of directories by giving image name? [closed]
I have a list of directories (I don't know the exact count). I have an array list of image names. I want to find the exact location of these images among these directories efficiently by using a Java ...
2
votes
1
answer
38
views
Number of Palindromic Substrings- error in dynamic programming
I'm trying to solve the number of palindromic substrings problem using DP.
The problem requires us to find the number of palindromic substrings in a string.
My current code is as follows:
def ...
0
votes
0
answers
40
views
Reduced Row Echelon Implementation in Java
Via this gist, I am trying to build a custom rref calculator thus I have
edie-zhou's implementation of this rref pseudocode asper:
public static void main(String[] args){
double[][] rref;
...
0
votes
0
answers
14
views
How to find a safer limit of CPU and MEMORY of a EC2 based on previous utilisation
I am running a EC2 workload for 60 days. I do see my work load have max utilization let say 90% and average utilization let us say 30%. Though max is 90% but observed during 60 days hardly 3/4 time ...
1
vote
2
answers
79
views
find if a number set has intersection with another set
background:
the service port number in firewall access-list has different format like:
single number: 22,443
range:10000-65535
I am working around some analysis to the firewall, need to find if a ...
0
votes
0
answers
29
views
Removing certain percentage of data from a list
I have many cluster of 3D points. Each cluster has an id. From every id cluster(example 1), i am trying to remove the cluster that is the most farthest in terms of distancefrom the heighest point in ...
-1
votes
1
answer
65
views
array cycle leaving the last element [closed]
I want this algorithm to work by moving each element of the array to right side and the last element to the first.
this is my program
int* cycle(int* arr, int n) {
//int temp = arr[n-1];
int* ...
0
votes
1
answer
67
views
Time out on Leetcode 160 Intersection of Two Linked Lists
I am trying to solve Leetcode 160. Intersection of Two Linked Lists:
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked ...
0
votes
1
answer
60
views
Improving our algorithm with SQLite vs storing everything in memory
The problem...I’m trying to figure out a way to make our algorithm faster.
Our algorithm...is written in C and runs on an embedded Linux system with little memory and a lackluster CPU. The entire ...
-1
votes
2
answers
52
views
Dumb algorithm-related question: how do I calculate a hit/miss cache ratio taking time into account
All right, I'm sure this is a duplicate of a question somewhere (I refuse to believe I'm the only idiot struggling with this), but I can't find it.
It seems so easy on paper, and yet here am I writing ...
1
vote
3
answers
72
views
Efficient pythonic way to compute the difference between the max and min elements of each tuple in a large list of tuples
Using the following code, I am trying to calculate the difference between the max and min elements of each tuple in a large list of tuples and store the results in a list. However, the code runs for ...
0
votes
2
answers
105
views
Is it possible to increase the precision of a floating point sum of a harmonic series in C past 10^-8?
Given a harmonic series 1 - 1/2 + 1/3 - 1/4... = ln(2), is it possible to get a value of 0.69314718056 using only float values and using only basic operations (+,-,*,/). Are there any algorithms which ...
-2
votes
0
answers
25
views
sum of each subarray and return the max value in javascript [duplicate]
I want to return the some of each subarray and compare and return which that have the max value
ex
[1,2,3] = 6
[3,6,7] = 16
[11,8,6] = 25
then return the 25 because is the max value.
how can I do ...
-2
votes
0
answers
54
views
Is it possible that different interprets output different results?
Recently I've had an exam from programming (Python). One of the problems stated (there maybe some minor translation errors):
Write a program that asks the user to enter an array of non-negative
...
0
votes
0
answers
10
views
genetic algorithm or different algorithm to add practical materials
Is it possible to add practical materials and theoretical materials using the genetic algorithm only? Or does it need other different algorithms?
is it possible to add practical materials and ...
-1
votes
0
answers
43
views
Hi, I wrote the following code to analyse the time complexity plot of a linear search algorithm, it just doesn't give a straight plot(ideal)
`import random
import time
from matplotlib import pyplot as plt
noKeys=1
reps=1000
listSize=[]
timeElapsed=[]
def Search(arr,src):
for i in range(len(arr)):
if arr[i]==src:
...
-1
votes
2
answers
53
views
How to do a consecutive subarrays in JavaScript [duplicate]
I am studying algorithms in JavaScript; I am trying to generate consecutive subarrays but I don't know to do it.
I have the following array:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
I want to split it in ...
2
votes
1
answer
51
views
Iterating over XML object in Powershell
I am trying to write a script that starts with the most inner XML element and loops up the XML node until it gets to a specific node:
For example:
<bookstore>
<book category="cooking&...
0
votes
0
answers
27
views
How to solve the TSP-angular problem in polynomial time? [closed]
I need help on a complex problem.
The task is to calculate/approximate the shortest round-tour through given city-coordinates while avoiding turning angles of > 62,5 degrees.
This problem ...
-4
votes
0
answers
40
views
I want The meaing of this Syntax in JAVA [closed]
public int[][] merge(int[][] intervals) {
List<int[]> res = new ArrayList<>();
if (intervals.length == 0 || intervals == null)
return res.toArray(new int[0][]);
Arrays....
0
votes
3
answers
42
views
How can I show the arrows of my sorted table according to my sort order in angular?
I have a table that I sort from largest to smallest or alphabetically.
here is the html of the part I'm sorting
<tr>
<th scope="col" [appSort]="dataList&...
-1
votes
0
answers
30
views
An interesting way of writing code to print prime numbers within a specified range (Python) [closed]
(Not a question.)
We were tasked by the professor today to write code that prints positive prime numbers within a range. My answer shocked him so I thought I'd share; what are your thoughts on it? Lol....
-4
votes
0
answers
37
views
what algorithm for jigsaw puzzle? [closed]
Yesterday I did an experiment to make a puzzle game but I didn't find the algorithm,
I can't solve this code for search algorithm. Can anyone help me :(
This code :
https://github.com/SantaKolosovska/...
0
votes
3
answers
108
views
Rotate an array by k steps in c++
We have given an array of n size and we to have to rotate it by k times where k can be greater than n in some cases .
My try -
#include<iostream>
using namespace std;
void inputarray(int arr[],...
0
votes
0
answers
25
views
Minimum spanning tree with node weights and edge weights problem [closed]
Minimum Spanninjg Tree with vertex weight and edge weight
So I have a second exercise as a continuation to the linked problem. Suppose we have the costs of airports all 0 and we want to solve the same ...
0
votes
0
answers
41
views
Recurrence Relation: Solve T(n) = 25T(n/5) + ((n log 5) / (log n))^2
T(n) = 25T(n/5) + ((n log 5) / (log n))^2
I am new to recurrence relation and was stuck on solving this above question and would like to seek some direction!
I do not think that I am able to apply ...
0
votes
1
answer
59
views
Pay with least change Javascript
I'm trying to guide my users with making cash payments. Let's say the user has two 200 dollar bills, one 100 dollar bill, one 50 dollar bill, two 10 dollar bills and three 5 dollar bill.
The user ...
-4
votes
0
answers
51
views
What needs to be changed in this Merge Sort algorithm to convert this JAVA code into C language? [duplicate]
static int[] mergeSort(int[] arr){
if (arr.length == 1){
return arr;
}
int mid = arr.length / 2;
int[] left = mergeSort(Arrays.copyOfRange(arr,0,mid));
...
0
votes
0
answers
16
views
supertrend function not returning data as per Parameter passed
I am using inbuilt supertrend function to get supertrend value.
My requirement is I want supertrend data with length=1, multiplier=3 .
When I change length & multiplier to any value then still I ...