|
||||||
| Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||||
|
Well, the Landau notation is often used to describe how the size of the digital input data affects an computer software algorithm's usage of computational resources. It is also used in many other scientific and mathematical fields to provide similar estimations.
__________________
Like an angel without a sense of mercy. |
|
|||||
|
Expanding on what R-G said:
O() actually defines a family of related functions whose dominant term is less than or equal to the function specified. The technical definition is that a function g(x) is O(f(x)) if there are two constants, C and X, such that for all x>X, g(x) < C*f(x). Usually, people will list the most conservative O() possible for the worst-case scenario. At work, we had a piece of code that was O(x^2), which ran just fine for our test data (around 100 records), but became very unusable for some of our customers (around 1,000,000 records). The processing time jumped from around 10,000 to around 1,000,000,000,000 time units. When we changed the code to make it O(x), it resulted in drastically improved performance for our larger customers (16 hours down to 15 minutes)
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
As an example: 5x^2 + 3x+2 is O(x^2). The reason is that 6x^2 > 5x^2+3x+2 when x>4. The x^2 term is the dominant term for 5x^2 + 3x + 2
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
| Sponsored Links |
|
|
|
|||||
|
Because 6x^2 will always be larger than 5x^2+3x+2.
Big oh-notation basically describes how an algorithm acts. Which is why the function Winged described is considered O(x^2). Take the following code for example: Code:
for(int i = 0; i < n; i++)
if(i % 2 == 0)
echo "Even Number";
}
}
`n` assignments [i = 0 each time the loop is ran] `n` comparisons [ i < n?] `n` increments [i++] `n` comparisons [ i % 2 == 0? ] `1` construct [ echo "Even Number" ] Assuming each unary or binary operator runs in constant time, this algorithm would really have a `4n` run time. Which is linear. Since Big-Oh only considers how the function acts it is said to be O(n)
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
It is 4n because there are 4 "instructions" that are ran n times.
Yes, it is O(n) and not O(4n) because the 4 is a constant which is ignored. Both O(4n) and O(n) says the algorithm is linear. Since oh-notation is only used to described how the algorithm grows [linearly, quadratically, exponentially, logarithmically, ect...] the constant has no purpose.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| pointers....or arrays | the_code_charmer | C and C++ | 4 | 01-16-2008 11:00 AM |
| Struct notation | kenna | C and C++ | 1 | 12-23-2007 12:55 PM |
| Big O notation | shinta | General Programming | 2 | 11-18-2007 10:36 AM |
| Variable Standards | Saint | General Programming | 5 | 05-14-2007 11:25 AM |
| 'BigOh' Notation | DansTransAM | General Programming | 3 | 09-14-2006 11:56 AM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 65%