This is one topic which was daunting to me whenever i saw it in college. I had skipped everything that there was to do with algorithm analysis and time complexity. But i feel like i have got some understanding on what it is and through this post i want to check if i really have understood it afterall.

 

Let me keep this as concise as possible. We are always looking at better ways of doing things. Increase in speed of getting something done is what we try to achieve in all our day to day activities. If we have two algorithm options , we almost always tend to prefer the one which gets shit done with less number of operations . So time complexity, asymptotic notation call it whatever you may - they are metrics the only ones we can trust on to see how an algorithm performs with the size of input.

 

For example let us take the case of  linear search and binary search algorithms. Linear search algorithm has a time complexity of O(n) , which means if there are 10 elements in an array it would take 10 comparisons in the worst case to find the element. If there are 1000 elements it will take 1000 elements and so on. Now let us take the case of binary search, binary search has a time complexity of O(log n) which means that if there are 1000 elements it will only take log 1000 comparisons to find the element in worst case.

So by looking at the time complexity we come to the conclusion that a binary search is way better than linear search.

The link below from stackoverflow explains the concepts in a greater detail.

http://stackoverflow.com/a/487278

 

Posted in useful | Comments(0)»

Problem Statement

 

Find the sum of all five-digit positive integers that

  1. are square numbers
  2. have all digits square
  3. and are NOT ordered numbers.

Clarifications:

  • An ordered number is one whose digits are in an increasing sequence. For example, is an ordered number but is not; is an ordered number but is not.
  • A square is one that can be obtained by multiplying a number by itself (in particular, is a square).

This problem was inspired by "Freaky Square Number!" by Mark Mottian, which was inspired by Problem #3 of the 2014 South African Programming Olympiad.

 

 

Here is my solution to the problem 

 

https://gist.github.com/kskrishnasangeeth/d9d383abfa5063fbb062

 

I have particularly made use of the power of Collections remove all feature for the solution. The solution might not be the most elegant way of looking at it, but i have to use somewhat brute force to come to it. I was more focussed on using the power of programming to reach the solution rather than simplifying and doing some math.

 

This is how my basic algo looks like

Step 1: Store in ArrayList A square numbers starting from 10000 to 99999

Step 2: Store in ArrayList B ordered numbers from 10000 to 99999

Step 3: Store in ArrayList C non-squared digit numbers from 10000 to 99999

Step 4: Sum elements in (A-B)-C

 

 

 

 

 

 

Posted in useful | Comments(0)»

 

Let me just say this at the very beginning , Arundhati Roy is a gem of a writer whose first book 'God of Small Things' is a favorite of mine. I could go on and on speaking volumes about how good a first book that is and why even if she never writes another novel, her book will continue to gain adoration and respect for time to come. But that is not what this post is about, I don't have the literary accumen to challenge Ms Roy but i feel like she is going through a period of decadence to have made such a statement on Gandhi.

 

Arundhati Roy while speaking at a function in memory of the great social reformer Ayyankali had given the audience a little more than what they expected, not just deviating from the topic, she surprised the heck out of everyone by suggesting that Gandhi's name should be removed from all institutions starting from universities. She accuses Gandhi of being a casteist by citing an article which he had wrote titled 'My Ideal Bhangi'. The article which appeared in the late 30's in Harijan had controversial quotes like the one given below 

 

“The ideal Bhangi of my conception would be a Brahmin par excellence, possibly even excel him. What qualities should such an honoured servant of society exemplify in his person? In my opinion an ideal Bhangi should have a thorough knowledge of the principles of sanitation. He should know how a right kind of latrine is constructed and the correct way of cleaning it. He should know how to overcome and destroy the odour of excreta and the various disinfectants to render them innocuous. He should likewise know the process of converting night-soil and urine into manure.

 

Even the die hard Gandhian would have a difficult time to turn the above mentioned passage to appear anything but silly and atrocious. But why would anyone want to project Gandhi as a perfect human to have ascended from the heavens when the idea of perfection itself is rubbish. He was a man of flesh and blood, he had few personality quirks just like all of us , he made few mistakes here and there. Still a major portion of world populace considers him as one of the finest to have represented our humankind and i am siding with the major portion here not because i want to follow the bandwagon but because of the simple fact that a man's life is measured by his contribution to bringing net positiveness in this world. And for all the quotes and proofs that anyone can come up with showing a darker side of Gandhi including a) how he was not a good father to his children b) on favoring Nehru over others c) Calling the south African blacks 'Kafirs' ; there exist a brighter side of Gandhi which shines over darkness, I feel obliged to quote Einstein here not to prove anyone a point but out of my respect for the Mahatma

"Generations to come, it may well be, will scarce believe that such a man as this one ever in flesh and blood walked upon this Earth.”

I am not planning on writing about the virtuos life which Gandhi lived, a good history book would serve the purpose . I want to focus my post on why people like Arundhati Roy find it fashionable to defame people who ought to be respected for generations to come. She represent a pseudo intellectual Left liberal group in India that sees only the wrong things happening in our country. They have been a group so good at criticising everything and anything in this country that now they are bored and want to  move onto something bigger like shackling the core belief system of peoople and what better way to achieve this than attack the most respected figure in India. Heck, i don't remember a positive thing she has said about India for a long time and i do follow her somewhat. Look at how all the global media has responded to the news , In their eyes she is a person of Indian orgin , a booker prize winning author who has travelled the lenght and breadth of the nation calling our most respected figure a casteist. A poor picture is painted and western media has found one more point to throw poor light on a man whom they have been trying to bring down from his high pedestal for a long time unsuccesfully.

 

For more than half a century we took pride in calling Gandhi the father of our nation, he has been our passport to gain respect and support through out the world all these years for our non aligned movement and attaintment of freedom through non violence has left most people in awe. But sadly there has always been   groups that has tried to undermine our growth story and tarnish our image, and people like Arundhati Roy are simply playing it to the hands of such groups.

 

Quoting the famous Macaulay speech again to drive home

'In one point I fully agree with the gentlemen to whose general views I am opposed. I feel with them, that it is impossible for us, with our limited means, to attempt to educate the body of the people. We must at present do our best to form a class who may be interpreters between us and the millions whom we govern; a class of persons, Indian in blood and colour, but English in taste, in opinions, in morals, and in intellect' 

 

Maybe Maccaulay had succeeded after all.

 

Ms Roy  baffles me quite a lot from her Kashmir seperation comments to her recent remark on Gandhi, i can understand when someone is criticising a system to see it get changed but in her remarks i see a fervent hatred and i can't quite see where it stems from. It is as if she wants to laugh at all our conventional belief systems.

 

Given a fair amount of time , i can come up with an article  that Hitler was a good man who turned to  the side of darkness since fate was tough on him. I could start with his wonderful paintings and come to an argument that anyone who could be so expressive in painting couldn't possibly carry all that malice in heart. I could explain his troubled upbringing and how he got fewer opportunities with arguments like 'If that art school in Vienna had accepted  him he wouldn't have become the dictator' . To put some strenght to article I could add some 'Freud' or probably a passage from his autobiography. In the end i would have enough material evidence to say that Hitler was a product of his surroundings and deep inside he was a good human being. With the right amount of research and some shiny words thrown here and there i could make few people believe in my story. Someone who is good at this sort of thing can convince a lot of people, someone with a Man booker prize to his/her credit can make a lot of people question their initial thoughts about hitler and make them do google searches like 'Hitler Good Man'. 

 

But no matter how many awards such a person had won, he/she would have nothing to say to the group of people who lived in Concentration camps seeing the 'Arbeit macht frei'  boards hoping for their life to end through work. Because when such a fictious award winning writer comes face to face with the survivors , there will be no more lies but the truth : Hitler was a bad man who brought nothing but misery to world. All the counter arguments will fail because truth is plane and simple.

 

Gandhi brought hope and peace to this world, taught us to lead a life in harmony without killing each other  (To know how big a deal those words are see what is happening in West Asia). He is a man with an iconic stature, anyone who is trying to bring it down is only trying  their charm at what advertisers call 'shock value' . You say that the Most important , most revered figure in Indian history is nothing but a casteist ; It creates a sudden shock wave in people on hearing often followed by strong negative emotions. I can't fathom why someone of Ms Roy's pedigree would resort to such a cheap form of publicity. 

 

To prove my point further let me take the case of an article which Ms Roy herself wrote for outlook magazine in 2010 . The article titled 'Walking with comrades' (Link : http://www.outlookindia.com/article/Walking-With-The-Comrades/264738 ) , is given the subtitle as 'Gandhians with Guns' and the article basically charms us by giving a shock value that the people whom we consider to be ferocious killers are actually very simple people fighting for a cause. See how she is ready to call them Gandhians in this instance , the word Gandhi is not yet derogatory for Ms Roy instead it is a symbol of respect. Fast forward 4 years and suddenly it seems like Gandhi is her worst nemesis , so much so that she wants his name removed from public institutions.

 

I can think of the act by Arundhati Roy only as a sacrilege  to our  belief systems , a form of Infinite Injustice that has been put on the man who went through a tough life so that people like Suzanna Arundhati Roy have right to free speech.