Approach to Learning Algorithms Using a Specific Language

So, for the summer, I decided that I could start learning algorithms before starting school. I was told that the class is pretty fast paced, and that the algorithms are not something you should do lightly (I tend to do this with all the coursework during the LOL semester).

The book we are going to use is Algorithms (4th edition) . Anyway, this is my problem.

I'm almost the third way through the book, but I just realized what I was doing. For example, I read and re-read sections that I do not quite understand. Then, if I feel confident enough, I will try to reproduce the same algorithm in java from my head. But by doing this, my code looks almost exactly the same as in the book ... in java.

I can’t say that I just remember the code after the code. I understand the concepts and they help me code these algorithms, but it seems to me that I can only implement these algorithms in java. I should note that I only know java at the moment.

TL; DR: I learn algorithms as if I am learning to play the guitar - repetition after repetition. But by doing this, I feel like I'm being fixed more, that I can only implement them in java. How exactly do you recognize the algorithms if the book you use is language dependent?

Thanks in advance.

+8
java algorithm
source share
6 answers

Do not confuse yourself

You are learning Java, so write them in Java. Especially if Java is your first language. Do not confuse yourself now, as you are trying to learn two things at once: like Java programs and how programs. You are learning both a new language and a way of thinking. Do not do too much, but add another tongue to this sauce.

Diversification

Later, or if you feel confident enough that you can take another language at the same time, it would obviously be useful to study another one and try to reproduce the algorithms without looking at the book.

Play and expand

What we could recommend to you is to look for derivatives of algorithms. Known options that have been documented, and where you can simply read the description of the option, so you can try to implement it from the "base" version, without having to read a book.

For example, if your book presented you with a linked list, you should find an algorithm for a doubly linked list or a circular linked list without reading more than a description of the desired result. Or something about original concepts that you clearly misunderstood.

Try it first, read on

I would recommend that you even try to implement the algorithms described in your book before they show you . The point of view of the Sedgewick algorithm is to see the canonical implementation, which is considered the standard scheme. If you just read the section leading to implementation (which we hope will be shown first), then just sit down with a book and try to figure out how you could do this. If you cannot do this, then you are too far ahead in your book and must step back and start from scratch.

+9
source share

Speaking of algorithms, they are essentially agnostics. There really is nothing stopping you from doing Sedgewick examples in C, Python, or some other language.

If you really don't know other languages, focus on Java. Of course, this is a little repetitive, but these bits will stick to you in good shape and testing time will come, you will be happy with the information.

Now you are in an interesting position, because the kind of thinking you need to write programs is very different from ordinary thinking. Add to this the fact that you are learning a completely new language with a different syntax, punctuation, etc. Practice really makes perfect, as there are many bits and parts to remember.

Oh, if you want to practice with algorithms, try the project Euler , kata code, and other request sites. These small problems can help you become familiar with the language, as well as enjoy the required type of thinking.

+2
source share

First, congratulations on your first steps in learning the code. I would say that you are already ahead of your peers by looking ahead during the summer.

As far as you fear only to implement algorithms in Java, you have already demonstrated that this will not be a problem for you. It seems that you are passionate enough to start work at an early stage, so you should not have problems with the implementation of the solution in several languages. In addition, most C / C ++ languages ​​(Java and C # for several), such as syntax, will be similar enough so that you can easily translate your knowledge.

The best advice I can give is CODE, CODE, CODE! Don't just read that algorithms actually implement them.

+1
source share

You do not say how well you know the mathematics underlying the algorithms. This will be the key to defining your object using code.

Sedgewick books are very good. I could freely select and test other books, such as Numerical Recipes and Numerical Methods That Work. See if you can clarify a different point of view.

If you don’t feel that you are getting enough copies of Java, see if you can translate them into another language, perhaps Python or just a functional alternative. If you can do this, you will find out what you have.

0
source share

I would either try to learn another language to make sure that you really can transfer it to another language (javascript will be my vote because it is simple and useful at the front and backend) or it writes the algorithms in pseudo-code, since it is more of language agnostic. Most languages ​​will look very similar to code. The only thing you need to be very careful about is when you rely on some aspect of the language (for example, generics or iterators in java) that you cannot use in another language, and this may leave a gap in your understanding.

Another way to verify that you really understand the algorithm is to make small changes to the problem and make sure that you can configure the algorithm to work. For example, if it is a sorting algorithm, try sorting several attributes, and not one, if it is a graph algorithm, make the graph a digraph and see how everything should change.

0
source share

I learn algorithms as if I am learning to play the guitar - repetition after repetition.

Then you do not learn algorithms. You learn repetition. Two different things. Using a programming language in an algorithm book is a secondary factor. This is just a learning tool, a detail of implementation.

What you need to focus on is understanding the structure, logic, and mathematical characteristics of the algorithm (and possibly the data structure associated with it).

What you need to do.

But by doing this, I feel like I'm being fixed more, that I can only implement them in java.

But this is because you focus only on how the algorithm is encoded (in Java in this particular case). You focus on implementation details.

When you learn to drive, you do not focus on how you learn to drive a Honda Civic or Nissan Maxima. You will learn the essence of what driving is, the rules of the thumb, the necessary precautions and laws governing driving.

Same thing with learning algorithms. You don't learn “Algorithms in Java” any more than “Algorithms in Haskell”. You learn Algorithms in the first place, the vehicle (without special cases) is secondary.

You should focus on what the algorithm does, how and why. Questions like "how / why does it work?" and most importantly * “what are the performance characteristics?” these are the things you should focus on.

Every good book of algorithms (including Sedgewick) carries this message. This is what you should focus on. How do you get to such a reorientation that the function of one personal learning strategy.

How exactly do you recognize the algorithms if the book you use is language dependent?

Without focusing on the language. Focus on the structure, focus on the data structures involved, invariants, preconditions and post-conditions. Understand the asymptotic behavior described in the notation Big-O (or Big-Omicron), Little-O / Little-Omicron, and Omega.

You learn algorithms, not program in Java using coding algorithms.

If you cannot make this mental leap, it means that you do not have enough practice or abstract analysis. This is not an insult, but observation and advice. Coding, the use of a programming language, as a rule, is secondary to the mathematical analysis of calculations, the focus of computer science (of which Algorithms are part of it).

NOTE I have been in Java for over 10 years, and although I enjoy working, I strongly believe that this is a bad tool for learning programming or CS topics.

It is best to use algorithms with A) a procedural programming language at the system level, such as C or Ada, or a high-level pseudo-assembler simulator, or B) a functional language such as Lisp or Haskell.

Object oriented functions in pure / pseudo pure OO languages ​​just get in the way.

Algorithms are mathematical structures with a character that describes how (operatively) and / or what (mathematically). The former is ideal for procedural programming, later for functional programming.

0
source share

All Articles