Calculating Complexity of a Problem-Calculation

  • Thread starter Thread starter kioria
  • Start date Start date
  • Tags Tags
    Complexity
AI Thread Summary
The discussion centers on calculating the number of distance calculations in a program that processes N points in Cartesian coordinates. The user has implemented a solution in C and is seeking to express the complexity of their algorithm in Big-Oh notation. They initially present a function f(x) related to the number of calculations but later clarify that it should be f(N). The key focus is on determining the correct form of f(N) and identifying a suitable g(N) to express the relationship f(N) = O(g(N)). The conversation emphasizes the need to analyze the number of loops and operations performed per loop to derive the complexity accurately. The user expresses confusion about the constants involved in Big-Oh notation and seeks guidance on how to properly formulate their function and find the constant C.
kioria
Messages
54
Reaction score
0
I have been given an assignment, a small one, which simply takes in number of points in cartesian coordinate format: (x, y) - then - the assignment specified that the program needed to calculate distances of every permutation possible - then return with the set(s) of points that had the shortest distance.

The problem given is simple, and I have coded in C - works perfectly OK.

But here's the problem:

What is the number of distance calculations executed by your program for an input instance of "N" points, as a function of "N", expressed in Big-Oh notation? JUSTIFY your answer.

I know that my program (which I think is efficient enough at this stage) calculates in this many steps:

f(x) = \sum_{n=2}^N (x - 1)

I also know that Big-Oh notation is something that f(x) is asymptotic to. For example:

g(x) = O(f(x)) = c.f(x) = c.\sum_{n=2}^N (x - 1)

Is this correct way of looking at the Big-Oh notation? How would I find the value of c?

Thanks

 
Last edited:
Computer science news on Phys.org
What's x? Presumably the complexity of your program, for an input of size N is
f(N) = [some function of N]
so I don't see where x comes into the picture.

Ultimately you want to be able to say that
f(N) = O(g(N))

meaning that there is some function g(N) such that your function
f(N) \leq C*g(N)
whenever N > k for some constants C and k of your choosing (k might be 0). C and k are whatever constants you need to make that inequality true. Depends on what f(N) is, so you need to get your f(N) into a more useful form.

(As a start, count how many times your program loops as a function of N, and how many operations it performs per loop.)
 
I messed up with my x's and N's, the top line should really be f(N). I am having trouble finding g(N) and the constant value C.
 
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...

Similar threads

Replies
1
Views
1K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
5
Views
1K
Replies
1
Views
1K
Replies
2
Views
3K
Back
Top