473,662 Members | 2,524 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 3201
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
2528
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 would be returned an instance of the class. The actual application I'm interested in writing would either have simple type attributes (int, string, etc.), or attributes using types already defined in a c-extension, although I'd prefer not to...
5
2151
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 called function, I am using p1->find(1) which is returning a valid iterator and not going to the end. I am returning p1 from the called function. But in the calling function, find(1) is going to the end, i.e unable to find the key 1, which was...
14
2724
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= 0; char *aString = 0; char *bString = 0; MY_NUM *a;
1
4236
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. From the log it looks like the problem happens when 2 threads insert 1 record each in the same table and then try to aquire a NS (Next Key Share) lock on the record inserterd by the other thread. Thanks Rohit
11
5987
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 work rst.close
3
1830
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 function and saved it as 'fileloader.py' def fileload(fname): infile=open(fname) dates = times=
1
1697
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 hoping someone can take a look and see where my trip-up lies. I've included just a snip from the html - where the debugger stops, thinking the problem is in the external js. Thanks in advance for any guidance!! Really stuck on this!! here is the...
53
4938
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
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8546
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.