What's the difference between an Algorithm and

2020-02-19 08:54发布

I was searching for "Undo/Redo algorithms" and found something marked as a duplicate, but the duplicate was a request for a "Undo Design Pattern". I'd really like an algorithm for this. I don't think I necessarily need a design pattern.

Is there a fundamental difference between "Design Pattern" and "Algorithm" or is it OK that someone uses the two interchangeably?

I'll hang up and take my answer off the air.

Ok, forgive me for thinking design patterns were just abstractions of algorithms. Here's a little table of my findings from the answers which were all very good.

   Design Pattern |    Algorithm
------------------|----------------
Abstract          | Concrete
Control Structure | Set of Actions    
Template          | Implementation
Flexible          | Deterministic
Blueprint         | Recipe

12条回答
贪生不怕死
2楼-- · 2020-02-19 09:16

A design pattern is a relatively vague description of how to solve a problem at an architectural level, with emphasis on flexibility and maintainability. An algorithm is a precise description of how to compute something specific, with an emphasis on correctness and efficiency.

查看更多
女痞
3楼-- · 2020-02-19 09:22

Design patterns:

  • a solution to a common but generic problem.
  • general solution to general problem.
  • often have to be implemented each time it is used.

Algorithm:

  • specific set of steps you can follow to answer particular problem.
  • implemented directly to solve specific problem.
查看更多
淡お忘
4楼-- · 2020-02-19 09:24

An algorithm is a specific set of steps to perform a task. Decoding an audio or video file would use an algorithm.

A design pattern is more of a template for designing a system with certain characteristics.

查看更多
迷人小祖宗
5楼-- · 2020-02-19 09:26

When I studied design pattern concept for the first time, I was also surprised why design patterns were introduced in the presence of algorithm. As my knowledge has been increasing with design patterns, I am reaching at this point that algorithm is entirely different approach to solve the problems and design pattern is different.

Design pattern is basically a recurring solution of same problem for a software application in a particular context which is somehow not related with algo, because algorithm is the step by step instructions to solve the problem.

查看更多
叛逆
6楼-- · 2020-02-19 09:27

An algorithm is like a recipe: a step-by-step process for performing some activity.

A design pattern is like a blueprint: an structured collection of objects and associations and actions to accomplish some goal.

查看更多
Root(大扎)
7楼-- · 2020-02-19 09:27

A design pattern would determine how you design an algorithm (or may have nothing to do with algorithms, but let's say we're dealing with one that does), whereas an algorithm will be a set of solid, repeatable, implementable, steps to doing something. So no, I wouldn't call them interchangable.

查看更多
登录 后发表回答