Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

When we say Big O is nlonn, what does it exactly means. My exact question is how we iterprete it performance wise.

Thanks in advance
Posted

The most common attributes of logarithmic running-time function are that:

the choice of the next element on which to perform some action is one of several possibilities, and only one will need to be chosen or the elements on which the action is performed are digits of n
This is why, for example, looking up people in a phone book is O(log n). You don't need to check every person in the phone book to find the right one; instead, you can simply divide-and-conquer, and you only need to explore a tiny fraction of the entire space before you eventually find someone's phone number.

Of course, a bigger phone book will still take you a longer time, but it won't grow as quickly as the proportional increase in the additional size.

We can expand the phone book example to compare other kinds of operations and their running time. We will assume our phone book has businesses (the "Yellow Pages") which have unique names and people (the "White Pages") which may not have unique names. A phone number is assigned to at most one person or business. We will also assume that it takes constant time to flip to a specific page.

Here are the running times of some operations we might perform on the phone book, from best to worst:

O(1) (worst case): Given the page that a business's name is on and the business name, find the phone number.

O(1) (average case): Given the page that a person's name is on and their name, find the phone number.

O(log n): Given a person's name, find the phone number by picking a random point about halfway through the part of the book you haven't searched yet, then checking to see whether the person's name is at that point. Then repeat the process about halfway through the part of the book where the person's name lies. (This is a binary search for a person's name.)

O(n): Find all people whose phone numbers contain the digit "5".

O(n): Given a phone number, find the person or business with that number.

O(n log n): There was a mix-up at the printer's office, and our phone book had all its pages inserted in a random order. Fix the ordering so that it's correct by looking at the first name on each page and then putting that page in the appropriate spot in a new, empty phone book.

For the below examples, we're now at the printer's office. Phone books are waiting to be mailed to each resident or business, and there's a sticker on each phone book identifying where it should be mailed to. Every person or business gets one phone book.

O(n log n): We want to personalize the phone book, so we're going to find each person or business's name in their designated copy, then circle their name in the book and write a short thank-you note for their patronage.

O(n2): A mistake occurred at the office, and every entry in each of the phone books has an extra "0" at the end of the phone number. Take some white-out and remove each zero.

O(n · n!): We're ready to load the phonebooks onto the shipping dock. Unfortunately, the robot that was supposed to load the books has gone haywire: it's putting the books onto the truck in a random order! Even worse, it loads all the books onto the truck, then checks to see if they're in the right order, and if not, it unloads them and starts over. (This is the dreaded bogo sort.)

O(nn): You fix the robot so that it's loading things correctly. The next day, one of your co-workers plays a prank on you and wires the loading dock robot to the automated printing systems. Every time the robot goes to load an original book, the factory printer makes a duplicate run of all the phonebooks! Fortunately, the robot's bug-detection systems are sophisticated enough that the robot doesn't try printing even more copies when it encounters a duplicate book for loading, but it still has to load every original and duplicate book that's been printed.
 
Share this answer
 
Comments
ridoy 29-Nov-12 6:57am    
+5
[no name] 29-Nov-12 6:59am    
Thanks man :)
Member 12592465 19-Jun-16 16:48pm    
Thanks a ton!!!
Ronnie Cruz 28-Dec-17 9:38am    
This answer originally appeared here:

https://stackoverflow.com/questions/2307283/what-does-olog-n-mean-exactly

Come one. Be a professional and attribute the author of the post.
The Big-Oh notation has a well-defined mathematical meaning. When you say that a function f of a variable N is big-Oh of some function g of N, it means that f(N) is bounded above by C.g(N) for all N [except maybe for the first values], where the coefficient C is called the "hidden constant". http://en.wikipedia.org/wiki/Big_O_notation[^]

For instance, when you say that a sorting algorithm has running time T(N) = O(N.Log(N)), where N is the number of elements to be processed, that means that the running time grows not faster that N.Log(N).

[Keep in mind that you need to scale these values with the hidden constant, which depends on how precisely the code is written in the innermost loops and how the compiler does its optimization job.]

When an algorithm has linear time behavior O(N), that means that solving the problem is not more complicated than merely stating the problem: just reading the input data takes time O(N). Algorithms with a linlog behavior (O(N.Log(N)) are also considered as fast ones. Things get worse with polynomial times like O(N^2).

XML
N       N.Log(N) N^2
10      33       100
100     664      10000
1000    9966     1000000
10000   132877   100000000
100000  1660964  10000000000
1000000 19931569 1000000000000
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900