Thoughts of a programmer

Binary Indexed Tree

Previous week, we saw how we can use Square root decomposition to solve our problem. This week, we will see how we can solve the same problem by using a different technique called Binary Indexed Tree (also called Fenwick Tree). Binary Indexed tree is a useful technique when we are dealing with a dynamic array of data where following type of ... Read more

Square Root Decomposition

Let’s consider the Problem Statement from HackerEarth. Basically, you are given an array \(A\) of size \(N\) and \(Q\) queries. Each query can be of two types - \(1\) \(i\) - add \(1\) to the \(i^{th}\) element of the array \(A\) \(2\) \(K\) - print the \(K^{th}\) odd number of the array \(A\) if it exists, else print \(-1\) And all t... Read more

Python & Terminal

(Note: All of these is related to Python 2. Python 3 may show different results.) While doing some office work, I came across this. I had written below line in my Python 2 interpreter. >>> s = '©' >>> s #for checking the value of s Surprisingly, I got the following value. '\xc2\xa9' The reason I was surprised,... Read more

Life of a binary

Almost every one of you must have written a program, compiled it and then ran it to see the fruits of your hard labour. It feels good to finally see your program working, isn’t it? But to make all of this work, we have someone else to thankful too. And that is your compiler (of course, assuming that you are working in a compiled language, not an... Read more

Threading Explained

Normally the programs that you write are single-threaded. By single-threaded, I mean that the processor starts at the first instruction in the program and then executes them one-by-one in the sequential manner, of course with some branching here and there, until eventually it reaches the last instruction in the program and the program ends. But... Read more