Python Forum
Floor approximation problem in algorithm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Floor approximation problem in algorithm
#3
(Dec-14-2022, 02:40 PM)deanhystad Wrote: Please wrap posted code in Python tags.
Thanks for the head up, corrected.

(Dec-14-2022, 02:40 PM)deanhystad Wrote: I don't see how a binary search is applicable. A binary search would work if page_exists(k) returned False when k >= number of pages, but it doesn't sound like that is what it does. Instead, if I understand you correctly, page_exists(k) returns False if k >= number of pages or if page[k] doesn't have any adds.
Thanks again, I understand the reference to binary search algorithm was wrong.

(Dec-14-2022, 02:40 PM)deanhystad Wrote: The code below demonstrates the problem. last_page() finds the last page when pages are contiguous, but when I make a list of pages that has holes, it can grab the last page before one of the holes.
In the non-contiguous data set, last page found the hole between 10 and 14 and decide that was the end of pages.

Your implementation of a binary search is also incorrect. The end condition is not test == 0, it is test == last page. The way to know that you found the last page is max = min + 1.
Pages are always contiguous (update the main post, I forgot to report that in the first place); so no problem with the "holes", as there are any in this case.
Algorithms are still a new thing for me, so this helps a lot for the future. Thank you, I understand where the problem was.
Reply


Messages In This Thread
RE: Floor approximation problem in algorithm - by gradlon93 - Dec-14-2022, 03:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 1,377 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  Floor division problem with plotting x-axis tick labels Mark17 5 2,180 Apr-03-2022, 01:48 PM
Last Post: Mark17
Big Grin question about simple algorithm to my problem jamie_01 1 1,722 Oct-04-2021, 11:55 AM
Last Post: deanhystad
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 3,116 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Floor division return value Chirumer 8 3,916 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE
  a weired problem after restructing algorithm homepoeple 0 1,598 Jan-15-2020, 06:25 PM
Last Post: homepoeple
  mapping-camera-coordinates-to-a-2d-floor-plan fauveboyxuuki 0 2,594 Dec-10-2019, 10:34 PM
Last Post: fauveboyxuuki
  Floor Division cf. math.floor() Devarishi 3 2,292 May-22-2019, 06:35 AM
Last Post: heiner55
  Logic of using floor division and modulus for a different variable at different time SB_J 2 2,563 Nov-01-2018, 07:25 PM
Last Post: SB_J
  python result problem of an iteration algorithm for power allocation Jessica 1 2,718 Sep-07-2018, 08:08 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020