An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

learn more… | top users | synonyms

-2
votes
0answers
10 views

printing numbers to a given number n and calculating the sum and count as well

printing numbers to a given number n and calculating the sum and count as well, but my programm is giving time limit exceeded . Please suggest to reduce the complexity ...
4
votes
1answer
27 views

Speed concerns of octree implementation

For couple of days now I am trying to speed up my Force-Directed graph implementation. So far I've implemented Barnes-Hut algorithm that's using octree to decrease number of computations. I've tested ...
-3
votes
0answers
20 views

Reserved words design pattern?

I want to implement the POSIX reserved words and my program to evaluate shell scripts such as sh -c 'for i in $(seq 1 1000); do ...... " ...
0
votes
0answers
10 views

Architecture of a complex web service using algorithms

I am building a web service that can track and analyze sets of events. It is similar to Mixpanel, but also include statistical analysis of the events (multi-parameters regressions, causality tests and ...
1
vote
1answer
52 views

Shortest path in maze

Please help review my code. ...
-4
votes
2answers
38 views

Rewrite 12 consecutive ints based on bizarre logic

Despite looking terribly ugly, it is pretty interesting due to some specific connections to cellular automata theory. I'm looking for ways of simplifying it further. This program takes 2.7 seconds to ...
2
votes
0answers
24 views

Comparing linear time strongly connected component algorithms in Java

So I have implemented three linear time (\$\mathcal{O}(V + E)\$) algorithms for finding strongly connected components of a (directed) graph. A strongly connected component is just a maximal subset of ...
-4
votes
0answers
47 views

How to parse a POSIX command line pipeline in C

I've refactored this function that was 200+ rows. Now it is "only" 161 rows and I can do further refactoring now that I have a strategy. I fixed all the errors and memory leaks and measured with ...
0
votes
1answer
38 views
0
votes
1answer
25 views

Optimizing and accounting for edge cases in Dijkstra's algorithm

I just recently wrote a program to simulate how multicast routing works. The program uses a weighted graph to represent the network and simply runs it through the algorithm. I would like to know if ...
8
votes
2answers
87 views

Finding a string whose MD5 starts like the digits of π

I tried to make a program to find a string whose MD5-hash starts like the digits of pi, where dot is omitted. Is there a faster way to do it than this: ...
1
vote
0answers
19 views

Algorithm and PHP Class to Compare companies' information and define similarity

The task is: I get companies' information from a large CSV file and then I need to compare this information with each company in the database to know if the company is a new one or if it is already in ...
3
votes
2answers
118 views

High execution time of LCS length program in Python2

I was trying to solve the Longest Common Subsequence problem on a HackerRank exercise. It's quite simple and straightforward, just print out the length of the LCS. I submitted this code: ...
3
votes
0answers
38 views

Octree creation for Barnes-Hut algorithm

I am trying to implement quadtree for my Barnes-Hut algorithm implementation. I am not sure that the code I've wrote so far is good implementation - it is dirty, and tend to be slow. Of course I am ...
1
vote
0answers
33 views

Union Find implementation

I am trying to complete this challenge. The user should enter a sequence of instructions, = to link two numbers, and ? to query ...
4
votes
2answers
61 views

Is this the right way to implement a simple hash table in C++?

Does this look like a proper implementation of a hash table in C++? Any errors anyone can find? Thanks in advance (: ...
1
vote
1answer
46 views

Mergesorting a stack in Java

I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have: StackMergesort.java: ...
1
vote
1answer
30 views

Longest Palindromic Substring

I wrote the following code for this problem. The problem is to find the longest palindromic substring. I think it is correct and is working correctly for all the test cases I entered myself. Now, the ...
3
votes
3answers
82 views

Calculate the Hamming difference between two DNA strands

Write a program that can calculate the Hamming difference between two DNA strands. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ The Hamming distance between these two ...
1
vote
0answers
27 views

Numerical differentiation using the y-intercept

I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). ...
-4
votes
0answers
23 views

Can anyone walk me through the logic of this algo for the task? [closed]

Here is the task itself. Cannot wrap my head around this algorithm. Could there be a more elegant solution for the task? Here is a solution (math) to an almost identical problem. ...
0
votes
0answers
16 views

Lazy segment tree implementation

I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially the ...
0
votes
0answers
36 views

Segment tree implementation in C++

I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, not "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially ...
3
votes
0answers
21 views

Sparse table implementation

I wrote a C++ implementation of a sparse table (I wrote it for an arbitrary function) and I want so much to ask for a review. I'd like to know how I can make it better, especially the consistency of ...
2
votes
1answer
43 views

Find the contiguous subarray within an array (containing at least one number) which has the largest sum

Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray ...
5
votes
6answers
332 views

Find maximum difference between values in an array

My task is to use the following pseudocode and improve it (make it run faster). Also I have to analyze the runtime of the given pseudocode and of my new code that i improved. What does this algorithm ...
0
votes
0answers
12 views

Reservoir sampling implementation in C

The distribution of unique values in input and output seems to be quite different in the following code, (h1), (h2); does the implementation have any obvious error ? ...
3
votes
1answer
44 views

Java Connect Four “Four in a row” detection algorithms

I am making a connect four type game for my end of the year project in my programming class. I am about to start building off of the console based version I have made and add a GUI, but I feel sort ...
0
votes
0answers
15 views

Unification with sequence variables and flexible arity functions

Today I wrote an implementation of the unification algorithm found in Temur Kutsia's 2002 paper. I didn't just do this for fun, it's related to other research I'm doing. I'm feeling more confident in ...
0
votes
1answer
42 views

Get time slots based on multiple workshops

I have a list of Workshops, each having open days (Monday, Tuesday etc.) and open time and close time (which will be same for each day). Now, Based on the current time, I need to find out next 7 days ...
2
votes
1answer
43 views

Import data module

I have a custom module to import nodes from a .txt file. (Drupal 7). My problem is I have a lot of nodes to import and this function takes so much time. ...
2
votes
2answers
62 views

Fractional Knapsack in Java

So I solved Fractional Knapsack problem: There are n items in a store. For i =1,2, . . . , n, item i has weight wi > 0 and worth vi > 0. Thief can carry a maximum weight of W pounds in a knapsack. ...
3
votes
1answer
63 views

A* Search with Array Lists

I implemented A* Search with Array Lists following the pseudocode here. I have been working with different algorithms on my own, and now, I am trying to optimize them so that I can run them with less ...
3
votes
1answer
49 views

Celebration Party Problem - Algorithm

I solved the following problem: Let's consider the following situation. You've invited a lot of children to a celebration party, and you want to entertain them and also teach them something in the ...
0
votes
1answer
31 views

p0-Pollard implementation

I should implement p0-Pollard with C++14 and a good algorithm. How may I improve my code? ...
3
votes
1answer
37 views

Minimum Refills from A to B

I am studying algorithms and I had to solve this algorithm: Consider the following problem. You have a car such that if you fill it up to full tank, you can travel with it up to 400 kilometers ...
5
votes
2answers
96 views

Counting sort using STL

I'm trying to learn to use the C++ Standard Library and some of the modern C++11 features. Can someone review my counting sort algorithm below and critique my style/algorithm/use of the STL? Thank ...
3
votes
1answer
53 views

Determining if a string is a palindrome of a permutation

I wrote code to determine if a string is a palindrome of a permutation. This exercise was taken from Cracking the Coding Interview. I'm looking for any tips on improving it. ...
1
vote
1answer
87 views

Implementation of Dijkstra's algorithm in C++

This is my implementation of Dijkstra's algorithm. Could you tell me what am I doing wrong and what should be fixed? I was not sure how to keep track of the shortest outgoing edge from a node and I ...
4
votes
1answer
78 views

Sort algorithm in c

I wrote this algorithm a while ago, and decided to revisit it and polish it up. It basically works by comparing each number with all the other numbers once, so comparing the first number to all ...
2
votes
0answers
62 views

Fast exact algorithm for subset sum problem in Java

I have implemented an \$\mathcal{O}(N2^{N/2})\$ algorithm for subset sum problem described in Wikipedia. That is what I have: SubsetSumFinder.java: ...
1
vote
1answer
58 views

Implementation of Prim's algorithm in C++

Could anyone comment on what could be done better and if I made any mistakes? ...
0
votes
4answers
120 views

Remove “b” and “ac” from a given string

I coded this solution for this problem: Given a string, eliminate all “b” and “ac” in the string, you have to replace them in-place, and you are only allowed to iterate over the string once Seems to ...
7
votes
3answers
192 views

Nucleotide Count

I am learning Java and hence practicing it from here. The solution seems pretty trivial to me but still I would like to have a honest review which would guide me to following ideas: Am I maintaining ...
5
votes
1answer
50 views

Python Octree Implementation

I'm working with 3D point clouds stored in Numpy arrays. I'd succesfully used the scipy's KDTree implementation for task like k-neighbors search and outlier filtering. However I wanted to try the ...
3
votes
1answer
49 views

Heap Sort implementation time complexity

I have implemented Heap sort, but i think the time complexity is more than (nlogn). Could anyone explain me; what is wrong in my code which makes more time complexity. I will be glad if the answer is ...
1
vote
0answers
20 views

Inpainting algorithm using conjugate gradient for colored images using Matlab

I am currently working on an inpainting algorithm : the input is a picture, I apply a Mask (random disposition of dark pixels) and then the algorithm tries to recover the original picture using the ...
0
votes
0answers
45 views

Suffix array algorithm

Here is implementation of the suffix array algorithm. I'm wondering if I can safely change this line: ...
5
votes
3answers
62 views

Java merge sort implementation

Is this a good implementation? ...
4
votes
1answer
112 views

VERY simple C# Set implementation

This is not meant to solve any insane real world problems. I just want to make sure my Set logic is right and the code looks okay. It feels weird implementing it with a ...