Options

Aid for learning algorithms

Disas_mainDisas_main Member Posts: 35 ■■□□□□□□□□
Hello, for a few days I'm stuck with learning algorithms. I didn't have any problem with the date strcutures I just look at the image of the data structure implement it without reading the given code and then optimize mine by reading the code. But the situation is different with algorithms I understand how they work, I read the code and when I start typing everything just disappears I took me a hole day to implement merge sort, and I can't rewrite the code again. How for sake did you learn algorithms any hints for remembering algorithms?

Comments

  • Options
    paul78paul78 Member Posts: 3,016 ■■■■■■■■■■
    To learn the basics, the only way that ever worked for me was to try to write it out in pseudocode. I use a C-style pseudocode because it's the language that I'm most familiar. And because I prefer to work with low-level systems so it suites me. But you can use whatever notation you like.

    What I found is that I only ever really learn an algorithm once I actually implement it in code and step through a debugger to see how it works.

    In reality though, I find that in the real world, I never really had to memorize algorithms. Instead, I focused on understanding the general nature of the algorithm, it's advantages, and when to apply it's use. And I do that with pseudocode.
  • Options
    NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    My suggestions would be to take a simple problem or task and reverse engineer it in your mind. For example, suppose you have an algorithm that takes a single input (string only) and returns that string in reverse order. Your pseudocode might look something like this:

    function reverse_me(string foo) {

    // reverse foo
    return foo;

    }

    The basic principle here is that you input foo and the return value of foo will be reversed. You job to understanding this algorithm is how the internals work. Do you chop up the string into individual chars, store it in an array, and then use a bubble sort to get the string reversed? Maybe you want to use the built in string.reverse function that is built into the programming language library. The point here is that you can build the algorithm one way to understand the basics, then using some research and a little testing, you can test which implementations work the fastest and more efficiently (this is a balancing game). As you start to understand how building and optimizing algorithms work, you can start to design and test more complex ones.

    If you are looking for a good book to help learn I would suggest this one:

    Introduction to Algorithms, 3rd Edition: 9780262033848: Computer Science Books @ Amazon.com

    A little pricey, but certainly worth it in my opinion! Hope this helps.
  • Options
    Disas_mainDisas_main Member Posts: 35 ■■□□□□□□□□
    Thank you guys, bacause of your answers I've found a way that works for me. I read only the pseudo code and then implement it in my mind, after that I implement the algorithm in Python and C++, I still forget the algorithm, but at least I'm able to make them work without so much pain.
  • Options
    JB3JB3 Member Posts: 21 ■□□□□□□□□□
    If you are looking for a good book to help learn I would suggest this one:

    Introduction to Algorithms, 3rd Edition: 9780262033848: Computer Science Books @ Amazon.com

    A little pricey, but certainly worth it in my opinion! Hope this helps.

    This is the book we are using in my Data Structures and Algorithms class. It is really good and I recommend it as well. I picked mine up used (but like new condition) for $40 from a seller on Amazon.
Sign In or Register to comment.