Go Back  HTML Forums - Free Webmaster Forums and Help Forums > COMMUNITY NETWORKING > The Lounge
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 03-27-2008, 11:22 PM
  #1
bsxiong
Super Deity (Level 18)
 
bsxiong's Avatar
 
Join Date: Jul 2004
Location: Twin Cities
Posts: 1,083
iTrader: (0)
bsxiong is on a distinguished road
algorithm help

Input: a list of items, along with n, the number of items in the list
Output: a message telling whether the list contains any duplicates.
Algorithm:
For i = 1 to n-1
........For j = i+1 to n
................If the i’th item equals the j’th item
................output ‘The list contains a duplicate’
................stop
Output ‘the list does not contain any duplicates’
Stop
(a) What is the fewest possible number of item comparisons done by the algorithm?


anyone. I have no idea how to read this
__________________

I wish i wasn't so bad, then maybe i would be badder. My existence is not just for me, but for everyone around me that i affects.
bsxiong is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-28-2008, 05:16 AM
  #2
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 5,880
iTrader: (0)
coothead is a jewel in the roughcoothead is a jewel in the roughcoothead is a jewel in the rough
Hi there bsxiong,
Quote:
What is the fewest possible number of item comparisons done by the algorithm?
One, if the first two items provided the match.

If the last two items provided the match then the the total number of comparisons/iterations would be...
n!/((n-2)! x 2) in the example below this would equate to 45
...of course, this value is also the total number of iterations for no matches.
Code:
<script type="text/javascript">

   var a=[1,2,3,4,5,6,7,8,9,0];
   var n=a.length;
   var b=0;
   var c,i,j;

window.onload=function() {
for(i=0;i<n-1;i++) {
for(j=i+1;j<n;j++) {
   b++;
if(b==1){
   c='iteration';
 }
else{
   c='iterations';
 }
if(a[i]==a[j]){
   alert('duplicate found after '+b+' '+c);
   return;
   }
  }
 }
   alert('no duplicate found after '+b+' '+c);
}
</script>
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-28-2008, 06:17 AM
  #3
bsxiong
Super Deity (Level 18)
 
bsxiong's Avatar
 
Join Date: Jul 2004
Location: Twin Cities
Posts: 1,083
iTrader: (0)
bsxiong is on a distinguished road
WOW! thanks coothead. Youre a genius!
__________________

I wish i wasn't so bad, then maybe i would be badder. My existence is not just for me, but for everyone around me that i affects.
bsxiong is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-28-2008, 08:28 AM
  #4
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 5,880
iTrader: (0)
coothead is a jewel in the roughcoothead is a jewel in the roughcoothead is a jewel in the rough
No problem, you're welcome.
p.s.
I believe that the word genius is reserved for the likes of Albert Einstein rather than that 'bald headed old fart' known as coothead.

Comments on this post
Pegasus agrees: I disagree. BHOF can be geniuses, too.
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-30-2008, 02:59 PM
  #5
Vege
♥♥♥
 
Vege's Avatar
 
Join Date: Sep 2004
Location: Finland
Posts: 2,500
iTrader: (0)
Vege will become famous soon enough
are you forced to use that algorithm?
__________________
I read the bible
Specially pg.681
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-30-2008, 03:04 PM
  #6
bsxiong
Super Deity (Level 18)
 
bsxiong's Avatar
 
Join Date: Jul 2004
Location: Twin Cities
Posts: 1,083
iTrader: (0)
bsxiong is on a distinguished road
yes, unfortunately i have to use it
__________________

I wish i wasn't so bad, then maybe i would be badder. My existence is not just for me, but for everyone around me that i affects.
bsxiong is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  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
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:18 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.