Skip to content
Browse files

Minor cleanup

  • Loading branch information...
1 parent 1cbb2e3 commit bcd6e6e2e3c90fb38d3957530a0a0f90dc3319b6 Andrey Paramonov committed May 30, 2010
Showing with 5 additions and 4 deletions.
  1. +3 −3 fibonacci.erl
  2. +2 −1 recursion.groovy
View
6 fibonacci.erl
@@ -6,12 +6,11 @@
-module(fibonacci).
-export([naive_recursive/1, bottom_up/1, squaring/1]).
--export([parallel_power/2, parallel_loop/3, parallel_squaring/1]).
-include_lib("eunit/include/eunit.hrl").
% Exponential:
-% T(n) = Ω(Φ^n), Φ is Golden section
+% T(n) = Ω(Φ^n), Φ is Golden ratio
naive_recursive(0) -> 0;
naive_recursive(1) -> 1;
@@ -39,7 +38,8 @@ squaring(N) -> [_,X,X,_] = power([1,1,1,0], N), X.
squaring_test() -> ?assertEqual(8, squaring(6)).
-% A^n; logarithmic algorithm
+
+% Matrix exponentiation A^n; logarithmic algorithm Θ(log n)
power(Matrix, 1) -> Matrix;
power(Matrix, N) when N rem 2 =:= 0 ->
View
3 recursion.groovy
@@ -135,7 +135,6 @@ assert 10 == inversionCount([5,4,3,2,1]) // n(n-1)/2
/*
* http://en.wikipedia.org/wiki/Heapsort
* http://datastructurefaqs.blogspot.com/2009/01/sorting-techniques-with-algorithm.html
- * No recursion actually
*/
def heapsort(list) {
heapsort(list, list.size())
@@ -152,6 +151,7 @@ def heapsort(list, count) {
list
}
+/* O(n) running time */
def heapify(list, count) {
def start = (count - 2).intdiv(2)
while (0 <= start) {
@@ -160,6 +160,7 @@ def heapify(list, count) {
}
}
+/* No recursion. CLRS, p.156, 6.2-5. O(log n) running time */
def siftDown(list, start, end) {
def root = start
while (root*2 + 1 <= end) {

0 comments on commit bcd6e6e

Please sign in to comment.
Something went wrong with that request. Please try again.