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.
1
vote
0answers
5 views
Inpainting algorithm using conjugate gradient for colored images using Matlab
I am currently working on an inpainting algorithm : the input is a picture, I apply a Mask (random disposition of dark pixels) and then the algorithm tries to recover the original picture using the ...
0
votes
0answers
37 views
Suffix array algorithm
Here is implementation of the suffix array algorithm.
I'm wondering if I can safely change this line:
...
2
votes
1answer
29 views
3
votes
1answer
80 views
VERY simple C# Set implementation
This is not meant to solve any insane real world problems. I just want to make sure my Set logic is right and the code looks okay. It feels weird implementing it with a ...
9
votes
3answers
1k views
Simple C# HashTable Implementation
Haven't put one of these together since college. How does this look overall?
...
1
vote
1answer
34 views
Levenshtein distance with edit sequence and alignment in Java
I have this program that computes a Levenshtein distance of the two input strings, their edit sequence, and the alignment:
LevenshteinEditDistance.java:
...
3
votes
1answer
99 views
Making the Levenshtein distance code cleaner
I was writing an implementation of Levenshtein distance in Python and I found my code really ugly.
Have you any idea how to make it more elegant?
...
2
votes
1answer
20 views
Anagram counter
Homework prompt was:
You are given two strings, a ‘parent’ string and a ‘query’ string respectively. Your task is to determine how many times the query string – or an anagram of the query string ...
1
vote
2answers
37 views
Summing all keys in the leaves of a tree
Input
The input contains a single text line with eight positive integers A, B, M, L1, L2, L3, D, R separated by one or more spaces. These parameters regulate the ...
-2
votes
0answers
13 views
C++ AVL tree implementation [on hold]
I am writing an AVL and I want to make it work the "iteration" way rather than recursive. I have therefore added additional *parent field in the structure and I am facing problems with it. I know it ...
5
votes
1answer
81 views
A* implementation is not running efficiently but gets correct result
I'm not entirely sure what code other people will need to see, if I miss something off that is important please leave me a comment and I will update it as soon as I possibly can.
I have coded an A* ...
0
votes
0answers
32 views
Pizza delivery problem: finding the best spot to set up a pizza shop
I received the following problem in an interview and submitted this solution but did not make it to the next round even though this was a working solution. I'm wondering how I can improve my code.
...
1
vote
1answer
43 views
My implementation of counting sort [on hold]
I've made the following implementation of counting sort. I don't think that I understand the algorithm fully but this implementation seems to be working correctly.
I've used the ...
3
votes
2answers
51 views
Function that strips trailing '0's from a float
I'm writing an embedded application in C, and at one point I need to convert a float into an ASCII representation of that float, so I can send the ASCII over a serial port. The protocol the serial ...
1
vote
0answers
15 views
Deterministic finite automaton in Java - follow-up
(See the initial and first iteration for description and motivation.)
Now I have incorporated all the remarks made by Tunaki, and it looks like this:
TransitionFunction.java:
...
0
votes
0answers
54 views
1
vote
1answer
23 views
0
votes
1answer
72 views
Custom Dynamic Array
Pretty simple class but just want to make sure I've approached it correctly.
...
4
votes
1answer
78 views
Finding number of times each string in an Array of strings occurs in a large stream of characters (i.e large string)
Interview problem:
Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the ...
0
votes
0answers
27 views
Inserting an element in the correct position in the sorted sub-array
Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Here is an small example ...
0
votes
1answer
36 views
Detecting cycle in LinkedList
Is this a fair/clean way to detect a cycle in a LinkedList? Should work for both single and double LinkedLists'.
...
0
votes
1answer
21 views
Generic LinkedList with add/exists/delete/dlear/iteration functionality
I've just been going through core data structures and algorithms recently, wanting to get back in touch with the core fundamentals. I'm starting simple with a ...
4
votes
2answers
58 views
all combinations of all sizes less than N
I want to generate all possible combinations (without duplicates) of all sizes less or equal than \$N\$, so for example if \$N=3\$ I want to generate the following
\$\{1\},\{2\},\{3\},
...
3
votes
1answer
25 views
String Matching w/o repeating the comparisons for common part of the two strings
In an attempt to think up a more efficient String Matching algorithm than the naïve \$O(n \cdot k)\$ one I came up with a slightly modified approach.
In my algorithm (code in Java), I tried a little ...
1
vote
0answers
44 views
Rolling up Invoice Items Matching Certain Criteria
I have a listing of invoice line items that I need to apply some convoluted business logic to. We have another listing of items that I compare the invoice items to and if I find matches, I then need ...
4
votes
3answers
72 views
Idiomatic ruby to calculate distance to points on a graph
Can this code be made more like idiomatic ruby using methods such as map or inject?
@random_tour is a variable length array of points on a graph:
...
-1
votes
0answers
14 views
Working with Astar Algorithm [closed]
I am Rewriting an A* Algorithm in C++ which I found on the internet, I'm compiling it to get the Route, but the while loop inside the path function iterates only once and returns out empty.
main.cpp
...
3
votes
1answer
50 views
Detect cycle in undirected graph
Below is my code to detect cycle in an undirected graph. Could anyone please review and let me know if I have taken care of all the cases?
The basic idea is to use DFS (non-recursive using stack) and ...
2
votes
3answers
143 views
Read numbers until a prime is entered then print non-primes
I'm a beginner at C#. I just want to know what is the C# way to do this by its convention and a better algorithm as well.
...
10
votes
5answers
799 views
Finding two consecutive triangular numbers with a given target sum
I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
3
votes
1answer
67 views
Tic Tac Toe with 3 AI modes or Two-Player
This is my first stab at a game AI, and I've been working on multiple game mode difficulties, so I decided to start with a simple game. :) I'm most concerned about efficiency of the AI algorithms, and ...
4
votes
1answer
54 views
Solution to the 0/1 knapsack in Python
So I made a version for the 0/1 knapsack problem myself (using matrix dynamic programming algorithm). Given a list of items with name, value, and weight, my function computes correctly the optimal ...
3
votes
1answer
51 views
Mining association rules in Java
Let \$I = \{ i_1, i_2, \dots, i_d \}\$ be the set of all possible items, and \$T = \{ t_1, t_2, \dots, t_N \}\$ be the (multi)set of all given transactions, where \$t_i \subseteq I\$ for all \$i \in ...
3
votes
3answers
78 views
Finding the number in a list that differs in parity
Given any string with a series of numbers find out which one of the numbers differs from the others in evenness and return its position.
Examples:
...
4
votes
1answer
56 views
Balanced parenthesis in Ruby
I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution.
...
2
votes
1answer
141 views
+50
Find median of two sorted arrays
Problem statement
There are two sorted arrays nums1 and nums2 of size m and ...
5
votes
1answer
52 views
4
votes
0answers
53 views
Creating a count inversion array of an unsorted array of unique integers
Given an array:
arr = [2,3,1,4]
I could write a count inversion array such that counting all numbers n2 after a certain ...
2
votes
2answers
72 views
Constructing a 4×4 grid of words
I have an ArrayList which contains Strings with a size of 1000. I am looping through that ArrayList and finding words and trying to form a square from them. For example as follows:
...
2
votes
2answers
102 views
Algorithm to rotate array elements in Ruby
I wrote this algorithm to rotate elements in an array. It's not very efficient, but it works. It has another disadvantage that it doesn't rotate right (it would be nice to pass it negative steps, for ...
-2
votes
1answer
139 views
On Finding Coin Jams
The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...
2
votes
1answer
72 views
-5
votes
0answers
49 views
finding two strings in a set of data
**does anyone know how to create a code to solve this question **
**cough cough this is on bluej **
How many URLs on this website end with either ".com" or ".com/"?
...
2
votes
0answers
40 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 ...
4
votes
2answers
39 views
Number of ways to make change for an amount
Task
Write a program that, given the amount to make change for and a list of coins prints out how many different ways you can make change from the coins to STDOUT.
My approach
The number to make ...
6
votes
2answers
79 views
Melsort — Sorting with encroaching lists
For the nth time already I come back with yet another alien sorting algorithm. Today I will present Melsort, implemented from the description I found in the paper Encroaching Lists as a Measure of ...
0
votes
1answer
14 views
Suggest me some improvements so that i could reduce the execution time less than 4 sec for any testing value [duplicate]
Here is the Code.
This code is for calculating the perfect squares between two given numbers. User can add the interval as well like for how many intervals he want to check the perfect squares.
...
0
votes
1answer
88 views
Cleaning up 3D bin packing [closed]
This is a follow up question to 3D bin packing in java (compare two codes)
I finished testing my code's result and started cleaning it up.
Could anyone please tell me what I should do or fix to ...
7
votes
3answers
186 views
Calculate Age in Seconds
I am a high school math and science teacher. I am working with my students on the concepts of algorithms, unit conversions, and functions. In class, to work on all these concepts, we just worked out ...
3
votes
2answers
55 views
The Boyer-Moore Majority Vote Algorithm
I have started learning Java recently and was looking into some easy algorithms.
I found the Boyer Moore voting algorithm here.
I am trying to get better at writing good code for my solutions. Please ...