Saturday, January 28, 2017

The Alchemist - The winds will never feel the same again! ;)

When I began to read this book during my flight, the person next to me told me that I would see this book with a different perspective 10 years from now. I don't know about that, but I really found this book quite awesome.

There are a few recurring themes in the book.


The very first, and one around which the story revolved is of the treasure. The treasure that the king told him of. The treasure that his dreams told him about. The very same treasure that took him from Spain to Egypt.

But when I was done reading this book, I asked myself if the treasure really mattered to him at the end. If you really ask the soul of Santiago this question, his answer is going to be no.

You know what his real treasure was - his journey. The journey that evolved him in so many different ways. He came to know other businesses, understood the language of the world, met the woman of his life, and realised so many different things.

So, once I completed this book, I didn't need a dream to happen to find my treasure. Neither do you! We just need to seek more than our routine life we are accustomed to, like Santiago was being a shepherd, and boy, that's where you will find the treasure.


Monday, December 19, 2016


< This is a live post, and will keep on updating till 30th of December 2017 >

It's 19th of December 2016, and I have not done anything of value in the past two days. But then I imagined a horrifying situation - what if the entire year or the entire life went the same way. Something that has disturbed me for quite too long!

As I take a glance at the past few years, I see myself improving over time, but there is no statistics of that. Also, couldn't this improvement be sped up?

I don't believe that a change in year number will change anything drastically, but with 2017, I am starting with measuring my improvement in quantity! :)


I will be measuring up myself in 2017 against the following yardstick -

1. My technical goals - It has to come first. There are so many awesome things happening in the world, and I am fortunate to be studying one such field of computer science. In the past years, I have set many goals, be it completing CS50 or Algorithms course, or learning probability or linear algebra, or building a chat app. How many of them have I completed. Rarely any!

With new insights, I would now be setting and achieving real goals, something that I can look up to, when 2017 would be coming to an end.

2. My technical posts - I have written quite a good number of posts this year on this blog, but how many of them are technical. Writing technical posts would force me to learn and explore the new stuff of computer science, and be better at explaining the same!

3. Reading books - This year I have completed less than 5 books, but reading a variety of books only increases our understanding. The goal for 2017 is a mammoth in itself, but my love for reading books should make this journey beautiful. Goodreads will help me keep track of that.

4. Watching Movies - There are so many awesome movies out there to watch, the ones I have a list of, but I don't. I haven't watched more than 20 movies this year. Seriously? A movie, every Friday!

5. Travelling Places - Tagging yourself as a "traveller" doesn't help, going out to places does.

6. MOOCs for self improvement - There are so many online courses that may not come under my technical goals, but I wish to take them for my own pleasure. This one goes for that.

7. Contribution to the society - All my learning becomes more useful, when I contribute back to the society in a useful way. And you know, how strongly I feel for the same.

These are the 7 points I would be looking back a year from now, and I am pretty hopeful that I would then proudly share what all I did the entire year!

I will be placing this post as a page on my blog, and will keep updating the page with my progress.

Happy New Year to all.

Wednesday, December 7, 2016

V for Vengeance

I didn't know what Vendetta mean when I heard the name of the movie. But now I do. I also know its power!

As I write this, a few of the movie scenes flash through my mind - V's crazy introductory monologue, his revolutionary speech, the kind of rebirth of Evey, the fall of the dominoes, and the final fight scene!

The movie, obviously, has the theme of anarchy vs dictatorship. Some would say that is all there is in the movie? But I disagree. Because if that's the case, people will start seeing their own government as a dictating regime, seeking absolute freedom for themselves.

But is it really this, the movie or the novel wanted to convey?

The government shown in the movie back-stabbed their own people. That's the government V is fighting against. One that was so hungry for power, that they killed their own people, to induce in them the fear!

This reminded me of Hitler and Holocaust. I don't know much about it, and this topic is what there is next on my list, with a few documentaries including Third Reich: The Rise and Fall, Banking with Hitler, and Adolf Hitler - The Greatest Story Never Told.


But there is more. There are many a elements in the movie that makes it this awesome.

One is the evolution of ideas. The lines in the very first few minutes had me engaged. We all have experienced the power of ideas, at some point. These are the very same ideas that shaped the world, for both good and bad.

I would just quote those lines from the movie!
I've witnessed first hand the power of ideas, I've seen people kill in the name of them, and die defending them... but you cannot kiss an idea, cannot touch it, or hold it... ideas do not bleed, they do not feel pain, they do not love... And it is not an idea that I miss, it is a man..
And then at the very end, these lines by V speaks of the influence of an idea on the people who believe in them!
Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy. And ideas are bulletproof.

And then the part of the movie where Evey Hammond is in prison. When V told him that she was not in any real prison, and he made all this up to remove her fear, the feelings of her when she feels the rain reminded me of Batman.

Isn't it the same theme going all around? The only way not to let our fears overpower us, is to face them.

When death was seeing her in her face, she was calm. I felt a little disturbed. She found an idea to cling to, which was more to her than her life!

And then her feelings when V set her free. That reminded V of his own feelings when he became free. To put it simply, God is in the rain.


The killings of people belonging to other religions, and homosexuals felt disgusting. The story of Valerie was moving. How come being a homosexual was a crime? These words couldn't feel more real.
I remember how "different" became dangerous.
And the way the news was being fabricated by the media is something even we can relate to. There can't be any other time where keeping our eyes and ears open could be more important.

His remark on the power of words was something to think about.
Because while the truncheon may be used in lieu of conversation, words will always retain their power. Words offer the means to meaning, and for those who will listen, the enunciation of truth.

There were many other lines in the movie that were really deep. I am just quoting here a few of them, just as a reminder to self.
[1] ...A building is a symbol, as is the act of destroying it. Symbols are given power by people. Alone, a symbol is meaningless, but with enough people, blowing up a building can change the world.
[2] Your own father said that artists use lies to tell the truth. Yes, I created a lie. But because you believed it, you found something true about yourself.
[3] Vi Veri Veniversum Vivus Vici. By the power of truth, I, while living, have conquered the universe.
[4] Our integrity sells for so little, but it is all we really have. It is the very last inch of us. But within that inch we are free.

.. Every inch of me shall perish. Every inch, but one. An Inch, it is small and it is fragile, but it is the only thing the world worth having. We must never lose it or give it away. We must never let them take it from us.

I couldn't resist myself from quoting the mentioned quotes of Shakespeare.

V: [V interrupts the three policemen about to rape Evey, whips out a dagger, and quoting the sergeant from Macbeth Act I Scene 2] "The multiplying villainies of nature do swarm upon him
[skips 4 lines from the original Shakespeare]
V: disdaining fortune/with his brandish'd steel, which smoked with bloody execution...?


V: [Quoting Polonius from Shakespeare's Hamlet Act 3, Scene 1] We are oft to blame in this, - / 'Tis too much proved - that with devotion's visage/ And pious action we do sugar o'er/ The devil himself.


V: And thus I clothe my naked villainy / With old odd ends stolen forth from holy writ/And seem a saint when most I play the devil.
[quoting Shakespeare's Richard III, Act I Scene 3]


V: [Quoting Viola from Twelfth Night Act I Scene 2] Conceal me what I am, and be my aid For such disguise as haply shall become The form of my intent.

and finally the lines that even I have to say the generations that went by, and the ones who remain in the future, the people I will never meet.
Even though I do not know you, and even though I may never meet you, laugh with you, cry with you, or kiss you. I love you. With all my heart, I love you.

Friday, October 21, 2016

A few simple graph problems, and their interestingly cute solutions!

Recently, I was solving a few graph problems from here, and I found the questions to be simple yet challenging! By this, I just mean that the questions didn't ask for any advanced knowledge from my side, and yet it was a challenge to come up with simple solutions for them.

There were many questions, for which I too came up with my answers, but they were complex. On the other hand, the given solutions were quite simple, and they had an aesthetic beauty that only an algorithmist can understand. Hence, the cuteness.

I am just providing the questions here in brief, and the underlying thought process that led to those cute solutions. For a detailed study, which you must do, go here.

  1. Design an algorithm that finds all bridges in undirected, connected graph G in O(V · E) time.

    Actually this is the third part of one question. They beautifully and thoroughly made the students think over the solution. The key idea is to think of the BFS tree of the graph.

    First, they asked to prove that all the bridges will be present in the BFS tree of the graph. Then, to examine the running time of checking whether a given edge is a bridge or not. And finally they stated the problem that I mentioned.

    What an amazing way to teach students how to solve problems!

  2. To find an efficient algorithm to find the number of paths in directed acyclic graph G from s to t.

    Topological sorting, and storing the number of paths to all the vertices, using the previous counts to build the next ones!

  3. Suppose you are given a city map with unit distance between each pair of directly connected locations. Design an O(V + E)-time algorithm that finds the number of shortest paths between the source vertex s and the target vertex t.

    Always remember, BFS finds the shortest path to all the vertices in an unweighted graph. And then again, we can store the number of shortest paths to all the vertices, using the previous counts to build the next ones.

    But remember, we are finding the number of shortest paths in an unweighted graph!

  4. Consider a connected weighted directed graph G = (V, E, w). Define the fatness of a path P to be the maximum weight of any edge in P. Give an efficient algorithm that, given such a graph and two vertices u, v ∈ V , finds the minimum possible fatness of a path from u to v in G.

    Amazing question, and what a cute solution! A good reminder to self regarding what value does d[u] store for all the vertices. A simple change in RELAX method of Dijkstra's algorithm. Seriously, this never crossed my mind before I read the solution.

  5. Given four vertices u, v, s, and t in a directed weighted graph G = (V, E) with non-negative edge weights, present an algorithm to find out if there exists a vertex vc ∈ V which is part of some shortest path from u to v and also a part of some shortest path from s to t. The algorithm should run in O(E + V log V ) time.
    This is my favourite of all. The solution just requires understanding the basic definition
    d[u,v] = d[u,vc] + d[vc,v]. And there you have it.
I found all these questions to be quite mind-stretching, and yet looking out for only the elements of understanding in me!


Sunday, October 16, 2016


I really enjoyed watching this movie Waiting last night. It has something in it which most of us ignore.

If I am asked to summarize the message of this movie in a few sentences, it would go on something like this. Anything can happen in your life at any point of time. You might not accept it, but there is a good chance that someday something very bad will happen. You will be helpless. You will curse others for they have not felt your situation. But life moves on, and so should you!

If you ever face a situation where things are not in your hands, say just like in the movie, a very near one of you has met with an accident, crying doesn't help. Ofcourse, I agree it is easier said that done! But Naseeruddin Shah coveys it concisely - "However bad the situation may be, three things should never stop - eating, sleeping and bathing."

The movie also touches upon the issue of quality of life. And the opinion varies greatly, both in the movie and in real life. I am of the opinion that no one except the victim should have the right to decide what quality of life he wants to live.

But what if the affected person himself is depressed? I guess the doctor in charge should take over the rights. But how come we decide when shouold this be done. What if the quality of life for that person has really gone downhill just like it was depicted in Guzaarish? Conflicting!

I would love to hear your opinions in the comments!


While writing all this, two people and their quotes did cross my mind. And I guess quoting those down would be better than attempting to put it down in my own words.

Stephen Hawking has this great line in the end of the movie The Theory of Everything - "There should be no boundaries to human endeavor. We are all different. However bad life may seem, there is always something you can do, and succeed at. While there's life, there is hope."

This person has always been my inspiration. You ask, why? Read the lines in the previous para again. If this person whose quality of life worsened so much, could show this level of optimism, there should and must never be any point in my life where I should be sad or depressed about something bad going on with me!

Saturday, October 15, 2016

Lakes in Berland : Why coding your solution is a good idea?

I write about my solutions to the coding competition problems only for myself. For the problems that stretched my mind a little more. To bring myself a clarity of thought of what i did in the code. To understand my mistakes. Do not read it unless you have really nothing else to do in this awesome universe!

The question : Lakes in Berland. As simple as it could it be. I guess it didn't take me more than 10 minutes to figure out how to solve it. But there awaits the demon. The one everyone talks of. The implementation.

There is a reason why great programmers ask to code your solution. Because just knowing the solution isn't enough! And that is what happened in my case.

It took me quite a good long time, almost a day to get to a working solution! And no, it wasn't anything hard to code. It just reflects my weakness in implementing a solution.


While coding the solution, I was noting down all the mistakes that I did, due to which my test cases failed. Here they are in a proper format just to make myself realize my fallacies, and why I need to think a little more before submitting my solution all over again.

MIstake #0 : It took a lot of time to implement the dfs, and the lines of code that I wrote was way more than for the accepted code in C++; always a red signal.

Mistake #2 : I made a very big mistake as my code was allowing the non-starting vertices to be on the border, had to refactor my code to find the connected components!

Wednesday, October 12, 2016

Polycarp At The Radio - Importance of maths in programming!

Many people argue among themselves whether maths is important or not, when it comes to programming. I don't indulge in these arguments, neither this post is going to do anything similar.

But recently I tried to solve a problem which made me realize the importance of mathematical intuition when it comes to programming.

I started to solve this problem on Codeforces, Polycarp At the Radio, and hit sort of a dead end for more than a day.  But something got me hooked to this question. There was nothing special about it. No difficult algorithm tags. And still I was finding it difficult to code.

But I went on to code what I thought to be a good enough code to pass all the test cases. And no, I just didn't start monkey-typing on my keyboard. Yet the end result was around 200 lines of python code, with a lot of comments and debugging statements hidden within it.

And it doesn't stop there. My code still failed on a test case I knew of, I wasn't sure if there still exist other test cases it might fail upon, and just when things seemed to make sense, I realized I had no idea in hell or heaven how to change my code to pass this particular test case.


Finally, I gave up, and read the tutorial given for the same. And I just couldn't express how beautiful the solution is. So simple, so intuitive. I can't even say it to be mathematical. But something definitely mathematically intuitive.

And the code was just 40 lines long, with complete surety that it will work for all the test cases, whatever it may be! And this is why, my boy, mathematical intuition is important in programming.

I am linking a github gist here, containing both the buggy and the correct codes, to show how complex a program can get because of the lack of simple mathematical intuition.

Just give this puzzle a try before you hop on to another post of someone else! :)