MohamedG's Log

TW9oYW1lZCBFbC1HZWlzaA==

Selection of Majority in O(n)

Selection algorithms are very useful in many instances, like finding the majority. Given an array of size n that contains a majority item (an item that’s repeated more than n/2 times), we can find that item in O(n). Basically, we can consider it as a voting process, each occurrence is a vote and each item… Read more

Passing C++ Arrays by Value

Just in case you needed to, you can wrap an array into a struct/class and pass it by value to a function:template<typename T, int N>struct array {    T value[N];    T & operator[](int i) { return value[i]; }};template<typename T, int N>void passByValue(array<T, N> a) {    cout << “Value in function:” << endl;    for (int i =… Read more