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.
1
vote
2answers
96 views
PrettyPrint a Binary Tree (Follow Up)
I have improved the Pretty Printing of binary tree that I implemented previously. In this follow up I have made changes such that every tree is printed (not just a Complete binary tree).
Here is my ...
3
votes
3answers
149 views
PrettyPrint a Binary Tree
I was going through this tutorial for Pretty Printing a binary search tree and decided to implement my own version. Here is my implementation. This version works only for trees that are complete ...
-1
votes
0answers
37 views
Running average of an array of numbers [on hold]
I have implemented this Java code from the Pseudo code but I want to know if I can improve the implementation to make it better.
Algorithm 4.1. PrefixAverages1(X)
Input: X, a 1-D numerical array ...
2
votes
1answer
48 views
Merge Sort Implementation: Space Usage
I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm.
...
0
votes
0answers
15 views
How to determine the longest increasing subsequence using dynamic programming with nlogn complexity [on hold]
I am trying to find the longest increasing subsequence(LIS) of a given set of numbers with nlogn complexity. I am following the algo
...
7
votes
2answers
103 views
Mastermind code taking hours to calculate
I'm trying to implement Knuth's Five-guess Mastermind algorithm in my own version of Mastermind, but when running step 6 it takes my code hours to actually run through everything to get the neccesary ...
2
votes
1answer
55 views
Find files with similar contents
I'm not normally a C programmer but thought I'd take a shot at making something useful. This is a C utility I wrote to judge how similar several files are using the algorithm I think ...
2
votes
2answers
85 views
Find Missing Numbers in an int list
I have an alternative algorithm to the same problem as Finding missing items in an int list.
My implementation includes optional min and max bounds to selectively fill in the list.
The linked ...
-1
votes
1answer
43 views
Merge sort optimization and improvement
How to optimize this merge sort code to make it run faster? And how to call merge_sort function without user input by declaring necessary array in the code?
...
4
votes
4answers
103 views
2
votes
1answer
36 views
Is this an optimal implementation of merge sort?
I am taking an algorithm course and we are to implement merge sort that handles list of elements with even or odd number of elements and handles duplication, so I wrote this function:
...
0
votes
1answer
44 views
Least common ancestor in a binary tree
I saw this implementation of Least common ancestor and thought that it was very inefficient as it used Queues. I have tried to implement it using a normal tree ...
4
votes
3answers
97 views
Bresenhams line algorithm optimization
Based on these guidelines I optimised Bresenhams line algorithm, it now fits for all kinds of line cases like images a, b, c, d, e, f, g, h show in those guidelines.
This is my test.txt input file ...
14
votes
5answers
2k views
Linq me a FizzBuzz
I got this requirement recently:
Write some code that prints out the following for a contiguous range of numbers:
the number 'fizz' for numbers that are multiples of 3
'buzz' for numbers ...
3
votes
1answer
44 views
All balanced parentheses for a given N
Write a function (in Haskell) which makes a list of strings
representing all of the ways you can balance N pairs of parentheses:
Example:
...
0
votes
0answers
28 views
“Can you answer these queries I” challenge
I have tried to solve the following problem on SPOJ.com:
You are given a sequence
A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 )
A query is ...
2
votes
3answers
92 views
Stack implementation using vectors and templates with no overflow version 1.3
Below is the code for stack along with one or two extra options. Kindly let me know if there are any concerns/critical issues. Below are the links for previous versions.
Version 1.0
Version 1.1
...
-1
votes
1answer
72 views
Finding the distance from each array element to the nearest zero entry
I wrote a program, that gets a certain array and replaces each value in the array with the distance from it to the closest zero value.
Time complexity is 4n => O(n). (please correct me if I'm wrong, ...
3
votes
2answers
66 views
Implementation of Dijkstra's algorithm to find the shortest path in graph
This is my implementation of Dijkstra's algorithm in C++.
Please clarify
Whether the class design is proper or if it needs to be improved.
I am just hard coding the vertex based on the priority of ...
4
votes
2answers
145 views
Python Find All Adjacent Subsets of Set of Coins Which Have a Tails Minority
Given a sequence of heads and tails I want to find how many significant subsequences are in this sequence where the number of heads is not less than the number of tails. I want to achieve this in ...
2
votes
1answer
69 views
Binomial heap in Java
I have this implementation of a binomial heap providing insert, decrease-key and extract in logarithmic time.
MinPriorityQueue.java:
...
2
votes
2answers
60 views
Four fours to get any number
I decided to solve a problem from Code Golf called the four fours.
Problem description:
The Four fours puzzle is a popular recreational mathematical puzzle
that involves using exactly four 4s ...
1
vote
2answers
83 views
Counting a cycle
An interview question I got -
Each element of an int array points to the another element,
eventually creating a cycle. Starting at ...
2
votes
0answers
18 views
Implementation of the closest pair algorithm
I just started learning Go. To start playing with it, I've implemented the fast power algorithm:
Here is the pseudo-code I used (source):
...
4
votes
1answer
76 views
Finding the minimum number of required deletions to have a non-repeating string
I wrote code for the following problem:
Given a string, print out the number of deletions required so that the adjacent alphabets are distinct.
Please suggest different methods by which I can ...
3
votes
1answer
57 views
Fast incremental backup algorithm using RSYNC
I'm running a simple Bash script that uses rsync to do an incremental backup of my web server every hour. What I'm looking for is an efficient algorithm to delete ...
3
votes
3answers
123 views
Recurring dates within a range
I'm using this code to find out the recurring dates, within a given range. Is this the correct way to find out the recurring dates within a range of dates?
...
1
vote
1answer
93 views
Summation of Arithmetic Progression Modulo Series
Here is the link to the problem: Aladin on Kattis.com
Problem
Aladin was walking down the path one day when he found the strangest
thing: N empty boxes right next to a weird alien machine. ...
5
votes
2answers
87 views
Project Euler #5 (LCM 1 - 20) Follow up
I'm actually spending time on it, unlike the first time and going through, understanding and implementing the several suggestions I've landed on two different approaches.
Approach 1: Employing Java 8 ...
3
votes
3answers
69 views
4
votes
4answers
543 views
Project Euler #5 (LCM of 1-20)
Challenge: 2520 is the smallest number divisible by 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by 1-20?
Solution:
...
6
votes
4answers
124 views
Python 8-Puzzle and solver
I wrote a simple 8-Puzzle and solver and am interested in seeing how it might be improved. Please let me know if any style or design changes might enhance the readability/performance of my code.
...
4
votes
1answer
53 views
TDD and use case: cook dish with substitutions
This is code for a class that takes available ingredients and returns left over ingredients after making a dish.
Cesars: 2 carrot 4 ice burg 1 chicken 1 beans
Russian: 2 carrots 2 beans 2 chicken
...
3
votes
0answers
37 views
Fast power in Go
I just started learning Go. To start playing with it, I've implemented the fast power algorithm:
Any suggestions or criticisms regarding the coding style?
...
4
votes
3answers
106 views
Stack implementation using vectors and templates with no overflow version 1.2
Below is the code for stack along with one or two extra options. Kindly let me know if there are any concerns/critical issues. Below are the two link for previous versions.
Original
Version 1.1
...
4
votes
5answers
507 views
Reversed Binary Numbers
Here is my code for "Reverse Binary Numbers" in C.
Problem
Your task will be to write a program for reversing numbers in binary.
For instance, the binary representation of 13 is 1101, and ...
0
votes
1answer
44 views
Linear regression with visualization
I have created a small script that:
Creates a lot of random points.
Runs a small brute force search to find a rect that has a low error, that is a good fit for the data.
Runs a linear regression on ...
8
votes
1answer
74 views
Minesweeper analyze goes to N-Queensland
As @rolfl recently solved the N-Queens problem, I figured that it was time also for me to solve it.
My approach is significantly different from @rolfl's. I quickly realized that the N-Queens problem ...
4
votes
1answer
47 views
Random bits with a specified density (Bernoulli Trials)
I'm sure this is a fully 'solved' problem and expecting cross references but I can't find this on Google. I'm probably missing a keyword.
Here is a naive function for populating a ...
3
votes
1answer
68 views
Quicksort - follow-up
This is a follow-up to
Quicksort function
Like the previous code, this does not optimize for containers with large numbers of duplicate elements. How can I improve this code, particularly with ...
2
votes
0answers
40 views
Haskell in-place quicksort, Ord a => [a] -> IO [a]
As noted below, this is more or less a direct translation from http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C. I'm fairly satisfied with its readability right now compared to the C code; ...
12
votes
3answers
146 views
N-Queens - Brute force - bit by bit
A discussion in The 2nd Monitor made me realize I had never 'solved' the N-Queens problem. Additionally, as I read up on it, I realized that the 64-squares in a chess board would work well if ...
1
vote
1answer
46 views
Simple peak finder solution - O(log n)
I attempted a solution to a seemingly simple problem:
Peak Finder
Let input be a list. input[i] is a peak if ...
1
vote
0answers
19 views
Alpha Beta pruning for connect 4 [closed]
I have recently tried to implement the minimax algorithm for connect 4 to create a bot for it, to keep it simple (possibly complicating things) I used Python.
Here is what I have so far:
...
3
votes
1answer
54 views
Numeric center in Java
I got a proposed exercise from a Java2 book. This one wants me to find out the numeric centers.
A numeric center splits two list of numbers that make the same result when you add the numbers in each ...
4
votes
2answers
74 views
Implementation of a quicksort function
I am an absolute beginner to programming and am learning it using C. I have just learned function pointers and tried to implement a quicksort function using function pointers to determine the nature ...
4
votes
0answers
49 views
Dijkstra's algorithm in PHP
This is Dijkstra's algorithm in PHP. Regarding the data structure, I use a 2-dimensional array $_distArr[m][n]=length to store it. Are there any improvements for ...
4
votes
2answers
194 views
Stack implementation using vectors and templates with no overflow version 1.1
I have modified my code as per the suggestion given by some of the developers. Let me know if there are any further concerns or scope for improvements.
Original Version
...
7
votes
1answer
120 views
Sorting Algorithm Visualizer
Over the course of the past month I've worked on a little visualizer to show how different algorithms are sorted. I'm pretty happy with how it turned out but would be interested in any feedback ...
6
votes
2answers
82 views
Name filtering in Java
I have a search box for searching for people in a list of names.
Here is the code that runs every time the query changes. I could not find anything open-sourced for this, so I wanted to make sure ...