-3

While studying for Data structures and Algorithms, I noticed that there is a pattern/group in which every question falls into. Example - Given this, do/find that - Category 1. use these methods/techniques first and then approach it. Similarly for another set of questions.

Do we have a list of patterns which we can understand, so that next time we see a problem, we can identify which category it may fall into and follow those steps to approach it first rather than mixing up random ways of solving them?

This question is not about using which design-pattern like Singleton or Factory etc, but about categories of questions. Example - Whenever there is a string pattern matching question, try with TRIES first, then move to some other DS. If there is List traversal, use this specific technique first (whichever is most recommended based on time/space complexity), then try something else.

  • 2
    Possible duplicate of [Choosing the right Design Pattern](https://softwareengineering.stackexchange.com/questions/227868/choosing-the-right-design-pattern) – gnat Oct 09 '17 at 14:31
  • 1
    @gnat - Explained my problem in detail. – user2769790 Oct 09 '17 at 14:53
  • 4
    Programming or solving programming problems does not work like an automaton where you just feed some preconditions in and get some solution out. That is why you need trained experts for doing it seriously. – Doc Brown Oct 09 '17 at 18:41
  • @DocBrown This is something that has always puzzled me: if we have been doing this for so long, you would think that we would have it down by now, every problem that comes up should just be a slam dunk. What has gone wrong? Why in the world is there not just a list of problem :: solution pairs? If you ask an expert for a first cut answer, most of them will agree, so obviously the OP has a point. Once you have eliminated the impossible, whatever remains should just be bone-obvious. –  Oct 09 '17 at 19:28
  • 3
    @nocomprende: I am sure there has nothing "gone wrong". If problem solving shall ever become just a matter of looking into some "dictionary of already solved problems", lots of people (including myself) will become unemployed. But I am confident this will not happen during my lifetime. – Doc Brown Oct 09 '17 at 19:55
  • @DocBrown A Q&A site is predicated on the idea that there is a best answer (or at least some good answers) to a problem. Saying that there is not is a bit contradictory. Compile all the good entries and you have a catalog of answers to problems. Make it searchable... But there are so many other ways to accomplish the goal, I suppose. Such a Q&A site would never be useful. –  Oct 10 '17 at 18:56
  • @nocomprende: as you to wrote: to *a* problem (or lots of problems), but not to *any* problem, and I am really confident not to any interesting problem. And lots of problems simply do not fit to the Q&A format of this site, as we can see here every day. – Doc Brown Oct 10 '17 at 21:05

2 Answers2

7

Like design patterns in Software Engineering, I would avoid approaching problems with the intent of using a data structure.

The biggest pitfall with design patterns is that engineers will try throwing design patterns at a problem, and hope that it works. In reality, design patterns should be emergent as you get closer to solving the problem, and then you can better evaluate your solution.

I recently finished interviewing students at a college for a Software Engineering position, and the biggest trip-up was when someone tried to apply an inappropriate data-structure or algorithm to a problem right off-the-bat.

I'm not aware of any lists for data-structures for certain problems, and while I agree it would be useful, I would be wary of using any for starting a problem, only for understand the pro-and-cons of a given approach.

JRJurman
  • 347
  • 1
  • 10
3

No. Such a list of patterns doesn't exist.

Because the problem I'm currently solving has never been solved before: different environment, different domain context, different assumptions, different constraints, different expectations from users...

It is more efficient to teach people how to deal with new problems than to build an hypothetic list of patterns that anyone could apply.

mouviciel
  • 15,473
  • 1
  • 37
  • 64
  • What shall we teach about how to deal with new problems? Perhaps approaches that have been found successful in the past? What shall we teach about programming *at all*? Things people have already done. We cannot teach general-purpose problem solving, it would be like teaching "how to be smart". I think that 99% of the time, programmers are simply doing things that have been done many times before, with slight variations. We should realize this, pool our efforts, and solve some real problems with the excess capacity that becomes available. But, that would be a general solution, I suppose. –  Oct 10 '17 at 22:08
  • @nocomprende - We can teach methodologies of how to approach a new problem such as, for instance, decompose it in subproblems that have been solved before. But actually, in the end, the whole teaching process aims at selecting smarter people. – mouviciel Oct 11 '17 at 08:07
  • If it is basically a selection process, perhaps we should start at an earlier age and concentrate efforts only on those suitable for any particular field? –  Oct 11 '17 at 11:42