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.
2
votes
0answers
18 views
Search/sort/create functionality, implements bubblesort and sequential search
I've moved my main() to the bottom of the code block in order to fit it all in one class for this submission. If there is a better way to do it?
...
2
votes
0answers
11 views
Radix sort with integer divisions
Here's a perhaps naive but simple implementation of Radix sort in Java.
It works with any radix, and both positive and negative numbers.
...
0
votes
1answer
17 views
Generic list heapsort in Java
This is an implementation of heapsort as seen on Programming Pearls, adapted for java List collections. It is working on a copy of the list passed-in on purpose at the moment.
...
1
vote
1answer
27 views
Performing Gauss-Jordan elimination on a matrix in Java
I have this small "framework" for representing matrices with entries of primitive type double, and performing Gauss-Jordan elimination (for solving systems of ...
-2
votes
0answers
16 views
What is the logic error in the given NQueen algorithm? [on hold]
I wrote the following code for NQueens. But I end up with wrong answer. Could some one help me find the error in this?
...
5
votes
1answer
51 views
Exchange system of numbers
I've got the following task:
Keeping in mind Horner's Scheme, write an application that converts a given number x in ...
-2
votes
0answers
11 views
Implementing Scanline Algorithm [on hold]
I'm trying to implement a scan line filling algorithm for random triangles given 3 points as arrays and a color. I'm getting some weird results. Please ignore the optimization of the code, I'm just ...
4
votes
2answers
61 views
Check if a binary tree is balanced
Looking for code-review, optimizations and best practices. This question is attributed to geeksforgeeks.
NOTE: Please help me verify space complexity, as I am creating 'TreeData' objects in ...
5
votes
1answer
40 views
TCP Server using NIO to save data from IoT clients
I've built a small single threaded TCP server using NIO.
This server is used by small client devices to report things like temperature, when the device has been switched on, when it switches off, and ...
2
votes
1answer
31 views
K-means clustering algorithm in python
Here is my implementation of the k-means algorithm in python. I would love to get any feedback on how it could be improved or any logical errors that you may see. I've left off a lot of the ...
5
votes
4answers
91 views
Pi-calculating program
I saw this question and answer about calculating pi on Stack Overflow, and I decided to write my own program for calculating pi. I used Python and only integers (I didn't want to use floating point ...
3
votes
4answers
147 views
Count the ways to partition an array into two equal sets
I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items.
Suppose ...
0
votes
0answers
15 views
C++: Implement a Deque using a Doubly Linked List [on hold]
My assignment is to implement a deque data structure through the use of a Doubly Linked List. For some reason an "unhandled exception" occurs in Visual Studio whenever I try to run it, and the output ...
3
votes
2answers
55 views
Removing duplicates from an array
I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
2
votes
2answers
42 views
Premium palindromic primes
Challenge: Write a program which determines the largest prime palindrome less than 1000.
The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
5
votes
1answer
67 views
Paint fill function
Implement the "paint fill" function of image editing programs: Given a
screen point and new color fill the surrounding area.
Any comments on the code below?
Time complexity: ...
9
votes
1answer
117 views
Reading, processing and counting an array setting limits
Last weekend my teacher asked me to create code to solve a problem:
Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array ...
0
votes
1answer
33 views
Permutations of a string
I wrote the following code to permute the characters of a string assuming there is no repeated character.
I also want to make sure the space complexity of this algorithm is \$O(n*n!)\$: There are ...
3
votes
2answers
314 views
QuickSort for a List<T>
I want my QuickSort class to have a static sort method that sort any List for any object that extends Comparable. Have I coded my class correctly? Can I make the use of generics a bit cleaner or is ...
2
votes
1answer
39 views
Improving time complexity of cheapest travel route algorithm
Below is the code to find the cheapest route for a passenger. stationsUnexplored is a Queue to which stations are added and ...
2
votes
2answers
154 views
Is there some way of taking advantage of code reuse in this example?
I am implementing a set, using an array as the backend.
Here is how I declared it (and some method implementations):
...
7
votes
1answer
493 views
An Army of Ones
I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it?
Challenge:
...
6
votes
2answers
82 views
Gauss elimination
The gauss function takes 3 parameters:
a pointer to the matrix of coefficients
the number of variables
a pointer to matrix of solution
...
5
votes
3answers
324 views
Harvard CS50 Problem Set 1: greedy change-making algorithm
The goal of this code is to take dollar or cents input from the user and give out minimum number of coins needed to pay that between quarters, dimes, nickels and pennies. If this code can be ...
1
vote
0answers
18 views
Binary heap implementation in Golang
I have implemented a binary heap in Go to get familiar with the language.
GitHub
...
4
votes
0answers
32 views
Brute Force (and not) Bejeweled AI
My approach to solving the problem of selecting the best match on a bejeweled board is a fully object oriented approach. Some of the other relevant code can be found in my previous questions ...
1
vote
0answers
20 views
Bidirectional Edmonds-Karp algorithm in Java
The Edmonds-Karp algorithm relies on breadth-first search in order to find an augmenting path in the residual flow network. This version of the algorithm uses bidirectional breadth-first search in ...
6
votes
1answer
134 views
4
votes
0answers
29 views
Resource-constrained project scheduling
I'm trying to implement an algorithm for a resource-constrained project scheduling problem. I have several resources, resource constraints and all of this is in ...
3
votes
0answers
31 views
Edmonds-Karp algorithm for maximum flow in Java
I have this implementation of Edmonds-Karp algorithm for finding maximum flow in networks. It runs in \$\mathcal{O}(VE^2)\$ time.
What do you think?
AbstractMaximumFlowFinder.java:
...
2
votes
0answers
23 views
Kruskal's algorithm in Java - follow-up
The previous and initial iteration at Kruskal's algorithm in Java
Now what I did is remove the fields and let the actual Kruskal-routine create the required data structures in the local scope, ...
3
votes
1answer
32 views
Disjoint-set data structure in Python 3
Inspired by this question, I decided to implement a Disjoint-set data structure in Python 3. I mainly followed this description for understanding the algorithm (but did not do the optimizations for ...
3
votes
2answers
59 views
Counting the proportion of vowels in substrings
I'm looking for an algorithm to make my code faster and better for big strings.
Problem link
Let the simple prettiness of a string be the count of vowels (I, E, A, O, U, Y) divided by the length of ...
4
votes
2answers
38 views
Cubic “bezier” curve of grade n
This is code I wrote for calculating bezier curves as quickly and RAM efficiently as possible.
I would like to know if there are faster ways to optimize anything, because I am very new to C++ and ...
3
votes
4answers
626 views
1
vote
2answers
55 views
Setting every element in an array to a given value
Given the length of an array and a char, I would like to replace every element in a char array with that given char.
Using a ...
0
votes
1answer
40 views
Solving the rod-cutting problem using dynamic programming
I've written what I believe is a valid dynamic programming solution to a variation of the rod cutting problem. In this problem, the goal is to make as few cuts as possible on a rod of length n.
I ...
6
votes
1answer
100 views
An algorithm that finds the number of “lined up columns”
I found this question in an old exam in computer science. I solved it in a good way, but I'm not convinced that my solution is the best solution. I believe that there's a better way to solve it.
...
5
votes
1answer
76 views
Beat detection algorithm implementation
What is the quality of the code I've written? Is it easy to read or is it a low-quality piece of code? Also, is there any way I can improve the algorithm itself (beside changing C parameters)?
...
3
votes
3answers
93 views
Pouring water between two jugs to get a certain amount in one of the jugs
I wrote a solution for a jug problem (given two jugs of water of different sizes find the steps needed to get specific amount of water in one of the jugs). I'm hoping for some input on my code. How ...
3
votes
2answers
169 views
Hacker Rank - Lonely Integer
This is the problem statement for Lonely Integer.
There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once.
Input Format
...
3
votes
3answers
191 views
Determining if a pair exists in a large sorted array
I'm doing practice interview questions from here. Here is the one I am currently on - if you are given a very large sorted int array, then check of there exists a ...
2
votes
3answers
397 views
Finding duplicates in two sorted arrays
This is an interview question from here. Specifically, the second asked for a function that took in two sorted arrays of integers with no duplicate values within a single array and which returned an ...
2
votes
1answer
39 views
Increase efficiency and velocity autosuggestion algorithm
In my project, for inserting an autosuggestion function (also in presence of little insertion errors, like Google), I've created this class:
...
2
votes
2answers
140 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
185 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 ...
3
votes
2answers
83 views
Merge Sort Implementation: Space Usage
I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm.
...
7
votes
2answers
114 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 ...
3
votes
1answer
66 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
94 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 ...