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

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!

主站蜘蛛池模板: 济宁市| 梁河县| 容城县| 平昌县| 遂宁市| 宜州市| 平舆县| 阿荣旗| 汕头市| 丰镇市| 永顺县| 泰兴市| 南和县| 光山县| 东港市| 宁津县| 涞源县| 福州市| 西乡县| 泸溪县| 博乐市| 万安县| 兴业县| 临洮县| 安福县| 莒南县| 宝兴县| 高雄县| 辉南县| 蓬溪县| 鄂尔多斯市| 兴文县| 白水县| 伊通| 班戈县| 台山市| 会东县| 且末县| 云龙县| 日照市| 元氏县|