Tagged Questions

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.

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 ...
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 ...
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 ...
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. ...
53 views

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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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' ...
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: ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
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: ...
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: ...
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. ...
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? ...
157 views

Fibonacci heap in C

(See the next iteration.) I have rewritten a Fibonacci heap implementation from Java to C. fibonacci_heap.h: ...
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 ...
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 ...
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, ...
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 ...
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 ...
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, ...
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 ...
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: ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 (...
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 ...
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 ...
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 ...
50 views

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

I would like to know how can improve my solution. ...
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 ...