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.
1
vote
1answer
19 views
Find shortest paths in a matrix using Dijkstra's algorithm
The problem is as follows:
I have a matrix with impassable fields those are marked by the input. There is also a castle which reaches up the right side of the matrix. I have to find how many paths can ...
1
vote
1answer
11 views
Candie distribution algorithm
I am studying algorithms and I solved this problem under Dynamic Programming section:
Alice is a kindergarten teacher. She wants to give some candies to the
children in her class. All the ...
-6
votes
0answers
19 views
minion game from HackerRank [on hold]
https://www.hackerrank.com/challenges/the-minion-game
code is giving answers as per the following link. however test cases on hackerrank are failing... Thanks!!
a link on this site related to the ...
0
votes
0answers
13 views
Remove overlapping n-grams
I'm trying to write a compression algorithm that works by splitting the input into n-grams, and it's working, but I've start to run into a problem. This piece of code is supposed to remove ...
2
votes
1answer
33 views
Maxflow for baseball elimination game
I have a problem similar to the baseball elimination. Given some teams, the number of wins they have and the number of games they have left between each other I have to find for which team it is still ...
3
votes
1answer
70 views
Arranging Buttons on a Process Enumerating Application
I had the following piece of code for populating a list of currently running processes in an IT Self-Help application :
...
0
votes
0answers
21 views
Building an index of items from an iterable-of-tuples
Is there a more conventional / standard / easy-to-read way of building an index of tuples from an iterable than this:
...
1
vote
0answers
37 views
Mergesorting a stack in Java - a new algorithm
(See the previous iteration.)
Now I have implemented a stack merge sort that does not have to reverse every substack after sorting it, and it allocates the two auxiliary stacks only once prior to the ...
3
votes
1answer
46 views
Running shell commands in a pipeline
I'm writing a shell in C for Linux and BSD. My code was unreadable before but I did a rewrite and now it is much more readable. The purpose of the code is to create a command pipeline and execute it.
...
4
votes
1answer
32 views
Secure file system utility functions
For Khronos, I've had to develop these utility functions to help me deal with storing the .wav files. However, they could also be used in a variety of ...
1
vote
2answers
30 views
SPOJ “TESSER” - Getting TLE using KMP algorithm
The TESSER - Finding the Tesserect problem is tagged as a problem to be solved by Knuth-Morris-Pratt (KMP) algorithm. I'm using KMP, but am still getting time-limit-exceeded.
Task
Each of T test ...
1
vote
1answer
108 views
Fast Document Distance, C++
This is an attempt at a fast "document distance" implementation in C++. For reference, I found this problem in MIT's OpenCourseware 6.006 algorithms course.
A quick look at the ...
0
votes
0answers
22 views
Searching for index of node using traversing least possible path
The following is my code where I'm searching for the index of Doubly Linked List's node by traversing least possible paths.
...
5
votes
4answers
283 views
2
votes
1answer
40 views
1-dimensional and 2-dimensional Peak Finding Algorithm
I have the following code for a peak finding algorithm in Python 3.4.3. A peak is an element that is not smaller than its neighbors.
...
-1
votes
0answers
12 views
Running dfs twice to find the diameter of the tree? [closed]
I am trying to solve this problem on spoj. This problem, although being straightforward, I am failing to get the bug in my code having tried for 3 days straight. My approach is to run dfs twice, ...
-1
votes
0answers
11 views
Output the shortest path of a graph between given 2 nodes [closed]
I have written code to output the shortest path between two nodes
Input Format-First line contain two numbers ,indicating nodes and edges , second line contains 2 numbers among which shortest path ...
4
votes
2answers
63 views
0
votes
0answers
4 views
lexicographic rank of a string with duplicates [closed]
Given a string, find its rank among all its permutations sorted
lexicographically. For example, rank of “abc” is 1, rank of “acb” is
2, and rank of “cba” is 6. Assuming there can be duplicate ...
1
vote
0answers
52 views
Hunt n' Kill algorithm
Last day I implemented the Hunt and Kill algorithm in JavaScript, using HTML5 without any libraries. I would like my code to be reviewed.
How it works
I start with a 2D array filled with walls ...
-3
votes
0answers
27 views
Printing numbers to a given number n and calculating the sum and count as well
This prints numbers to a given number n and calculating the sum and count as well, but my program is giving "time limit exceeded." Please suggest ways to reduce the complexity.
...
5
votes
1answer
42 views
Speed concerns of octree implementation
For couple of days now I am trying to speed up my Force-Directed graph implementation. So far I've implemented Barnes-Hut algorithm that's using octree to decrease number of computations. I've tested ...
1
vote
1answer
63 views
-5
votes
2answers
46 views
Rewrite 12 consecutive ints based on bizarre logic
Despite looking terribly ugly, it is pretty interesting due to some specific connections to cellular automata theory. I'm looking for ways of simplifying it further. This program takes 2.7 seconds to ...
3
votes
0answers
35 views
Comparing linear time strongly connected component algorithms in Java
So I have implemented three linear time (\$\mathcal{O}(V + E)\$) algorithms for finding strongly connected components of a (directed) graph. A strongly connected component is just a maximal subset of ...
0
votes
2answers
61 views
LRU algorithm implementatin
In this code:
tmr represents timer array
n represents number of frames in memory
m ...
0
votes
1answer
29 views
Optimizing and accounting for edge cases in Dijkstra's algorithm
I just recently wrote a program to simulate how multicast routing works.
The program uses a weighted graph to represent the network and simply runs it through the algorithm.
I would like to know if ...
9
votes
2answers
134 views
Finding a string whose MD5 starts like the digits of π
I tried to make a program to find a string whose MD5-hash starts like the digits of pi, where dot is omitted. Is there a faster way to do it than this:
...
1
vote
0answers
25 views
Algorithm and PHP Class to Compare companies' information and define similarity
The task is: I get companies' information from a large CSV file and then I need to compare this information with each company in the database to know if the company is a new one or if it is already in ...
3
votes
2answers
127 views
High execution time of LCS length program in Python2
I was trying to solve the Longest Common Subsequence problem on a HackerRank exercise.
It's quite simple and straightforward, just print out the length of the LCS. I submitted this code:
...
3
votes
0answers
41 views
Octree creation for Barnes-Hut algorithm
I am trying to implement quadtree for my Barnes-Hut algorithm implementation. I am not sure that the code I've wrote so far is good implementation - it is dirty, and tend to be slow.
Of course I am ...
1
vote
0answers
36 views
Union Find implementation
I am trying to complete this challenge. The user should enter a sequence of instructions, = to link two numbers, and ? to query ...
4
votes
2answers
68 views
Is this the right way to implement a simple hash table in C++?
Does this look like a proper implementation of a hash table in C++? Any errors anyone can find?
Thanks in advance (:
...
1
vote
1answer
62 views
Mergesorting a stack in Java
(See the next iteration.)
I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have:
...
1
vote
1answer
43 views
Longest Palindromic Substring
I wrote the following code for this problem. The problem is to find the longest palindromic substring.
I think it is correct and is working correctly for all the test cases I entered myself. Now, the ...
3
votes
3answers
87 views
Calculate the Hamming difference between two DNA strands
Write a program that can calculate the Hamming difference between two DNA strands.
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^ ^ ^ ^^
The Hamming distance between these two ...
2
votes
0answers
31 views
Numerical differentiation using the y-intercept
I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). ...
0
votes
0answers
18 views
Lazy segment tree implementation
I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially the ...
0
votes
0answers
41 views
Segment tree implementation in C++
I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, not "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially ...
3
votes
0answers
23 views
Sparse table implementation
I wrote a C++ implementation of a sparse table (I wrote it for an arbitrary function) and I want so much to ask for a review. I'd like to know how I can make it better, especially the consistency of ...
2
votes
1answer
44 views
Find the contiguous subarray within an array (containing at least one number) which has the largest sum
Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray ...
5
votes
6answers
342 views
Find maximum difference between values in an array
My task is to use the following pseudocode and improve it (make it run faster). Also I have to analyze the runtime of the given pseudocode and of my new code that i improved.
What does this algorithm ...
0
votes
0answers
14 views
Reservoir sampling implementation in C
The distribution of unique values in input and output seems to be quite different in the following code, (h1), (h2); does the implementation have any obvious error ?
...
3
votes
1answer
50 views
Java Connect Four “Four in a row” detection algorithms
I am making a connect four type game for my end of the year project in my programming class. I am about to start building off of the console based version I have made and add a GUI, but I feel sort ...
1
vote
0answers
19 views
Unification with sequence variables and flexible arity functions
Today I wrote an implementation of the unification algorithm found in Temur Kutsia's 2002 paper. I didn't just do this for fun, it's related to other research I'm doing. I'm feeling more confident in ...
1
vote
1answer
45 views
Get time slots based on multiple workshops
I have a list of Workshops, each having open days (Monday, Tuesday etc.) and open time and close time (which will be same for each day). Now, Based on the current time, I need to find out next 7 days ...
2
votes
1answer
44 views
Import data module
I have a custom module to import nodes from a .txt file. (Drupal 7). My problem is I have a lot of nodes to import and this function takes so much time.
...
2
votes
2answers
64 views
Fractional Knapsack in Java
So I solved Fractional Knapsack problem:
There are n items in a store. For i =1,2, . . . , n, item i has weight wi > 0 and worth vi > 0. Thief can carry a maximum weight of W pounds in a knapsack. ...
3
votes
1answer
64 views
A* Search with Array Lists
I implemented A* Search with Array Lists following the pseudocode here.
I have been working with different algorithms on my own, and now, I am trying to optimize them so that I can run them with less ...
3
votes
1answer
52 views
Celebration Party Problem - Algorithm
I solved the following problem:
Let's consider the following situation. You've invited a lot of children to a celebration party, and you want to entertain them and also teach them something in the ...