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
2 views

sorting by reversal in genome rearrangements

I am just learning sorting by reversal in genome rearrangements and have faced a problem. Is there any way to prove that Sorting one non-identity permutation to another non-identity permutation is the ...
0
votes
0answers
3 views

Applying design-principles to programming contest codes: Is it effective

Because I believe the algorithm is one of the most critical part for good codes, I often solve algorithm problems in codeforces(or some other such services). I also know that design, as well as ...
-1
votes
0answers
33 views

River crossing with A* algorithm

I found this problem online, The problem: Five family members (A,B,C,D,H) and their five dogs (a,b,c,d,h) encountered a river to cross. A boat can take 3 at the same time. All five family members ...
0
votes
1answer
20 views

Find smallest commons multiple - a different algorithm

I am follow FreeCodeCamp challenge at "Smallest common multiples" Here it is: Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all ...
0
votes
0answers
12 views

color-coding algorithm for the longest path

before anything i would like to make clear yes it is for an college assignment, and I'm looking for help on understand the algorithm to be able to implement it. So I've this assignment that cam be ...
1
vote
1answer
16 views

How to locate empty (f.i. white) space in a picture fast

What is the fastest & most efficient way to locate empty (white) space in a System.Drawing.Image? (There is no need to say to use LockBits and unsafe...) My task is to find the location to place ...
0
votes
0answers
22 views

Parsing a chemistry nomenclature to return a number : Is it a wise use of hard-coding?

I am developping an IUPAC (chemical name) parser in the same vein as this one: http://opsin.ch.cam.ac.uk/ For that, I need to assign different values to each name of chemicals functions: alcohols, ...
0
votes
1answer
50 views

What algorithm does java use to typecast int to byte? [duplicate]

How byte b= (byte)400 is a valid statement although 400 is out of range? I want to know the algorithm java uses to bring 400 within byte's range.
2
votes
3answers
79 views

Linked list reverse without using the loop?

I was asked by one of my senior executives that is it possible to reverse an singly linked list without using an loop? If yes, how? His smile seemed to tell me that it is possible but I could not ...
-4
votes
0answers
25 views

Pseudo code of selection sort using recursion [on hold]

Pseudo code of selection sort using recursion. No loops in the recursive method. The parameter of the function should be : function(array, begin index,end index)
0
votes
1answer
50 views

How to prove the correctness of the algorithm for “Arrange given numbers to form the biggest number”?

Arrange given numbers to form the biggest number gives the algorithm. It uses the following text to prove the correctness of the algorithm: So how do we go about it? The idea is to use any ...
1
vote
1answer
15 views

Python - Networkx search predecessor nodes - Maximun depth exceeded

i'm working in a project using the library Networkx ( for graph management ) in Python, and i been having trouble trying to implement what i need i have a collection of directed graphs, holding ...
-4
votes
0answers
28 views

K-complementary pairs of array is not working [on hold]

I want to implement K-complementary pairs of array implementation with O(NlogN) efficiency. I have found the algorithm as follows and working fine for some scenarios. But I found it is not working for ...
1
vote
2answers
74 views

Summing up numbers in an array

Suppose I have an array of N non-negative integers, each of which can be very large (0->100,000). Let us also suppose that N can very large (~100,000,000). For an array [a0 a1 ... aN-1], I would like ...
1
vote
2answers
65 views

Generate All Possible Permutations of Vector of Objects

Given a vector of coordinates corresponding to city locations on a grid, how can I generate every permutation of these point objects? I suspect there is a problem with using a user-defined class (...
0
votes
1answer
22 views

Is it possible for an algorithm to have asymptotic bound of a trigonometric function?

Like an algorithm with theta(sin(n)) It doesn't have to be tight, I imagine that it would be difficult to construct one given that these functions can be negative. That being said, is there such an ...
0
votes
0answers
28 views

Comparing chained exponents

Given two lists of small integers, is it possible to determine which list produces a larger result, when each element is raised to the power of the remaining elements? For example, the list 1,2,3 ...
0
votes
2answers
19 views

finding the route between 2 nodes in a directed graph?

I am struggling with following piece of code, as I try to write a function for finding if there is route between two nodes: the main where I can isThereRoute function. ArrayList<Node> visited =...
0
votes
1answer
30 views

Max Sum Subarray - Divide and Conquer

I created a recursive function that takes in an array of ints, and returns the sum of the continuous subarray with the largest sum. Example: input: 1 4 -9 8 1 3 3 1 -1 -4 -6 2 8 19 -10 -11 ...
2
votes
1answer
72 views

Why is this algorithm using the bitwise and operator in Java?

I see an algorithm such as: for (int i = 1; i < sums.length; i++) { /* * dynamic programming: * 1. remove a single block from the current subset of blocks * ...
-1
votes
1answer
18 views

How to find the intersection of two lines given a point on each line and a parallel vector

I need an algorithm that can find the intersection of two 2D lines. Each line will come in the form of a point on the line and the dx/dy of a parallel vector. I've tried parameterizing each line and ...
4
votes
1answer
55 views

Which grows faster 2^(2^n) or n^(2n)

I am quite sure that the former function grows faster. But when I plotted it on Wolfram alpha, the latter seemed to dominate. In general, if I want to compare f(n) and g(n), can an analysis of log(f(...
1
vote
4answers
38 views

Does a machine learning algorithm copy the data it learns from?

I am not a programmer, rather a law student, but I am currently researching for a project involving artificial intelligence and copyright law. I am currently looking at whether the learning process of ...
1
vote
0answers
21 views

Stuck with DFS/BFS task (USACO silver)

competitive programming noob here. I've been trying to solve this question: http://www.usaco.org/index.php?page=viewproblem2&cpid=646 The code I wrote only works with the first test case, and ...
0
votes
1answer
59 views

Algorithm to find the most optimal match of multiple groups of objects

I apologize in advance for the long question, I tried to summarized it as much as I can. I am developing an application for a martial arts league. the first module of the application Requires to ...
2
votes
3answers
28 views

Resize hashtable when max chain length is reached

I am implementing a hashtable for educational purposes. The hashtable is implemented with an array and collision is dealt by using linked list. The instructions says that I can insert same items ...
0
votes
0answers
19 views

Comparing a set of coordinates (strokes?) for a percentage difference

I have 2 paths A and B. For example: A = {(1,1), (2,2), (3,3)} B = {(2,2), (3,3), (5,5), (6,7)} Each pair of elements is a line, starting at the element before it. The beginning element is the ...
0
votes
1answer
51 views

how do I prove n^3.5 is not O(n^3)

How do I prove n^3.5 is not O(n^3)? I am doing this for my algorithm class. It says I need to prove it using proof by Contradiction!
3
votes
1answer
62 views

Algorithmic improvement for finding minimum sum in a Binary Search Tree

I wrote the following function to find out the minimum sum of any path in a Binary Search Tree: int minSumPath(TreeNode* root) { if(root==NULL) return 0; int sum = root->value; ...
15
votes
3answers
696 views

Strange algorithm performance

For context, I wrote this algorithm to get the number of unique substrings of any string. It builds the suffix tree for the string counting the nodes it contains and returns that as the answer. The ...
0
votes
0answers
45 views

Algorithm Poisonous Plants too slow for high test cases

Hello i was trying to solve the Poisonous Plants algorithm problem on hackerrank here is the Link And my solution is good, it works fine but when we have high test cases it is too slow. I made my own ...
0
votes
0answers
43 views

Insert Algorithm for an Ordered Linked List C++ [on hold]

I'm writing an insert algorithm for an ordered linked list (Insert function sorting the list alphabetically) The algorithm seems not working properly. Any help with it would be appreciated, thank you. ...
0
votes
1answer
27 views

Increase the efficiency of K-complementary pairs of array into O(NlogN)

I want to implement efficient method of K-complementary pairs of array of integers match with O(NlogN). Below is my code and it is not working. Could anybody help me to resolve this. I have tried ...
-1
votes
1answer
17 views

Grid Column Touch Determination Algorithm

I'm looking for an efficient algorithm to determine which of 6 columns of the screen a user touched. The available information is which cell of an on-screen grid the user touched. The screen's grid ...
-2
votes
1answer
24 views

Maximal subset sum smaller than a given value

You are given an array of integers and a number k. The question is to find a subset such that the sum is maximal and smaller than given number k. I feel like there is a dynamic programming approach to ...
0
votes
1answer
40 views

I have the wrong algorithm for testing overlapping rects (?)

Give a rect s1 = {x, y, w, h} and another rects s2 = {x, y, w, h} and a vector v = {x, y}. And assuming that s1 has moved according to v, I want to check if it is overlapping. I have this algorithm: ...
0
votes
0answers
30 views

datastructure for fast set cardinality

I have a big set of elements(approximate millions or hundred of millions) (it is looks like static data) and multiple predicates on set(approximate thousands) and would like to make fast approximate ...
7
votes
3answers
129 views

Algorithm implemented in ruby to add one to a number represented as an array

I need advice on my ruby based solution to a problem on Interviewbit. The problem is as follows Given a non-negative number represented as an array of digits, add 1 to the number ( increment the ...
1
vote
1answer
53 views

Shortest paths with with a distance function that is dependent on shortest paths?

I would like to compute the shortest paths from every node to every other node in a directed graph. The inital distance from every node to every adjacent node is given. However my distance function ...
-1
votes
1answer
23 views

How do I find a sub sequence of a given length within a sequence such that the sum of that sub sequence is max?

For ex -: Let the sequence be = {1, 8, 2, 9} and the length of sub sequence = 2 then the max sum that can be obtained is from the sub sequence {8, 9} and that sum is 8 + 9 = 17. How do I write an ...
0
votes
2answers
32 views

How can we choose which element to be representative in a Union-find data structure?

When we merge two sets for example A={1,2,3} and B={6,7,8},let 1,8 be the representatives of both the sets respectively,now if we merge both the sets what will be the representative of the resultant ...
1
vote
2answers
71 views

Finding the shortest path nodes with breadth first search

I am running breadth first search on the above graph to find the shortest path from Node 0 to Node 6. My code public List<Integer> shortestPathBFS(int startNode, int nodeToBeFound){ ...
-1
votes
0answers
30 views

Implimentation of the Gaussian Elimination in python

I have been trying to implement a variation of this quadratic sieve factoring algorithm. In my code, I skipped the sieving step for now and just performed brute force for find 199-smooth numbers. ...
0
votes
0answers
22 views

Confused about NP hard and reduction

By definition NP-hard is at least as hard as the hardest problems in NP. And wiki states a problem H is NP-hard when every problem L in NP can be reduced in polynomial time to H So if the time ...
1
vote
3answers
56 views

C++ How can I keep count of items entered, then output each item and how many times it was entered

I'm trying to write a program for gr.12 that allows the user to enter a bunch of items and counts them (e.g. entering 'dog' twice will output 2 dog). Typing 'END' terminates the list. Here's my code:...
0
votes
2answers
34 views

K-complementary pairs using given array of integers effectively

I am very new to programming. I need to find the K-complementary pairs using given array of integers effectively. I have written the below code. It includes the duplication. I need to eliminate that ...
-1
votes
0answers
36 views

Asked in zendrive Interview [on hold]

Given a string say S of length L having letters in range [A-Z], We have to delete M characters from S such that the remaining string should say S' of length (L-M) should be lexicographical largest ...
2
votes
0answers
27 views

Is there an algorithm for determining the smallest set of solvable linear equations

I have a set of N equations with W variables. For efficiency sake, I need to find the smallest number of linear equations that are solvable. For example, if I have the following as input: 2a = b - ...
-1
votes
2answers
30 views

Thomas Solver Algorithm Python 3

I need to write a program implementing the Thomas algorithm. My program compile just fine but when i compared to the np.linalg.solve function in numpy im getting to different results for the same ...
0
votes
1answer
28 views

How to perform k-means algorithm in MATLAB?

I'm new to matlab and I want to know how to perform k-means algorithm in MATLAB, and also I want to know how to define cluster centers when performing k means. For example, let's say I'm creating an ...