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
84 views
Determining if an std::string contains a numerical type
I recently came across this SO question asking for methods to determine if a std::string represents an integer. There is also this SO question for ...
-3
votes
0answers
19 views
What is wrong with my program's algorithm of optimal strategy? [on hold]
The link to the question-(https://www.codechef.com/IPC15P1C/problems/GGAME)
My understanding is that if you xor the values of all the piles and it turns out to be 0 then Alice will lose, else Bob ...
7
votes
3answers
79 views
Searching the same values in an array
If I am not mistaken, this method has a complexity \$O(N^2)\$:
...
11
votes
2answers
83 views
Dynamic Programming: Fibonacci-like recurrence relation
This is a problem from my Introduction to Algorithms textbook.
Consider the infinite sequence of numbers An|n>0 = (1,1,3,4,8,11,...) defined recursively as follows.
$$
A_n = \left\{\begin{aligned}
...
8
votes
6answers
1k views
Custom algorithm for hashing and un-hashing password
I am attempting to create functions for getting an algorithm, hashing and un-hashing a string.
As it stands, it works, and very well. But, I feel this is not secure enough and someone could easily ...
8
votes
1answer
68 views
Max element of input iterator range
I came across this SO question on why std::max_element requires a ForwardIterator (as apposed to an ...
4
votes
0answers
29 views
Heap update generic algorithms
In the standard library, there are no algorithms for element updates. This makes it unsuitable as a queue for a Dijkstra's algorithm, for example. Thus I implemented generic heap update functions with ...
-4
votes
0answers
25 views
Sort array by reversing chunks [on hold]
So, I have a working (C++) program, but it's not optimized enough.
The goal is to sort the array, but you can ONLY swap chunks of it, and it's about the amount of swaps you have to do to get the ...
4
votes
1answer
38 views
Optimal matrix chain multiplication in Java
Preliminaries
Given two matrices
$$
A = \begin{pmatrix}
a_{11} & a_{12} & \dots & a_{1q} \\
a_{21} & a_{22} & \dots & a_{2q} \\
\vdots & \vdots & \ddots & \vdots ...
11
votes
1answer
142 views
Secret Santa with Groups on Swift
I am working on an special version of Secret Santa with internal sub-groups.
Typical Secret Santa (SS) requirements:
Cannot be assigned to themselves
Should be random
Every participant should be ...
11
votes
3answers
114 views
Braces and Brackets Autocomplete
I need to complete a sequence of braces and brackets like [ ], ( ), { }, or reject the ...
6
votes
1answer
37 views
Anagram Substring Search
I am having difficulty understanding the runtime and space complexity while implementing the said question.
Following is the code:
...
6
votes
0answers
38 views
DisjointSets/UnionFind implemented as a State Monad
I began implementing an immutable DisjointSets data structure in Scala. It ended up as a state monad as I realised I was passing state around.
I'm new to both the State Monad and Disjoint Sets so any ...
8
votes
2answers
215 views
Finding indexes of numbers that sum to a target
I've taken this algorithm question, which is to find the indexes of any two numbers in an array that sum to a given number. It is quite a simple problem to solve. But it is the execution time of my ...
5
votes
2answers
223 views
Mapping & Sorting Randomly Generated Numbers
Below is the assignment I was given and the coding is what I have came up with. I would appreciate criticism on how I did and on ways to have gone differently about it.
You want to number your ...
6
votes
1answer
44 views
Normalizing forces for basketball game
Recently I found the need to implement a normalization formula in a couple of places in my basketball game, so I created some static methods inside of a class to do so.
...
4
votes
2answers
37 views
Vertex cover approximation in JavaScript
I believe this runs in \$O(V+E)\$ but I wouldn't be able to explain the reasons why. I was looking for some general code review and any help on understanding the runtime.
...
8
votes
2answers
152 views
Quick Sum TopCoder (Brute Force solution)
Given a string of digits, find the minimum number of additions
required for the string to equal some target number. Each addition is
the equivalent of inserting a plus sign somewhere into the ...
7
votes
1answer
50 views
Implementing LSD radix sort
I would love a code review of this LSD radix sort implementation. I've rolled my own, and have implemented counting sort as well. I feel like some of the data structures I've chosen could be improved. ...
10
votes
2answers
44 views
What a crooked way to compute the next straight string (advent of code 11)
This year I have been participating in the Advent of Code series of challenges, and it just so happened that I'd be doing them in Javascript. Not my usual weapon of choice, but I do have some ...
7
votes
3answers
61 views
Solving for every variable in a number of physics formulas
I'm working on making an iOS app to solve physics problems and I'm starting by just having it solve basic kinematics problems with the following formulas (I've coded it in C instead of Swift to start ...
4
votes
1answer
53 views
Determine if all characters are unique in string: Without using Bitwise operator
I am implementing the said question on "Cracking the Coding interview" using HashSet. Please have a look and suggest how I can improve the efficiency of the ...
3
votes
0answers
27 views
Recurse on complex Perl data structure, applying needed rules
Inspired by this answer and previous a commentator of code review use:
Given a complex Perl data structure, traverse/jigger/modify as follows:
If ORACLE_SID is ...
2
votes
0answers
15 views
Return the Euler Cycle for a graph with es6
My algorithm for finding an Euler tour of a digraph, G⃗, if such a tour exists, starting from some vertex, v.
...
6
votes
1answer
86 views
Algorithm to find pair with max sum from two arrays
Algorithm to find pair with max sum from two arrays
A[0 ... n] and B[0 ... n]
A[i] + B[j] = max (A[i] + B[j], with i < j)
i,j < 99999; n < 99999
My ...
4
votes
1answer
85 views
Seven-segment display GUI
I am building a GUI to display a digital clock face (four seven segment displays), and I have a selector to switch between 12/24-hour formats. I have working code to show both formats, but it is ...
4
votes
1answer
63 views
Java Quicksort Algorithm
I am trying to work on writing readable code and reducing the amount of redundant code I write. I find this hard to do especially when it comes to algorithms. So, I wrote a quicksort program to ...
4
votes
3answers
126 views
Finding prime numbers in user specified array
I have a program that searches for prime numbers in an array specified by the user. The program starts by asking how big the user wants the array to be, then asks how many threads to split the ...
0
votes
1answer
67 views
3
votes
1answer
71 views
Windowed Sieve of Eratosthenes in Java
I wanted to try and use the Sieve of Eratosthenes to find all prime numbers between some arbitrary bounds 1 <= m <= n. The simple implementation of the sieve ...
0
votes
1answer
88 views
7
votes
4answers
135 views
Goldbach’s Conjecture in Python
Input Format
Input starts with an integer n (1 ≤ n ≤ 100) indicating the number of cases. The following n lines each contain a test case of a single even number x (4 ≤ x ≤ 32000).
Output Format
For ...
3
votes
1answer
35 views
Finding the largest not-necessarily contiguous alternating binary string after inverting any sub-string from a given string
I'm having problems solving this problem within the time limit.
Alternative Thinking
http://codeforces.com/contest/603/problem/A
Kevin has just recevied his disappointing results on the USA ...
2
votes
2answers
56 views
Project Euler 22: Names scores alternative
Can someone tell me how to improve my following python code.
Code:
...
6
votes
2answers
47 views
Bell numbers calculation in C
This is my implementation of the bell() function to calculate the n-th bell number in C.
Along with it I made the factorial() ...
6
votes
3answers
62 views
Sorting networks
Yesterday I read a fascinating article on Wikipedia about sorting networks.
Comparator networks are abstract devices built up of a fixed number of "wires" carrying values, and comparator modules ...
6
votes
2answers
567 views
HackerRank: ACM ICPC Team
I made a solution to this problem from HackerRank :
You are given a list of N people who are attending ACM-ICPC World
Finals. Each of them are either well versed in a topic or they are
not. ...
3
votes
1answer
42 views
My implementation of (open) Knight's Tour
This is my implementation of the (open) Knight's Tour on a 5v5 board. My original assignment for CS was to solve the Knight's Tour from any startings position (0,0 -> 4,4). The goal for myself was to ...
1
vote
3answers
94 views
Longest common subsequence (LCS) for multiple strings
How would you improve this code? Particularly the check and check_all functions?
The time complexity of the algorithm of mlcs is \$O(|\Sigma|MN)\$, where \$\Sigma\$ is the alphabet, M is the number ...
4
votes
0answers
48 views
Comparing puzzle solvers in Java
I have this program that solves a \$(n^2 - 1)\$-puzzles for general \$n\$. I have three solvers:
BidirectionalBFSPathFinder
...
7
votes
2answers
42 views
Function to find the minimum depth of a tree
For a leetcode problem to find the minimum depth of the binary tree, I have written the below solutions. The solution is accepted, but can I do any other changes to make the code elegent?
...
3
votes
1answer
60 views
Comb sort in Java
Comb sort may be thought of as a generalization of bubble sort. The following is my implementation:
...
3
votes
0answers
43 views
Moving buttons is very slow
I have a very simple app which removes buttons and re-adds buttons to certain layouts when a button is clicked. The problem is this process is taking a very long time. How do I speed this process up?
...
13
votes
2answers
146 views
Exact sort - sorting with few move operations
A while ago, I found a somewhat interesting sorting algorithm named Exact-Sort, which is introduced with the following somewhat bold claim:
No sort algorithm can sort an array with less position ...
6
votes
2answers
190 views
Ascending Order Algorithm
I wrote a simple function to sort an array of integers in ascending order. Here is the code -
...
7
votes
2answers
327 views
Program to determine total stops taken by elevator
I was asked a question to write a optimal program that would determine the total number of stops a elevator has taken to serve X number of people.
There is a elevator in a building with M floors. ...
4
votes
4answers
144 views
Mastermind: Evaluating the guess
The evaluate_guess function below returns the evaluation of a guess with respect to Mastermind game rules:
...
2
votes
2answers
196 views
Improving the time complexity of my back pack algorithm
Is there anyone who can help me improve the time complexity of this backpack algorithm, for which I already use sliding array to improve the space complexity.
The problem is as follows:
Given ...
4
votes
3answers
259 views
12 hours to 24 hours conversion function
I have made a time format converter which converts 12 hour format to 24 hour format. My convert_to_24() takes a string in format of ...
1
vote
3answers
85 views
Simple 1-dimensional labyrinth
I am training a colleague who is familiar with Python but has a limited knowledge of C# and complexity. I thought the following problem could be a good start.
You are in a desert, there is a ...