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.
0
votes
0answers
8 views
Glueing Java collections into a heap
I have implemented this heap (priority queue) data structure using java.util.TreeMap and java.util.ArrayDeque. The operations ...
3
votes
1answer
53 views
HackerRank “Save Humanity”
The "Save Humanity" problem on Hackerrank asks us to:
... find all substrings in the patient DNA that either exactly matches the virus DNA, or has at most one mismatch.
For example: ...
2
votes
2answers
56 views
0
votes
0answers
35 views
Generating a random ObjectID
We want to ensure that certain documents in our DB get distributed well across the shards. Currently the documents are sharded by their _id, but they are often ...
-3
votes
0answers
44 views
C++ program hung at receiving input (Google codejam 2009 problem) [on hold]
Hi I'm trying to solve the following problem:
http://code.google.com/codejam/contest/dashboard?c=189252#s=p0
I'hv written the code, but my program keeps receiving infinite inputs. I tried to convert ...
3
votes
1answer
77 views
Minimum window substring
The minimum window substring problem from leetcode.com asks:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity \$O(n)\$.
...
3
votes
0answers
45 views
Subtraction in a spreadsheet column numbering scheme
The idea of the algorithm is to decrease a number from a word.
Is there a better way to write this algorithm?
limitiation:
it is important to decrease with a limit, if BB is the word we
decrease ...
-1
votes
2answers
61 views
Finding consecutive occurrences of a value in an array
Given an array, return True if the array contains consecutive values:
...
-1
votes
0answers
28 views
1
vote
1answer
108 views
Winning logic for Tic Tac Toe and OO design
I'm a Java beginner and I've just started learning about GUI. However, I'm not sure about GUI coding conventions and whether I'm getting the object orientation part of it right. I feel like I'm ...
9
votes
1answer
88 views
Naive parallel Sieve of Eratosthenes in Java
My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower compared to access/modify an array of boolean. Second, the parallel execution only happens on the ...
-1
votes
0answers
23 views
Algorithm to draw the shortest path in grid
I want to find the shortest path between two points in the grid, and than mark the path with '+' sign. I found the shortest path using BFS algorithm, but now I'm not sure how can I mark it using ...
3
votes
1answer
37 views
Implementing the Barabási–Albert model
I am writing a code for Barabási–Albert(BA) model with specific node and edges.
The algorithm is almost like [1] as follows:
...
1
vote
1answer
126 views
Random iteration over an array using divide and conquer
I have created a utility class which allows random iteration over an array.
The idea is pretty much a divide and conquer approach.
...
5
votes
1answer
42 views
Bottom up (iterative) mergesort in C
I have this C implementation of the bottom-up (iterative) mergesort:
mergesort.h:
...
6
votes
1answer
73 views
High performance triangle - axis aligned bounding box clipping
Implementation of a Robust (i.e. with a finite plane thickness) Sutherland–Hodgman algorithm for clipping polygons against an axis-aligned bounding box. I use the following code only for clipping ...
5
votes
3answers
111 views
Bubble Sort in Objective-C
Following is Objective-C method implementation I did for one of the most simplest sorting algorithms, Bubble Sort to sort an array of integers.
Note:- I have defined it as a static method in the ...
3
votes
3answers
858 views
Making as many unique strings as possible by removing two characters
I'm attempting a programming challenge type task in C#, where the goal is to determine how many unique strings can be obtained by removing two characters. The prompt for the task implied that I should ...
2
votes
1answer
33 views
DisjointSet with O(1) find and O(1) amortised union
Does this code outperform the common implementation with path-compression and union-by-rank? I'm still okay with a review.
GitHub
...
7
votes
3answers
380 views
Algorithm to compute the n-th derivative of a polynomial in Python
As a personal exercise, I'm trying to write an algorithm to compute the n-th derivative of an ordered, simplified polynomial (i.e., all like terms have been combined). The polynomial is passed as an ...
1
vote
1answer
54 views
Moving MP3 files from one directory to another using regex
This is a simple script for moving my MP3 files from one directory to another. I'd like to know if there is a more efficient way to handle my task in the script. I analyzed the algorithm to be ...
0
votes
0answers
8 views
Selection Sort trouble with indexes [migrated]
Actually I'm dealing with CodeAbbey problem, so I don't want answer as code, but explenation about that, what I am doing wrong. http://www.codeabbey.com/index/task_view/selection-sort
My Selection ...
4
votes
1answer
63 views
Tic Tac Toe algorithm using itertools
I'm looking for feedback on the readability of my code and opinions on the pick_best algorithm. I do this stuff for fun when I have time, and never get a chance to have anyone else look at it. ...
0
votes
0answers
33 views
Finding shortest paths in a Wikipedia article graph using Java - second attempt
I have improved Finding shortest paths in a Wikipedia article graph using Java.
Now I have this:
AbstractWikipediaShortestPathFinder.java:
...
0
votes
1answer
48 views
Partitions of a number (backtracking) - time efficiency
I had to write an algorithm that prints the partitions of a natural number in lexicographic order. Example of I/O:
If the algorithm reads from ...
6
votes
2answers
87 views
Find number of plus in a 2d array
Problem
CharGrid
The CharGrid class encapsulates a 2-d char array with a couple operations.
int countPlus()
Look for a '+' pattern in the grid ...
4
votes
1answer
82 views
Basic Internet banking application
I programmed in Java before, but I feel that I lack the "true way" of programming (OOP concepts, design, algorithm), so I started to learn all of these but I need your opinions and suggestions so I ...
1
vote
1answer
50 views
Javascript Parallax Scrolling Text
I built a 404 page which involves parallax scrolling text. The program updates the position of 100-200 text nodes at each animation frame called with ...
4
votes
1answer
115 views
Number of divisors of a factorial
I was solving the DIVFACT problem from Sphere Online Judge:
Given a number, find the total number of divisors of the factorial of the number.
Since the answer can be very large, print the answer ...
2
votes
0answers
40 views
Implementation of the Minimum Stop Algorithm in Javascript
I started taking the Algorithm design class from Coursera. So into the third week they talk about Greedy algorithms and walks through a sample problem.
This is the Problem Statement that I could find ...
2
votes
0answers
67 views
Find minimum distance in matrix
Challenge URL:
http://acm.scu.edu.cn/soj/problem.action?id=3330
Windy has a matrix A with size N*M which only contains 0 or 1. The
distance between Axy and Apq is: |x-p| + |y-q| Can you help ...
3
votes
2answers
51 views
Queue resizing array implementation
After learning about linked list implementations of a queue I was asked to try a resizing array implementation. I'm looking for constructive criticism.
...
5
votes
2answers
147 views
My online hangman solver
I've created a simple hangman solver at solver.lukesalamone.com, and although I'd consider myself proficient in webdev I am by no means an expert. The trick with this is that since HTTP is stateless, ...
0
votes
1answer
53 views
Find common items between two collections, and set values in one collection when matched
I want to find common items between two collection, and set values from one collection to another collection. I am aware of similar posts on the web, but they are different from this post. I want to ...
3
votes
1answer
152 views
Project Euler #549: Divisibility of factorials
This is the problem:
Calculate
$$\sum_{i=2}^{10^8} s(i)$$
where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$.
Quite mathematical, I've found a better way than brute ...
1
vote
1answer
55 views
Tic Tac Toe Algorithm revisited
I had previously submitted a tic tac toe code. I followed some of the changes suggested. This is my new code.
...
0
votes
0answers
26 views
Finding largest sum of submatrix
I found a way to output the biggest sum of square submatrix, but it should work faster. Can someone suggest a better way?
...
4
votes
0answers
49 views
Finding shortest paths in a Wikipedia article graph using Java
(See also Finding shortest paths in a Wikipedia article graph using Java - second attempt.)
I have this sort of a web crawler that asks for two (English) Wikipedia article titles (the source and the ...
4
votes
1answer
76 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 ...
2
votes
1answer
70 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 ...
1
vote
1answer
60 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
94 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
49 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
39 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
128 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
95 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 ...
5
votes
3answers
83 views
Merging 3 sorted linked lists
I already know how to merge two linked list, but I needed to code a function that'll merge three already sorted linked lists into one.
I wrote a code and it is working fine, it takes care of null ...
2
votes
1answer
93 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 ...
5
votes
1answer
33 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
44 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 ...