07 March 2018

UVA 10474 - Where is the Marble? (Explanation)

Problem Explanation 
After reading the problem what do you think? Is it a problem of linear searching or anything else? Yes you can solve it by one for loop or linear search. But I think this is not a good solution.
Good approach is using binary search algorithm.
The important information I found from the description is " She would count 1...2...3" that is Meena always count from the start.
So suppose you have 5 numbers like 5 5 5 5 5 then Meena will count the first one. So if you just implement the binary search algorithm then also it will not work. You have to ensure that if there are same number in the list. And to do this just decrees the value of end index of the algorithm.
Don't forget to sort data😜
Here is the sudo code

begin =0
end = array_size-1
while begin<=end
if key_alue and mid value are same then
index = data[mid] and end = mid-1
or if key_value is greater than mid value then
begin = mid+1
or if key_value is smaller  then mid value then
end = mid-1

If you need to see the code then just  click 

1 comment:

  1. 888casino New Jersey Review | December 2021 - JTM Hub
    › nj-casino-new › nj-casino-new 익산 출장마사지 Sep 4, 2021 — Sep 4, 2021 888casino New Jersey review including 정읍 출장샵 ratings, games, customer support and more. Read about our casino review & 나주 출장마사지 claim a 서귀포 출장샵 $2,500 risk-free  Rating: 3.9 14 votes 서울특별 출장안마

    ReplyDelete

UVA 10679 - I Love Strings!!