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
1answer
29 views

Improving performance for Depth-first search algorithm

I am using the following Depth-first search algorithm to compute value of a property called rotation_absolute based on previous values of ...
2
votes
1answer
70 views

Lazy prime number generator

There are multiple Project Euler problems (e.g. 7, 10) that deal with prime numbers. I decided make a reusable solution that could be used for most of them. I wrote a method to generate an infinite* ...
1
vote
0answers
45 views

Finding a Cartesian product of multiple lists

I came up with an extension method to find a Cartesian product of multiple IEnumerable sets. I was able to achieve lazy enumeration via ...
9
votes
1answer
62 views

n-queens puzzle in Python

I want to increase the efficiency and reduce the time complexity for the n-queen problem in n*n matrix chess. I am able to run only still (11*11) in normal time otherwise for the big number it is ...
-4
votes
1answer
35 views

Two similar tests on different variables [on hold]

I've had a doubt about something. Let's say I have 4 variables, A1, A2, B1, B2. If A1 > 0 or B1 > 0, I have to check if A2/B2 is also > 0. What I have is the following but I'm finding it a bit ...
1
vote
1answer
34 views

Cumulative transition matrix Markov Chain simulation

I have a cumulative transition matrix with probabilities for all the possible states from 1 to 5. Now the algorithm for simulating future states is following: the initial state is selected randomly, ...
-2
votes
1answer
75 views

Parsing JSON in one go using state machine solution

I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
4
votes
0answers
37 views

Shortest path navigation across a grid using Best First Search

The code below is an implementation of the Best First Search algorithm for navigation of the shortest path across a 2D NxN matrix. As a heuristic for the search I use the standard distance formula. ...
-7
votes
0answers
23 views

Java - TicTacToe with AlphaBeta pruning [closed]

I'm trying to implement a minmax algorithm with alpha beta pruning in a tic tac toe game in java. The code appears to be right but when I call the main cMove ...
1
vote
2answers
128 views

Divide list into batches

Three questions: is there a more performant way, is there a more suscinct, strike that, a way of expressing this where if you read just the body it is immediately apperent what the alorithm does, and ...
3
votes
3answers
340 views

Optimizing timeline generation

I have a bunch of processes that are being executed on different virtual machines. All of those processes have a StartDate, ...
-3
votes
0answers
92 views

Lisp - Help in vacuum agent code [closed]

I know I have this question in StackOverflow and was answered by Vitane Many thanks to him. However, I tried implementing his code, it returns me error that says it is not a structure of the type. ...
2
votes
0answers
34 views

Parallel merge sort in Java

I have rolled my own parallel merge sort. My performance figures are as follows: Seed: 1457521330571 java.util.Arrays.sort() in 6840 ms. Sorted: true java.util.Arrays.parallelSort() 3777 ms. ...
0
votes
2answers
46 views

Implementing permuted index in C++

I have implemented a program that produces a permuted index. Actually it is this exercise: http://stackoverflow.com/questions/4015016/what-is-a-permuted-index Could anyone tell me if I did something ...
5
votes
3answers
148 views

Duplicate-preserving collection intersection

Python sets are magical things. Mutable, deduplicating data stores with handy operator overloads for &, ...
0
votes
1answer
39 views

Finding Kth Permutation Sequence

I have written a program to display the kth permutation sequence of a string made up of letters 'O' and 'Z' . I tried optimizing it but my code have not passed test cases due to timeout issues.Looking ...
2
votes
0answers
28 views

Sort Algorithms in Julia

Similar to this question here, I am trying to implement sort algorithms in Julia, as part of a package. The code for the implementation is as follows: ...
1
vote
3answers
90 views

Logic for shuffling sliding puzzle

I'm working on a sliding puzzle, one little project as a hobby, and yesterday I thought that instead of working on an algorithm to figure out a solved puzzle, it would be easier to make an algorithm ...
2
votes
1answer
33 views

Fractional Knapsack

This is my solution to an assignment on the fractional Knapsack problem. I take as problem input the following pieces of information: The number of item types The total weight limit For each item ...
6
votes
3answers
315 views

Rotation of elements in an array

We had to write a program that would perform rotation of elements in an array. The array size was entered by user, so it had to be in a sense, dynamic. Rotation or Circular Shifting Initial Array: ...
3
votes
0answers
33 views

Implementation of Dijkstra's Algorithm in JavaScript that returns both shortestDist/shortestPaths

I decided to try to understand the basic idea behind Dijkstra's algorithm better so I implemented it in JavaScript (the only language I am proficient in as of now) so I could really see what was ...
7
votes
0answers
127 views
+100

Decompose polarimetric SAR covariance matrices in MATLAB

I have the following code to implement the algorithm described in the article Adaptive Model-Based Decomposition of Polarimetric SAR Covariance Matrices by Arii, van Zyl, and Kim, in IEEE Transactions ...
2
votes
1answer
19 views

Printing the minuend and subtrahend in a Minimum Difference algorithm

I have a Minimum Difference algorithm, and I wanted to expand on it by printing the actual elements that were subtracted. I'm just wanting to know if this is the best way to do it. ...
3
votes
2answers
40 views

Parallel integer Quicksort in Java

Now I have that parallel Quicksort for (primitive) integer arrays. ParallelIntQuicksort.java: ...
3
votes
1answer
48 views

DFS algorithm too slow

I am practicing my coding on leetcode, and my submission, although correct for small cases, is timing out for large ones. Could you please let me know how to improve my code? The question is as ...
3
votes
2answers
50 views

Search algorithms in julia

I've been trying to implement the basic search algorithms: Sequential search for ordered and unordered arrays and the binary search algorithms, as part of a package. So, this is the implementation: ...
2
votes
3answers
20 views

Longest Collatz sequence in Python

I came across this problem: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) ...
4
votes
2answers
42 views

Storing disassembled data in a structured way

I want to store the information returned by the dis function of the dis module in a structured way, using a dict, associating the mnemonics of each code of a line to the correspondent line number. ...
2
votes
3answers
114 views

Reverse digits and add until a palindrome appears

The following code is a C solution to the following problem UVA 10018. The Problem The "reverse and add" method is simple: choose a number, reverse its digits and add it to the original. If ...
3
votes
0answers
44 views

Expression parser using Shunting-yard algorithm

I've been working on a expression parser which will be part of another project (some sort of DSL). This parser basically uses the Shunting-yard algorithm, except for the case of parenthesis: here it ...
6
votes
3answers
57 views

Korean word segmentation using frequency heuristic

This a continuation of a previous question. I want to thank Joe Wallis for his help with increasing the readability of my code. Although the changes made by Joe Wallis did increase the speed of the ...
1
vote
1answer
71 views

Reading input fast in Java for competitive programming

I have been solving problems on Timus Online Judge. In the beginning, I didn't worry much about I/O operations, so I just took some code from the internet and focused more on the logic. But after ...
1
vote
2answers
42 views

An easy algorithm for encrypting and decrypting binary data using a cipher key in Java

I have this easy en-/decryption algorithm. Disclaimer However, I have absolutely no prior experience in information security, encryption, and so on, so bare with me. Encryption Encryption works ...
2
votes
2answers
197 views

Parsing JSON in one go

I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
2
votes
0answers
35 views

Needleman Wunsch algorithm in Scala

The Needleman–Wunsch algorithm is an algorithm used in bioinformatics to align protein or nucleotide sequences. Here is an implementation in Scala: ...
4
votes
2answers
62 views

A command line general sudoku solver in Java

I have this command line program that asks the user to (partially) input the source sudoku with some missing values, and after that validates the input and solves it. See what I have: ...
2
votes
0answers
36 views

An iterator returning all possible solutions to n-queen problem in Java - follow-up

(See the initial iteration.) Now I have slightly improved performance of the iterator. Whenever we have set a queen at a particular board cell, the previous iteration sacrifices \$\mathcal{O}(n)\$ ...
2
votes
2answers
126 views

Java method to check if a binary tree is a valid BST

I wrote a Java method (along with a private class) to check if a binary tree is also a binary search tree (BST). I would like some feedback on the design of my solution. Here is a brief description ...
3
votes
2answers
67 views

Find two numbers that add up to a given total, from a formatted string

The full challenge from codeeval.com can be viewed here. Input Your program should accept as its first argument a filename. This file will contain a comma separated list of sorted numbers ...
-1
votes
0answers
40 views

Radix-sorting in Java [on hold]

import java.util.Arrays; import java.util.Scanner; public class RadixSortCodeReview { ...
2
votes
0answers
37 views

An iterator returning all possible solutions to n-queen problem in Java

(See the next iteration.) Given a positive integer \$n\$, I have an iterator that returns all possible solutions to \$n\$-queens problem one by one: QueenIterableV1.java: ...
2
votes
2answers
43 views

splitting multiple joined words, port from perl to PHP

Though i have never worked on perl, not even once. I have ported the perl code into PHP and it seems like giving a correct result. But as I am going to use it on production server. I want this code ...
1
vote
3answers
75 views

Duplicate Line Finder

I recently wrote a program that reads a plain text file, and compares every line and alerts you if any are similar, based on a float value that you pass in to a function. ...
2
votes
2answers
83 views

Dictionary algorithm, computing all case options

I am building this algorithm as part of a larger project for a network security class. The gist of this part is that I have been given a dictionary, and I need to find every possible option for a word ...
4
votes
1answer
50 views

C++ class for disjoint-set/union-find on integers

I have implemented the disjoint-set data structure. The purpose is to group integers together. For example, if I want to find out the groups of integers where each adjacent neighbors are same: ...
1
vote
1answer
60 views

MSD radix sort in C++

I have this MSD radix sort in C++: ...
1
vote
1answer
51 views

Searching Subdirectories of a Subdirectory for Registry Keys to Delete

Please let me know if I can improve my question in any way I build/maintain an IT Support Self-Help App and recently had the need to include some registry key manipulation when users experience ...
3
votes
0answers
39 views

Segmenting brain images (Dicom format) using region-growing algorithm

I have a list of images in a folder where num denotes the index of image and I used num to run the iterations in a "for loop". ...
3
votes
0answers
56 views

Integer tree sort in Java

I have this algorithm for sorting integer arrays. Basically, it's a balanced tree sort which creates a tree node for each distinct integer, and in each tree node it maintains a counter counting how ...