I have two different ideas to learn algorithms, but I can't find out which one is best and faster for learning:

1 — Learn a specific algorithm then try to solve the related problems .

2 — Try solving random problems and then try to learn the algorithm that can solve this problem .

And any other ideas to make the learning more efficient?

Auto comment: topic has been updated by Mhammad1 (previous revision, new revision, compare).You can solve CodeMonk contests on HackerEarth.com, it provides simple contests concerned with some topics and adds tutorials on this topic. Here you can find previous and upcoming challenges (and tutors);

I personally like the second way but I sometimes go with the first one too.

The idea of using the second way is that if something is commonly given in problems you'll quickly find out and learn it. What you will not know is the algorithms that are rare and probably complicated, which is fine for a beginner. This however works only if you solve a lot of problems so you can learn variety of algorithms. If you don't have time to solve tons of problems then perhaps the first way is better.

Having said that if you sometimes stumble upon an algorithm or structure you're not familiar with, it's good practice to learn about it and if it turns out to be useful then learn it and solve related problems :)

I do a combination of the two, though I think I do 1 more than 2. The second way is necessary, and the only way that you will become a better coder is by solving more problems. But I like to think that my toolbox for solving problems is big, and I follow the first way in order to build this toolbox. With a wider toolbox, solving problems becomes easier and applying the second method after this makes you a better problem solver.