algorithm-archivists / algorithm-archive

A collaborative book on algorithms
https://www.algorithm-archive.org
MIT License
2.35k stars 354 forks source link

Book Corrections - Complexity Notation & Euclidean Algorithm #352

Open Uabanur opened 6 years ago

Uabanur commented 6 years ago

While reading through the leading chapters of the book on https://www.algorithm-archive.org/ (august 10'th, 2018) I found some sections/descriptions which felt incomplete, and thought I might give my feedback.

Complexity Notation:

Euclidean Algorithm:

Gathros commented 6 years ago

The Euclidean Algorithm problem has been solved, in #366, thanks.

dovisutu commented 5 years ago

Well... For the logarithmic algorithm in book, if you run it on a parallel computer, it might be logarithmic if the 2 branches of this algorithm are parallel running. But if you run it on a serial computer, this never work -- it'll just take O(n) to run. Maybe we can use binary search:

template <typename Iter, typename T>
Iter binary_search(Iter first, Iter last, T target) {//searching in an ascending ordered vector
    Iter middle = first;
    middle += (last - first) / 2;
    if (target == *middle) return middle;
    if (target > *middle) return binary_search(middle + (last - middle) / 2, last, target);
    else return binary_search(first, middle - (middle - first) / 2, target);
}

But problem is this should belongs to Sorting and Searching Chapter. Maybe waiting for a better idea?

dovisutu commented 5 years ago

I think the better way to realize logarithmic algorithm by "array outputing" is the following:

template <typename Iter>
void logarithmic_algorithm(Iter first, Iter last) {
    std::cout << *(first + (last - first) / 2) << endl;
    if(last - first == 0) logarithmic_algorithm(first, first + (last - first) / 2);
}

but it's in c++, and I don't know Julia so much. Well, maybe I'll create a branch for it.