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

-1
votes
0answers
15 views

skip list insertion in java [on hold]

I'm trying to insert an element into a skip list. While I think that my search function does what it's supposed to, I don't seem to be able to wrap my mind around how I'd go about inserting an ...
1
vote
0answers
22 views

Finding shortest paths in a Wikipedia article graph using Java

I have this sort of a web crawler that asks for two (English) Wikipedia article titles (the source and the target), and proceeds to compute the shortest path between the two. My code is as follows: ...
3
votes
1answer
40 views

Managing IDs using AVL trees

In a txt file there are IDs and next to them there are their neighbours like this: 1 1 1 2 1 3 2 1 2 4 2 8 3 5 Using AVL trees I store the IDs in one AVL ...
-3
votes
0answers
13 views

Apriori Algorithm - Mining association rules in Java [on hold]

Scan the transactions to find L1 For ( k = 2; Lk-1 !empty; k++) { Generate Ck from Lk-1 Count the occurences of itemsets in Ck Find Lk L1: set of all frequent 1-itemsets with counts no less than the ...
2
votes
1answer
50 views

Travelling Salesman Problem solver

I am writing a program that can implement algorithms to solve the TSP. My goals: The solver can record every algorithm step, so that the whole solving process can be later visualised by charts or ...
0
votes
0answers
16 views

Rearrange String such that similar characters are placed at least 'K' distance apart

So I was asked this in an interview, and I had to write this code on a white board. Sadly I couldn't complete the code :( . I've realized that writing code on white board is completely different ...
0
votes
3answers
77 views

Detecting if two given strings are isomorphic using Java data structures

So I have written the following code and it works for various same length isomorphic strings I have tried. However I am not sure what are some time complexity improvements and coding tweaks that could ...
2
votes
1answer
35 views

Maximum clique problem: fast heuristic

I have implemented an algorithm which computes a maximum clique via a heuristic. The pseudo-code can be found in this Paper (see Algorithm 2). Maximum Clique Problem Given an undirected, simple ...
3
votes
1answer
31 views

Queue implementation using two stacks

Here's my code and I want to know if there's a better method for doing so. While the question has stated two stacks I wonder if we could do only with one as well? ...
4
votes
1answer
73 views

Maximum profit from buy and sell offers

Given a list of sell offers and a list of buy offers for an item I want to determine how many units to trade for maximum profit. Each offer consists of a price and a maximum amount of units being ...
2
votes
1answer
59 views

Algorithm for Tic Tac Toe

Currently, I am using an algorithm that finds the best move based on the existing states of the board. Is there a better way to do it? Is there a data structure that I can use? I have also considered ...
3
votes
1answer
73 views

POSIX arithmetic expansion

I understand that a shell should be able to perform arithmetic expansion. My shell can do it: $ echo $((1+2*3+4*5)) 27 My solution uses the lemon parser where I ...
4
votes
1answer
23 views

Cyclic “dependency detection” in JavaScript

I have written some simple code to detect cyclic dependencies for a module loading system and I'd like some feedback on how I can go about improving it. The code itself finds the first cycle in the ...
0
votes
0answers
40 views

Parallel integer tree sort algorithm in Java

Introduction In this post, I will present a parallel sorting algorithm for sorting primitive integer arrays. Treesort Treesort is an algorithm which iterates over the input array and constructs a ...
2
votes
1answer
52 views

Beating a dead horse: Project Euler 4

The task A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the ...
-2
votes
0answers
31 views

Preventing Infinite Loops PHP [closed]

Let's say I'm building a simple ORM. The models this ORM works on can (and do) relate to each other in various ways. Most of these relations are pretty simple; however, it gets kind of tricky when ...
4
votes
1answer
91 views

Algorithms to find various kinds of paths in graphs

I think many here are familiar with the graph data structure. Not very long ago, I implemented as an exercise a supposedly simple Graph application that does some traversals. To note, the most complex ...
0
votes
1answer
8 views

JavaScript 2D Grid Wrapper

I have written a simple wrapper for a 2D grid in JavaScript that allows me to resize the grid dynamically and I'd like to know if there's any way I can improve on my code. Here is the code itself: ...
5
votes
2answers
50 views

Processing a sequence of additions and deletions

I am working on a program which manages a list, and must be able to insert new items, and delete ranges of items. I want the user to be able to specify the insertions and deletions in terms of the ...
2
votes
1answer
34 views

Creating List of String elements that occur a certain amount of times using only the List ADT

I am tasked with creating a list with no duplicates of all String elements, in this case first names, of an ArrayList. The method is passed a threshold, and the ...
1
vote
2answers
57 views

Counting pairs of integers which have a predefined difference

I'm doing this HackerRank problem: Given \$N\$ integers, count the number of pairs of integers whose difference is \$K\$. So far, I've ended up with this code: ...
4
votes
0answers
44 views
+100

Find group of available stalls in an aisle

An aisle is defined as two rows of six stalls each. A stall is adjacent to another if it is directly next to it or across from it. My method finds out how many stalls can be found in a chain from ...
2
votes
1answer
33 views

Calculate the lattice paths in an n*n lattice (Project Euler #15)

Project Euler #15 is to find out all the distinct possible ways there are to move from the first point (1,1) to point (n,n) in an n*n lattice. ...
2
votes
1answer
49 views

Insertion sort in JavaScript

Here is a REPL of the code. The idea here is to learn how the basic insertion sort algorithm works rather than to use existing sort libraries. How can it be clearer and more efficient? ...
2
votes
1answer
29 views

Distributing a purchase quantity into rated bands

I am working on a monthly billing application that utilises a rate band pricing mechanism to reward increasing consumption within a designated billing period. For example: Say I have the following ...
-2
votes
0answers
51 views

Can anybody help me with this (graph theory)?

I am preparing for job interviews and learning Analysis and design of algorithms. I have solved many problems using dynamic programming and greedy methods, but I am struck with this problem and unable ...
5
votes
1answer
94 views

Caches implementation in C++

I had a test task for internship where the main part was in implementing fixed size caches with different displacement policies (LRU/LFU/FIFO). I did that task, but was refused afterwards. Now I am ...
4
votes
1answer
74 views

Checking to see if array can be sorted using only one operation

I'm doing this HackerRank problem, which asks whether an array of up to 100000 integers can be sorted in ascending order by exactly one of the following: swapping two elements reversing a subarray ...
12
votes
0answers
93 views

Implementing The Proper Undead's Cave Generator

I recently stumbled onto a very old article about procedural dungeon generation on this site. Unfortunately, the author did not provide any code, only a description of the algorithm he used. Wanting ...
2
votes
0answers
35 views

Manhattan/Tchebyshev Distance - O(n^3) Solution

This is a variant of the Manhattan Distance problem. The input is a 2D matrix of boolean with the true cells representing location of an ATMs(or anything for that ...
4
votes
4answers
141 views

Subdividing intervals that contain the largest error values

I'm trying to accomplish the following: Start out with 1 interval on the real line. This interval is processed in some function and out comes an array of errors (size < 10 usually). The maximum ...
1
vote
1answer
51 views

Graph and minimum spanning tree in Python

Here is my Graph class that implements a graph and has nice a method to generate its spanning tree using Kruskal's algorithm. I want to: Make it pythonic Improve readability Improve the abstraction ...
1
vote
0answers
28 views

Give the variable length permutations (combinations) of a set of strings

This code is a proof-of-concept which I intend to convert into a static utility / helper class. I'm looking at this review from a structure or performance viewpoint. Small detail such as whether it ...
2
votes
1answer
88 views

Find shortest paths in a matrix using Dijkstra's algorithm

The problem is as follows: I have a matrix with impassable fields those are marked by the input. There is also a castle which reaches up the right side of the matrix. I have to find how many paths can ...
3
votes
2answers
35 views

Candie distribution algorithm

I am studying algorithms and I solved this problem under Dynamic Programming section: Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the ...
0
votes
0answers
16 views

Remove overlapping n-grams

I'm trying to write a compression algorithm that works by splitting the input into n-grams, and it's working, but I've start to run into a problem. This piece of code is supposed to remove ...
2
votes
1answer
52 views

Maxflow for baseball elimination game

I have a problem similar to the baseball elimination. Given some teams, the number of wins they have and the number of games they have left between each other I have to find for which team it is still ...
3
votes
1answer
77 views

Arranging Buttons on a Process Enumerating Application

I had the following piece of code for populating a list of currently running processes in an IT Self-Help application : ...
2
votes
1answer
33 views

Building an index of items from an iterable-of-tuples

Is there a more conventional / standard / easy-to-read way of building an index of tuples from an iterable than this: ...
1
vote
0answers
41 views

Mergesorting a stack in Java - a new algorithm

(See the previous iteration.) Now I have implemented a stack merge sort that does not have to reverse every substack after sorting it, and it allocates the two auxiliary stacks only once prior to the ...
3
votes
1answer
59 views

Running shell commands in a pipeline

I'm writing a shell in C for Linux and BSD. My code was unreadable before but I did a rewrite and now it is much more readable. The purpose of the code is to create a command pipeline and execute it. ...
4
votes
1answer
37 views

Secure file system utility functions

For Khronos, I've had to develop these utility functions to help me deal with storing the .wav files. However, they could also be used in a variety of ...
1
vote
2answers
37 views

SPOJ “TESSER” - Getting TLE using KMP algorithm

The TESSER - Finding the Tesserect problem is tagged as a problem to be solved by Knuth-Morris-Pratt (KMP) algorithm. I'm using KMP, but am still getting time-limit-exceeded. Task Each of T test ...
1
vote
1answer
134 views

Fast Document Distance, C++

This is an attempt at a fast "document distance" implementation in C++. For reference, I found this problem in MIT's OpenCourseware 6.006 algorithms course. A quick look at the ...
0
votes
0answers
22 views

Searching for index of node using traversing least possible path

The following is my code where I'm searching for the index of Doubly Linked List's node by traversing least possible paths. ...
5
votes
4answers
298 views

Finding factorials

How can this script be optimized? ...
2
votes
1answer
50 views

1-dimensional and 2-dimensional Peak Finding Algorithm

I have the following code for a peak finding algorithm in Python 3.4.3. A peak is an element that is not smaller than its neighbors. ...
4
votes
2answers
64 views

Probabilistically pick a candidate

I have a list of candidates which looks like this: ...
2
votes
0answers
55 views

Hunt n' Kill algorithm

Last day I implemented the Hunt and Kill algorithm in JavaScript, using HTML5 without any libraries. I would like my code to be reviewed. How it works I start with a 2D array filled with walls ...
5
votes
1answer
44 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 ...