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

4
votes
2answers
24 views

“Critter Tracking: When does it cross its own path?” Part 2

Basic Info: This question is my second attempt at this question. It is based on a question similar to this Codility question. The input (an int array), the outpout (an integer) and the method ...
4
votes
3answers
117 views

Implementation of Sieve of Eratosthenes algorithm

I have made an implementation of Sieve of Eratosthenes algorithm in Java, and am not certain that it is as efficient as possible. I have looked at other peoples implementations on Google, and on this ...
5
votes
2answers
50 views

Text justification

This is the Text Justification challenge at LeetCode: Given an array of words and a length \$L\$, format the text such that each line has exactly \$L\$ characters and is fully (left and right) ...
1
vote
1answer
31 views

Inserting a node at a specific position in a linked list

Given a node class like class Node { int data; Node next; } Provide an implementation to Insert a node at a specific position in a linked list ...
5
votes
3answers
87 views

“Critter Tracking: When does it cross its own path?”

Added: Version #2 of this question Minor Update/Additonal information: This question is based on a Codility question similar to this one. The input (an int array), the outpout (an integer) and the ...
3
votes
3answers
23 views

Determining which octant has a specific point

I am interested in octants in plane geometry, which basically involves dividing a plane into 8 equal parts according to a certain point. Octants are particularly useful while implementing the ...
5
votes
1answer
47 views

Caterpillar uneaten leaves

K caterpillars are eating their way through N leaves, each caterpillar falls from leaf to leaf in a unique sequence, all caterpillars start at a twig at position 0 and falls onto the leaves ...
1
vote
0answers
12 views

Range Query - Range Update

This is the problem statement: In most of the range query-update questions, we are asked to update some range of the array with some constant_value which can be ...
3
votes
1answer
41 views

Non-recursive approach to the Rod-Cutting

I've given the Rod-Cutting Problem a go with a non-recursive approach that use a cache instead, with a bottom up approach. For anyone who hasn't heard about the Rod-Cutting problem, it's defined as ...
3
votes
1answer
51 views

Batch Gradient Descent running too slowly

Following Data Science from Scratch by Joel Grus, I wrote a simple batch gradient descent solver in Python 2.7. I know this isn't the most efficient way to solve this problem, but this code should be ...
4
votes
1answer
51 views

A* algorithm solution to “intermediate space probe” challenge

This code is my solution to this Reddit challenge: Description: NASA has contracted you to program the AI of a new probe. This new probe must navigate space from a starting location to an end ...
3
votes
2answers
72 views

Even Fibonacci numbers under 4,000,000 (Project Euler #2)

Prompt: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
4
votes
2answers
621 views

The stocks problem - find the biggest profit that can be made

The Stocks Problem: Given an array of n integers representing the price of a stock over the course of n days, determine the maximum profit you can make if you can buy and sell exactly 1 stock ...
6
votes
1answer
65 views

Topological sort

The algorithm works in steps: Produce the graph in the form of an adjacency list e.g. this graph 0 - - 2 \ 1 -- 3 produces this adjacency list ...
3
votes
2answers
143 views
+100

Memory efficient A* (AStar) Algorithm

I am writing a solved for 15 puzzle game which will find the solution path to any NxN board. For easier boards the algorithm works great solving almost any 3x3 boards, most 4x4 boards, but when I go ...
3
votes
1answer
50 views

Python Knapsack problem: greedy

A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for ...
3
votes
1answer
47 views

Substring searching with Knuth–Morris–Pratt

My program uses the Knuth–Morris–Pratt algorithm to search for a particular substring in a .txt file and then store it in a binary search tree. Note that ...
7
votes
1answer
56 views

Python Knapsack problem using branch and bound algorithm

I wrote a code in Python to solve Knapsack problem using branch and bound. I tested it with the case from Rosetta and it outputs correctly. But this is my first time to write this kind of code, I am ...
-1
votes
1answer
40 views

Singly Linked List with Generics and Comparable Data [closed]

I am currently reading about the thread-safe implementation of a linked list. Although I implemented this linked list while keeping in mind the issues from the first code review (Binary Tree). I would ...
3
votes
1answer
91 views

Stable reversed Tartaglia's triangles

Inspired by Minimising the triangle I am writing a fully tested program to solve the following problem: A triangle needs a good foundation. Every row in the triangle is derived from the sum of ...
6
votes
1answer
107 views

Solving a partially completed 10x10 tournament schedule

My buddy schedules a dart tournament, and got into trouble when there were some scheduling conflicts. He has the first 3 weeks in the books, and needs to finish out the rest of the schedule. Turns out ...
10
votes
2answers
296 views

WaTor Code in Java

I just coded a version of WaTor, a population simulation game in which fish and sharks move around, breed, and eat each other. I am wondering how I did and if there are better ways to do some of the ...
1
vote
0answers
29 views

Project Euler#61: Cyclical figurate numbers

Project Euler Problem 61 asks: Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae: ...
5
votes
2answers
160 views

Intense worksheet manipulations: what price did I pay for performance optimization?

The code bellow was refactored for performance improvements for another user on this site. Functionality, high level: Sheet1 - CodeName aIndex: used as the main reference to the structure of the ...
3
votes
2answers
72 views

Auction Algorithm Optimization in C++

I have written the following Auction Algorithm implementation in C++ and I am having issues with performance. On my machine a problem size of 500 is solved in about 7 seconds while a similar Matlab ...
3
votes
2answers
75 views

Binary search tree implementation (with Node class)

I have implemented the Binary Search Tree in Java and would love to get reviews. I would like to have some comments on multi thread implantation. ...
2
votes
1answer
83 views

Finding two numbers that add to a given total

Given there's a list of random number and the amount I want to find. For example: [80, 98, 83, 92, 1, 38, 37, 54, 58, 89] And I want two numbers that add up to a given total in this case it's ...
3
votes
1answer
63 views

Hackerrank's Sherlock and Array

Challenge can be found here Problem Statement Watson gives Sherlock an array A of length N. Then he asks him to determine if there exists an element in the array such that the sum of the ...
1
vote
1answer
52 views

Printing all factorizations of a number

For example, if we have 120, the answer should contain (2,2,2,3,5),(2,60),(4,30),... Here is my not-so-good attempt ...
0
votes
1answer
26 views

Implementing quicksort with pivot of first, median or random

I am attempting to implement the quick sort algorithm whereby the pivot will be chosen by the user, and can either be median, first, or random. I am supposed to return a ...
4
votes
1answer
155 views

Dijkstra's Algorithm in Project Euler# 83: Path sum: four ways

The problem is from here: The page at Wikipedia said: Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. Set the ...
2
votes
2answers
60 views

Find all descendants deeply of tree structure from flat data

I have a flat data that represent the hierarchical relationship as below: ...
3
votes
1answer
52 views

Interval scheduling problem in C++

The problem I attempted to solve is described as: What is the largest subset of mutually non-overlapping intervals which can be selected from I? Where I is a set of N intervals where each ...
4
votes
1answer
120 views

Algorithm for detecting keyboard slips

I decided to make a script that will evaluate a user input and attempt to figure out what keyword they meant to type, by checking what characters are next to the ones they entered. ie. On a QWERTY ...
2
votes
1answer
51 views

Logging and profiling - automatic logging through annotations

I am working with a little project intended to allow applications to benefit from aspect oriented programming. The first aspect is logging, which is already working. However I want this code to be ...
5
votes
0answers
99 views

Backpropagating with Neural Network

I wrote a Java program implementing a neural network with backpropagation. For anyone who isn't familiar with Neural Networks and Backpropagation, here is a good resource. Here is another ...
4
votes
1answer
31 views

Finding kth min/max in BST

Please critique my code. (Specifically, I'm not sure if my use of member variables is appropriate.) Here is the main structure of my BST class: ...
14
votes
2answers
409 views

Do they have the POWER?

I'm working on a city building simulation game, and I have reached the point where I need to check whether tiles are connected to a power source. I decided on a flood fill for this, since it seemed ...
6
votes
1answer
41 views

Create random way from one point to another in map

I've coded a function which uses a map and creates a random way between two points. Startpoint is always 0/0 and the goal is somewhere else everytime on the map. Now I'd like to know if I could ...
15
votes
2answers
252 views

Minimising the triangle

A triangle needs a good foundation. Every row in the triangle is derived from the sum of the two values below it. However, there can be no repeated values, if a value shows up more than once the ...
1
vote
1answer
44 views

Arithmetic sequence in array

3 elements forms arithmetic sequence, when difference between any two consecutives of them is the same. In our task we are given array A. Any pair of integers in this array is called slice (eg. ...
3
votes
2answers
54 views

Backtracking all the words in the English alphabet that have 5 letters, where no 2 consecutive letters can be consonants or vowels

I have the following problem in my algorithms textbook: Write a computer program that generates and counts how many words of 5 letters of the English alphabet can be formed, with the condition ...
5
votes
4answers
551 views

Simple Binary Search Tree

At the moment I am learning algorithms and here I am trying to implement a simple binary search tree. I would like to know your suggestions on whether I am on the right track or not, and how this can ...
3
votes
1answer
70 views

Simple string-split by root and sufix algorithm

A classic problem to split a string into its "root and suffix": (Stemming) The word "walk" is the base form for word "walking" (suffix is "ing"); The file path ...
3
votes
2answers
90 views

Mystery sum with placeholder digits

I came across this coding problem. Back in primary school, maybe you were sometimes asked to solve a fill-in-the-blank sum - or "mystery sum" - in which certain digits are removed and you had ...
11
votes
2answers
299 views

Simple 2048 AI in Python

A few weeks ago, I wrote a Python implementation of 2048. Since then, I've been working on a simple AI to play the game for me. The code uses expectimax search to evaluate each move, and chooses the ...
4
votes
1answer
85 views

Tweets per second calculator (Talent Buddy)

This challenge is from Talent Buddy: Tweets per second Japan Castle in the Sky airing broke a Twitter record on August 3, 2013. At one point during the classic anime movie showing, ...
3
votes
2answers
69 views

Add two numbers represented by linked lists

I've just encountered this question and am trying to solve it using Java. Here is my solution to it, which may not be optimized or might not be right way to do it. Someone please review whether it is ...