Saturday, 26 November 2011

WHY ARRAY INDEX STARTS FROM ZERO

Honestly speaking, the doubt is not mine. I rarely think about C language so much that I get such genuine doubts. Its a friend's doubt. The list of answers I got goes here.

In programming languages like C the array name is essentially a pointer, a reference to a memory location, so the expression a[n] refers to a memory location away from n elements in the array. The first element in the array is exactly contained in the memory location that the array refers (0 elements away) so it should be denoted as a[0].

Another mathematical solution I found out really took me nowhere. So instead of typing my interpretation, I'm copy-pasting it here, so if anyone understood what it means, enlighten me.


"Dijkstra explains why we should index from 0. This is a problem on how to denote a subsequence of natural numbers, say for example 1,2,3,...,10. We have four solutions available:
a. 0<i<11 
b. 1
<=i<11c. 0<i<=10d. 1<=i<=10Dijkstra argues that the proper notation should be able to denote naturally the two following cases:
1. The subsequence includes the smallest natural number, 0
2. The subsequence is empty


Requirement 1. leaves out a. and c. since they would have the form -1<i which uses a number not lying in the natural number set (Dijkstra says this is ugly). So we are left withb. and d. Now requirement 2. leaves out d. since for a set including 0 that is shrunk to the empty one, d. takes the form 0<=i<=-1, which is a little...well, messed up! Subtracting the ranges in b. we also get the sequence length, which is another plus. Hence we are left with b. which is by far the most widely used notation in programming now."




There's  another explanation, by convention. It's easier to count the numbers from zero it says. Even the eight bits in a computer start from zero.

There are many other explanations and may be all of them are correct, but only these three interested me.
The first one seems most correct. the second one is correct may be because a mathematician explained it. :-) Well, so that's why the array index starts with zero, if you can find only one reason. ;-)

Sunday, 13 November 2011

R2020, A REVOLUTION IN CB'S WRITING!

Well, first I can say about this book is that I was surprised! Honestly, the standard of CB's writing is really changed, its very obvious. In all his previous books the smell of an IIT or at least an engineering college wouldn't leave his pages. But now, I really look up to him as a real story writer.

Enough of chatting about his writing. Let's jump into the book.

Well, as many of you may have read in many reviews this book is about two boys and a girl, who pursue their passions in Varanasi. Three of them are classmates from their childhood and all three take up IIT coaching to satisfy their parents even though none of them really desire it. Aarti Pradhan, the girl, wants to be an air hostess, Raghav Kashyap, her would- be husband wants to do journalism to change the world, and Gopal Mishra, the "educationist" simply wants to earn money.

The story revolves around how the Gopal opens an engineering college and, Raghav takes up journalism and tries to change the world and how Aarti, in the middle of her passion to become an air hostess struggles between the two boys who love her. The climax comes when Aarti, who had previously loved Raghav, is now cheating on him because he slowly drifted away from her because of his passion to start the revolution which he expects by 2020 by the youth of India to stop corruption. In the end, Gopal suddenly morphasizes into a good man and convinces Aarti that he's a terrible person to make her go back to Raghav again.

Many changes were noticed in this book as compared to the previous ones. There is a good portrayal of India's dark side and the dirtiness of the holy river Ganga, and how the politicians are making it dirty. The story also casts a good image of the real problems in India, the land problems, parents with non- IIT-ian children, corrupt MLAs, which is actually the best part. The whole corrupt system is well shown. As always, CB's ironical style of writing, with a shade of disapproval is there. Like all his other books, I half liked and half disliked it ;-).

The part I disliked was the unrealistic part. In the climax, Gopal goes to Kashyap to tell him that his girlfriend is no longer his girlfriend, and to remind him of his low status when compared to his status. At  Raghav's office (well, not exactly an office, you'll  know as you read the book..) he sees a small boy who's the son of a poor farmer who had travelled across a hundred miles to see Raghav. The boy,  Keshav, reminds Gopal of his childhood when he was pure and good. Another boy, Ankit, tells Gopal that Raghav is a very good person. These things miraculously work on Gopal's mind which was polluted for over six years, and suddenly, as suddenly as that, Gopal turns good. He sacrifices his girlfriend and his ego for the sake of a "revolution". How much bravery and strength of mind does a person need to sacrifice his ego and everything that he likes, for the sake of a revolution he never believed in, for the sake of a person he dislikes to the rock bottom, or, to take an idealistic side, for the sake of himself? If Gopal were really that brave, why would he give in to corruption in the first place?

I found this really unrealistic. I actually felt that he was writing for movies, because recently, all his movies are   being made into books. The unrealistic part was totally cinematic. Sorry CB but that's what I felt.

Over all, like all his other books, it's a fun read, may be a better read than the previous ones. So read on! :-)

                                                                             - Sharada Kuchibhotla.

Wednesday, 2 November 2011

weirdo

You come across so many kinds of people in college, some of them make you wonder at what kind of material god made them with. i came across one such person in my college. for privacy reasons her name is not disclosed. well, i gave her my phone number just that day and took her number. after going home i gave her a message and saved her number. so naturally i would expect her to contact me with that number only. ok fine, she did not reply to her message, which is not a very terrible thing because she rarely replies to msgs( or she told me so). at night 10:30, when all in my house were sleeping, she called. not with her number. with a different number. ok, my mother answered her call and told her im sleeping. she called again and asked my mother to wake me up. my mother is already irritated. she told she wouldnt wake me up. and she called again. and again. adn like that how many times do u think? around 7 times. my mother was close to shouting at her when she stopped calling.

the next day i asked her what her problem is. if you know telugu then you can catch the real funniness and gist of her speaking. for that reason im writing this in telugu. here her answer goes.."nenu..... na english text kanabadaledu.... chala tension vachesindi... nee bag lo emaina kalasipoindemo ani call chesa... me mummy ne baga visiginchesi nattuna... sorry cheppanani cheppeee.... lechaka ma daddy chesina calls anni chusi tittaru telusa.. emiti anni chesesav ani... phone rendu sarle cheyalanta... adi kuda mari urgent aitene... two  times kante ekkuva cheykodadanta... danini phone sense antaranta..."

god... i didnt know whether to laugh or scold her after listening to this. she called like... continuously seven times in a row in the middle of the night when everyone is sleeping and now she is telling something about phone sense. for me, it is common sense. that also she has to learn like giving it a name and getting it by heart or what?
so this is about the weird girl. i hope i offended no one.