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 09-08-2006, 04:50 PM
DansTransAM DansTransAM is offline
Newbie
 
Join Date: Jul 2006
Posts: 1
Rep Power: 0
DansTransAM is on a distinguished road
Default 'BigOh' Notation

In my data structures class we have been looking at certain Java code and determining how effecient the algorithm/code is.

Our teacher wants to able to look at code (for loops, if statements, etc) and be able to come to up with O notation of the algorithm. I have been having trouble identifying the BigOh number in general.

Any tips on looking at code? Nested loops?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-14-2006, 12:08 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,276
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

No loops = O(1).
one loop = O(n).
two loops = up to O(n^2).
three loops = up to O(n^3).
Recursion = who the heck knows??? could be O(ln(ln(n))) or O(n!)

O is not trivial to determine for many realistic cases.
__________________
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 09-14-2006, 11:44 AM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

What are you guys talking about? I've never even heard of Oh notation.
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-14-2006, 12:56 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,276
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 'BigOh' Notation

"Big-O" notation is a way to characterize functions. The definition is:
f(x) is in O(g(x)) if k*g(x) > f(x) for all x >N, and some constants k.

There are two aspects of a program that are usually measured with Big-O notation: memory usage and processing time (steps used). For a a given program, suppose that m(x) is the memory usage, and p(x) is the processing time, based on an input x.

If m(x) is O(1), then it used a fixed amount of memory, regardless of x.
If m(x) is O(x), then it is linearly related to x, or fixed. If m(x) is O(1), it is also O(x).
If m(x) is O(x^2), then it is quadraticly related to x. Obviously, the larger the function, the more of a memory hog our program is.

Similar analysis can be applied to p(x). It's usually not too hard to get m(x) with a low Big-O, but p(x) can be more of an issue. Sorting is a classic problem, which is easy to code in O(x^2), but cannot be gotten down to O(x). This means processing time MUST grow faster than the number of items being sorted. I wrote a program a while back that I estimated to be O(((x!)!)!). Needless to say, it became an issue to run it on any kind of useful data.
__________________
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
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


All times are GMT -5. The time now is 01:14 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