Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > University Math Help > Other Advanced Topics
Reply
 
Thread Tools Display Modes
  #1  
Old November 19th, 2009, 01:58 AM
Newbie
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
liberty is on a distinguished road
Default Algorithm

Let A be a 1- dimensional array with integers and "min" , "max", "number"
three integer numbers. find an algorithm that answers, if the value "number" is in the array e.g a [i] = number for some i, 1<= min <= i <= max <= n, and the complexity of the algorithms must be O(lgn)

I need some help on that! Thanks in advance!

Last edited by liberty; November 19th, 2009 at 08:41 AM.
Reply With Quote
Advertisement
 
  #2  
Old November 21st, 2009, 09:19 AM
CaptainBlack's Avatar
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 12,278
Country:
Thanks: 779
Thanked 4,001 Times in 3,227 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by liberty View Post
Let A be a 1- dimensional array with integers and "min" , "max", "number"
three integer numbers. find an algorithm that answers, if the value "number" is in the array e.g a [i] = number for some i, 1<= min <= i <= max <= n, and the complexity of the algorithms must be O(lgn)

I need some help on that! Thanks in advance!
The existence of max and min should not effect the problem, so you may as well answer the problem of finding an algorithm to determine if "number" is in the array of length n with (time) complexity O(\ln(n)) (or are we after the average complexity over all possible max and min?)

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno
Reply With Quote
  #3  
Old November 21st, 2009, 11:08 AM
Newbie
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
liberty is on a distinguished road
Default

Quote:
Originally Posted by CaptainBlack View Post
....
(or are we after the average complexity over all possible max and min?)
CB
hmmmmm......
The solution,(the algorithm) sould be implemented via a function (in a programming concept) and min max number should be arguments of the function. The function returns 1 if number is in the array and 0 otherwise. If the array was sorted, its binary searching that works. But the array is not sorted.
about the last question: hmm it talks about time complexity and not average time complexity...But its a good question anyway..I had not thought about that at all !
Thanks for your reply..it helps me.
Reply With Quote
  #4  
Old November 21st, 2009, 11:59 AM
Super Member
 
Join Date: Jan 2009
Posts: 592
Country:
Thanks: 69
Thanked 133 Times in 123 Posts
aidan will become famous soon enoughaidan will become famous soon enough
Default

Quote:
Originally Posted by liberty View Post
hmmmmm......
The solution,(the algorithm) sould be implemented via a function (in a programming concept) and min max number should be arguments of the function. The function returns 1 if number is in the array and 0 otherwise. If the array was sorted, its binary searching that works. But the array is not sorted.
about the last question: hmm it talks about time complexity and not average time complexity...But its a good question anyway..I had not thought about that at all !
Thanks for your reply..it helps me.
Your explanation made it foggier.

"min max number should be arguments of the function. The function returns 1 if number is in the array and 0 otherwise."

array[10][30][20][40][60][70]
Function MMN( min=13, max=37, num=60)

Should the function check for values outside the given minimum and maximum arguments?
I do not understand the reason for min/max being arguments to the function if you only want to know whether the number is in the array.

Reply With Quote
  #5  
Old November 21st, 2009, 01:25 PM
Newbie
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
liberty is on a distinguished road
Default

Quote:
Originally Posted by aidan View Post
Your explanation made it foggier.

"min max number should be arguments of the function. The function returns 1 if number is in the array and 0 otherwise."

array[10][30][20][40][60][70]
Function MMN( min=13, max=37, num=60)

Should the function check for values outside the given minimum and maximum arguments?
I do not understand the reason for min/max being arguments to the function if you only want to know whether the number is in the array.
Because the function may search in a sub array of the array.
Min max define the sub array.
In your example array[10][30][20][40][60][70]
10 is the first and 70 is the last. And there are 6 elements. If min = 1 and max = 6 and number is 20 function returns 1. Is there. But if min = 5 and max = 6 and number = 20 then function returns 0.Is not in that sub-array. But the worst (most difficult) case is for min = 1 and max = 6. Because the sub array in this case is the array. And the time complexity is dominated by this case.

Last edited by liberty; November 21st, 2009 at 01:41 PM.
Reply With Quote
  #6  
Old November 21st, 2009, 11:33 PM
CaptainBlack's Avatar
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 12,278
Country:
Thanks: 779
Thanked 4,001 Times in 3,227 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by liberty View Post
Because the function may search in a sub array of the array.
Min max define the sub array.
Which is why they are irrelevant for a worst case complexity since this must occur when min=1 and max=n

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno
Reply With Quote
  #7  
Old November 22nd, 2009, 07:37 AM
Newbie
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
liberty is on a distinguished road
Default

Quote:
Originally Posted by CaptainBlack View Post
Which is why they are irrelevant for a worst case complexity since this must occur when min=1 and max=n

CB
I agree..I have bad news..
The reason that i post this, was that my believe was that the question is wrong. You cant make an algorithm that it works in O(lgn) if the array is not sorted. (Beacause you must check all the elements, if the array is not sorted) And today i learned that this is true. I had asked if the question was wrong and if should be given that array is sorted, and they ansewred you must deal with the general case. But today i asked again and...
ok...
aidan, CaptainBlack,sorry and
MANY THANKS!!
Thank you guys.
Reply With Quote
  #8  
Old November 22nd, 2009, 08:11 AM
CaptainBlack's Avatar
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 12,278
Country:
Thanks: 779
Thanked 4,001 Times in 3,227 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by liberty View Post
I agree..I have bad news..
The reason that i post this, was that my believe was that the question is wrong. You cant make an algorithm that it works in O(lgn) if the array is not sorted. (Beacause you must check all the elements, if the array is not sorted) And today i learned that this is true. I had asked if the question was wrong and if should be given that array is sorted, and they ansewred you must deal with the general case. But today i asked again and...
ok...
aidan, CaptainBlack,sorry and
MANY THANKS!!
Thank you guys.
If the list is sorted then binary search should do this in O(ln(n))

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 01:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.