When you pick a random developer and you ask him, hey, what is the time complexity lower bound for a search algorithm, the answer, which has become today almost a reflex is O(nlgn) which is also called linearithmic.

If you search Wikipedia for the running time of radix sort it's saying hold to your chair, O(n), how could that be you ask? It makes a few assumptions and does it more efficiently, it's trick is that the look and peek into the keys themself s, and then it manages to be a non comparison based algorithm.  So while it's true that the lower bound of search algorithms which are based on comparisons is O(nlgn) for non comparison based (such as radix sort) it's O(n)

If you have the array already sorted we could say that our running time for sorting the array is O(1), so aren't we tricking reality, the difference is that the O(n) on radix sort holds also for a non-sorted array.

Examples of sorts which are comparison based sorting algorithms are all the usual ones like quick sort, merge sort, heap sort, bubble sort, insertion sort.

Here is a very naive intuition behind how you can do sorting without comparing anything.

Let's say that you have a random list of numbers, let's say we generated a random list of numbers in between the range 0 to 1000 .  Now as they are random they are unordered, and we would like to order them.

How would you do this without any comparisons?  One way to do this is to create a new array.  Now we are going to scan each of the randomly generated numbers and use the value of the number to insert it into this new array.

So if our random numbers were

101, 202, 50, 900

Then our new array could look like this:

A = 0
A = 0
...
A = 1
...
A = 1
...
A = 1
...
A = 1
...
A = 0

Note that we could put any value inside those array cells.  It's very convenient however to just put 1 because if we could have duplicates then we could increase this number to 2.

Next in order to get the sorted array we would simply scan this array and print the number the index of the array every time we see 1, and if we see 2 we print this number twice.

This looks great and this is O(n) and this is not even radix sort, this is called counting sort, why would we then even need radix sort?

The answer is that we needed in the new array as many cells as the range of numbers ( 0 - 1000) we had in our original list.  So we could find the minimal number then the maximal one and then create an array of that range.

But what if our array to sort is so huge, meaning if this was not just a list of numbers from 0 to 1000 but lets say credit card numbers or social security numbers then our range would be really large so you might find that you need to create an array of size 1G or even more without special optimization.

Radix sort optimizes this so that the array that you need to create its size the space that it's going to take is simply, according to the range of digits, so if your digits are from 0 to 9 it doesn't matter how many numbers we have what is the range we simply need an array of size 10 to accommodate all the digits.

This so cool because we get to enjoy all words both a fax O(n) sort and also low on space consumption.

Now how does it do that! We create a new array like we created before but now each cell is simply the digits. So we have this array now.,

A =
A =
.
.
.
A =

Now what do we do with this array, we scan the numbers and for each scan we are going to do to start with first digit and then put all the numbers that have this digit at this place on the array.  So if the first digit from right LSD (The Least Significant Digit) we do LSD because we want the highest significant digit to have the last word because it is the most important so it would be the one to actually say the last word and who comes after whom.

So we take the first digit scan each number lets say we see 3 numbers that end with 0, we put all those numbers in A.  We see 2 numbers that end with  so we put these numbers in cell number .

So if we had 202, 153, 103 to sort out first scan which looks at the LSD would do

A = 202
A = 153, 103

Now we go to the middle digit but now we don't scan the original numbers we scan the numbers according to their order in the helper array that we have just build, if we don't do that we lose all the sorting that we did with this last digit! and again we put the items in our array

A = 202, 103
A = 153

Now we go to the most significant digit and we get

A = 103
A = 202

Now we get to the A = 153, so we put it in A note that when we put it in put it as the last item on A which turns it out to be sorted this is because we already sorted by the previous digits. so hence we get:

A = 103, 153
A = 202

And now we if scan our helper array we get: 103, 153, 202 which is a sorted array!

There are a few other ways to do this, such as storing exactly the output indexes of the radixly sorted array, but we won't do this now.

### Dev OnCall Patterns

Introduction Being On-Call is not easy. So does writing software. Being On-Call is not just a magic solution, anyone who has been On-Call can tell you that, it's a stressful, you could be woken up at the middle of the night, and be undress stress, there are way's to mitigate that. White having software developers as On-Calls has its benefits, in order to preserve the benefits you should take special measurements in order to mitigate the stress and lack of sleep missing work-life balance that comes along with it. Many software developers can tell you that even if they were not being contacted the thought of being available 24/7 had its toll on them. But on the contrary a software developer who is an On-Call's gains many insights into troubleshooting, responsibility and deeper understanding of the code that he and his peers wrote. Being an On-Call all has become a natural part of software development. Please note I do not call software development software engineering b

### SQL Window functions (OVER, PARTITION_BY, ...)

Introduction When you run an SQL Query you select rows, but what if you want to have a summary per multiple rows, for example you want to get the top basketball for each country, in this case we don't only group by country, but we want also to get the top player for each of the country.  This means we want to group by country and then select the first player.  In standard SQL we do this with joining with same table, but we could also use partition by and windowing functions. For each row the window function is computed across the rows that fall into the same partition as the current row.  Window functions are permitted only in the  SELECT  list and the  ORDER BY  clause of the query They are forbidden elsewhere, such as in  GROUP BY ,  HAVING  and  WHERE  clauses. This is because they logically execute after the processing of those clauses Over, Partition By So in order to do a window we need this input: - How do we want to group the data which windows do we want to have? so  def c

### Functional Programming in Scala for Working Class OOP Java Programmers - Part 1

Introduction Have you ever been to a scala conf and told yourself "I have no idea what this guy talks about?" did you look nervously around and see all people smiling saying "yeah that's obvious " only to get you even more nervous? . If so this post is for you, otherwise just skip it, you already know fp in scala ;) This post is optimistic, although I'm going to say functional programming in scala is not easy, our target is to understand it, so bare with me. Let's face the truth functional programmin in scala is difficult if is difficult if you are just another working class programmer coming mainly from java background. If you came from haskell background then hell it's easy. If you come from heavy math background then hell yes it's easy. But if you are a standard working class java backend engineer with previous OOP design background then hell yeah it's difficult. Scala and Design Patterns An interesting point of view on scala, is