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
0answers
9 views

Refactored version of Okasaki's skew-binomial heaps in Standard ML

In his book, Purely Functional Data Structures, Chris Okasaki provides an implementation of skew-binomial heaps (p. 137). Unfortunately, the book isn't (legally) freely available anywhere, but his ...
2
votes
1answer
27 views

Functional Scrabble Word Score

Homework: Write a function to score a scrabble word. values is a global dict formatted as values = {'a': 1, 'b': 3,...} The ...
4
votes
1answer
45 views

Combination generator in Java

Given a positive \$N\$, the following class generates all possible non-empty sets \$A \in \mathcal{P}(\{0, 1, \dots, N - 1\})\$ in lexicographic order. Also, it provides a method that can be used to ...
1
vote
0answers
26 views

Dijkstra algorithm implementation in F#

I'm trying to implement Dijkstra algorithm in F# for finding the shortest path in a undirected tree using a heap. I've used the type PriorityQueue found here and the code can be found here. ...
4
votes
1answer
53 views

Hacker rank Jesse and Cookies

I am trying to solve a problem in hacker rank and the question is as follows: Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value \$K\$. To do this, Jesse ...
3
votes
1answer
216 views

Find given number by summing up integers from 2 sorted arrays

I am working on an algorithm question in which I need to find out pair of number out of 2 sorted arrays which sum up to the given number. I need to print out the indexes of those pairs rather than ...
2
votes
0answers
39 views

Dynamic graph in C++11 with shortest path algorithm

I've been designing a dynamic graph to improve my understanding of C++11. The dynamic aspect means that it could represent the hyperlink structure of a chunk of the internet, with node deletion ...
2
votes
4answers
133 views

Consecutive whitespace reduction

I pursued an according algorithm with an absolute best performance, the following class embodies the solution. Any comment is welcome. ...
6
votes
2answers
70 views

Dijkstra's algorithm using collections.namedtuple

I decided to try out some named tuples by implementing Dijkstra's algorithm to find the cheapest routes in a file like this (where each line represents node_a is ...
5
votes
1answer
88 views

A* implementation

I wrote a little A* implementation by my own and would like to have some feedback ;) The code is in OOP way, thus we can use an other pathfinding algorithm easily. The "Base" is just the interface ...
2
votes
1answer
41 views

Maximum subarray problem solved with divide and conquer also for the all negative element case

Solving the maximum subarray problem with added cases of finding non maximum non contiguous subarray as well. I used divide and conquer approach and tackled the 'all negative' case by keeping a ...
3
votes
0answers
37 views

DocsGatherer - gathering and organizing fragmented documents

This script is used for gathering fragmented documents from your computer, and organizing them by extensions. Here is the main things my algorithm does: Search through path(s) Stores documents' ...
8
votes
1answer
58 views

Scala implementation of @rolfl's integer-partitioning algorithm

While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution: ...
-1
votes
0answers
30 views

Given a path to a directory, print the path to the biggest file in it - revision 2

The problem description is in the title. Revision 1 I followed the suggestions from this answer. In this revision: if (files != null) is used instead of ...
1
vote
2answers
84 views

Fibonacci heap in C - follow-up

(See the previous iteration.) I have incorporated some points made by ChrisWue and refactored my Fibonacci heap implementation: fibonacci_heap.h ...
6
votes
1answer
124 views

A* algorithm in C# for use in a game

I recently started up again on a 2D game engine I have been working on over the last couple of years. I managed to implement a version of the a* algorithm that seems to work fine for my game, but it ...
7
votes
2answers
167 views

Calculating the fastest strategy in OGame

For a game I am playing, OGame, I am trying to calculate the fastest strategy to reach a certain state in the game, relevant parts of the game for this question are: You can build different types of ...
7
votes
5answers
478 views

Count how many times values has appeared in list so far

I have a list of non-unique values. I want to output a list of the same length where each value corresponds to how many times that value has appeared so far. The code I have written to do this seems ...
3
votes
3answers
70 views

String Compaction Algorithm

I've been working on improving my C coding. I wanted to write two string algorithms: to trim white space from the beginning and end of a string to compact a string I have a few problems with this ...
8
votes
3answers
446 views

Integer quicksort in Java

I have this Quicksort implementation that sorts arrays of int (not Integer). It has comparable performance to Java's ...
7
votes
1answer
57 views

Assembler listings parser components: Operands parser

I'm building the above mentioned parser. It reads a string of assembler instructions. I want to become a better coder, so I wanted to get a code review to start learning to do things property. As we ...
1
vote
2answers
51 views

Implementation of merge sort in Python

I was working on an assignment and I was hoping to know if the merge sort algorithm I wrote in Python was not making any unnecessary computations. ...
3
votes
0answers
45 views

Determining if a genetic sequence is palindromic

Adding another level to my previous question on 'normal' palindrome identification, in this one I'm interested in identifying genetic palindromes. Here's my attempt: ...
4
votes
1answer
66 views

Determining if a sequence is a palindrome

To complement this Java question on palindrome identification, I came up with this C++(14) version: ...
9
votes
5answers
1k views

Ackermann function

I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine. ...
0
votes
0answers
28 views

Computing the curvature of a 2D image

I have some MATLAB code that computes the curvature of a 2d image. It computes it iteratively using forward and backward differences. Could you offer some tips for how I can optimize this code? ...
3
votes
1answer
157 views

Fibonacci heap in C

(See the next iteration.) I have rewritten a Fibonacci heap implementation from Java to C. fibonacci_heap.h: ...
4
votes
4answers
84 views

Soundex algorithm implementation in Java

Just started learning Java Strings. Tried to implement the Soundex algorithm. Package to hold the String related functions ...
4
votes
1answer
55 views

soundex implementation

The soundex algorithm maps several spellings of a name to a 4 character term. (hopefully mapping all different transcriptions to the same term) The steps as described in Introduction to information ...
4
votes
1answer
48 views

Recursive backtracking Sudoku solver

I'm trying to learn more algorithmic techniques and I came across an interesting application of recursive backtracking: solving a Sudoku puzzle. I'm looking for a review concerning code style, ...
5
votes
1answer
66 views

Displaying a randomly sized array as a table

This program creates an integer array with a random size of 5-50 elements (inclusive). It then fills the array with random numbers between 0 - 100 (inclusive). The interesting part comes when I then ...
3
votes
3answers
415 views

An integer is even subset of another integer

An integer m is defined to be an even subset of another integer n if every even factor of m ...
7
votes
1answer
75 views

Path finding algorithm using recursion in Python

Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal. In the maze defined, ...
1
vote
2answers
44 views

Getting prime numbers, custom example [closed]

I was tasked this in class today, so the teacher could judge where our skills are. I am not an experienced C++ programmer, and I made a mistake on my sheet, so I came home and wrote this. I saw ...
3
votes
1answer
52 views

Turning an Integer into an array of ints

My goal here is pretty simple, I want to turn a number like 12435987234 into an array of integers in reverse order. So that would look like: ...
4
votes
1answer
36 views

Proportional sorting of web scrape results

If you have a given list of lists what's the best way to sort them proportionally? Is there a better way to do this? The idea is that in a case of web scraping, you would want to avoid hitting google ...
4
votes
2answers
58 views

Find all integers between m and n whose sum of squared divisors is itself a square

Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two ...
5
votes
3answers
431 views

Checking if string characters can be arranged to form another string

I am working on a code project that checks if all the characters in str1 can be arranged to form another string (str2). If all ...
3
votes
3answers
123 views

Algorithm to find leaders in an array

An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array. Solves it in linear time ...
2
votes
2answers
41 views

Count overlapping substrings

I'm looking for feedback on the actual logic of this simple python 2.7 script. The automated grader passed it, but I expect it could be make more 'pythonic'. It was written for homework, and some of ...
5
votes
2answers
58 views

Basic Scheduler, codingame 'Super Computer' Challenge

I have built a program that handles the basic scheduling requests for CodinGame's Super Computer challenge. Specifications (taken from CodinGame) The Goal In ...
3
votes
2answers
63 views

The Grid Search

Given a 2D array of digits, try to find the location of a given 2D pattern of digits. Input Format The first line contains an integer, T, which is ...
3
votes
4answers
113 views

Computing integer square roots in Java - follow-up

(See the previous iteration.) My two previous methods for computing the integer square root of a number \$N\$ ran in the \$\mathcal{O}(\sqrt{N})\$ worst case time. Now I have added a method (...
11
votes
1answer
89 views

Glue Shredded Pieces (CodeEval)

I have solved problem 185 on CodeEval, Glue Shredded Pieces. The solution got a 100% score on all tests (edit: see comments), within the allotted time and memory constraints. I'm looking mostly ...
0
votes
1answer
73 views

Optimum Tree traversal algorithm Topcoder

I'm practicing a 1000 point algorithm problem on the topcoder.com arena. The problem is as follows:      You work for an electric company, and the power goes out in a rather large apartment complex ...
1
vote
1answer
44 views

Iterative depth-first search and topological sort in Java

This is the iterative depth-first search, that does not abuse the stack. Also, I gathered some information from DFS that may be useful; for example, I am able to do topological sort using the result ...
3
votes
2answers
50 views

Find the range of index of consecutive integers from a sorted array

I would like to know how can improve my solution. ...
5
votes
2answers
88 views

Pagination algorithm based on scores

I need to divide scoreResult into pages (which is already ordered by score column from highest to lowest), and each page cannot contain too many records (e.g. 12 is ...
7
votes
6answers
258 views

Reordering a list in python so that no neighboring elements are equal

Basically I need to order a list, so that an element is not the same as the element that comes after or before it. For example [1,2,2,3,1,3,3] should come out as [3,1,2,3,1,2,3], [3,2,3,1,2,3,1] or ...
2
votes
3answers
145 views

Wet Boxes problem: counting points on a triangular grid

As a solution to the B. Wet Boxes problem : B. Wet Boxes Bob works in a warehouse which contains a large pile of boxes. The position of a box can be described with a pair of integers (x, ...