Code your way through Competitive programming!

If you’re wondering how to be an ace programmer, then one of the best ways to do so is through competitive programming. Topcoder, Hackerearth, SPOJ, etc all must ring a bell, these are sites that provide high-quality problems to you that are a little difficult to crack. Competitive programming needs a slightly different approach than regular programming.

How is competitive programming different from normal programming?

I got this excerpt from a popular Quora answer which could answer it best:

Answer for: How is competitive programming different from normal programming?

This basically tells us that in developmental programming, we need to write an efficient code. However, competitive programming requires a code which “just works” with the given conditions.

So, what exactly do you need to “kill the lion” in 2 minutes?

  • You need to know the basics of a language, pick any, C++ or Java, whichever you’re comfortable with.
  • Pick an online judge. Some popular ones are: topcoderSPOJcodechef and hackerearth.
  • Start with simple problems such as Div 2, 250
  • Practice these problems thoroughly such that you earn around 240 points a day.

Sounds easy? Well, for those of you who have tried a hand at it must know that TERMS like TLE(Time limit exceed), MLE(memory level exceed) and WA(Wrong answer)  are so good at giving NIGHTMARES!

How to be a Ninja Competitive programmer?

To gain crazy ninja skills at competitive programming, one needs to have a grasp of a few specific topics.

Topics mostly covered in contests are:

  1. Graph algorithms: Breadth first search (BFS), Depth first search(DFS), Strongly connected components (SCC), Dijkstra, Floyd-Warshall, Minimum spanning tree(MST), and Topological sort.
  2. Dynamic programming: Standard dynamic programming problems such as Rod Cutting, Knapsack, Matrix chain multiplication, etc
  3. Number theory: Modular arithmetic, Fermat’s theorem, Chinese remainder theorem(CRT), Euclidean method for GCD, Logarithmic Exponentiation, Sieve of Eratosthenes, and Euler’s totient function
  4. Greedy: Standard problems such as Activity selection
  5. Search techniques: Binary search, Ternary search, and Meet in the middle
  6. Data structures (Advanced): Trie, Segment trees, Fenwick tree or Binary indexed tree(BIT)
  7. Bitmasking
  8. Game theory: Basic principles of Nim game, Grundy numbers, and Sprague-Grundy theorem

Our newest online course Eminence indulges in all of these so-called tricky topics just so that can ace that programming contest in just three months.  Eminence will be taken up by Ankush Singla who has a Bachelor’s degree in CS from IIT Delhi and Masters in Computer Science from Stanford University; and Parikh Jain, the “ninja” of competitive coding who holds a degree in CS from Delhi Technological University (DTU). Register now to book yourself a seat in a course that will brush up your competitive skills to a whole new level. 

 Eminence

Why Coding should be taken as a skill rather than a subject?

skill_blog

A night before the data structures exam, I’m biting my nails and cursing why did I have to choose engineering, planning a strategy on what topics to leave and what to study, just enough so that I pass this semester without a back. I’m sure I’m not the only one who does this. All-nighters are the only way we know how to study in college, cramming the subject just the night before the exam.

Most people literally cram entire codes to topics a night before the exam. Guys, you are legends! But the fact is in the long run, this won’t help you. The more you cram, the less you’ll remember what it was about. Also, in the next semester, when a bigger version of the subject appears, you’ll start again with the same old cycle of cursing the subject, your decision of taking the course, the education system and so on.

Programming, instead of rote learning it as a theoretical subject, should instead be approached more practically. It should be understood and the codes should be practised instead of cramming. The concept of syntax, dealing with a problem through a particular method, and the “logic” should be understood. If you’ve done this bit, I bet you don’t even need to open the book before the exam(but please do).

Before I enrolled in the course at Ninjas, I didn’t even know that there was an actual code for Hashing ( I possibly must have left the entire chapter then :p) possibly because I thought it did not carry enough weightage for the exam. But I was so wrong.

Coding Ninjas not only teaches you a language, they teach you how to study. They start with absolute basics so that even newbies who don’t  know “hello world” can relate to the subject. The classes are loaded with brain teasers to kick start your brains, short teaching sessions and more questions to practice so that you focus on problem-solving instead of cramming. They don’t focus on the language or syntax but most importantly on how to approach the problem so that you can do the same for any other language. All of this, not only fascinates you but makes you fall in love with the world of programming.

Subjects which used to be complicated and scared you till death will now look like a piece of cake. Not only this, imagine actually creating something from scratch. Now imagine, a lot of people actually using “that” something which you made. Sounds like magic? Well, it is! This is what programming does for you. Your favourite app or the website that you love to browse are all things essentially based on programming.

To quote Ankush sir, the most empowering moment of his career was when he and his team launched the Facebook timeline and more than a 100 million people used it on the very day it was launched!

Get inspired. Start programming today to build something amazing for tomorrow!

PS: The weightage of hashing? Well, it’s supposedly one of the most frequent questions asked by Amazon. Don’t make the same mistake. :3

How to master a language inside out?

If you’re a newbie coder and slightly struggling with programming, don’t fret too much! Coding can be slightly taxing at first, especially when you are new to it. But once you make sure that you give it enough time and work, you’ll love it!

So, let’s face it, you want to learn a language, and there are so many ways you can do that, but the question is how can you really master a language? “Master” is a heavy word, but today all those bigwigs are actually looking for expertise coders. Besides, programming can be really stressful if you don’t approach it with a right mindset and attitude.

So, here are 7 ways to master a language inside out:-

1. DON’T DO IT IN ONE NIGHT

The idea of learning a skill overnight is exhilarating, yes! and being so used to those “all nighters” for college examinations can make us think that that’s the only way to study, but NO, trying to cram programming overnight can be a big mistake.

One needs to take it one session at a time, giving every session ample amount of time and using it more practically than mugging up the theory.

2. ENROLL IN A COURSE

Of course! What’s better than enrolling yourself in a course where you have amazing mentors to guide you, newbies like yourself to get along with, and TA’s to assist you through every step. An environment of healthy competition and learning in a group will not only keep you highly motivated, but you’ll also learn at your own pace.

Register for our courses  here!

For all those who are too lazy to get out from their houses(it’s the heat, we don’t blame you!) or people who live too far from our center, we have this awesome option for you, ONLINE COURSES! with amazing features like adaptive learning, individual TA support, and lots more! (A little bit of promotion never killed anyone!)

3. PRACTICE! PRACTICE! PRACTICE!

Well, who doesn’t get a hard time from the semicolon and the brackets?! If you don’t have any prior coding experience, the number of syntax rules in any coding language can make your head go for a spin. The best approach to this is practice, one needs to practice a lot of questions and over a period of time, those silly syntax rules will come naturally to you.

One needs to take practice seriously, solving a lot of questions will definitely build your expertise in the field and your approach to solving questions will develop, turning you into a Code Genin.

4. IF YOU CAN’T EXPLAIN IT, YOU SIMPLY DON’T UNDERSTAND WELL ENOUGH

A very interesting approach to learning anything is the Feynman approach, based on the great physicist Richard Feynman who believed that the best way to grasp something is by breaking it into simpler concepts and teaching it to someone.

Explaining things to someone else will help you analyse your weak areas and will definitely solidify the concepts in your mind. It will help diagnose the weaker niches and compel you to learn things better from a newer angle.

5. JOIN COMPETITIVE PROGRAMMING

One sure wants that edge when they’re learning the language, don’t they?  To get that extra panache in your coding realms, one must start with competitive programming. Competitive programming is a mind sport taking place in particular forum involving participants to program according to provided specifications.

Competitive programming will allow you to code under tight specifications. This will strain you brain to think under constraints, increasing your skills exponentially! Also, coding in an environment of healthy competition will keep you glued to it.

Join the world of competitive programming at CodeZen, Stand out in the leaderboard and win amazing cash prizes!

6. PLAY WITH PROJECTS

Once you’re comfortable with the language, syntax and the concept, it’s time to put those skills in to use! For absolute newbies, think of  a simple game like Tic-Tac-Toe, Othello, to head start with your skills. Building even a small project will not only build your confidence but you’ll know exactly how to apply your newly acquired knowledge actively.

Be creative! Code something that interests you or what you’d actually want to use. Projects will help you retain a lot better and will interest you at a very personal level.

7. DON’T PANIC!

Relax! It’s not you, it’s programming.

Programming can be a little intimidating and it’s okay to struggle with it. The important thing is to keep yourself on track and keep trying. Ask help when you need it, try different resources and keep recalling previous concepts. Give it a little time, and it will surely come your way.

Embrace your bugs and errors. Learn how to debug and avoid them in future. Practicing can help you build confidence, and that will keep you away from stress.

Recursion (The Good, the Bad and the not so Ugly)

Recursion is a topic most beginner programmers fear and when you get the hang of it, it works like magic (Congrats! Not a noob anymore). When someone introduces recursion, they say it’s basically a function which calls back itself, and your brain goes like WHAAAAAT??

So here’s this GIF which not only gives you a complete mindfuck but also a visual description of what recursion is. Too scary huh? Well, not really. Once, you get an idea of how recursion works and  which base case to work with, it runs smooth as ice. Sometimes, you won’t even be able to fathom how your code worked when it did.
Well, the mantra for recursion is ” Let recursion do the work for you”.

THE GOOD

1. For all those people who want to make their code look pretty as a picture, recursion is the best way to do that. Recursion makes a code more compact, readable and so very elegant.
2. If you can master recursion, it can turn out to be your best friend. Solutions using recursion are easier to strike and code. It also avoids redundancy of code, and your codes are easier to read and maintain.
stackbuddies

3. Three magic words: tail call optimization: Some functional languages implement this wizardry. So basically, what happens is, if a function’s return expression is a result of a function call, the stack frame is reused instead of pushing a new stack frame in the call stack. Sadly, only a few imperative languages have this wizardry.

 

The secret magic of tail call

THE BAD

A lot of programmers avoid using recursion and believe that it is less efficient than it’s iterative counterparts.

 1. Recursion can lead to the perils of stack overflow. To understand better, let’s look at the steps for functions call:-
  •  space is carved out on the stack for function arguments and variables.
  •  arguments are copied into this new space
  • control jumps to the function
  • function code runs
  • function results are copied into the new value
  • stack rewounds to its previous position
  • control jumps back to the caller
Mostly, all of these steps consume more time than their iterative counterparts. Therefore, recursive methods are relatively less efficient in those cases.
recursionagain
2. More importantly, when most programs start, they allocate a single chunk of memory to the stack, if that memory is used, the entire program crashes due to stack overflow.
3. Each function call eats up a lot of space. That amount of space isn’t recovered until the function returns. Iterative methods do not suffer from such problems.
r_219071_tbWYT