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.

learn more… | top users | synonyms (2)

0
votes
0answers
5 views

Wondering if there is a good algorithm for gating two countdown variables

In the http spec, there is flow control per stream and per connection. you can have N streams on a conneciton with N window sizes and the connection has a window size as well. so we have ...
0
votes
0answers
8 views

Check if polygon is inside polygon

So, this is a well discussed subject, but it seems to always end up with algorithms doing the point-in-polygon operation extended with edge intersection detection for cases where the outer polygon is ...
2
votes
1answer
22 views

Delphi factorial operations precision

SITUATION I need to make a program for my maths course about Combinations and Permutations. If you want to calculate them you have to deal with factorials and I have written this typical recursive ...
1
vote
1answer
43 views

Complexity computational difference between O(N+m) and O(NM)

In the algorithm below I cannot understand why the complexity is O(N+M),as calculated by codility.com examination tool, instead of be O(NM). I suppose it is O(NM) because of the two iteration one ...
1
vote
1answer
21 views

Construction heuristics in binary integer programming

I have been trying for find answers to this question, but I cannot find anything comprehensive. I am looking to find an algorithm or heuristic to construct an initial feasible solution to the binary ...
0
votes
0answers
16 views

Choosing a particular route for a shuttle vehicle upon demand

I'm trying to solve a problem where I have no idea what algorithm is to be used here to get the optimized answer. The problem is like this... Consider there are 10 shuttle vehicles and 2 different ...
-7
votes
0answers
56 views

Program in C++ about the pie chart? [on hold]

Some progress bars fill you with anticipation. Some are finished before you know it and make you wonder why there was a progress bar at all. Some progress bars progress at a pleasant, steady rate. ...
-1
votes
5answers
44 views

How braces affect code output

While I am implementing Selection sort method and executing it, some of elements are sorted while other are not. I checked over the internet about a correct implementation but I didn't find any ...
-3
votes
0answers
16 views

How does the greedy principle apply in UVa 1199/ LA 2949 - Elevator Stopping Plan? [on hold]

Given a list of floors an elevator has to stop. And given that the elevator stops for 10 seconds at each floor and it takes it 4 seconds to move up and down one floor with life and 20 seconds ...
0
votes
2answers
58 views

Suggestions for performance improvements Java code

Hello I am just doing this for fun and I am trying to figure out if there is a more efficient/faster way to do this. Make all possible combinations of a given list of numbers and letters then print ...
9
votes
7answers
212 views

Sort an array of integers into odd, then even

I have a problem I found on an algorithm forum elsewhere. I have an array with random numbers (for example, [5, 2, 7, 9, 2, 3, 8, 4]) which should be returned to me sorted by odd then even. The order ...
1
vote
0answers
46 views

Boggle - count all possible paths on a N*N grid. Performance

While reading up this question, I wondered why no one would "simply" iterate all the possible paths on the boggle grid and have the word-tries follow and then cancel the path if there is no match in ...
0
votes
1answer
28 views

Task assigning algorithm

I'm trying to figure out what the most efficient way of assigning tasks to people. Here is what I'm struggling with: you have X number of people that are all eligible to do work each person can do X ...
-2
votes
1answer
19 views

Avoiding database when checking for existing values

Is there a way through hashes or bitwise operators or another algorithm to avoid using database when simply checking for previously appeared string or value? Assuming, there is no way to store whole ...
1
vote
1answer
21 views

Implementation of Bellman-Ford algorithm in python

I am doing an exercise for the course "Algorithms on Graphs" on Coursera and I a have to implement the Bellman-Ford algorithm to detect if a graph has a negative cycle or not, outputing 1 and 0 ...
-1
votes
2answers
36 views

Efficient way of finding rectangle coordinates in 0-1 arrays

Say I have an MxN matrix of 0's and 1's. It may or may not be sparse. I want a function to efficiently find rectangles in the array, where by rectangle I mean: a set of 4 elements that are all 1'...
-1
votes
0answers
29 views

Longest Common Subsequence Bitstring Implementation [on hold]

Following is a spoj problem which asks us to find the longest common subsequence of a string. Problem Link: LCS0 I first tried O(mn) time and O(max(n,m)) space complexity which yielded me TLE. I ...
1
vote
1answer
29 views

Interview : Maximum path sum in a 2-D matrix using recursion. Recovery of the path

Question Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which maximizes the sum of all numbers along its path. Note: You can only move either down or ...
-3
votes
1answer
45 views

Run-time error in a code

Problem: On standard stream of input we get sequence of sets of numbers from diapason [0, 31]. Every set finished by -1. Every set may be empty and numbers may be repeated in set. You need to find XOR ...
0
votes
2answers
53 views

Extracting data from a .txt in c

I have read the topic How to extract data from a file in C but I'm still in trouble with an extraction of data from a file in C because I have a precise request. Here is an example of a .txt I have to ...
-1
votes
2answers
43 views

maximum y speed to pass through line segments with a given maximum x speed

Given a sequence of line segments Si, each with coordinates Xi and Yi (for each i, Yi+1 is greater than Yi) and each of length b in the x direction, how can I calculate the maximum y speed to pass ...
-2
votes
0answers
22 views

The Thomas Method Algorithm for solving three diagonal system in Multi-step Wide-Angle (Pade(2,2)) Beam Propagation Method

I'm trying to simulate in Matlab a 2D gaussian beam propagation in free propagation region using multi-step Wide-Angle BPM (Pade(2, 2)) with Crank-Nicholson scheme. Since SO doesn't support LaTex, ...
0
votes
1answer
8 views

Calculate Elasticsearch Query Complexity (Scalabilty)

I'm doing a project with ElasticSearch and the goal of the project is to optimise the time of request, now I'm trying with 1Go of data and the request took about 1200ms, I wanna calculate the time ...
3
votes
1answer
37 views

Why doesn't the time complexity of Sieve of Eratosthenes algorithm have the argument sqrt(n)?

I'm trying to understand the Sieve of Eratosthenes algorithm time complexity. Everywhere online, it says the time complexity is O(nloglog(n)), but I don't understand why. Here is some pseudocode ...
2
votes
3answers
37 views

Algorithm - find all permutations of string a in string b

Say we have string a = "abc" string b = "abcdcabaabccbaa" Find location of all permutations of a in b. I am trying to find an effective algorithm for this. Pseudo code: sort string a // O(a loga) ...
3
votes
1answer
28 views

Can someone clarify the difference between Quicksort and Randomized Quicksort?

How is it different if I select a randomized pivot versus just selecting the first pivot in an unordered set/list? If the set is unordered, isnt selecting the first value in the set, random in itself?...
-3
votes
1answer
27 views

caesar cipher object doesn't support assignment python

Write a method that takes in an integer offset and a string. Produce a new string, where each letter is shifted by offset. You may assume that the string contains only lowercase letters and spaces. ...
0
votes
2answers
113 views

How to find number of integers in a given range has even set bits

I want to know how many numbers say x, in a given range lets say l and r, l < r, present where number of 1's in binary representation of x is even. Is there any efficient way to find that?
0
votes
0answers
20 views

Seven class classifier not giving desired results in StanfordNLP python

I am trying to use Stanford's named Entity Recognizer. I want to use the 7 class classifier because I even want to detect time(or date) and other things in a sentence. When entering the sentence: "He ...
2
votes
2answers
39 views

Finding the “difference” between two string texts (Lua example)

I'm trying to find the difference in text between two string values in Lua, and I'm just not quite sure how to do this effectively. I'm not very experienced in working with string patterns, and I'm ...
1
vote
1answer
30 views

Space complexity in memoized fibonacci code

void allFib(int n) { int[] memo = new int[n + 1]; for(int i = 0; i < n; i++){ System.out.println(i + ": "+ fib(i, memo)); } } int fib(int n, int[] memo) { if (n <= 0) return 0;...
0
votes
0answers
15 views

Efficient kNN graph construction with deferred selection of k

Using Levenshtein distance as a metric, I want to find the exact k-nearest neighbours for all elements in a large set of strings, but I am not yet sure how high a value of k I will require. Is there ...
0
votes
0answers
9 views

One-way flight trip implementation in Python [migrated]

I came across the following problem (found on the SO link below): One-way flight trip problem Given a flight trip that includes a number of transfers: we have a ticket for each part of the trip; ...
-6
votes
0answers
37 views

How to list all k elements in array length n in javascript [on hold]

I want to ask how to list all k elements in array length n in javascript
4
votes
5answers
145 views

Why Is This Factorial Algorithm Not Accurate

Sorry I feel stupid asking this and am prepared to lose half of my points asking this but why does this algorithm not work? It works up to a point. After the number 13 the factorials are a little off. ...
0
votes
2answers
20 views

KMeans evaluation metric not converging. Is this normal behavior or no?

I'm working on a problem that necessitates running KMeans separately on ~125 different datasets. Therefore, I'm looking to mathematically calculate the 'optimal' K for each respective dataset. However,...
2
votes
2answers
29 views

How to modify this Held-Karp algorithm to search for Hamiltonian path instead of cycle?

I implemented Held-Karp in Java following Wikipedia and it gives the correct solution for total distance of a cycle, however I need it to give me the path (it doesn't end on the same vertex where is ...
0
votes
0answers
14 views

Verification of B+-tree proof

I'm trying to proof the following theorem: "Proof that all internal keys (that is, all keys that are not in a leaf) are different in a B+-tree". I tried to proof this by induction. Induction basis: ...
-3
votes
0answers
39 views

Largests common divisor of two products

Given two integers N and M (1 <= N, M <= 1000), then N integers A[0], A[1],..., A[N-1] and then M more integers B[0], B[1],..., B[M-1] (1 ≤ A[i], B[i] < 1.000.000.000), I am supposed to ...
0
votes
0answers
36 views

How can I build a ranking algorithm based on user options?

I have a web application where the user can search for different products of a certain category based on a set of options and it should return him the best product, not only by price but also the one ...
0
votes
2answers
40 views

Find words sequence in a document

Using Java (on Android) I try to find a way (fast one...) to resolve this problem : I have a list of words (around 10 to 30) and a document. The length of the document can vary too, maybe around 2500 ...
1
vote
1answer
30 views

Is a multilayer neural net of 2 neurons just the same like 1 neuron

AND logic and OR logic can be solved by just 1 neuron. However, XOR logic needs a neural network of 3 neurons in 2 layers: (neuron1)\ \ +----- (neuron3) / (neuron2)/ ...
2
votes
3answers
47 views

Implementing merge sort in Java: Only zeroes

I'm trying to implement some sorting algorithms in Java working on int-arrays as an educational process. I currently try to wrap my head around merge sort. Yesterday I got pretty far, with a result of ...
5
votes
4answers
42 views

How can I write a SQL Server stored procedure to get the following output?

I have a SourceTable like this with 2 column names: Col 1 | Col 2 ------------------ A | 2 B | 3 C | 4 D | 2 E | 1 F | 0 The first column has ...
1
vote
3answers
34 views

Effective algorithm to find the latest updated json

I receive some information by a request in javascript. I have a json variable: var response for example. Then each of them has an update date element: response[0].updateDate is the updateDate of ...
0
votes
0answers
29 views

Which algorithm used to go through all the branches [on hold]

There is a delivery person and 9 branches of Courier service which items should be delivered by one delivery person. So this delivery person start to delivery items in head branch. I have all the ...
-1
votes
0answers
25 views

Days calculation between a range

I have the following problem In a given range for example 1 Jan 2017 to 31 Jan 2017, How many days of the following range events period occurred? Example 1 range 1 Dec 2016 / 30 Jun 2017 = 31 2 ...
0
votes
1answer
52 views

Get height of the div on window resize

I have a function that resizes divs depending on how high (in pixels) other divs with the same class are: <script type="text/javascript"> function resizeTheDivs(tag){ // first get ...
0
votes
2answers
70 views

Random with condition

I have the following code to extract records from a dbcontext randomly using Guid class: var CategoryList = {1,5}; var generatedQues = new List<Question>(); //Algorithm 1 :) if (ColNum > 0) ...
0
votes
5answers
82 views

Setting random variables C# that equal add up to a total

I'm creating a game in which someone opens a chest and the chest will give them a random prize. The maximum I can give out is 85,000,000 in 10,000 chests which is 8,500 average however I want some to ...