What would you do if I ask you to find the k-th smallest or largest element in an unordered set of numbers? Sort the numbers? God, you are boring…

Most programmers immediately answer with sorting when they are asked to find k-th smallest element. Why is that? Well, because it is simple! All you need to do is a call to a sort function and you are good to go. But can we do any better? I guess I wouldn’t be writing this if we couldn’t…

Let’s start by finding the smallest/largest element in the set. …


Okay, this one should not take long. The entire purpose of this post is to introduce the idea of utilizing randomness in order to improve the performance.

Initially, I was planning to write on a different subject but half-way through I realized a short post on randomized algorithms might be beneficial for the subject. So, here goes: a randomized algorithm is simply an algorithm that uses some sort of randomness at some point during your algorithm to improve the performance by uniformly distributing the inputs.

This subject is heavily based on probabilistic analysis, hence requires a strong mathematical background. However, I will be skipping the calculations in this post and just going to show you how randomized algorithms can be used to improve performance. …


Did you ever wonder how data compression programs like WinRAR or WinZip work? And did you ever ask yourself if we can compress the data, why not store and use it that way in the first place? If so, welcome to the third chapter of the series: Huffman Codes.

So, I just solved my 200th question in HackerRank after being off for nearly two years, which was incidentally about Huffman Decoding and found myself writing this post. Let me start by asking a question: How can you modify the data in your computer to take less space? …


Image for post
Image for post

This story is a direct sequel to my previous post on Greedy Algorithms, so you may want to check that out first. It is still okay if you are only interested in Dynamic Programming and want to skip it since I will be explaining the problem again.

When I was a university student, dynamic programming was the hardest topic in the Algorithms class for me. That was mainly because of being have to read long pages of redundant explanations prior to understanding the actual problem. …


If someone asked me to describe what a software engineer does in a single word, my answer would be optimization. The fact is most of the time we don’t look for the best solution and we don’t look for the cheapest either, but we look for the optimum one. Sacrificing your time for the best solution is a noble cause, but there may come times where the best solution is overkill and you don’t always have the resources (time, money, etc.) to go after your ideals. In fact, you don’t always need the best solution either, just a fairly good one might suffice. …

About

Can Bayar

Senior Software Engineer, Rock Vocalist & Guitarist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store