This is a simple but interesting problem, which can be easily solved with O(n2) time complexity, but it demands to reverse your logic to solve it in O(n) time. Problem: Let's say, there is an array arr=[1, 2, 3, 4, 6, 7, 8, 2, 5] Now we need to find all pairs of numbers, which … Continue reading Problem: Find all pairs
Category: arrays
Selection Sort
Selection sort is quite simple, but because is simple is then easy to understand. It's complexity is O(n2) so it's not very suitable for production quality code and there are (obviously) other faster sorting algorithms, but it's good to get a grip of it and treat it as an introduction to sorting algorithms. Basically this … Continue reading Selection Sort
Difference Array
Today I am going to introduce you to a pretty cool algorithm, which would allow you to update multiple ranges in an array in O(n) time ! Let's say you got an array, and you need to update ranges of it with given values. So as an input you would receive a two dimensional array … Continue reading Difference Array