My path to algorithm Learning

Source: Internet
Author: User
About

Strictly speaking, the question of this article should be my path to learning data structures and algorithms, however, this writing method is too difficult-Besides, algorithms in CS usually refer to data structures and algorithms (for example, an introduction to algorithms actually refers to data structures and algorithms ), so I think the question of this article is reasonable.

What did this article talk about?

  • I have learned data structures and algorithms over the years.
  • Some good algorithm books and tutorials.
  • The importance of algorithms.
Beginner

The first time I got into touch with the data structure is the data structure course for the next semester of my sophomore year. However, this course didn't get me started-I was busy selling all kinds of MP3 and headphones, and I didn't care about these courses at all-I had to take a key exam anyway, as a result, the most important undergraduate course in computer science was neglected by me.

I had to look for a job when I was in my junior year. The second year's tossing proved that I don't have any business talents. I still have to rely on code to mix food in the future, at that time, I was horrified to find that I had almost no idea about the editing process. So I developed a book development plan similar to the five-year plan of the founding of the People's Republic of China, this includes books on C language basics, data structures, and computer networks.

The first step of the Reading Plan is to select books. I once asked the "senior" and "Great God" who I thought were very good at that time about which algorithm books should be read, and the "senior" recommended the introduction to algorithms, there are also a few "Great gods" who recommend the art of computer programming (I am wondering if they have turned over these books). After reading these two books, I find that I really cannot understand them, fortunately, I accidentally discovered the magic website Douban, which contains many quality book reviews, so I bought all the computer books with high comments and seemingly not so scary-It turns out that Douban is much more reliable than these "Seniors" or "Great gods.

Data Structure and algorithm analysis-C language description

 

Data Structure and algorithm analysis-the C language description is the first book I learned about the data structure: At that time, there were a lot of places that I could not understand, so I made a mark to read it repeatedly; the Code could not understand it, as a result, I copied it to the book and studied it repeatedly. When some algorithms fail to figure it out, I drew all its intermediate states and deducted them repeatedly. It turns out that although this learning method looks silly and inefficient, it did a good job for me who was so stupid at the time-silly people use silly methods, in addition, most of the questions in this book are classic interview questions, so that I will see the beauty of programming in the future, the first reaction is that the question of this product is not all copied from others.

I still remember that this book, in order to illustrate how important an algorithm is, takes the largest subsequence and as an example at the beginning to take the complexity from O (N3) to O (n2) then I went to O (nlgn) and finally to O (N). At that time, my heart was really admired = Why Nima was so cool,

In addition, I also typed all the data structures in this book before the graph algorithm. Later I went to my internship and put it on my resume, now, I think it's really silly.

With the knowledge I learned from this book growth plan, I finally found an internship.

Getting started

I didn't use any algorithms in my internship (now it seems that I am constantly building existing APIs and writing a bunch of code that I don't know right or wrong ), after discovering that people around me have been working for a few years but are still doing the same thing with me, I am getting more and more uneasy. Although I had no plans for myself at the time, I knew this was not what I wanted to do.

Microsoft DreamWorks

 

Microsoft's DreamWorks became the last straw to overwhelm camels at this time. This book's description of Microsoft's Asian Research Institute gave me the determination to "look for a job for a company like this, however, I am pessimistic and find that neither my current abilities nor my diploma can meet the requirements of the Microsoft Research Institute. In conflict, I have completely overturned my idea of "working after graduation, quit your internship and prepare for the postgraduate entrance exam.

I do not need to repeat the details of my postgraduate entrance exam, but I still clearly remember that I was surprised and excited to find that the opposite of Beihang dormitory is the Microsoft Sigma building, the feeling of taking another step away from the ideal is almost amazing.

Algorithm Design and Analysis

My postgraduate career is definitely a negative model-skipping courses, internships, writing water papers, and doing water research, however, I was quite self-satisfied-I carefully listened to Professor Han's algorithm design and analysis courses from start to end.

HAN Jun impressed me the most in two ways: When I went out during the class break, I smoked with a few students, and explained the sharp and unambiguous algorithm.

 

Although Han has never mentioned it on his own initiative, I am sure that the foundation of algorithm design and analysis is his de-facto textbook, because his course structure is almost the same as that of the book.

If the data structure and algorithm analysis-C language description is my data structure enlightenment, then Han Jun's curriculum and algorithm design and analysis foundation is my algorithm enlightenment, combined with courses and books, I understand and master simple but powerful algorithm tools such as complexity analysis, Governance Division, governance reduction, governance change, dynamic planning, and backtracking.

Algorithm Introduction

 

The introduction to algorithms is another algorithm book that I accidentally read at this moment. unlike an ordinary algorithm book, this book starts from a creative perspective-if we say what algorithms are introduced, the introduction to algorithms is about how to create algorithms. Combining the previous algorithm design and analysis basics, this book expands the number of algorithm problems that I can solve by an order of magnitude.

Then, by coincidence, I entered the Microsoft Asian Emy of engineering internship and took a step closer to my ideal.

Consolidate

My internship at the Microsoft Engineering Institute is a very, very important turning point in my postgraduate stage:

  1. I made a small project in the past.
  2. During this period, Baidu's internship interview was frustrated and he had read a lot of programming books.
  3. Microsoft's internship has become one of the few highlights on my resume (I have no score, I have no paper, and I have no ACM ).

Here we will not talk about 1 and 3 (not with the topic of this Article), but I will focus on 2.

Since there were not many projects in the group at that time, the small piece I was responsible for was done in advance, and mentor threw me a Kinect and a Windows Phone for me to study and study, naturally, there is no deadline, so I am a zombie and I will take the time three or seven: 7 minutes to change Windows Phone, 3 minutes to read books & classic papers.

However, one thing interrupts this comfortable life --

Baidu internship interview

Kiyou pushed the post in Baidu's practice. At that time, I felt that the post was shining brightly, so I threw my resume with the abnormal psychology of the domestic IT environment + abuse of the interviewer, on the first page, my senior friend burst out: He asked me to write a stof (string-to-floating-point number), and I did not write the complete implementation after a long time, then I quickly wrote a version in the dormitory and sent it to my brother's mailbox.

This has caused a great shock to me --

  • I couldn't even go through Baidu's internship interview.
  • It turned out to be a weak programming force.
  • It turned out to be an algorithm.

I started my second "Five-year Plan", and the time allocation for the three-seven open plans was changed to seven-three open: Seven-Point reading and three-point WP. The focus of this phase has changed from prinle le to implementation -- Talk is cheap, show me the code.

Elements of Programming

 

I have always thought that all the books with "elements of" in their names are cool, so I almost did not hesitate to buy this elements of programming, in fact, the code in this book (or the STL code) is indeed: fast, cruel, accurate, and the three elements of the Ancient Dragon master are all in one.

C interfaces and implementation

 

Baidu's interview experiences have prompted me to realize another problem. Most companies need to write C code on paper during interviews, but I rarely use C (C # in most cases #), considering that I have not been able to change the company's interview process, I need to improve my ability to write C code (even for interviews ). After a Google call, I locked C interfaces and implementation-another book on how to write C code that is so cool and cool-looking that Amazon commented on: probably the best advanced c Book in existance.

Strictly speaking, neither of the above two books is a traditional algorithm book, because they focus not on algorithms, but on the Implementation of classical algorithms (Implementation). However, this is exactly what I need: I can describe the principles of the algorithm, but it is silly to give an elegant, correct, and concise implementation, even if it is stof, a simple to explosive "algorithm ".

Still the previous silly learning method: After repeatedly studying and copying the code to the book over and over again, I have read a considerable number of programming practice books, and I feel that my programming skills have been greatly improved. In addition, I have gained new skills-coding on paper. This has also become one of the three axes for job interviews.

Application

To be honest, since my undergraduate internship, I have always felt that algorithms can be used in addition to interviews, I even wrote an article that was so self-reading that I was so stupid that I could not move on to the so-called "Daniel" who was "Basic" or "internal strength, here we extract a piece of text that seems silly but seems to be truth at the time:

So what algorithms, basics, internal skills, and so on, please close your mouth and use Rome. Algorithms are not a prerequisite for programming, and mathematics does not prevent a person from becoming a good programmer. At least in my opinion, all the basic functions of an algorithm are the tricks of the hacker. The practical programs that can be used by multiple compilers are king. Of course, if you are a pure theorist, you should say nothing to me.

However, it is interesting that, not long after I wrote this article, I used algorithms for all the projects I made, big and small, advocating useless algorithms. I was wondering if I was willing to show my face.

LL (k)

My first internship at Microsoft was doing code coverage analysis-computing code coverage for T-SQL stored procedures.

After a simple look at the documents related to SQL Server, I quickly found that SQL reporting service can record the execution statement and row number of the T-SQL, so line coverage is done, but the boss said that line coverage is too naive, and we need more practical block coverage ).

After reading the definition of block coverage, I found that I need to analyze the syntax of the T-SQL, in the absence of a good T-SQL parser, can only do one by yourself:

 

The odd story is that when I was working on this project, I just saw the language implementation patterns of the anlr author in half. What is the concept of LL (K), packrat, and AST Walker.

As a result, their own according to the T-SQL of the official ebnf, three to five in addition to two in a T-SQL storage process of LL (k) parser, the Code into AST, then, an external ast Walker is used to generate an HTML report covered by a code block. The entire process is less than a week.

Old nature is very satisfied-I suspect that his original plan was to spend two or three months to complete this project, because I did not do much work in the two months after this project, and I had a leisurely tour every day.

Pinyin Index

Pinyin index is a small module in the private app of my mobile phone app. You are expected to provide a smart prompt in the text box of your mobile phone:

For example, enter China:

 

Similarly, input pinyin should also give a prompt:

 

Chinese matching is simple, but it takes time to think about pinyin matching-I found Microsoft's pinyin library for the first time, however, I found that the bird library of Microsoft could not run on the mobile phone. After studying it, I found that WP7 had a limit on the number of items of dictionary. It seems that 7000 or 8000 items will crash, there are more than 20 thousand standard Chinese characters, Nima.

In addition to the "Ms" and "Chinese character" pitfalls, You have to upload a library by yourself:

  1. First, we sorted the 20 thousand Chinese characters and made them into a super-long string.
  2. Next I used int16 to index all Chinese Characters in pinyin (more than 500 ).
  3. Next, we will use int64 to establish the association between Chinese characters and Pinyin-the Chinese characters have polyphonic characters, so we need to pack multiple pinyin characters into one int64. This is simple, and bit operations will be done.
  4. Finally, we use binary + displacement unpack to directly retrieve Chinese characters from Chinese characters to pinyin.
  5. Later, I tested the performance at a speed of more than 50 times that of the original MS database, and the code volume was only 336 lines.

The user is very happy-because I completed all the polyphonic words he did not expect, and it was smooth.

I am also very happy, because I did not expect my own database to be dozens of times faster than ms, and dozens of times smaller at the same time.

From this point on, I have become particularly familiar with people who make wheels-you have to think about it. If you need a plane wheel, but there are only bicycle wheels on the market, and the boss is urging you to hand over, what can you do.

Fast String Matching

As mentioned above, the boss threw me a Windows Phone during my Microsoft internship and asked me to study it. When I had a good time, I felt that it was too difficult to find a contact.

For example, if you are looking for "Zhang Xiaoming", WP can only be located under Z-classification-this means that I need more than 70 contacts under Z-classification (Zhang surnamed Zhao surnamed Zhong, etc) linear search in it. Every time I had to slide for four or five seconds to find the boy surnamed Zhang.

 

This TMD is too silly. The old and broken Nokia three years ago supported initial positioning, 996-> zxm-> Zhang Xiaoming, nima's Windows Phone in the new age will be so weak.

I searched and found that there was no easy-to-use dial-up program, so I directly copied a dial-up program supporting matching the first letter and threw it into the WP forum.

As a result, there are various problems right away-the most important reflection is that the speed is too slow. Some users may even report that the buttons sometimes take half a second to respond. Ben asked his address book size: about 3000 people.

 

In addition to the amazing Address Book, I realized that my character string matching algorithm had a serious performance problem: Reading everyone's name and calculating the pinyin, then match one by one -- if the number of contacts is too large, the speed will inevitably be poor.

So I began to think hard about whether there was a high-end algorithm that could search for multiple strings at the same time, so that I could get this application faster when I was muttering through the subway in the past two days.

 

Finally, I found the answer in algorithms on strings, trees and sequences-there is indeed a way to search multiple strings at the same time: tries, in addition, this book also uses a full chapter to explain how to get the multiple string comparison. It seems that I was so busy that I went viral.

Not to mention the specific details. After the algorithm is changed, the matching speed is about 90 times faster, and the code is dozens of lines shorter. Even if there are 10000 contacts, it can be done within 0.1 seconds, and the speed bottleneck will be handled happily by the algorithm.

Writing efficient programs

After that, I made several projects, more or less using "self-made" algorithms or data structures. The most amazing one is to write pages in an e-book reader, I wrote a fast paging algorithm based on the simulated annealing principle. In fact, this algorithm is indeed very fast-but the problem is that I don't know why it will be so fast.

In short, algorithms are a weapon that maximizes the performance of limited computing resources. When computing resources are surplus, algorithms are useless, however, once the efficiency bottleneck is reached, the algorithm is the first in the fight (because the algorithm doesn't cost money! Or I have to change the CPU to buy SSD to upgrade Ram. It hurts !!). Some may think this is a problem, because the labor cost of writing new algorithms is sometimes higher than that of increasing hardware-but don't forget that increasing hardware efficiency is also based on the scalable algorithm.

 

Speaking of optimization, here we will mention writing efficient programs-it is difficult to find a book about code optimization (I suspect that no one dared to write it since knuth said that premature optimization is the source of all evil, the root of all evil, write it), note that this book is about code optimization-optimization without changing the architecture, algorithms, and hardware. Although some trick in the book, such as variable reuse or loop expansion, is outdated, it is still a good book.

Improve

Internship is the second summer of study, followed by the job season.

During the job season, I had an inexplicable sense of revenge-niima's previous Baidu internship interview, Lao Tzu, was hacked by you, and this time I am looking for a job, I want to bring you back, Nima.

Looking back at the time, the psychology was silly and naive, but this dark Psychology also played a positive role: I did not dare to neglect anything, as a result, at the end of March, I began preparing for a job test interview, two months earlier than my classmates.

I didn't give questions as much as I did with my colleagues. Instead, I continued to read books and copy code to learn algorithms, because I thought the interviewer would not ask questions that were rare and outrageous. In fact, the same was true.

Algorithm Design Manual

 

Because many coding interview forums have mentioned this Redbook, I have also followed suit. Facts have proved that the description of the part of backtrack template is sufficient for the book price, not to mention its heuristics and after-school questions.

Programming Pearl & more programming Pearl

 

 

There is no need to introduce these two books. I have never heard of these two books. The former is partial to algorithm theory, while the latter is partial to algorithm anecdotes. The former is capable of improvement, and the latter is worth reading.

The science of Programming

 

When I read the proof of Binary Search's correctness in programming Pearl, I was so addicted that the correctness of the original program can also be deduced, then I found the science of programming of David gries in the reference in that chapter. I thought it was amazing when I looked at the name, and I made an opening book directly.

It is worthy of being the book cited by programmers. after learning the science of programming, Ben has gained the skill to prove the correctness of simple code segments-the second of a three-pronged job interview.

Proving the correctness of a simple code segment is a magical skill-because most companies require a piece of code on paper during the interview, and then the interviewer checks the code, if you can prove that the code you write is correct, what else can the interviewer be picky about?

Afterwards, there will be various interviews. In short, there will be a series of project experiences and proven by code and correctness on paper.

Evolution

After the graduation season, There will be various types of happy jobs. After the happy days, Ben found that there will be another problem: insufficient algorithm capabilities.

It is said that most of my colleagues in the future are ACM players, and Ben has never engaged in algorithm competitions, and the algorithms and data structures that he knows are extremely basic: high-end data structures such as cellular automation, Fibonacci heaps, or line segment trees can only spell their English names, and they have never been used in combination, so they are so anxious.

In order to avoid being despised by the employee, coupled with his consistent algorithm inferiority, Ben forced himself to study the algorithm again:

Algorithms 4th

 

Algorithms is the first book to repeat algorithms. Although it is actually an entry-level book on data structures, algorithms is indeed suitable for learning algorithms that have been forgotten at that time, only for review.

The biggest highlight of this book is that it achieves the ultimate in visualization and formatting-maybe it is not the best data structure entry book, but it is the best typographical book I have ever read, the reading experience is amazing. Of course the content of this book is also good, especially the part of The Red/black tree.

6.851 advanced data structures

 

Advanced data structures is an advanced data structure tutorial of MIT. Why can I find this tutorial? Because Google advanced data structures is the first such item.

This course contains a variety of data structures and algorithms that break down the original world view, including but not limited:

  • Data Structure with "memory ).
  • Van emde boas (insertion, deletion, precursor and successor complexity of the last day ).
  • O (1) time complexity of the LCA, rmq and La solutions.
  • Fantastic suffix tree construction method with O (n) time complexity.
  • O (lglgn) BST.
  • ...

In short, the climax is repeated, and the only difference is that they are not made in a circle. In the future, Ben will find time to repeat them one by one.

Summary

From algorithm exposure to the present, it may take about seven years: At the beginning, I had a strong reputation for algorithms. After my internship, I had advocated useless algorithms. After reading and researching, I was pushed back to the reality.

How is it like the affirmation in dialectics to the negation and then to the negation of the negation.

Now, a considerable number of people who advocate algorithms do not understand the importance of algorithms. If you have never used algorithms to solve practical problems, how can you prove that algorithms are useful? The vast majority of people who advocate the useless theory of algorithms are nothing but a low-level coders-they have never encountered problems that need to be solved by algorithms, and naturally do not know how important algorithms are.

Peter norvig once wrote a wonderful book review of the object. I think it is still applicable to replacing the object with an algorithm:

To use an analogy, if algorithms were about automobiles, it wocould be for the person who wants to know how cars work, how they are built, and how one might design fuel-efficient, safe, reliable vehicles for the 21st century. the people who hate algorithms are the ones who just want to know how to drive their car on the highway, just like everyone else.

Professor Erik demaine of MIT is more direct:

If you want to become a good programmer, you can spend 10 years programming, or spend 2 years programming and learning algorithms.

All in all, if you want to become a code farmer or a skilled engineer (Code monkey), you can skip algorithms because they are useless to you; however, if you want to become a good developer, solid algorithms are essential because you will constantly fall into some traps that can only be crawled by algorithms.

My path to algorithm Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.