Hacker News new | ask | show | jobs
Data structures and algorithms practice problems and their solutions (medium.com)
72 points by abhimt 3124 days ago
6 comments

This was already posted under a different link.

https://techiedelight.quora.com/500-Data-Structures-and-Algo...

In fact it seems as the author on Medium "forgot" to mention his sources.

As scientist (Molecular Biology background) who has transitioned to being a part-time self-employed developer, how often do you CS/CE people use any of this in real life? Is all this just equivalent to the Chinese imperial civil service examination system [0]?

0. https://en.wikipedia.org/wiki/Imperial_examination

This is a valid criticism from a practitioner point of view. From someone doing research in algorithms and data structures or someone just curious about it at an intellectual level, there is a different criticism:

All this focus on algorithms for the sake of interview-preparation gives the false impression that the field is a closed body of work. In reality it is an active and lively field of research with many (even most) basic questions not yet understood.

Someone could go through these 500 questions and for (almost) all of them formulate variants/extensions that would be open research questions. So instead of memorizing them, ask for each: Is this the best possible solution? Can I prove it? What if I restrict what the algorithm can do? What if I give the algorithm extra powers? What if the data comes online? What if the input is noisy? What if I want to optimize space usage instead of time? Is there a trade-off between the two? Etc. etc.

And related to the parent question: does the problem model a real practical problem? Why not? Can the model be changed to be more realistic?

All that being said, at a first look, the list seems like a quite nice collection of techniques.

Not to mention it suggests these problem exist in isolation. These are neat problems with neat-looking solutions, mostly curated for elegance. Some are useful for embedded programming (doing X or Y in place or under certain time complexity).

This is almost never what you encounter in practice. In practice, you tend to get handed someone's creaking code and asked to build upon it.

My post wasn’t intended to be a criticism - I was genuinely interested to know the answer.

I work on what are considered hard CS problems and I rarely find the difficult part is knowing some data structure or algorithm, but in finding a way of translating real world problems into something that makes sense in code.

I am not sure of your study of problems but you have spoken like techno-functional user. Finding a good translation surely is a big part but then getting things correct is also required. Writing couple of joins to get the correct data is fine but getting the correct join or data type or structure is also required. The difference being running a code for couple of hours vs in couple of minutes.
I am not suggesting that the right data structure is not important, just that is not where the difficulty lies. I can solve problems that my far more CS knowledgable employees can't because I have a better understanding of the domain. My solutions are not always the most elegant, but they work (most of the time).
My point is on the elegance of a solution. As you said your solution works but that can be attributed to your domain knowledge. But the affect of your solution might be understated. We have people who write direct queries after much discussion with us. While we can't directly point them out, the queries tend to run for hours affecting other people's work and then we have to rework the whole thing all over again.
Almost never at the frontend. Sometimes at the backend. Once a month probably. But you never know which of these you may need. Asking stuff like this on an interview is idiotic. I'm talking about web dev.

It can be really useful if you're writing a compiler or something like that. There's a lot of problems in molecular biology, which need some complicated algorithms.

In web development, almost zero relevance. They are looking for the keys under the lampost [1].

Some of those algorithms are already implemented by library functions. Others are really not relevant. However:

1. I needed some non trivial algorithm maybe once or twice in the last 5 years. Knowing you can do that in o(n) or o( log n) is handy. Knowing the solution is better :-)

2. Binary search is important. I saw a program looping through potentially 4000+ API calls to look for an element when a binary search could have nailed it down in a few hits (the server didn't have a search API for what the program had to do.)

[1] https://en.wikipedia.org/wiki/Streetlight_effect

Surely you know about Rosalind ? It's an online collection of programming problems related to bioscience. Each problem has a pamphlet with biological/genetic background.

There is no online IDE you must use, and no time limit. However, you're asked to paste or upload the output within a few minutes of downloading the randomly generated input dataset, so your solutions must be efficient. Rosalind encourages Python and provides relevant tutorials, but you can use any language you like. Rust, Lua, Javascript, Smalltalk, LISP, Nim, INTERCAL, Bash or Scala - it's up to you.

I have seen Rosland before [0]. It is fun, but the really difficult problems are the ones with tons of biological edge cases. The level of complexity biology throws at you is truly staggering.

0. http://rosalind.info/problems/locations/

How much math do programmers need?

https://danluu.com/math-bias/

Some of these answers are not great, and wouldn't stand up to interview scrutiny. For example, the "Check if linked list is palindrome or not" problem says copying the list would be too expensive. The proposed answer (recursion) some how avoids this.

The solution is technically right, but it's making a copy of the list too. The intuition is wrong.

I work as a developer in enterprise environment since 4 years. So far I didn't encounter any of the above issues. However we have a set of other issues mostly connected to maintainability of a code base or refactoring of legacy code. I would love to see a set of interview questions that target our issues too.

(Our best approach so far was to test people with the gilded rose kata and see how they manage the problem without reimplementing it from scratch)

A list of only 500 potential problems for an interview.

All right class, remember to read the textbook cover-to-cover over the weekend, as your first quiz may, or may not, cover the entire course.

But don't be nervous, it's only worth 95% of your grade.

Soo... let's create a github repo and solve all these? :D
Cool idea!