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

0
votes
0answers
7 views

Logic for shuffling sliding puzzle

i'm working on a sliding puzzle, one little project as a hobbie, 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 ...
1
vote
1answer
7 views

Rotation of elements in an array (optimisation)

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
21 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 ...
2
votes
0answers
29 views

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
16 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. ...
2
votes
2answers
33 views

Parallel integer Quicksort in Java

Now I have that parallel Quicksort for (primitive) integer arrays. ParallelIntQuicksort.java: ...
3
votes
1answer
40 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
40 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: ...
4
votes
2answers
40 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
107 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
43 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 ...
-2
votes
0answers
48 views

Implement Stack Using Array [closed]

i have designed a Stack using array in C++ i don't understand 2 things 1.) The Stack is of fixed size that i am setting in #define MAXSIZE 10 and when i push ...
6
votes
3answers
52 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
67 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
36 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
0answers
14 views

Getting the Wrong Answer for my Approach [closed]

Here is aQuestion Link. I have tried solving this Question using Bitmask, But i am getting the Wrong Answer. Can Anybody help me to figure out my mistake. ...
2
votes
2answers
103 views
+50

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
33 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
120 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
64 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 ...
0
votes
0answers
37 views

Radix-sorting in Java

import java.util.Arrays; import java.util.Scanner; public class RadixSortCodeReview { ...
2
votes
0answers
36 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
42 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
49 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
46 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
30 views

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

How do I increase its performance? %CORD_XY(1),CORD_XY(2) is the seed point %LEN Denotes the number of images in a folder %num is used to iterate in "for loop" % "img" here is single image from the ...
3
votes
0answers
55 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 ...
3
votes
0answers
24 views

Adaptive counting sort for integer arrays in Java - follow-up

I have refactored this. Once again, the running time can be anything between \$\Omega(n)\$ and \$\mathcal{O}(n^2)\$, yet it adapts to "smoothness" of the input array. ...
3
votes
1answer
74 views

Redirecting arriving customers to the nearest empty queue

I have a task to make a checkout line controller. First it receives, as input, an amount of checkouts and commands. Then commands that are C for coming and L for leaving, and after those the number of ...
3
votes
2answers
47 views

“ACM ICPC Team” challenge on Hackerrank

ACM ICPC Team You are given a list of \$N\$ people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of ...
3
votes
1answer
42 views

Count the number of checks each method had to perform before fully sorting the array

So I'm writing a program that compares Bubble, Selection, Merge, and Quick Sort. All 4 methods are given a randomized array of 1000 elements and I count to see how many times it takes a method to ...
1
vote
1answer
77 views

Shell Sort Comparisons/Exchanges Counter

I need to analyze shell-sort. Currently I am working with it having an increment of N/2. I will then go on to try more efficient increments. However, my count for ...
4
votes
2answers
84 views

Finding the indices of the two items whose price adds up to to a value

I've solved the Google Jam store credit problem. but there's some inefficiencies that I want to get rid of them to improve the algorithm and reduce the multiple iteration. What are other better ways ...
3
votes
1answer
33 views

Sum to zero of all triples in a list - n^2 running time

As part of an interview, I had to submit a code sample to solve the classical "triples sum to 0" problem. The reviewer said the algorithm needed to be in n2 time, and I was later informed that the ...
2
votes
1answer
58 views

String similarity calculation

For string similarity, it is defined as longest common prefix length. For example, "abc" and "abd" is 2, and "aaa" and "aaab" is 3. The problem is calculate the similarity of string S and all its ...
3
votes
0answers
88 views

Nonlinear Nonparametric Regression

I explain the nonlinear correlation coefficients in this paper and provided the code in this post. The nonlinear nonparametric regression is an extension of this work and its description can be found ...
2
votes
0answers
41 views

An AVL-tree based order statistic tree in Java

I have this java.util.Set implementation that is based on AVL-trees, which implies that the set is sorted. However, it provides two additional operations: ...
3
votes
0answers
44 views

CLRS(Introduction To Algorithms) implementation of BFS and DFS in Java

This is the implementation of BFS and DFS i have tried to follow from CLRS.Please suggest what can be improved in this code. ...
5
votes
1answer
274 views

Longest Substring in Java

This is my function for determining the Longest Substring between two strings in Java. ...
5
votes
0answers
56 views

An iterator returning all possible partitions of a list in Java

Given a list of \$n\$ objects and an integer \$k \in \{ 1, 2, \dots, n \}\$, this iterator generates all possible ways of partitioning the elements in the list into exactly \$k\$ disjoint, non-empty ...
5
votes
0answers
77 views

An iterator returning all possible permutations of a list in Java

I have this class that iterates over all permutations of an input list: PermutationIterable.java: ...
5
votes
3answers
194 views

Print all anagrams together in a sentence in Java

I know a lot of memory is being used, but how do I make this more efficient in space(and time) . ...
1
vote
2answers
59 views

Combination generator in Java - 2nd iteration

I have refactored the previous combination generator, and now it is an iterator returning combinations as lists. It hides larger constant factors as the previous version, yet it is really easy to use: ...
2
votes
1answer
57 views

Finding smallest number of moves

We are given a map of sides of length n and m (both n and m are less than 1000), divided into n*m fields (squares of side 1). The map looks (for example) like this: ...
2
votes
0answers
20 views

Complex Space Factorization

I have posted a discussion on Math.SE regarding visualizing the complex space and effects of factorization methods on that space. A quick link to the paper is available here. I have 3 routines in ...