473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help determining Big O function to describe operation trip count

2 New Member
I have done some searching on Google, and from what I understand, big O is referring to the magnitude of the trip count. In essence, it's an approximation of the trip count, not an exact value like done in most of your ordinary math classes, correct?

Expand|Select|Wrap|Line Numbers
  1. for ( j=0; j < n; j++ ) 
  2. {
  3.     for ( k=0; k <= j; k++ )
  4.         A[j] = A[j] + C[k]*B[j];
  5. }
  6.  

so what exactly is the bigO for that code block? the outer loop runs N times. The inner loop runs J + 1 times, right? Since k = 0 and k <= to J, not < J.
then, J runs N times. So would it be something like N*N+1? I'm totally confused. any help would be much appreciated!
Nov 26 '08 #1
5 3197
ValValVal
27 New Member
In the program inner loop runs times depending on the outer loop.

Expand|Select|Wrap|Line Numbers
  1. for ( j=0; j < n; j++ )  
  2.     for ( k=0; k <= j; k++ ) 
  3.         A[j] = A[j] + C[k]*B[j]; 
When it runs in 1st outer loop it runs 1 time, in 2nd- 2 times in 3rd- 3 times.
So we can sum up the amount of time the expression
Expand|Select|Wrap|Line Numbers
  1.    A[j] = A[j] + C[k]*B[j]; 
will be run is

1+2+3+...+n
which is sum of arithmetical progression.
It equals n(1+n)/2 =(n*n+n)/2

so my guess big O of A[j] = A[j] + C[k]*B[j]; is (n*n+n)/2.

hope it helps,
Val
Nov 27 '08 #2
JosAH
11,448 Recognized Expert MVP
@ValValVal
Which boils down to a big-Oh of n^2 (just take the factor with the highest exponent).

kind regards,

Jos
Nov 27 '08 #3
KalEl
2 New Member
Okay I see what you did there, but I don't understand the division of two. Is that because there are two loops nested in one another? If so, I think I get it, thanks alot! Appreciate it if you could clear this up as well.

Thanks a bunch and happy turkey day!
Nov 27 '08 #4
ValValVal
27 New Member
No it is just that to calculate
1+2+3+...+n
I looked up handy formula
S(n elements of arithmetical progression)=n*(1+n)/2

Good Turkey Day,
Val
Nov 27 '08 #5
JosAH
11,448 Recognized Expert MVP
@KalEl
You want to add 1+2+3+ ... + n; assume n == 6 for example; the following figures show those numbers twice, one with asterisks and another one with capital Os. Combine those two figures: you have 6*7 == 42 symbols which is twice what you needed, so when you want to add 1+2+3+4+5+6 you have 6*7/2 == 21 symbols. In general when you add 1+2+3 ... n you have (n*(n+1))/2 == (n*n+n)/2 symbols.

Expand|Select|Wrap|Line Numbers
  1.                *
  2.             *  *
  3.          *  *  *
  4.       *  *  *  *
  5.    *  *  *  *  *
  6. *  *  *  *  *  *
  7.  
  8.  
  9. O  O  O  O  O  O
  10. O  O  O  O  O
  11. O  O  O  O 
  12. O  O  O
  13. O  O
  14. O
  15.  
  16.  
  17. O  O  O  O  O  O
  18. O  O  O  O  O  *
  19. O  O  O  O  *  *
  20. O  O  O  *  *  *
  21. O  O  *  *  *  *
  22. O  *  *  *  *  *
  23. *  *  *  *  *  *
  24.  
kind regards,

Jos
Nov 27 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2520
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
5
2145
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
14
2709
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in=...
1
4220
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
11
5978
by: Karl Irvin | last post by:
My program looks like this: Dim db As DAO.Database, rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType = 'Invoice'") Do some...
3
1820
by: Luke | last post by:
I'm pretty stuck at the moment and wondering if anyone can spot the problem. Trying to create a function that will read a text file into a list and return that list. I wrote the following...
1
1682
by: phrnck | last post by:
Hey all, I'm updating and adapting a gallery-type website that was done in FrontPage, in an old version. I've gotten most of it to work in modern browsers, but am stuck on one function... I am...
53
4890
by: Aaron Gray | last post by:
Due to M$'s stupidity in not making DOMElements first class citizens the following will not work :- function isElement( o) { return o instanceof Element } It works for FF, Opera and Safari.
21
479
by: coolguyaroundyou | last post by:
See the below code: void func(int x) { printf("%d",x); } int main() { int j=0;
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.