March 2019
Intermediate to advanced
336 pages
9h 9m
English
An algorithm is of logarithmic complexity if the processing time is proportional to the logarithm of the input elements. The logarithm base is typically 2. The following tree is a binary tree with LeftNode and RightNode. The insert operation is of O(log n) complexity, where n is the number of nodes.
Logarithmic complexity is presented as follows:
//main package has examples shown// in Hands-On Data Structures and algorithms with Go bookpackage main// importing fmt packageimport ( "fmt")// Tree structtype Tree struct { LeftNode *Tree Value int RightNode *Tree}
As shown in the following code, the Tree class has the insert method, which inserts the element given m is the integer element:
// Tree insert method for inserting ...
Read now
Unlock full access