Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a quadratic process?

I was reading the Go programming language book (by Donovan and Kernighan) and about their example echo1, they said: "This is a quadratic process that could be costly if the number of arguments is large, but for echo, that's unlikely". What does quadratic process mean?, and how is it costly if the number of arguments is large?

Thanks.

like image 373
Omar Avatar asked Jan 17 '17 19:01

Omar


1 Answers

Generally speaking quadratic means something that pertains to squared numbers. In this context it means that the cost of the process is proportional to the square of the input size. This is because strings are concatenated using += operator which is expensive in Go as strings are immutable and a new string must be created in memory every time you concatenate. More efficient ways to concatenate strings include writing to bytes.Buffer and converting it to string, or using strings.Join function

like image 127
jussius Avatar answered Nov 18 '22 17:11

jussius