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.
0
votes
0answers
10 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
22 views
0
votes
1answer
15 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
1answer
61 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
10 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
116 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
34 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
31 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
57 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
41 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
74 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
24 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? [on hold]
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
15 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
35 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
19 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
329 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
43 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
14 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
60 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
61 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
30 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 ...
4
votes
1answer
74 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
52 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
86 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
77 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
119 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
17 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
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 ...
9
votes
3answers
1k views
Simple C# HashTable Implementation
Haven't put one of these together since college. How does this look overall?
...
1
vote
1answer
49 views
Levenshtein distance with edit sequence and alignment in Java
I have this program that computes a Levenshtein distance of the two input strings, their edit sequence, and the alignment:
LevenshteinEditDistance.java:
...
3
votes
1answer
19 views
Get all combination of a nested object
I have JSON data which can be an object/array of recursively nested object or array. The value of an array can not be null, but a value in an object can be null. And I would like to return all ...
3
votes
1answer
114 views
Making the Levenshtein distance code cleaner
I was writing an implementation of Levenshtein distance in Python and I found my code really ugly.
Have you any idea how to make it more elegant?
...
3
votes
1answer
38 views
Anagram counter
Homework prompt was:
You are given two strings, a ‘parent’ string and a ‘query’ string respectively. Your task is to determine how many times the query string – or an anagram of the query string ...
0
votes
2answers
64 views
Summing all keys in the leaves of a tree
My program takes 35 sec to run example 2. How can I make my program faster?
...
5
votes
1answer
91 views
A* implementation is not running efficiently but gets correct result
I'm not entirely sure what code other people will need to see, if I miss something off that is important please leave me a comment and I will update it as soon as I possibly can.
I have coded an A* ...