GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jun-2006, 10:25
Jokky Jokky is offline
New Member
 
Join Date: Jun 2006
Posts: 3
Jokky is on a distinguished road

Complexity Analysis


I'm starting to learn about Complexity Analysis and am finding my text a little hard to understand. I borrowed a book from someone to learn it and in the book it has a problem that asks:

Find the complexity of the function used to find the kth smallest integer in an unordered list array of integers.

CPP / C++ / C Code:
int selectkth(int a[], int k, int n)  {
	int i, j, mini, tmp;
	for (i = 0; i < k; i++) {
		mini = i;
		for (j = i+1; j < n; j++) 
			if (a[j]<a[mini])
				mini = j;
		tmp = a[i];
		a[i] = a[mini];
		a[mini] = tmp;
	}
	return a[k-1];
Last edited by LuciWiz : 22-Jun-2006 at 14:13. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 22-Jun-2006, 20:13
Blake's Avatar
Blake Blake is offline
Regular Member
 
Join Date: Nov 2005
Posts: 330
Blake is a jewel in the roughBlake is a jewel in the roughBlake is a jewel in the rough

Re: Complexity Analysis


It's O(nk). That's not a tight bound though.
  #3  
Old 23-Jun-2006, 13:05
Jokky Jokky is offline
New Member
 
Join Date: Jun 2006
Posts: 3
Jokky is on a distinguished road

Re: Complexity Analysis


Quote:
Originally Posted by Blake
That's not a tight bound though.

What do you mean by the above?
  #4  
Old 23-Jun-2006, 13:19
Blake's Avatar
Blake Blake is offline
Regular Member
 
Join Date: Nov 2005
Posts: 330
Blake is a jewel in the roughBlake is a jewel in the roughBlake is a jewel in the rough

Re: Complexity Analysis


If g(z) is a function, a tight bound on g is a function f(z) such that there exists constants c1 and c2 with c1f(z) < g(z) < c2f(z) for all z sufficiently large. In this case, for nk, we can find c2 but not c1.
  #5  
Old 03-Jul-2006, 20:17
Jokky Jokky is offline
New Member
 
Join Date: Jun 2006
Posts: 3
Jokky is on a distinguished road

Re: Complexity Analysis


I came up with the answer

f(n) = 0( m * n )

Would that be correct?
  #6  
Old 03-Jul-2006, 20:19
Blake's Avatar
Blake Blake is offline
Regular Member
 
Join Date: Nov 2005
Posts: 330
Blake is a jewel in the roughBlake is a jewel in the roughBlake is a jewel in the rough

Re: Complexity Analysis


What is m?
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Preferred program for audio input analysis e30 C++ Forum 2 11-Jun-2006 16:56
conversion double to float donaldk C Programming Language 5 12-Feb-2006 23:16
hashing help saiz66 C++ Forum 1 06-Jul-2004 06:16
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 02:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:11.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.