All Questions
14 questions
9
votes
2
answers
1k
views
Implementation of Viterbi algorithm along with unit tests
Introduction to the Algorithm
A system can be in N different, unobservable states, (i.e, we never know in which state the system actually is). The system also has a finite number of possible ...
3
votes
3
answers
469
views
A tiny Java library for generating Gray codes
This library is for generating Gray codes. A Gray code over \$n\$ bits is a list of \$2^n\$ different \$n\$-bit strings subject to the following constraint: two adjacent bit string differ in only one ...
6
votes
1
answer
130
views
Benchmarking efficient inversion counting algorithms in Java
Given an array \$A = (a_1, a_2, \dots, a_n)\$, the number of inversions in \$A\$ is the number of index pairs \$i,j\$ (\$i < j\$) such that \$a_i > a_j\$. We can find the number of inversions in ...
2
votes
0
answers
681
views
A fast integer key map in Java via a van Emde Boas tree
Introduction
The following data structure is a dictionary mapping primitive int values to any value type. Basically, under the hood it is a hash table, where a ...
1
vote
1
answer
893
views
Generic trie implementation in Java
I implemented a Trie data structure in Java, to test my understanding of the concept. I tried (pun intended :) ) to follow TDD steps along the way (i.e., add first a failing test case, and implement ...
4
votes
1
answer
209
views
Algorithms to find various kinds of paths in graphs
I think many here are familiar with the graph data structure. Not very long ago, I implemented as an exercise a supposedly simple Graph application that does some traversals. To note, the most complex ...
7
votes
3
answers
900
views
Nucleotide Count
I am learning Java and hence practicing it from here. The solution seems pretty trivial to me but still I would like to have a honest review which would guide me to following ideas:
Am I maintaining ...
5
votes
1
answer
573
views
Test whether target string is substring of source string
The code is self-explanatory. It has \$O(n)\$ complexity, and it tells whether a given string is the substring of the source string. Are there any cases where this algorithm fails? Is there anything ...
5
votes
1
answer
201
views
Are AVL trees equal? - revision 3
The original question
Given two binary trees, return true if they are structurally
identical, and false otherwise.
Are AVL trees equal?
Are AVL trees equal? - revision 2
This revision on GitHub
...
1
vote
1
answer
198
views
Are AVL trees equal? - revision 2
Revision 1.
This revision on GitHub
In addition to the solution itself, I wrote tests for all the possible
cases.
It seems you have verified all execution paths are covered.
You are right. ...
8
votes
1
answer
819
views
Are AVL trees equal?
I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
5
votes
2
answers
471
views
Longest substring with unique characters
Find the length of the longest substring without repeating characters
Any comments on my code?
...
3
votes
2
answers
2k
views
Radix sort with integer divisions
Here's a perhaps naive but simple implementation of Radix sort in Java.
It works with any radix, and both positive and negative numbers.
...
4
votes
1
answer
135
views
TDD and use case: cook dish with substitutions
This is code for a class that takes available ingredients and returns left over ingredients after making a dish.
Cesars: 2 carrot 4 ice burg 1 chicken 1 beans
Russian: 2 carrots 2 beans 2 chicken
If ...