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

3
votes
4answers
123 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
10 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 ? ...
2
votes
1answer
32 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
13 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
41 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
42 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
55 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
57 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
47 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
27 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
36 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
71 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
49 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
78 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
53 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
55 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
118 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
191 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
49 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
48 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
16 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
61 views

Java merge sort implementation

Is this a good implementation? ...
4
votes
1answer
110 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
45 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
18 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
112 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
37 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
63 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* ...
0
votes
0answers
39 views

Pizza delivery problem: finding the best spot to set up a pizza shop

I received the following problem in an interview and submitted this solution but did not make it to the next round even though this was a working solution. I'm wondering how I can improve my code. ...
1
vote
1answer
48 views

My implementation of counting sort [closed]

I've made the following implementation of counting sort. I don't think that I understand the algorithm fully but this implementation seems to be working correctly. I've used the ...
3
votes
2answers
56 views

Function that strips trailing '0's from a float

I'm writing an embedded application in C, and at one point I need to convert a float into an ASCII representation of that float, so I can send the ASCII over a serial port. The protocol the serial ...
1
vote
0answers
17 views

Deterministic finite automaton in Java - follow-up

(See the initial and first iteration for description and motivation.) Now I have incorporated all the remarks made by Tunaki, and it looks like this: TransitionFunction.java: ...
0
votes
0answers
56 views

3D Bin Packing using Java

This is a follow up question to 3D bin packing in Java ...
1
vote
1answer
23 views

Assigning neighbor in a binary tree

This code is to solve the problem as mentioned here: ...
0
votes
1answer
76 views

Custom Dynamic Array

Pretty simple class but just want to make sure I've approached it correctly. ...
4
votes
1answer
87 views

Finding number of times each string in an Array of strings occurs in a large stream of characters (i.e large string)

Interview problem: Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the ...
0
votes
1answer
38 views

Detecting cycle in LinkedList

Is this a fair/clean way to detect a cycle in a LinkedList? Should work for both single and double LinkedLists'. ...
0
votes
1answer
22 views

Generic LinkedList with add/exists/delete/dlear/iteration functionality

I've just been going through core data structures and algorithms recently, wanting to get back in touch with the core fundamentals. I'm starting simple with a ...
4
votes
2answers
61 views

all combinations of all sizes less than N

I want to generate all possible combinations (without duplicates) of all sizes less or equal than \$N\$, so for example if \$N=3\$ I want to generate the following \$\{1\},\{2\},\{3\}, ...
3
votes
1answer
26 views

String Matching w/o repeating the comparisons for common part of the two strings

In an attempt to think up a more efficient String Matching algorithm than the naïve \$O(n \cdot k)\$ one I came up with a slightly modified approach. In my algorithm (code in Java), I tried a little ...
1
vote
0answers
54 views

Rolling up Invoice Items Matching Certain Criteria

I have a listing of invoice line items that I need to apply some convoluted business logic to. We have another listing of items that I compare the invoice items to and if I find matches, I then need ...
4
votes
3answers
83 views

Idiomatic ruby to calculate distance to points on a graph

Can this code be made more like idiomatic ruby using methods such as map or inject? @random_tour is a variable length array of points on a graph: ...
3
votes
1answer
57 views

Detect cycle in undirected graph

Below is my code to detect cycle in an undirected graph. Could anyone please review and let me know if I have taken care of all the cases? The basic idea is to use DFS (non-recursive using stack) and ...
2
votes
3answers
143 views

Read numbers until a prime is entered then print non-primes

I'm a beginner at C#. I just want to know what is the C# way to do this by its convention and a better algorithm as well. ...
10
votes
5answers
809 views

Finding two consecutive triangular numbers with a given target sum

I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
3
votes
1answer
70 views

Tic Tac Toe with 3 AI modes or Two-Player

This is my first stab at a game AI, and I've been working on multiple game mode difficulties, so I decided to start with a simple game. :) I'm most concerned about efficiency of the AI algorithms, and ...