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.
-4
votes
0answers
17 views
0
votes
0answers
35 views
Run-aware merge sort
The concept is very, very simple: let's do merging run by run. (A run is, a range without decrement.)
...
0
votes
0answers
27 views
Recursive Search Binary Tree C# [on hold]
I am trying to find out if this program can check if a binary tree is BST or not,
...
2
votes
2answers
56 views
Finding all the prime factors of a number
I want to calculate all the prime factors of a number in the range 2 ≤ N ≤ 107. Here is my function:
...
3
votes
2answers
46 views
is_Prime() function on PHP
I tried to make an is_Prime() function in PHP. What do you think about this code?
...
2
votes
3answers
82 views
Algorithm to add all lucky numbers under [N] to a Vector
A lucky number is defined as a positive integer whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. I need to ...
1
vote
1answer
19 views
Compare a sequence with the reference frequency of hexamers
I have written this function (and others similar to that one) But I am not sure I am using references on their full power.
My currently concerns is if I make a huge use of memory. The subroutine ...
2
votes
2answers
66 views
Finding the longest sequence of increasing numbers in an array
A continuation of this queston.
The task's description can also be found there.
After reformatting the code and getting rid of the ArrayIndexOutOfBounds check,it ...
4
votes
1answer
36 views
Find the longest sequence of increasing numbers in an array
I have the following task: to find the largest sequence of increasing numbers in an array.
I'll give you an example : 2 3 4 1 50 2 3 4 5 will return the sequence ...
2
votes
1answer
27 views
Calculate conditional probabilities and perform naive bayes classification on a given data set
I wrote a class that I'm using to calculate conditional probabilities of a given distribution as well as perform naive bayes classification. I'd like to get a code review done to tell me if there is ...
1
vote
1answer
33 views
Recode algorithm for merged cells on HTML table
Is there any way to improve this algorithm maybe making it so faster avoid using foreach? Maybe with a recursion?
The output of my algorithm is a table with 3 merged columns, each row will have its ...
5
votes
1answer
36 views
Knight's Travails in ruby
The task was to build a knight_moves method which when called would display the simplest path from one given square to the other given square.
My Solution:
...
2
votes
2answers
88 views
Algorithm for motion detection using ultrasonic sensor on Arduino
I am using a ultrasonic sensor to detect motion by looking at the variance of the sensor readings, however my algorithm is very prone to give false positives thus erroneously rising a motion event.
...
3
votes
1answer
66 views
Collection of exact string matching algorithms in Java - follow-up
Now I have incorporated all the suggestions made by bowmore in the previous and initial iteration of this collection. Also, I have added the Boyer-Moore algorithms, both conventional and naïve.
As of ...
3
votes
1answer
76 views
Compress numbers in a string array (#3, #1, #2, #4) to range (#1:#4)
This function takes a string array,
{"foo", "#123", "#124", "bar", "#125", "#126"}
makes a new array with the numbers converted to a range:
...
11
votes
2answers
208 views
Collection of exact string matching algorithms in Java
(See the next iteration.)
I have this small collection of exact string matching algorithms:
Knuth-Morris-Pratt algorithm,
Finite automaton matcher,
Rabin-Karp algorithm,
Z algorithm.
The main ...
1
vote
1answer
55 views
Convert numbers in a string array (#3, #1, #2, #4) to range (#1:#4)
Updated question: Compress numbers in a string array (#3, #1, #2, #4) to range (#1:#4)
This function takes a string array,
...
-1
votes
2answers
102 views
Binary search algorithm
Would this recursive solution's speed be comparable to a non-recursive solution?
...
0
votes
0answers
49 views
Floyd-Warshall algorithm and a tiny all-pairs shortest path library in Java
Now I have implemented the Floyd-Warshall algorithm with emphasis on dropping space complexity from \$\Theta(V^3)\$ to \$\Theta(V^2)\$. Also, I tried hard to make the API as logical as possible. What ...
3
votes
1answer
47 views
Find largest connected cells of value 1 or greater
My goal is to find the largest connected "cell" of 1's in a matrix.
My approach has been to search the surrounding area of a cell that is not on a border and then if it hasn't been visited, and has a ...
0
votes
0answers
33 views
Long arithmetic addition implemented functional style
This implementation uses ECMA6 syntax and babel as transpiler. You can use this code to add integers which is bigger then Number.MAX_SAFE_INTEGER
...
2
votes
3answers
124 views
Long arithmetic addition in JS
The implementation of the algorithm which adds two number in string form with arithmetic rules.
...
6
votes
2answers
88 views
Jaccard distance between strings in Rust
The Jaccard distance between two sets is the size of their intersection divided by the size of their union. For example, the distance between {1, 2, 3} and ...
3
votes
0answers
32 views
100 Doors Problem in perl
I'm solving this in perl:
https://github.com/kennyledet/Algorithm-Implementations/tree/master/100_Doors_Problem
Puzzle:
There are 100 doors in a long hallway. They are all closed. The first ...
1
vote
0answers
25 views
Computing even huger Fibonacci numbers in Java - follow-up
See the previous and initial iteration.
I have incorporated almost all the suggestions by Peter Taylor:
The actual method returns a BigInteger instead of ...
2
votes
4answers
86 views
Prime number generation algorithm
I'm making a prime number scanning algorithm in Java. It uses the concept of the Sieve of Eratosthenes to efficiently find the prime numbers.
It works well and can calculate all the prime numbers ...
2
votes
2answers
53 views
Sum of proper divisors
Given a natural number \$n\$ (\$1 \le n \le 500000\$), please output the
summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is ...
3
votes
1answer
74 views
Count Acute, Right and Obtuse triangles from n side lengths
EDIT : The Code after changes suggested by @vnp. CODE
Problem Statement: We have N sticks. The size of the ith stick is Ai. We want to know the number of different types of triangles created with ...
1
vote
1answer
50 views
Check if a Binary Tree is a Binary Search Tree
Given a binary tree, I need to check if it satisfies the Binary search tree property i.e. left child is less than or equal to the current node and right child is greater than or equal to the current ...
3
votes
1answer
76 views
Read text file filled with numbers and tranfer to an array in Java. Then use threads to help calculate the max in the array
This is my ProcessDataFileParallel.Java file. I'm taking numbers from a txt file and putting it into an array in Java. While it works, I would like to improve the code and possibly change some ...
2
votes
1answer
88 views
Algorithm to find edges of groups of intersections running to slow
I have an algorithm that takes in an array of interections found between lines in an image. It then has to look for any instances where there are a group of intersections together, remove the middle ...
3
votes
0answers
62 views
ID3 Decision Tree in python
I've been working my way through Pedro Domingos' machine learning course videos (although the course is not currently active). His first homework assignment starts with coding up a decision tree ...
2
votes
1answer
25 views
1
vote
0answers
51 views
Breadth and Depth First Search in Ruby
I was tasked with building three individual methods; one to create a Binary Search Tree (BST), one to carry out a Breadth First Search (BFS), and one to carry out a Depth First Search (DFS).
Create ...
8
votes
1answer
342 views
Implementing a fast DBScan in C#
I tried to implement a DBScan in C# using kd-trees. I followed the implementation from here.
...
2
votes
2answers
82 views
Computing even huger Fibonacci numbers in Java
See the next iteration.
I have that method for computing Fibonacci numbers \$F_n\$ (\$n = 0, 1, 2, \dots)\$, that relies on computing
$$
A =
\begin{pmatrix}
1 & 1 \\
1 & 0
\end{pmatrix}^n.
...
3
votes
2answers
731 views
Computing huge Fibonacci numbers in Java
I have this small Java program for computing particurly large Fibonacci numbers (10000th Fibonacci number is computed in about 220 milliseconds). The key idea here is to use lists of digits, which is ...
3
votes
1answer
59 views
Generating the maximum number possible from an array
I have the following code in Scala as a solution to the problem:
Find the maximum number possible from the given Seq of Integers while keeping the individual numbers intact
e.g.
Seq(2,5,9,4) ...
1
vote
2answers
58 views
1
vote
2answers
66 views
Arduino microcontroller based event handler program, send sensor readings over serial bus
I am working on a project with an Arduino microcontroller and a Raspberry Pi. The code will have to do the following:
If the variance calculated of the ultrasonic sensor detections exceeds 1000, a ...
17
votes
2answers
250 views
Calculate all possible distributions of n objects to k containers
Let's say I have \$5\$ apples, thus \$n = 5\$. I have three bags (\$k = 3\$), each having the capacities of \$4\$, \$4\$ and \$2\$:
$$c = { \{4, 4, 2 \}}$$
I'd like to calculate the number of ways ...
2
votes
2answers
44 views
Count number of matching nodes in a Binary tree
Problem
Count the number of matching nodes in the subtree rooted at some node n.
Solution
...
1
vote
1answer
41 views
QuickSort - 3 pivot choosing methods via factory
I'm happy to hear thoughts and ideas on structure/performance/testing/whatever and multi-threading, which I haven't gotten into yet with Python.
Latest code here. Assignment file and a few test files ...
3
votes
2answers
191 views
Most efficient FizzBuzz solution in Ruby
I would appreciate any feedback concerning my analysis of the most efficient FizzBuzz solution programmed in Ruby. I submit that a Case-statement solution is more efficient than utilizing a ...
4
votes
2answers
200 views
My 15 puzzle solver is too slow
It takes my code over 700 seconds to solve simple puzzle:
2 7 11 5
13 0 9 4
14 1 8 6
10 3 12 15
My function ...
4
votes
1answer
49 views
Github pagination
I wanted to copy the behavior of github's pagination. Here is what it turned out: http://jsbin.com/dihohiseca/5/edit?js,output
It works fine, but I have a feeling that there is a lot of room for ...
1
vote
0answers
56 views
AVL tree implementation
So I've just created an AVL tree in Java. However when I test its running time using the following code:
...
3
votes
2answers
312 views
Binary tree data structure
I am learning about the binary tree data structure and implemented some basic functionality.
It was working great with module level functions until I realized that I need to keep track of the root ...
2
votes
1answer
42 views
Extract data from large JSON and find frequency of contiguous sub lists
I have been writing some code (see component parts here and here) that:
Takes a very large JSON (15GB gzipped, ~10million records)
Extracts the relevant parts of the JSON into a list of lists
...
2
votes
1answer
53 views
Shortest path from U to V using at most k nodes
I'm trying to solve a problem that asks for a shortest path between two cities with at most k nodes.
The first line of input has the number of test cases. On the second line 3 integers are given, ...