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.

learn more… | top users | synonyms

1
vote
0answers
23 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
11 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 ...
2
votes
0answers
23 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
14 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
43 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
28 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
42 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
58 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
23 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
607 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
48 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. ...
-4
votes
0answers
12 views

About the Nodes ( states ) in BFS algorithm [on hold]

i am confused about the BFS algorithm , i know how can i do the BFS in graph search , for example , a-b-c-d and so on if i have a maze , for example to the maze : ...
3
votes
1answer
66 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
73 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
60 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
35 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
50 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
94 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
98 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
47 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
78 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
94 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
47 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
45 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
78 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
78 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
232 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
38 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
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
1answer
63 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: ...
-1
votes
1answer
75 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
46 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
76 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
67 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
66 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
115 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
64 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
69 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
45 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
118 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
58 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
99 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 ...