# Questions tagged [algorithm]

49513 questions

1

votes

1

answer

82

Views

### control a lot of ifs in calculating number value of String in Java like (“-3.1+0.12*0.0023-34.1/2.1”)

I wanna to solve my Homework about calculating number value of String in Java like '-3.1+0.12*0.0023-34.1/2.1'
I have limitations to use only Arrays and Strings and not use recursive functions (as first year student)
What I try?
I am trying to solve it by parsing string char by char.
I try this meth...

1

votes

1

answer

25

Views

### Confusion regarding the algorithm to be applied for CCHESS

I am aware of the fact that I have to apply Dijkstra's algorithm to get an answer.The entire algorithm is explained in depth in one of the answers .
However why do we need to apply Dijkstra's algorithm to this problem.According to my knowledge Dijkstra will find the shortest distance path.
But the p...

1

votes

1

answer

91

Views

### How to train a machine to label individual words in a text

For a text (say):
'I am leaving India today. I am headed to USA for a week.'
'I am travelling from India to USA'
I need to train the machine to label USA as 'Destination' and India as 'Source'
I am using SpaCy's NER to extract the locations.
How should I proceed to create a training set and train it...

1

votes

2

answer

127

Views

### Choose some numbers coding in Gray Code

I have to write a programm that shows some numbers coding in Gray Code. I already found an algorithm written in C++ in this page ( https://www.geeksforgeeks.org/given-a-number-n-generate-bit-patterns-from-0-to-2n-1-so-that-successive-patterns-differ-by-one-bit/ ).
But I want to create a new method t...

1

votes

1

answer

54

Views

### Append new characters to a Palindrome. Efficient or Dynamic way to check if the new string still a Palindrome?

Say I have a palindrome s and I am going to keep appending characters at the end of s for fun. But I want to stop once s is no longer a palindrome.
Now I am lazy so I don't want to rescan s to determine if it is a palindrome every time when a new character is appended to s. I am wondering if there...

1

votes

1

answer

142

Views

### Optimise straight corners A* algorithm for pathfinding

I'm working on the pathfinding for placing roads in a grid based RTS city building game, since I already used the A* algorithm for the pathfinding of vehicles I figured it would be convenient to use it for this task as well. Since our roads are just simple squares I couldn't use the original algorit...

1

votes

1

answer

245

Views

### How to calculate all possible combinations of values to cover dynamic amount?

I am attempting to return all the possible unique combinations of ‘piping’ needed to at least cover the amount of feet provided.
This problem is similar to common coin change algorithms.
Pipes come in increments of 10', 25', and 50'.
I’ve looked at examples from here and here which seem to be...

1

votes

0

answer

314

Views

### How to model an algorithm to apply discounts to prices?

I was asked to developed a solution to apply easily applying discounts to products in a ecommerce store and I tried to do it in the most generic way.
Let's say we have the following products:
Product A: $5
Product B: $20
Product C: $7.50
And we have the following discounts:
2-for-1 for the Produc...

1

votes

2

answer

79

Views

### Find maximum number of sets which is satisfied specific condition

Given some set of numbers:
156, 434, 600
How to find the maximum number of groups which is over 500? It allows you to make a group with even only one element. But it is not allowed to use an element repeatedly among groups. So, in the above example, the answer is:
2 // {156, 434}, {600}
I hope to m...

-1

votes

0

answer

14

Views

### Algorithm to enumerate all sequences?

I'm researching the following problem:
Input:
N where N is an integer.
K where K is a positive integer, K

0

votes

0

answer

5

Views

### Finding an O(log n) stretch tree in a nxn grid graph

Describe a O(log n)-stretch tree in a n × n grid graph. For one construction, it might be convenient to have n be of the form n = nl = 2(nl−1)+1, and n0 = 1. You may assume this. (In a grid graph, you have an n × n array of nodes where each vertex is connected to the vertices above/below/to the...

1

votes

1

answer

216

Views

### LSTM with Numpy, can't find a definitive algorithm

I am doing LSTM from scratch and am following this guide, but the loss is not decreasing but increasing. This is the best guide I have found thus far but that is not saying much as even this one is incomplete. Aside from spotting the problem specific to my code I would appreciate any sources showing...

1

votes

1

answer

62

Views

### Error in the algorithm of ordering nodes in the undirected graph

The idea is to construct a list of the nodes in the undirected graph ordered by their degrees.
Graph is given in the form {node: (set of its neighbours) for node in the graph}
The code raises KeyError exception at the line 'graph[neighbor].remove(node)'. It seems like the node have already been del...

1

votes

1

answer

28

Views

### Gameresearch / Understanding generation of player id

I've collected data based on game statistics.
I can't figure out what might be the function behind the generation of player ids. I think its based on the registration time of the user/player.
Here is a sample of player ids, sorted:
59f39d7046b16841df49bb76
59f39d7046b16841e06b1b47
59f39d7102153a762...

1

votes

0

answer

45

Views

### Complexity O(n^(1/2) log m)

Let n divides m-1.
There is an algorithm similar to below:
for k in factors of n
for i < log(m)
The complexity of finding factors is O(n^(1/2)).
I think this algorithm is O(n^(1/2)log m).
But I also think this algorithm can be O(m^(1/2)log m).
Because n|(m-1), O(n^(1/2)) can approximate to O(m^(1/2...

1

votes

0

answer

98

Views

### Best method for Edit Distance and LCS algorithms

I'm writing a monografie for college about optimizations in Edit Distance and LCS algorithms.
Searching the internet I found two optimizations The four Russians method and Ukkonen Algorithm.
I have to test it with this SPOJ problem (which requires a better Big O than O(NM) or O(N^2)). My question i...

1

votes

0

answer

256

Views

### Explanation of pathfinding/a* algorithm?

Do someone want to explain me (in pseudocode too) how the pathfinding/a* algorithm can be implemented in Python? I searched all over the internet but I am not able to understand how to calculate H-cost or G-cost. I found some source code, but it is too difficult for me (I am still a newbie).
Let's t...

1

votes

1

answer

56

Views

### receiving an input string and return a list of sub-strings and the number of occurrences of each sub-string

I need to write an algorithm \ program that received only single output (string) and return all the possible substrings and the number of occurrences of each substring.
I managed to do so, using 2 for loops, and complexity time of O(N^2).
My Question is - Is there more efficient way to do so with lo...

1

votes

1

answer

36

Views

### Find Neighbors of Different Type in Carousel List for Pair of the Same Type (Circular List)

I have a collection that behaves like a carousel i.e.: the last item is followed by the first item. In this collection (List of IdentifiedAnimal), there is a pair of values that are always together (Mammals). They can be even the first and the last themselves.
My goal is to find the nearest neighbo...

1

votes

0

answer

27

Views

### Is there a more efficient method than this to calculate the volume of an advanced 3D object?

In a project I'm planning to calculate the volume of an advanced 3D object by creating an array of 1x1 unit squares which make up a grid, passing that grid through the object and, every 1 unit of distance, running collision detection on each square with the object, so essentially we're really creati...

1

votes

0

answer

35

Views

### Python/NumPy - Tail letter placement algorithm

I'm currently trying to write a program that correctly centers handwritten letters in a similar fashion to Microsoft Word. Using a standard handwriting grid for comparison, the bottom of the letter is placed right on the lowest gridline for most letters: Image.
However, there are five tail letters w...

1

votes

2

answer

69

Views

### Experiment with find algorithm using sentinel

I was experimenting with some known algorithm which aims to reduce the number of comparisons in an operation of finding element in an unsorted array. The algorithm uses sentinel which is added to the back of the array, which allows to write a loop where we use only one comparison, instead of two. It...

1

votes

0

answer

121

Views

### Counting unique records in HIVE/SQL with many-to-many mapping based on a uniqueness criteria

The problem description is given as follows:
A user may have multiple accounts and multiple phone numbers linked to that account.
A single account might be linked to one or more phone numbers.
A single phone number might be linked to one or more accounts.
No two users will have the same account.
N...

1

votes

0

answer

81

Views

### calculating time complexity of complex functions

I am learning how to find the time complexity of an algorithm. I am unable to find out the time complexity (in terms of big O) of the following function:
6n^3/(logn +1)
Is there any easy way to calculate it?

1

votes

1

answer

72

Views

### Time Complexity of Finding All Possible Sums

Here is a solution to an algorithm that wants me to find all possible sums given an array of coins and their corresponding quantities. I am having a hard time deriving the time complexity of this algorithm. Any help would be much appreciated, thanks!!
const coins = [1, 2, 3];
const quantity = [1, 2,...

1

votes

0

answer

67

Views

### Max area quadrilateral inside a convex

I'm having trouble finding an efficient algorithm for the next problem: Given a convex polygon of size N (when N > 4), find a quadrilateral which is inclosed in the polygon with a maximal area
You can solve it in O(N^4) by choosing 4 points on the polygon and calculating the area (and finding the ma...

1

votes

0

answer

146

Views

### What algorithm does git diff use to detect similar (copied/renamed) files?

What algorithm does git diff use to detect similar (copied/renamed) files?
What is the complexity with respect to the number of files and the size of files in the repository?
Does whitespace matter? (e.g. indenting a whole file)
Does it work on text only?
Is there a risk of similarity detection ti...

1

votes

1

answer

77

Views

### leetcode subset javascript code returns empty array

i am new to algorithms and have a silly question about a leetcode problem. The problem is asking for all subsets for a given array which only contains distinct integers.
In my code, the console.log of the list array gives me what I want, which is a group of subsets of the input. But it does not pas...

1

votes

0

answer

76

Views

### vba faster performance array shuffling algorithm

I am running the below algorithm on an array of 100k items (I would like to expand it to 1m if possible) and am facing performance issues. I would like to reduce the processing time down to a few seconds. I am pretty sure the first loop is causing the code to slow down. Is it possible to automatical...

1

votes

0

answer

61

Views

### How do you build algorithms to optimize high scores on games

My favorite app I have ever played is drop7, a puzzle game. I have linked the wikipedia page if you're not familiar with it
https://en.m.wikipedia.org/wiki/Drop7
Since I've started playing this game Ive just been trying to get high scores in their blitz round because it's a quick game. I want to wr...

1

votes

1

answer

74

Views

### Tween to create the effect of one object follows another-LibGdx

I have a object(named frame) on screen,it will move either left or right according to where I move my finger.
public void handleSwipeInput() {
if (MyInputProcessor.isTouchDown) {
float movedir = MyInputProcessor.dist > 0 ? 1 : -1;
float speed = 30;
float actualSpeed = Math.abs(MyInputProcessor.dist...

1

votes

1

answer

41

Views

### Deriving the subsolution table for LCS from the brute force solution

I'm working on the LCS problem using dynamic programming. I'm having trouble deriving the DP solution myself without looking at the solution.
I currently reason that given two strings, P and Q:
We can enumerate through all subsequences of P, which is of size 2^n.
We can also enumerate through all su...

1

votes

2

answer

104

Views

### Multiple solutions in Shorthest Path Algorithm (A*)

So the other day I found a website, where I could refresh my knowledge about algorithms and I was bumped into a problem.
What will happen, if I run an A* algorithm on a map, where two - exactly the same - possible solutions are available?
How the algorithm decides, which solution is the better? Whic...

1

votes

0

answer

90

Views

### Creating a steepest descent algorithm to determine a 3D affine warp

I want to implement the 2.5D inverse compositional image alignment. For that I need to create an steepest descent image. I followed the implementation from Code Project for a 2D image alignment. But I am searching for 3D warp information and because of that also for a 3D steepest descent image.
To...

1

votes

0

answer

124

Views

### Large number division with linked lists in C

I am trying to represent a string that holds any number to infinity. This number must be an integer and return its value as a result. Right now, my goal is to do this representation but for division only. So lets say we have 125 as our numerator, and 5 as our denominator. The answer should be 25 rig...

1

votes

0

answer

85

Views

### Calling the value of a function inside another function C

I'm trying to implement my own algorithm for a brute-force program in C but I can't figure out what I'm facing at a certain point. Here's the code:
#include
#include
#include
#define CHUNK 1024
void combinations(char nums[],char candidate[],int current_len,int n3,int len) {
if(current_len == len)...

1

votes

1

answer

63

Views

### How can I implement the function “divide” in a functional Divide-And-Conquer Java algorithm?

I am trying to implement a functional version of the Quicksort algorithm.
My professor asked me to keep this as the signature:
public static List myQuickSort(Function trivial,
Function solve, Function divide,
Function combine, List input)
I created an auxiliary class named Pair, which goes like...

1

votes

0

answer

351

Views

### Creating questions from sentences

I'm trying to create an algorithm that could transform sentences to questions. This is the code:
def sentence_to_question(arg):
hverbs = ['is', 'have', 'had', 'was', 'could', 'would', 'will', 'do', 'did', 'should', 'shall', 'can', 'are']
words = arg.split(' ')
zen_sim = (0, '', '')
for hverb in hver...

1

votes

0

answer

35

Views

### AVL tree insert case need a clarify

I read several online document about implementing AVL tree using balance factor(Not using a height data field in Node structure), when insert into the tree, there is one case I could not figure out.
The document is from here(also from here has similar function) , the balance factor is defined as hei...

1

votes

3

answer

587

Views

### Optimize algorithm for determining qualifying score from a predefined range

Problem:
You are given a list(1-D array) of scores(some numbers).
You are given two more lists:
lowerLimits : A list that contains lower limit value(s)
upperLimits : A list that contains upper limit value(s)
Your task is to find out how many counts of scores fall within the inclusive range of each...