Skip to Content
Learning JavaScript Data Structures and Algorithms - Third Edition
book

Learning JavaScript Data Structures and Algorithms - Third Edition

by Loiane Avancini
April 2018
Beginner to intermediate content levelBeginner to intermediate
426 pages
10h 19m
English
Packt Publishing
Content preview from Learning JavaScript Data Structures and Algorithms - Third Edition

Comparing complexities

We can create a table with some values to exemplify the cost of the algorithm given its input size as follows:

Input Size (n) O(1) O(log (n)) O(n) O(n log(n)) O(n2) O(2n)
10 1 1 10 10 100 1,024
20 1 1.30 20 26.02 400 1,048,576
50 1 1.69 50 84.94 2,500 Very big number
100 1 2 100 200 10,000 Very big number
500 1 2.69 500 1,349.48 250,000 Very big number
1,000 1 3 1,000 3,000 1,000000 Very big number
10,000 1 4 10,000 40,000 10,000,0000 Very big number

 

We can draw a chart based on the information presented in the preceding table to display the cost of different big O notation complexities as follows:

The preceding chart was also plotted using JavaScript. You can find its source code in the examples/chapter15 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning JavaScript Data Structures and Algorithms

Learning JavaScript Data Structures and Algorithms

Loiane Avancini

Publisher Resources

ISBN: 9781788623872Supplemental Content