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
3answers
7 views

Digit swap wrong examples

swap digit problem This problem is screwing with my mind because of the examples. If I have: 38276 Then the next biggest is 87632 But the problem points it out as the next biggest being 38627 ...
0
votes
0answers
14 views

Miller Rabin primality test two types?

I encountered two types of Miller Rabin primality test methods suddenly. One which uses randoms and another does not use randoms. Is there a hidden random generation inside the second one or what? ...
-3
votes
1answer
28 views

What is this matrix in php? And what does it do?

I came across this encryption algorithm, and I grabbed the algorithm it uses which looks like to be an matrix, but I do not know what it does or how to use it? Help! <?php $array = [ 2 => ...
1
vote
0answers
45 views

Which is the best data structure for searching under these conditions

I have a system with some factors, say A, B, C, and D. There can be different values of all these factors. Let us consider few values to have a better understanding. Let's say A has 4 different ...
0
votes
1answer
22 views

Genetic algorithm to solve a quadratic equation

I have a problem understanding the process for genetic algorithms. I found examples of maximizing a function over an interval, and I think I understand them, but how can a genetic algorithm be used to ...
0
votes
1answer
39 views

What is the time complexity of this in-place array reversal?

Is this function O(n) or O(log(n)) time complexity. function reverse(array) { for (var i = 0, j = array.length - 1; i < j; i++, j--) { var temp = array[i]; array[i] = array[j]; array[...
0
votes
1answer
8 views

Calculate max flow efficiently using Ford Fulkerson after removing edge from the flow

Suppose that a maximum flow for G has been computed using Ford-Fulkerson, but an edge is now removed from E. how the maximum flow can be efficiently updated.
0
votes
2answers
41 views

2d array to 1d array C#

I've got two algorithms converting random 2d arrays (m х n or m х m) to 1d array. I'm wondering if there is a way to make them work als in the opposite direction and convert the result to 1d array ...
0
votes
1answer
21 views

How to make fast frequently updated collection in Java, sorted by member object's property?

I have a collection of items, and every item is a simple object with several fields. List<MyObject> where MyObject = { long value1, long value2 } I need collection to be sorted by ...
-3
votes
1answer
13 views

How secure is to use Rijndael symmetric encryption algorithm

Please let us know how secure is Rijndael symmetric encryption algorithm. The key is stored in web config file.
0
votes
0answers
49 views

Converting a Recursive to Loop

I have written a program to solve a program , but unfortunately for large data set it's give me java.lang.StackOverflowError Here is piece of code: public static int go_gone(int curr , int sum , ...
0
votes
0answers
15 views

Neo4j Big time difference between same Query

I'm here because I have a little trouble with Neo4j. I'm storing in a Neo4j Database k-ary Complete Trees, with attributes on both Vertexes and Edges. We are talking about 2 millions / 2.5 millions of ...
0
votes
0answers
24 views

Is this a correct implementation of MergeSort=? [on hold]

i'd like to know, if the following code is a good implementation of MergeSort? Can you rate it on a scale from 1 (bad) to ten (really good? Thanks for your help! I tried some examples and the code was ...
1
vote
0answers
18 views

Calculate maximum flow efficiently after adding a new edge in Ford Fulkerson algorithm?

Suppose that a maximum flow for G has been computed using Ford-Fulkerson, and a new edge with unit capacity is added to E. How the maximum flow can be efficiently updated. (t is not the value of the flow ...
-11
votes
0answers
42 views

How to find Top K largest numbers? [on hold]

my application should find largest k numbers from a big file contains a lot of random numbers for example for the following file content : 3,5,12,54,12,3,654,11,46,7,3 if the users input is k=3 the ...
-5
votes
0answers
17 views

Tree implementation in java Code Explanation [on hold]

I want to know what this piece of code means: class Node private List<Node<T>> children = new ArrayList<Node<T>>(); private Node<T> parent = null; private T data = null; ...
1
vote
2answers
56 views

lack of memory in C program [duplicate]

I wrote the program below ti implement an algorithm with big arrays but when N is over 820 i have a segmentation fault problem (core dump) because of memory. I use 3 big arrays to implement my code. ...
0
votes
0answers
30 views

Path planning implementation python [on hold]

Is there any framework with efficient implementations of path planning algorithms (like A* https://en.wikipedia.org/wiki/A*_search_algorithm) in python? Obviously for some people, python and ...
0
votes
1answer
36 views

Fastest way to find the event with most viewers at a given moment?

Problem: There is a special day, when <=1'000'000 events are hold. There are <=1'000'000 viewers watching those events (not necessarily the same number). Special day is divided into <=100'...
0
votes
0answers
30 views

Algorithm for vector difference upon itself

What is the fastest known algorithm for computing the difference of a vector upon itself. If i have a row-vector A with dimension n x 1 and i take the transpose A'. Then how can i compute the ...
0
votes
1answer
28 views

php Script to generate schedule

I want to distribute some personnel in a week every day there are 3 times 7h-15h 15-23h 23h-7h . The problem that I don't want a person to show more than one time in a day. I want to distribute ...
0
votes
1answer
18 views

How to parse stock data from objects into an array

I am using the Recharts library to plot some stock market data. However, the simple line chart requires a very strict data structure like so {name: 'Page A', uv: 4000, pv: 2400, amt: 2400} I have ...
0
votes
1answer
22 views

Search from specific to general from large ruleset

I have a table that stores price of products in that is hierarchically organized from country level to store level. create table price_list( product_id number, country_id number, region_id number, ...
0
votes
3answers
68 views

How can I find the most frequent word in a huge amount of words (eg. 900000)

I am facing a task which is generating 900000 random words and then print out the most frequent one. So here is my algorithm: 1. move all number into a collection rather than printhing out them 2. ...
3
votes
2answers
67 views

How and why does this code work? Finding the minimum number of steps to change one word to another

I'm researching on how to find the minimum number of steps required to convert word1 to word2, and came across the following implementation with the rules: Given two words word1 and word2, find the ...
0
votes
0answers
12 views

Something wrong with my PollardP1_rho code but I don't know how to fix it

I tried to use MillerRabin + PollardP1_rho method to factorize an integer into primes in Python3 for reducing time complexity as much as I could.But it failed some tests,I knew where the problem was....
0
votes
0answers
32 views

2 Dimensional Knapscak algorithm

I am trying to get the algorithm(close to optimal) for a variant of 2 dimensional knapsack problem, below is the problem description. lets say we have n number of rectangle R1(l1,w1) R2(l2,w2).........
0
votes
2answers
60 views

Find duplicate in a table

I have a table that contains duplicate. The way to identify a duplicate is - the key should be in the same group(1,2,3 or 4) - the p should be the same - P is an id that say this keys are the same ...
4
votes
2answers
64 views

How to group two value arrays to n value arrays in the below example?

I already have many two value arrays for example in the below ary = [[1, 2], [2, 3], [1, 3], [4, 5], [5, 6], [4, 7], [7, 8], [4, 8]] I want to group them into [1, 2, 3], [4, 5], [5, 6], [4, 7, 8] ...
0
votes
2answers
62 views

Java - numbers with at least one 7 and one 9 in its digit

I have to code a program to determine how many positive integers under 1,000,000 have at least one 7 and at least one 9 among its digits by examining the digits in each number from 1 to 999,999 ("...
1
vote
1answer
10 views

Reconstruct version control from set of files

I am looking after an approach for the following task: given a set of files that are highly similar (I am using Fuzzy hashing here), I would like to know if there is an algorithm that allows to label ...
1
vote
2answers
30 views

Find circles containing only zeros in an arbitrary binary matrix

Given a binary matrix of arbitrary size, I need to find circles which fit into this matrix and only cover "0"-fields and no "-1"-fields. For this example 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 ...
0
votes
1answer
17 views

What is the 'roughness constant' of this midpoint displacement algorithm, and how can I modify it?

I've taken code from "Midpoint displacement algorithm example", cleaned it up a bit, and resuited it to work as a 1D linear terrain generator. Below is my new version of the doMidpoint() method: ...
2
votes
2answers
36 views

Combination Algorithm from multiple sets

I am trying to write an algorithm that tells me how many pairs I could generate with items coming from multiple set of values. For example I have the following sets: {1,2,3} {4,5} {6} From these sets ...
-2
votes
1answer
36 views

Algorithm to return the possible combination batches of required materials

I have a problem, example I need to build a sofa using 300 meters of leather. my materials come in different batches. 10m 20m 30m 40m 40m 50m 100m 200m 300m My goal is to find the best combination ...
0
votes
1answer
25 views

Finding Big-Theta of functions

I guys, I am trying to find Big-θ for the following functions, did I solve them correctly? Q: Find a theta notation in terms of n for the number of times the statement x := x + 1 is executed. 1) for ...
-1
votes
1answer
32 views

Modifying Bellman-Ford to support a second edge weight

So given the initial and final nodes, I need to use the Bellman-Ford alg to: Find a path with the lowest cost while Remaining under a specific time duration Each edge has cost and time/duration ...
0
votes
2answers
55 views

Detect UILongPressGestureRecognizer direction not compare initial point

if (gesture.state == UIGestureRecognizerStateBegan) { _initial = [gesture locationInView:self.view]; }else if (gesture.state == UIGestureRecognizerStateChanged){ CGPoint p = [gesture ...
1
vote
1answer
43 views

Complexity Reduction to O(n) Over Multiple Simultaeneous Vector Iteration

So I have 2 string vectors with the following content: tokens: name name place thing thing u_tokens: name place thing Now my task is to simultaneously loop through both these vectors and find the ...
0
votes
1answer
45 views

Kill all threads when one of them has ended earlier С++

I am looking for ways how to resolve of my problem in C++ . Detailed description (brief description is below): I am writing the sudoku solver. I have already created bruteforce method (check which ...
0
votes
1answer
29 views

Randomly assign a flag with specific percentage rate requirement

I was asked to do a algorithm to assign a one out of three messages to each record of file. Client want Message 1-- selected for 80% times of total 3 message randomly. Message 2-- selected for 10% ...
0
votes
1answer
26 views

Can there be more than one answer for matrix chain multiplication?

I'm studying for an Algorithms exam, and one of my problems is to find the optimal matrix chain multiplication for the following: A1: 5x7 A2: 7x10 A3: 10x7 A4: 7x5 I ended up with the solution ((...
0
votes
0answers
41 views

Loop in an algorithm which is dependent on hex value

I am only learning c and I am trying to implement a for loop from an algorithm. I am so so confused in how to implement it, please see my attempt below. Any help or thoughts would be greatly ...
1
vote
1answer
42 views

Create binary tree of fixed size

I am trying to create a binary tree. Only thing I am given is the number of the nodes in the tree. The first thing popped in to my head is to use an index(BFS order) to keep the track of the number of ...
-1
votes
1answer
26 views

Convert logical formula to DNF in vb.net

I need a function to convert a formula like this: (A = 1 AND (B > 4 OR C > 5)) OR (A = 3 AND (B > 4 OR C > 10)) to a DNF format. The formula could be more complex that this example. ...
0
votes
3answers
22 views

Looping over a bitmask

This is a submission to the TopCoder SRM 466 "Lottery Ticket" problem. I've seen this pattern used multiple times for this problem. Nick likes to play the lottery. The cost of a single lottery ...
1
vote
1answer
46 views

String compression algorithm in Java

I am looking to implement a method to perform basic string compression in the form of: aabcccccaaa -> a2b1c5a3 I have this program: import java.util.Scanner; public class Main { public ...
1
vote
3answers
58 views

Count number of movements of A to B

I have the following problem. On a chessboard, I have a knight on a given square (shown in red), and I need to find the path the knight can take to reach another square (shown in green). I have to ...
1
vote
1answer
34 views

Algorithm: How to re-arrange a time-range event (interval) list based on wether time events overlap, faster than O(n^2)?

Let's say I have an array of time ranges like so: [ { name: 'A', startTime: '10:15', endTime: '11:15'}, { name: 'B', startTime: '10:45', endTime: '14:15'}, { name: 'C', startTime: '15:35', ...
-2
votes
0answers
33 views

finding the kth smallest element in 3 sorted arrays of size n

suppose we are given three sorted arrays A[1 .. n], B[1 .. n], and C[1 .. n], and an integer k. Describe an algorithm to find the kth smallest element in A U B U C in O(log n) time. Thanks for the ...