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
vote
2answers
22 views

Text font size adapting to space

In order to practice my programming skills, I am trying to implement a Button class, to use in pygame. I know there are libraries like PGU, I do this to improve in programming. I spent a bit of time ...
0
votes
0answers
26 views

Flatten an array

I have got this interview question which has asked me to write a production level code which flattens the arbitrary nested array of arrays. Code ...
1
vote
1answer
21 views

A simple Insertion Sort implementation in Java

I've written a InsertionSort algorithm in Java and I want a review on these: Performance improvements. Code conventions. Algorithm design improvements. Cleaner approaches. I would highly ...
3
votes
3answers
38 views

A simple bubble sort implementation in Java

I've written a Bubble Sort algorithm in Java and I want a review on these: Performance improvements. Code conventions. Algorithm design improvements. Cleaner approaches. I would highly appreciate ...
10
votes
8answers
1k views

Given three numbers, find the second greatest of them

I've just coded this for my country's programming Olympiad. I want to know if this method is a good approach in terms of readability and performance. I would also like to know how to improve it. Note:...
4
votes
1answer
58 views

Max difference between two array elements

Can I get feedback on below code? Problem statement is Maximum difference between two elements such that larger element appears after the smaller number Would this solution be still considered O(n) ...
1
vote
0answers
32 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
73 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
63 views

Merge sort Python implementation

Is this efficient? ...
0
votes
0answers
39 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
1answer
80 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
54 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
63 views

Finding consecutive occurrences of a value in an array

Given an array, return True if the array contains consecutive values: ...
-1
votes
0answers
31 views

How to add some items to an array based on a condition?

I have these two queries: ...
1
vote
1answer
111 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 ...
8
votes
1answer
99 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
25 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
41 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
133 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. ...
4
votes
1answer
43 views

Bottom up (iterative) mergesort in C

I have this C implementation of the bottom-up (iterative) mergesort: mergesort.h: ...
5
votes
1answer
77 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
116 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
864 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
34 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
382 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
58 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 \$O(n^2)...
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
64 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
34 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
91 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
84 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
119 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
68 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
52 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
54 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
163 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
57 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
50 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
77 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
75 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
73 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
97 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 ...