官术网_书友最值得收藏!

  • Go Systems Programming
  • Mihalis Tsoukalos
  • 239字
  • 2021-07-02 18:08:05

The Big O notation

The Big O notation is used for describing the complexity of an algorithm, which is directly related to its performance. The efficiency of an algorithm is judged by its computation complexity, which mainly has to do with the number of times the algorithm needs to access its input data to do its job. Usually, you would want to know about the worst-case scenario and the average situation.

So, an O(n) algorithm, where n is the size of the input, is considered better than an O(n2) algorithm, which is better than an O(n3) algorithm. However, the worst algorithms are the ones with an O(n!) running time because this makes them almost unusable for inputs with more than 300 elements. Note that the Big O notation is more about estimating and not about giving an exact value. Therefore, it is largely used as a comparative value and not an absolute value.

Also, most Go lookup operations in built-in types, such as finding the value of a map key or accessing an array element, have a constant time, which is represented by O(1). This means that built-in types are generally faster than custom types and that you should usually prefer them unless you want full control over what is going on behind the scenes. Additionally, not all data structures are created equal. Generally speaking, array operations are faster than map operations, whereas maps are more versatile than arrays!

主站蜘蛛池模板: 嵊泗县| 特克斯县| 铁力市| 乐东| 汝州市| 灵武市| 宜州市| 武清区| 武义县| 那坡县| 昭平县| 建瓯市| 五华县| 香格里拉县| 都昌县| 县级市| 南郑县| 南充市| 怀来县| 禄丰县| 湄潭县| 城口县| 宣恩县| 峡江县| 敖汉旗| 绥江县| 洪湖市| 凤阳县| 丰台区| 马龙县| 延津县| 迁西县| 喀什市| 台湾省| 宝丰县| 昂仁县| 凤城市| 大渡口区| 黑河市| 松滋市| 蒲江县|