Tagged Questions
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.
5
votes
2answers
970 views
Really fast knight 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 ...
2
votes
0answers
41 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
28 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
45 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
69 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
67 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 ...
5
votes
0answers
39 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
0answers
35 views
Box-Triangle intersection algorithm
So recently I wrote an algorithm to generate decals.
To do so I used code from https://www.geometrictools.com/ for an algo to find if triangles intersect with an aligned box.
I was wondering how/if I ...
3
votes
2answers
73 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
64 views
Reverse vowels in a string
What do you think about this solution? I guess there are too many lists...
...
0
votes
1answer
25 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
33 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
42 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
72 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
70 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
58 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
67 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 ...
5
votes
1answer
176 views
+100
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
37 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 ...
0
votes
0answers
18 views
Counting Inversion(swaps) and key comparisons in quicksort [closed]
I'm trying to count the number of inversions and key comparisons in quicksort.
The recursion is throwing me off. My code seems right but it returns a positive swap count for an already sorted list, ...
3
votes
2answers
45 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
141 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
0answers
22 views
Multivariate Linear Regression using Gradient Descent in Haskell [closed]
I do not believe my code is producing good results, even when changing alpha and the number of iterations, and still when using univariate which has a best fit line of y = 2x + 0, for example.
...
0
votes
1answer
54 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
29 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
110 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:
...
-1
votes
1answer
74 views
My implementation of Karatsuba Multiplication in C++
I have recently implemented Karatsuba's multiplication algorithm in C++ for my Algorithms course. It is a very sloppy implementation because I ran out of time, yet criticism would be appreciated. I ...
3
votes
1answer
44 views
Hash-optimization and Wilson-maze generation algorithm
I've finished optimization of Wilson algorithm (maze generation) from "silly and slow" algorithm of choosing unvisited cells:
...
-1
votes
1answer
75 views
Complexities: Filtering out nested array inside an array
I am doing some iteration over an array which have another set of array (the nested array). I need to .map() the outer array in such a way that it should filter out ...
2
votes
1answer
59 views
Data structure and movement for tilt maze (part 2)
This is a design data structure and movement for a tilt maze. For example, this one.
My major idea is learned from abrarisme's smart idea of using two boolean matrix to represent wall. Please refer ...
4
votes
1answer
64 views
Finding the max cost from the minimum cost incurred on travelling
This problem is from INOI 2014 , where I have find out the maximum cost of traveling through the cities but taking the minimum possible route cost , here is an excerpt from it,
Indian National ...
6
votes
4answers
110 views
Repeatedly partitioning an array equally as far as possible
I solved HackerRank Nikita and the Game. The implementation is correct as program passes all test cases.
Nikita just came up with a new array game. The rules are as follows:
Initially, ...
3
votes
1answer
62 views
Serialize and deserialize a tree
Suppose each node of a tree has maximum n children. I want to serialize and de-serialize for a tree. My current solution is doing pre-order traverse, and using <...
-1
votes
2answers
68 views
Calculating the number of extended family members [closed]
The problem here says to find the number of extended family members of the president,
N people live in Sequence Land. Instead of a name, each person is
identified by a sequence of integers, ...
3
votes
1answer
44 views
Data structure and movement for tilt maze
This is a design data structure and movement for a tilt maze. For example, this one.
My major idea is to divide into Ball, Maze,...
1
vote
0answers
14 views
Greedy recursive search [closed]
So I am trying to implement a groupSize method and a helper functions.
Here is one idea: set up a local Set of Spots to hold spots you’ve found so far in the cluster. From the current spot-position, ...
7
votes
4answers
115 views
Calculate the number of palindrome numbers in the given ranges
I've written a program that calculates all of the palindrome numbers in the given range, but the code is slightly slower than needed. I've tried to improve algorithmic complexity to the best of my ...
4
votes
0answers
53 views
Split string to space-separated words based on dictionary
This program is based on as old retired Google interview question where you're supposed to create a program that will split a string into space-separated words, if the string is composed of valid ...
0
votes
1answer
94 views
Check for balanced parentheses in JavaScript
I just implemented the balanced parentheses problem in JavaScript. For those of you who are new to this problem, a statement of it would be:
Give a string of parentheses (including braces and ...
3
votes
3answers
133 views
Prime factoring function using recursion
As a programming exercise, I decided to make a prime factoring function using recursion:
...
2
votes
1answer
68 views
Producing residues of combinatorics on strings
Basically, this code does multiplication of chosen operations.
...
2
votes
0answers
49 views
Online Principal Component Analysis with spectral bounds
I have question regarding online PCA implemented in the paper. I am interested in the Algorithm 2. I am not certain if there is a bug in my code can someone confirm if my code is correct? The ...
4
votes
2answers
144 views
Square root function
As a programming exercise I made a square root function in C# using recursion, here is the function:
...
-2
votes
1answer
58 views
Symmetric cipher [closed]
Can someone please review this algo and say if it has some weak places and/or what kind of algo is this (caesar, block etc)?
...
2
votes
1answer
442 views
Xoring in constant time in Java
I was inspired by this answer and the explanation and decided to support negative numbers. While testing, I noticed that the solution didn't handle the case with one number in the given range. A quick ...
3
votes
5answers
91 views
Print the next smallest and next largest number that have the same number of 1 bits in their binary representation
Given an integer , print the next smallest and next largest number that have the same number of 1 bits in their binary representation.
How can I improve this?
...
7
votes
1answer
189 views
Quickselect algorithm in Swift
I recently answered a question
on Stack Overflow about finding the k-largest element in an array, and
present my implementation of the Quickselect algorithm in Swift for review.
This is essentially ...
2
votes
2answers
118 views
High performance, branchless Intersection testing: sphere-aabb & aabb-aabb
From my tests:
AABB-Sphere: 2954.8 tests per ms.
AABB-AABB: 1087.0 tests per ms.
The sphere test is almost 3 times faster, but the two intersection tests seem to perform about the same number ...
4
votes
0answers
52 views
Algorithm to park cars with minimal moves (2nd version)
I'm working on a car move problem. Suppose we have origin parking position for each car, [-1,1,2,3,7,6,4,5] (which means first position is empty, car with ID 1 ...
1
vote
3answers
60 views
Finding the nth machine encountered on the journey
Recently I came across this problem in the IARCS server,here is an little excerpt from it,
A well-known bandit who used to haunt the forests around Siruseri was
eliminated by the policemen a few ...