Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "algorithm problem size" actually mean?

Tags:

algorithm

I'm currently in a Data Structures course at my university and did do some algorithm analysis in a prior class, but it was the section I had the most difficult time with in the previous course. We are now going over algorithm analysis in my data structures course and so I'm going back through my textbook from the previous course to see what it says on the matter.

In the textbook, it says "For every algorithm we want to analyze, we need to define the size of the prob- lem." Doing some Google searching, it's not entirely clear what "problem size" actually means. I'm trying to get a more concrete definition of what a problem size is so I can identify it in an algorithm.

I know that, if I have an algorithm that is sorting a list of numbers, the problem size is n, the size of the list. With that said, saying that doesn't clarify what "problem size" actually is, except for in that context. An algorithm is not just a process to sort numbers, so I can't always say that the problem size is the number of elements in a list.

Hoping someone out there can clarify things for me, and that you all are doing well.

Thank you

like image 640
GainzNerd Avatar asked Jun 08 '26 00:06

GainzNerd


2 Answers

The answer is right there in the part you quoted (emphasis mine):

For every algorithm we want to analyze, we need to define the size of the problem

The "problem size" is only defined numerically relative to the algorithm. For an algorithm where the input is an array or a list, the problem size is typically measured by its length; for a graph algorithm, the problem size is typically measured by the number of vertices and the number of edges (with two variables); for an algorithm where the input is a single number, the problem size may be measured by the number itself, or the amount of bits required to represent the number in binary, depending on context.

So the meaning of "problem size" is specific to the problem that the algorithm solves. If you want a more universal definition which could apply to all problems, then the problem size can be defined as the number of bits required to represent the input; but this definition is not practical, and is only used in theory to talk about classes of problems (such as those which are solvable in polynomial time).

like image 97
kaya3 Avatar answered Jun 10 '26 19:06

kaya3


The problem size is the number of bits needed to store an instance of the problem, when it is specified in a reasonable encoding.

like image 43
gnasher729 Avatar answered Jun 10 '26 17:06

gnasher729