TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How should I study algorithms and datastructures?

29 pointsby PixZxZxAabout 8 years ago
Dear all, I am currently studying towards a Bachelor&#x27;s degree in Computer Science in Sweden. Right now I am attending a course called &quot;Algorithms and datastructures&quot;, where we get an introduction to sorting, searching, priority queues etc.<p>If feel that I need to spend a lot of time in order to really understand the essence of the algorithms, which gets very time consuming when you need two days only to understand insertion sort and merge sort.<p>How do I study these topics the most efficiently? How well should I know certain algorithms and datastructures?

7 comments

veddoxabout 8 years ago
Short answer: code them ;-)<p>Long answer:<p>The Algorithms and Data Structures course is one of the foundational courses of a CS degree. Even if you think you don&#x27;t need to be able to implement the algorithms you learn in your work later on, it is important to have some idea of which algorithms exist for a given task.<p>Also, and perhaps even more importantly, understanding how these algorithms work really hones your problem solving skills. You learn how to abstract the information given to you as part of a problem into an appropriate data structure, and what kind of operations you can carry out with which data structures. You learn how to cope with several different layers of abstraction and develop an intuition for programming approaches that are fast and&#x2F;or light on memory. Basically, the ADS course doesn&#x27;t teach you how to be a programmer, but how to <i>think</i> like one.<p>As for studying for this course: there&#x27;s nothing like doing it yourself. Chances are, you already have to do so anyway as part of your course work. Take the programming tasks seriously and really do try to do it yourself. (Get friends to help you by all means, but don&#x27;t let them do the work for you.)<p>I would advise you not to slack either: based on your information and the ADS course at my uni, I&#x27;m guessing that you&#x27;re still at the very beginning of your degree. It isn&#x27;t going to get easier in terms of workload, and the algorithms you learn about later on in the course are a lot more complicated than those at the beginning. But if you&#x27;ve made the effort to understand the first bunch of algorithms, you&#x27;ll be in good shape to understand the latter ones too. So yes, it is hard work, but you can do it :-)
marvyabout 8 years ago
Two days to understand the ESSENCE?? I understand that there are a lot of details, and those can take a lot of time to master, but the essence should be really quick. To wit:<p>1. Merge sort. Given two sorted sequences, they can be merged in linear time. Given an algorithm that does so, we can sort a list in O(n log n) time, as follows: split the list into two equal halves, merge sort each half, and then merge the result. (The base case is that sorting lists of length 1 is really easy.)<p>2. Insertion sort. Let&#x27;s say you want to sort in increasing order. To make things concrete, let&#x27;s say your given list is<p>[3, 1, 4, -1, 5, 9, 2, 6, -5, -3]<p>You start by walking through the list: 3, 1, ... WAIT. That&#x27;s not right, 1 should come before 3. Let&#x27;s drag it to the front of the list where it belongs. We now have:<p>[1, 3, 4, -1, 5, 9, 2, 6, -5, -3]<p>Now we again walk through the list: 1, 3, 4, -1 ... WAIT. What&#x27;s -1 doing here, let&#x27;s drag it to the front of the line:<p>[-1, 1, 3, 4, 5, 9, 2, 6, -5, -3]<p>Again: -1, 1, 3, 4, 5, 9, 2, ... WAIT. What&#x27;s 2 doing here, we need to drag it forward, but not all the way to the front:<p>[-1, 1, 2, 3, 4, 5, 9, 6, -5, -3]<p>And so on. Is this what you meant by essence?
评论 #14136955 未加载
Jtsummersabout 8 years ago
This may be too late for you to notice it, hopefully not. Something useful for me was not learning any particular algorithm or data structure in depth, but learning the &quot;shapes&quot; of algorithms and data structures.<p>When starting out you&#x27;ll be learning, for example, the different sorting algorithms in great detail. This isn&#x27;t terribly useful later on (the level of detail at least). What is useful is that they each have a shape, a style of functioning. Merge sort as one of the quintessential divide-and-conquer algorithms provides an excellent template for other algorithms with the same shape, but meant to compute something different. While bubble sort is a terrible sort algorithm, the pattern of bubble sort for computation is present in numerous algorithms. Same with insertion sort and shell sort and the rest.<p>It&#x27;s like language acquisition, or at least like language acquisition is for me. When learning Spanish, I learned a lot of specific instances (hablo, hablas, habla, hablamos, hablan as 5 distinct things). Then I learned the pattern (grammar rules, -ar verbs generally drop the -ar and -o means I &lt;verb&gt;, -as means you &lt;verb&gt;, etc.), then I focused on root words in vocabulary (hablar means to speak) rather than memorizing every conjugated form of a verb.<p>Same as physics and calculus. Learn specific cases at the start, then you learn the rules, then you apply the rules to new forms to construct novel (to you) solutions.<p>And as others said, code. My algorithms class didn&#x27;t require much programming, technically, it was rather high level. But I coded everything I could to try things out and understand them. Sitting down with pencil and paper to understand it was sometimes helpful, but the act of coding was more effective.<p>EDIT: High level in that it was focused a lot on the maths of algorithm analysis. I had one earlier in college that was more practically focused, on implementing algorithms, but the one that really stuck with me was the later one.
kiloreuxabout 8 years ago
I would first ask. Do you really need this in your day to day life? I know a lot of companies use this for hiring, but you can still get a job without them.<p>However if you still want to study them, there are plenty of resources online, like this youtube channel[1].<p>Taking 2 days to understand insertion sort is fine but you just need to practice learning more often and use the things you learn more often. Even if it&#x27;s on toy projects.<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;user&#x2F;mycodeschool" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;user&#x2F;mycodeschool</a>
评论 #14158425 未加载
kerneldeveloperabout 8 years ago
I must recommend two books, both of them are awesome. One is Algorithm by Sedgewick and the other is The Algorithm Design Manual by Steven S. Skiena. You can read the first book and then the other. If you want some challenges and practice, try LeetCode and HackerRank. By the way, it&#x27;d be better to keep a discrete math book at hand, it would help you if you encounter some mathematical proof problems. I would recommend Discrete Mathematics and Its Applications by Kenneth H. Rosen for reference.
vskarineabout 8 years ago
not the fastest but IMHO most practical way is through <a href="http:&#x2F;&#x2F;www.usaco.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.usaco.org&#x2F;</a> training program @ <a href="http:&#x2F;&#x2F;train.usaco.org&#x2F;usacogate" rel="nofollow">http:&#x2F;&#x2F;train.usaco.org&#x2F;usacogate</a>, it&#x27;s free and it will teach you to code and use most data structures and algorithms you&#x27;d ever encounter
fadzlanabout 8 years ago
Would this count?<p><a href="https:&#x2F;&#x2F;visualgo.net&#x2F;en&#x2F;sorting" rel="nofollow">https:&#x2F;&#x2F;visualgo.net&#x2F;en&#x2F;sorting</a>