March 2019
Intermediate to advanced
336 pages
9h 9m
English
An algorithm is of linear complexity if the processing time or storage space is directly proportional to the number of input elements to be processed. In Big O notation, linear complexity is presented as O(n). String matching algorithms such as the Boyer-Moore and Ukkonen have linear complexity.
Linear complexity, O(n), is demonstrated in an algorithm as follows:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt packageimport ( "fmt")// main methodfunc main() { var m [10]int var k intfor k = 0; k < 10; k++ { m[k] = k * 200fmt.Printf("Element[%d] = %d\n", k, m[k] ) }}
Run the following commands:
go run linear_complexity.go
The following screenshot displays the output: ...
Read now
Unlock full access