An algorithm is a precise plan (in the format of a sequence of steps) on how to solve a particular problem.

learn more… | top users | synonyms

3
votes
1answer
23 views

Iterative Flood Fill implementation in C [on hold]

I am trying to implement an iterative version of flood fill in C: ...
2
votes
0answers
22 views

Detecting connected acyclic through Tarjan strongly connected components variant

I want to verify that a given directed graph is connected and acyclic (DAG). I have implemented a modification of the Tarjan's strongly connected components algorithm in imperative style (as the ...
10
votes
3answers
1k views

Dining Philosophers Algorithm

Please visit the http://en.wikipedia.org/wiki/Dining_philosophers_problem for algorithm discussion. I have written below java program to solve this problem by Arbitrator solution algorithm mentioned ...
2
votes
0answers
36 views

K-Mean with Numpy

I have implemented the K-Mean clustering Algorithm in Numpy: ...
3
votes
2answers
61 views

Game of Life generation procession algorithm

I've tried to make Game of Life in console and this is the algorithm I used to generate new generation: ...
2
votes
2answers
55 views

Ruby Mod 11 implementation

I wrote this Ruby Mod 11 (perhaps it's a bit generous to call it that) implementation to validate Brazilian CPF documents, which use a Mod 11 algorithm. CPF format is a 9 digit number followed by two ...
5
votes
4answers
119 views

NULL-eating / elimination version of fgets() in C

I've come up with the following routine to read data from a file stream, but I don't want any NULLs in the stream to terminate the string early. This function will ...
4
votes
0answers
39 views

Equivalent binary trees (structure & values)

I am following the Golang tour and I have been asked to build a couple of functions to manipulate binary trees. My code runs as expected, but I would like to know if I could further improve my code. ...
1
vote
1answer
59 views

Large arrays make runtime very slow

So I have the following code that takes the input of two arrays, and apply some queries to match elements from DBpediaClassesArray with elements from ...
-5
votes
0answers
18 views

Permutations Without Repetitions [closed]

I wanted to generate all permutations of an array of integers without repetitions. For this I first presort the array and then process it. i tried different ways to avoid the repetitions (that didnt ...
4
votes
1answer
44 views

Zeckendorf numbers the Clojure way

I'm just getting into Clojure, and I wanted to make sure I am writing code the "Clojure way". The challenge I took on is Zeckendorf numbers (fairly trivial). ...
7
votes
1answer
82 views

Topological Sort and Graphing in Python 3

I wrote a program for DFS traversal, topological sort, find all vertices, and has_cycle methods. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to ...
5
votes
1answer
58 views

Summing up distinct elements in steps (follow up)

This is a "follow up" to an answer I gave on this question : Summing up distinct elements in steps Here are the OP's requirements : "My current task is to find a score from an array where the ...
6
votes
1answer
78 views

Check a collection of prices against an associated collection of minimum prices

I would like to find a more efficient way to solve this problem. My current implementation has 3 separate loops through the data. I'm creating an algorithm to check a collection of prices against an ...
0
votes
2answers
67 views

Josephus Problem in Java

Problem The Josephus Problem is a famous mathematical puzzle that goes back to ancient times. There are many stories to go with the puzzle. One is that Josephus was one of a group of Jews who ...
2
votes
2answers
12 views

Performance of RegExp vs Rune Loop

I was recently talking to someone about a function I wrote to mimic (very basically) the string interpolation function String.Format() found in the C# language. ...
5
votes
1answer
91 views

Groupby in NumPy

To avoid the XY problem, here is an example of what I need. Given the sorted integer input array [1 1 1 2 2 3], I would like to produce the following slices, ...
4
votes
1answer
38 views

Stable partition in Numpy

In essence, I need to do a stable partition: All elements of the 1D np.array a that are present in ...
6
votes
1answer
53 views

Bitmap problem performance boost

Problem statement: Input is a rectangular bitmap like this: 0001 0011 0110 The task is to find for each black (0) "pixel", the distance to the ...
2
votes
0answers
39 views

Circle Shadow Experiment

I'm trying to create a light system, with the midpoint algorithm and Bresenham Line Algorithm. I'm trying to redraw all the time (1 option) or redraw when I need to. When the circles are too big it ...
8
votes
5answers
479 views

Program for finding Fibonacci primes

I think it could have been designed with more object orientation. I don't like how one of my methods calls another from within the method, but I wasn't sure how to return the result because it is a ...
0
votes
1answer
64 views

Find number of inversions in a given array

Can you please give me a hint on how to improve performance of the following algorithm meant to find the number of inversions in a given array? ...
4
votes
2answers
118 views

Reverse Game HackerRank Ruby Solution

Problem Statement Akash and Akhil are playing a game. They have N balls numbered from 0 to N−1. Akhil asks Akash to reverse the position of the balls, i.e., to change the order ...
2
votes
2answers
42 views

Swap Kth node from beginning with Kth node from end in a Linked List

Given a singly linked list, swap kth node from beginning with kth node from end. Swapping of data is not allowed, only pointers should be changed. This code is attributed to geeksforgeeks. I'm ...
7
votes
2answers
51 views

External / File-based mergesort

I've implemented an external mergesort to sort a file consisting of Java int primitives, however it is horribly slow (fortunately it does at least work). Very little happens in the sort method: it ...
4
votes
0answers
26 views

Fowler–Noll–Vo hash function in Lua

I recently coded this FNV-1a hash function in Lua. Are there any apparent performance improvements that could be implemented? ...
2
votes
4answers
566 views

Sorting Algorithms

A group of basic sorting algos. Based on Algorithms, 4th Edition - Robert Sedgewick | Kevine Wayne. Just making sure all of my logic and everything is correct. ...
2
votes
2answers
53 views

Find a triplet from three linked lists with sum equal to a given number

Given three linked lists, say a, b and c, find one node from each list such that the sum of the values of the nodes is equal to a given number. For example, if the three linked lists are ...
5
votes
2answers
86 views

Binary search: first/last/random occurrence

I've written some code to "binary search" a list, and return the first occurrence of the target: ...
6
votes
1answer
48 views

Splitting plain text dictionary data to multiple files, round 2

This is a continuation of my earlier question. I have a plain text file with the content of a dictionary (Webster's Unabridged Dictionary) in this format: ...
2
votes
1answer
39 views

Find the nearest (small) number x where x can be represented by sum of cubes

I recently came across a problem where a number \$x\$ is given and I have to find \$y\$: \$y < x > 1\$ \$y\$ can be expressed as \$a^3 + b^3\$ (more than one combination) Example: If 4105 ...
3
votes
3answers
91 views

A practical example of evenly distributing n lists into a single list

I had previously asked about how to evenly distribute the items in n lists into a single list and was referred to this question. I made a practical example of my solution for this in VBA for Excel, ...
11
votes
3answers
179 views

Substitution cipher algorithm performance boost

This algorithm is meant to read a string of numbers on an input, a naive substitution cipher code (A = 1, B = 2, ..., Z = 26) and output the number of ways the code could be interpreted (e.g. 25114 ...
7
votes
2answers
92 views

Splitting plain text dictionary data to multiple files

I have a plain text file with the content of a dictionary (Webster's Unabridged Dictionary) in this format: ...
8
votes
3answers
62 views

More imitation of Enumerable in VBA

I was inspired by Me How's question to see how far I could push an imitation of .Net's Enumerable Class. The new functions can obviously handle Collections, but can also handle any collection-type ...
1
vote
1answer
31 views

Remove all nodes which don't lie in any path with sum >= k

Given a binary tree, a complete path is defined as a path from root to a leaf. The sum of all nodes on that path is defined as the sum of that path. Given a number K, you have to remove (prune the ...
1
vote
0answers
28 views

Extract Leaves of a Binary Tree in a Doubly Linked List

Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the ...
1
vote
0answers
59 views

Optimizing implementation of Dijkstra

I am using a std::priority_queue to implement Dijkstra's algorithm: ...
13
votes
3answers
692 views

Credit Card Validator Algorithm

I'm writing an algorithm to read from a file a list of numbers, and for each, determine if it is valid. If it is, then display which card type it is. Here is my code so far (using Luhn's algorithm): ...
2
votes
3answers
106 views

“Remove Friends” problem time efficiency too slow

I'm doing this problem: After getting her PhD, Christie has become a celebrity at her university, and her Facebook profile is full of friend requests. Being the nice girl she is, Christie ...
4
votes
1answer
54 views
5
votes
2answers
66 views

Java Trie Implementation

I am creating a Trie class in Java, and am wondering what else can be done to make it even better. I am hoping to add concurrency to speed querying up. ...
3
votes
4answers
994 views

Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?

Example: If a linkedlist list contains 10->20->30->40, and 2nd node has to be deleted then the output should be 10->30->40 This question is attributed to Geeksforgeeks. Looking for code-review, ...
4
votes
3answers
103 views
3
votes
3answers
238 views

Split string by character in Java

I have this code, which goes through a string and split it using a char delimiter. I am concerned where it can be improved. Main concerns are speed and memory usage with speed as the priority. Any ...
2
votes
0answers
33 views

Kullback-Leibler (KL) distance between inside and outside contour code

I am trying implement the distance measurement between two distributions. The detail is described in here and input image . Let short summarize the idea of the paper: The input image is divided ...
2
votes
0answers
32 views

Isometric Projection and Culling

Link to live Codepen. Hello! I'm working on a small isometric drawing system, in Javascript. After much help from the Gamedev section, reading old questions, I've got something working. ...
2
votes
2answers
64 views

Simple wildcard pattern matcher in Java (follow-up)

This is a follow-up review of Simple wildcard pattern matcher in Java I have built a simple wild card pattern matcher algorithm. I am concerned where it can be improved further. Main concern is ...
0
votes
0answers
21 views

Non recursive lambda evaluator that “magically” optimizes tail recursion [migrated]

I think pasting my main method GetTermValue plus the StackFrame class and a couple of helper methods (...
10
votes
1answer
104 views

Simple wildcard pattern matcher in Java

I have built a simple wild card pattern matcher algorithm. I am concerned where it can be improved. Main concern is algorithm. Any other improvements are welcome too. What it should does: ...