Showing posts with label algorithms. Show all posts
Showing posts with label algorithms. Show all posts

Saturday, 28 June 2014

SPOJ Fever

ACM ICPC 2014-This year problems were hard as many good teams could solve only 3-4 problems. This time IIT Indore (A new IIT) secured the first place among Indian Colleges beating big colleges like IIIT Hyd,IIT Bombay,IIT Madras,IIT Roorkee . Congratulations to all the teams after all going for ICPC World Finals is in itself a big achievement .

This week I was a little busy in answering the queries of some curious souls who just now cleared JEE and about to join the premier institutes of the country, it always feels good to guide someone who is asking for your opinion.I always advise people to opt for that stream/branch in which they have interest .

 I took a break from my Topcoder practice and started SPOJ problems . For the first time I successfully applied a top down Dynamic Programming approach in 1 question . I was waiting for this moment for past 2/3 months . It feels very good after seeing a problem solved after so many unsuccessful attempts .

Sieve of Eratosthenes - 

I learnt how to apply Sieve of Eratosthenes. This method is very fast(for numbers of the order of some millions) to find whether a  given no. is prime or not . The approach is simple, suppose we have a no. N we want to find whether this no. is prime or not we just need to look at all the primes <=Square root(N) lets say we want to know whether 431 is prime or not so we need
  Sqrt(431) ~20.7 we just need to check whether primes <20 i.e. 2,3,5,7,11,13,17,19 can divide this no. or not .
So, 431 is an odd no. so not div by 2
sum of digits is 8 so not div by 3
end digit is 1 so not div by 5
431%7!=0 , 431%11!=0,431%13!=0,431%17!=0 and 431%19!=0 . Ohh! I took a random no. and it was a prime! I need to find the probability of finding a prime no. randomly from the set of natural no. :P Just kidding :D . Recently, I found out that this probability is inversely proportional to the logarithm of the chosen number N .

So this is how Sieve works and if you know all the prime less than sqrt(N) then this method is very fast .

Thanks for reading and keep coding .


Sunday, 25 May 2014

Learning the hard way

So, now I've decided to push my coding skills to a new level. This week I was solving Div 2 250 problems on Topcoder . On an average I am doing 3-4 problems on it spending around 30-60 minutes on each of them trying to understand them and coding them.If I get stuck at something I am reading the editorials of the problem to further check my solution or to get new ways to do the same problem.This not only improves my coding skills but gives me a different approach to do the same question also.As of now I am not participating in SRMs and Codeforces contests  because I want to first sharpen my axe for a good amount of time and then cut the tree smoothly rather than cutting the tree with the blunt axe .

I am learning C++ these days.Its good to go with C++ when you have C basics with you.

Also this week I participated in Codechef's short contest and  managed to solve 2 problems . This was the first time when I could solve more than 1 problem on their contests and now I am ranked 1226 worldwide and 721 in my country in short contests.

I am certainly improving day by day . I can see that improvement as now I can think much more faster on how to solve a particular solution and I will continue to practice more and more..

Saturday, 17 May 2014

A week full of algorithmic coding

Last sunday I participated in the round 1C of Google Code Jam 2014 and secured 4128 position after solving one small input problem ,that means I am out of my first ever GCJ participation . I am quite happy as well as satisfied with my performance in the competition as I am still in the early stages of learning phase I think my performance was good .
My performance in GCJ 14 at a glance -

Qualification Round - ranked 15128(Solved 3 problems)
Round 1A - 3624(without solving a single problem :P )
Round 1B - 6209(solved 1 ques)
Round 1C - 4128(solved 1 ques)

It may not look good but after knowing the fact that this performance was given by a person who learnt his first programming language just 5 months back!! it certainly looks good isn't it ?
I look forward to improve my algorithmic skills and I will make sure that I'll improve my performance in the next GCJ . 
Today my semester result got announced and I scored an 'Ex' 10/10 points in lab section of programming course and 9/10 'A' in Theory course .Good to see those letter grades in the grade sheet. :)
I was practicing binary search and top down approach(Dynamic Programming) these days .
I was amazed to see the power of simple algorithm of binary search thanks to the Topcoder tutorials. 
Algorithmic Coding Rocks!!!