What is the big deal about Big-O notation in computer science?

前端 未结 14 582
广开言路
广开言路 2021-01-31 11:30

How would Big-O notation help in my day-to-day C# programming? Is it just an academic exercise?

14条回答
  •  再見小時候
    2021-01-31 11:54

    Naw, I was wondering that too, but now I find myself thinking about big-O just about every time I use a library.

    Big-O lets you know the asymptotic running time of any function, that way you can decide whether data structure A is faster than data structure B for your purposes.

    For example, you might be tempted to use something like an ArrayList when what you really need is a Queue. When you try to add an element to an ArrayList, if you can see that the running time is O(n) (because it needs to create a new array and copy all the elements over... sometimes) but in a Queue it's O(1) then you can easily see that the queue would be faster. This is actually kind of a poor example as there are many other differences between these two structures, but you get the idea ;)

提交回复
热议问题