Friday, November 11, 2011
travel - how it is for me
I felt an urge to write this post while travelling from pune to mysore, via bangalore, by train. People suggested me to make the trip by bus, that would have saved me some 10 hours. I agree, but the time I "wasted" is far from waste for me. Travelling by train gives me long hours isolated from the known world, to ponder over the past, present and future, to look far into the darkness from the door of the train, to find the melancholy in the mechanical sound of the wheels on tracks, to feel the cool breeze across my body, laden with the smell of the unknown surroundings, and all these have a rejuvenating effect upon my mind and body. Often trains halts at small stations, or crossings, and wait for clear signals, all the better for me, I come down from the train, and minutely observe all around me. A squirrel nibbling at a crumpled packet of fast food thrown away from some train, a rural child gazing with wide eyes, an weak old man ploughing with an even weaker pair of bullocks, people fetching water, abundantly from wells or canals somewhere, and scarcely from mud holes somewhere else, a house of cranes in a tree half submerged in a water, orchard of long trees standing in rows, and suddenly falling into line as my sight moves from the moving train, there is no short of watching in and out. There are more things missed out in perceiving something than what is captured in our mind. I try to gather a minute percent more from that what is missed in usual, and the pleasure brought so accounts for the wasted time, for me.
Sunday, October 23, 2011
There is a simpler solution to any problem than the simplest ever found
This is about a programming problem that kept me bugging for few days. In a popular site hosting coding challenges, I faced this problem where I was to handle connections between nodes, and decide whether a specific pair of nodes are connected or not.
The first approach I tried using 2D arrays - a pretty easy one, but it grossly failed when number of nodes crossed some 20000. I laughed at myself, why in the first place I have thought of allocating some 20000 x 20000 bytes in memory! It would neatly bring a heap space error in no time.
I got another trump - hashing. Using HashMap and HashSets (I am a java person, by the way) to represent a graph structure. And a crisp search logic (over BFS or DFS) - that's it! My code was ready in no time.
And it failed in no time!
Recursion in the search logic soon went out of boundary bringing up a Stack Overflow.
I scratched my head over the problem, changing this and that to alter the flow, but I couldn't make it run for more than some 30000 nodes. Next I was thinking of Threading in recursion, but anyhow left it there to think fresh the day after.
Ideas come to me at night. It strikes. The next day I used a 1D array, positions denoting the nodes and values denoting a cluster that node belongs to. In absence of hashing, iterations were a bit more time consuming, still the code scaled well. Searches were fast, and it handled some 600000 nodes in 12.6 minutes.
I couldn't submit the solution, though, because my code was developed on linux simulated on a windows machine, and it was failing either on build or compilation on the server where I was to upload the solution.
I always believe that there is a simpler solution to any problem than the simplest ever found. There has to be. Adding recursion to this view, there is no end of finding a better solution, only you need to have the patience and dedication to find it.
Note 1: I will decide on a better title of this post later on.
Note 2: Does the view work in real life? I am currently thinking of instances.
The first approach I tried using 2D arrays - a pretty easy one, but it grossly failed when number of nodes crossed some 20000. I laughed at myself, why in the first place I have thought of allocating some 20000 x 20000 bytes in memory! It would neatly bring a heap space error in no time.
I got another trump - hashing. Using HashMap and HashSets (I am a java person, by the way) to represent a graph structure. And a crisp search logic (over BFS or DFS) - that's it! My code was ready in no time.
And it failed in no time!
Recursion in the search logic soon went out of boundary bringing up a Stack Overflow.
I scratched my head over the problem, changing this and that to alter the flow, but I couldn't make it run for more than some 30000 nodes. Next I was thinking of Threading in recursion, but anyhow left it there to think fresh the day after.
Ideas come to me at night. It strikes. The next day I used a 1D array, positions denoting the nodes and values denoting a cluster that node belongs to. In absence of hashing, iterations were a bit more time consuming, still the code scaled well. Searches were fast, and it handled some 600000 nodes in 12.6 minutes.
I couldn't submit the solution, though, because my code was developed on linux simulated on a windows machine, and it was failing either on build or compilation on the server where I was to upload the solution.
I always believe that there is a simpler solution to any problem than the simplest ever found. There has to be. Adding recursion to this view, there is no end of finding a better solution, only you need to have the patience and dedication to find it.
Note 1: I will decide on a better title of this post later on.
Note 2: Does the view work in real life? I am currently thinking of instances.
Why am I in office every weekend?
I work in an IT farm in India, away from my hometown, and I am connected to my friends and relatives mostly over phone calls. When they call me up on weekends, and get to know that I am in office, the same expression follows - 'hey man, your job sucks ... office in weekends !'
Why? Can't a software developer working in an IT farm love his work? Agree, that is probably not the case with most of the people out there, but still I don't understand why it is tough to believe one is satisfied with his work in this field.
I love reading books in the night. I love to travel, but not with the sun blazing overhead. Work keeps me better than a movie, sometimes, in these dry noons. The calmness and solitude at office, and a soothing tone in my player, makes me think better and work better. And by work I mean the work I love to do, not those assigned to me by my job.
I am writing this post too on a Sunday noon, from my office. Few years down the line, who knows, looking back on it, I might feel the same about myself - 'you were crazy man - making it to office on weekends!'. But not today.
Why? Can't a software developer working in an IT farm love his work? Agree, that is probably not the case with most of the people out there, but still I don't understand why it is tough to believe one is satisfied with his work in this field.
I love reading books in the night. I love to travel, but not with the sun blazing overhead. Work keeps me better than a movie, sometimes, in these dry noons. The calmness and solitude at office, and a soothing tone in my player, makes me think better and work better. And by work I mean the work I love to do, not those assigned to me by my job.
I am writing this post too on a Sunday noon, from my office. Few years down the line, who knows, looking back on it, I might feel the same about myself - 'you were crazy man - making it to office on weekends!'. But not today.
Subscribe to:
Posts (Atom)