Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-2007, 04:00 PM
shinta's Avatar   
shinta shinta is offline
Newbie
 
Join Date: Nov 2007
Location: Austin, TX
Posts: 7
Rep Power: 0
shinta is on a distinguished road
Send a message via AIM to shinta Send a message via MSN to shinta
Default Big O notation

include Detailed information on the Big O? im not so sure of what it is and how it works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-17-2007, 09:34 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,278
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

Big O is not a language specific concept. It is an upper bound of the measurement of an algorithm's efficiency (usually either memory or time). When analyzing an algorithm, you aren't looking for whether the there are a lot of lines, but the types of loops that are present (along with implicit loops due to recursive function calls).

The formal definition (from memory) is the following:
A function g(x) is considered O(f(x)) if there exists C and X such that, for all x>X, C*f(x) > g(x).

Human translation: g(x) is bounded above by a scalar multiple of f(x) for all sufficiently large x.

This has a few implications that are relevant:
1) x^2, 2*x^2, 3*x^2, etc are all O(x^2) (where x^2 is x squared)
2) trivial cases such as x=1, x=2, x=3, are usually not relevant for analysis.
3) x^2 is O(x^2), O(x^3), O(x^4) etc. So knowing an algorithm is O(x^2) does not mean that it can't be more efficient, but rather that x^2 is a worst-case scenario that may not actually occur.

Some basic big-O's listed in order from best to worst are:
O(1), O(ln(x)), O(sqrt(x)), O(x), O(x^n), O(n^x), O(x!)

For rough and dirty analysis, code with no loops/function calls is O(1). Code with a single for loop is O(x), code with nested for loops is O(x^n) where n is the level of nesting. Code with recursive function calls can range from O(ln(x)) to O(x!) or worse.

Interesting side note. I wrote a sorting problem a while back that I believe was O(((x!)!)!). It ran nicely when the input was 9 and 3 (took about a minute), sucked when the input was 12 and 3 (didn't finish after running for 5 hours).
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-18-2007, 11:36 AM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 474
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default

You've missed O(nlog(n)) which is the theoretically the most efficient you can make a comparison sorting algorithm in the worse case.

Big O is about mathematics. A field called computational complexity. Basically, how long does an algorithm take to finish given various characteristics of the data set. Usually we consider size (how long does a sort take given a list of size n) of the data set but computational complexity also alters depending on the composition of the data set. Take insertion sort, it scales O(n^2) but it takes much longer for data that is reverse sorted than it does some average set of data. Counting sort OTOH varies with the range and size of the data set, data sets where the highest and lowest values are 1 and 1m will sort far slower than data sets of the same size but where the extreme values are 1 and 10.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable Standards Saint General Programming 5 05-14-2007 12:25 PM
'BigOh' Notation DansTransAM General Programming 3 09-14-2006 12:56 PM


All times are GMT -5. The time now is 06:20 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads