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.
3
votes
2answers
27 views
Convert a double list to a grouped string
The program has an input a list of doubles and the output needs to be a string containing the list values grouped by their value. The list values will be grouped if they are equal. Something like: ...
3
votes
1answer
34 views
Topologial Sort in Python
I am trying to self study algorithms and this is my attempt at topological sort using Tarjan's version of DFS. It runs correctly for the graph I included. Can someone tell me if this is correct and if/...
0
votes
0answers
24 views
find k nearest points
Working on a problem to select k nearest points for a given point, here is my code written in Python 2.7 and any advice for bugs, improvements are appreciated. Also welcome any general advice to ...
2
votes
1answer
30 views
sparse vector dot product
Trying to implement sparse vector (most elements are zero) dot product calculation. Here is my code, and written in Python 2.7. Major idea is to represent each sparse vector as a list (which holds ...
6
votes
2answers
47 views
Sum of the reciprocals of whole numbers adding to one
I have written some code which works out which sums of reciprocals of whole numbers sum to one, e.g:
\$\frac 12 +\frac 13 +\frac 16 =1 \$
\$\frac 17 +\frac 18 +\frac 19 + \frac1{10} + \frac1{11}+ \...
6
votes
2answers
95 views
Josephus algorithm using array in C#
I'm trying to write the Josephus algorithm as a project for school, however, I think that there is a better way than what I already have.
...
5
votes
3answers
170 views
HackerRank woman codesprint: minimum cost
Lauren has a chart of projected prices for a house over the next n
years, where the price of the house in the i-th year is <...
4
votes
2answers
63 views
Incrementing a sequence of letters by one
I'm creating a C# application that produces unique lines of data. The main purpose of the application is for me to learn C#. The secondary purpose is to have available lines of (dummy) data when ...
0
votes
0answers
17 views
Dijkstra's Algorithm using Priority Queue Java [on hold]
I need to implement Dijkstra's Algorithm using priority queue in Java. Here is my code so far:
...
1
vote
2answers
94 views
-3
votes
0answers
20 views
DP solution for the Pogo-Cow problem on USACO 2013 silver contest [on hold]
Problem link:
http://www.usaco.org/index.php?page=viewproblem2&cpid=345
Here is my code:
...
-3
votes
0answers
9 views
What errors exists within these Java implementations of bubble sort and selection sort [on hold]
Here is what I have for the bubble sort algorithm.
...
2
votes
2answers
203 views
Multiply two numbers
I am trying to implement multiplication of two numbers without using the * operator, as a practice for programming interviews. I have written two functions.
1) ...
2
votes
1answer
112 views
Remove comments from C-like source code
I am working on the problem of removing comments from C-like source code. Here is my code in Python 2.7, and if anyone could advise improvement areas (especially performance), or any functional bugs ...
1
vote
0answers
30 views
Find path from source to destination in tilt maze (part 2)
For a tilt maze general reference, you can refer to for example, this one.
Previous related code review discussion could be referred by this, and my major ideas how to define tilt maze data structure ...
0
votes
0answers
16 views
Game where two players take turns picking numbers until a target sum (part 3)
Here is a continued discussion (Game where two players take turns picking numbers until a target sum (part 2)), since it is new code and new topic for discussion, I start a new thread.
Working on the ...
3
votes
0answers
28 views
Shakesort Python3
Hello I've done the Shakesort Algorithm win O(N²) but doesnt seem that O(N²) is correct because it takes 6-9 steps in the while loop for a list of 4 integers and 4² is 8. ~1975 steps for 80 entries. I'...
-1
votes
0answers
17 views
Parametric mergesort in Scala with paramerized arrays and implicit conversion
I have created a second version of the code, posted in this question:
Merge sort in one Single Function in Scala
But this time using 2 functions, one only for the merge. The one for merge is a local ...
0
votes
0answers
44 views
Ordered array item insertion based on binary method
Array is sorted. I'm asking more about algorithm related stuff. I know that by naming conventions is not good here. Also error handling is not exists yet.
...
0
votes
0answers
36 views
Find max in-order difference in array
Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j].
If there is no solution possible, return 0.
Example :
A : [3 5 4 2]
Output : 2
for the pair ...
3
votes
1answer
51 views
Unique nucleotide permutations, Python itertools product
I'm searching for all the unique possible permutations of nucleotide given a defined length. By unique, I mean the reverse complement would not be counted.
ACGT
For example, permutations of length ...
3
votes
1answer
62 views
Merge sort in one Single Function in Scala
I have implemented a sortmerge in Scala in one single function. I would like to have it reviewed, so that I can have it well organized, and it is then doing what ...
1
vote
1answer
27 views
Tarjan's strongly connected components algorithm
Can anyone suggest to me how I can make this "nicer"? If you can see any glaring details that I could change to speed things up too, that would be great -- though it's not priority.
...
7
votes
2answers
618 views
To the right, to the left, now rotate
I was working on HackerRank: Circular Array Rotation which is about coming up with an efficient algorithm for array rotations in right-ward manner.
John Watson performs an operation called a right ...
3
votes
1answer
49 views
Snakes and Ladders using a magic die
This is a problem from here where you're given a magic die, and the objective is to find the minimum number of dice throws (hops) to go from the start point to the end of the board, and win the game.
...
3
votes
1answer
67 views
Return path to a value in a nested object
Description:
Its not a programming challenge but I though to write a small utility which will return the path to a primitive value in a possibly nested object. The idea is not original.
Code:
...
4
votes
2answers
75 views
Justify Text using LaTeX method
I wrote a bit of code that takes a file, justifies the text and writes to another file.
It uses a DP approach to minimise a badness metric, which is the amount of under or overshoot of the line ...
8
votes
3answers
2k views
Really fast Knight's Tour using concurrency and Goroutines
In less that 5 seconds on a normal PC, I found the answer in simple brute-force. Before I met Go, I didn't believe that it will be so easy to use all the power of the PC by using Go Goroutines for ...
3
votes
0answers
64 views
Python AVL Tree
While learning python, I decided to implement some data structures, this time AVL tree. I think the logic is correct, is there a way to make it more clearer and any ideas to add more tests?
...
3
votes
2answers
42 views
Bubble sort code
I tried avoiding nested loops and usage of too many variables. This is up for review and comments.
...
2
votes
2answers
53 views
CodeChef Chewing challenge
The ZCO is today and I did 5 problems to prepare for it overnight. One of the problems is the CodeChef Chewing problem.
The code takes an integer N that specifies the number of chewing gums, integer ...
4
votes
1answer
107 views
Binary search tree implementation in C#
I have implemented a BST for an assignment in C#. I am still in the process of implementing IEnumerable and ToList functions but ...
1
vote
2answers
99 views
A simple pocket calculator
I was searching the internet for some Python exercises, and I've found a lab assignment from University of Toronto. Here's the major of it:
Question 1.
Welcome Message In the if ...
6
votes
0answers
53 views
Battleships Player vs Computer Algorithm
I am a Year 12 student studying CS for my A-Levels. I have had previous Python experience but it is obviously not to professional/industry standard. Therefore, my goal for this review is for my code ...
3
votes
2answers
79 views
Initializing the edge values of 2D array in Java
I have been asked to write Java method code to do the below:
...
3
votes
3answers
98 views
Reverse vowels in a string
What do you think about this solution? I guess there are too many lists...
...
0
votes
1answer
29 views
Quadratic probing and hashing - search for words in text files
I created a program for a college class. After I got it working, I wanted to improve it. As a beginner, it is probably a mess.
Description
It uses a HashFunction ...
1
vote
1answer
53 views
find path from source to destination in tilt maze
For a tilt maze general reference, you can refer to for example, this one.
Previous related code review discussion could be referred by (Data structure and movement for tilt maze (part 2)), and my ...
0
votes
1answer
46 views
Quick sort a list of integers in place
This code is meant to sort a list of integers in place using quick sort.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures for an upcoming ...
0
votes
1answer
79 views
Calculating the difference between 2 arrays
I made this function to calculate the difference between 2 arrays and return it in a third array. I'm using this function as a part of stocktaking functionality I apply in my accounting system.
...
1
vote
2answers
84 views
Merging K Sorted Arrays
My aim is to merge k different sorted array with unique elements and I want a code review about it, here is my code below which is written in java;
...
4
votes
2answers
62 views
Red light, green light… kinda
For an assignment I had to create a client and a server that communicate over a well known FIFO. The server is required to use three threads to serve the client, managed by a semaphore.
The code was ...
4
votes
3answers
71 views
Showing animated company KPI stats
I am creating a web page in which I have 4 different numbers which show companies stats. I am using javascript to dynamically show these numbers from 0 to n (where 0 is the starting point of counter ...
6
votes
1answer
242 views
Finding overlaps between two lists of axis-aligned rectangles
I am trying to find an efficient solution for finding overlapping of n rectangles where rectangles are stored in two separate lists. We are looking for all rectangles in ...
3
votes
1answer
40 views
Merge sort a list of integers
This code is meant to sort a list of integers using merge sort.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures for an upcoming coding ...
3
votes
2answers
46 views
Binary search a sorted list of integers
This code is meant to do a binary search of a sorted list containing integers.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures for an ...
2
votes
4answers
145 views
Find the smallest divisible number for the given input 'n' such that number is evenly divisible by 1 to n
Given a number n, the task is to complete the function which returns an integer denoting the smallest number evenly divisible by each number from 1 to ...
0
votes
1answer
65 views
Calculate sum of digits from a given number using String's slice method
This is the "classic" algorithm for calculating the sum of digits uses the modulo-operator together with the division-operator. I had the idea of using the slice-method with a negative index for ...
0
votes
0answers
30 views
Protecting a cyclist from rain
The input consists of an integer, N, that determines the no. of km of the cyclist's route and an integer, K, that determines the ...
4
votes
0answers
126 views
Assembling and traversing a tree, given a list of items and parent pointers
I've written a function which takes input such as this:
...