• greenhorn@lemm.ee
    link
    fedilink
    English
    arrow-up
    11
    ·
    2 days ago

    My friend has some upcoming electrical work in his house, can you explain how to use binary search in this instance so I can tell him?

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      12
      arrow-down
      1
      ·
      2 days ago

      Oh, well, you switch off half the fuses, then you go check the wire.
      Let’s say the wire still has power on it, so now you know that none of the fuses in that half affected it (which you can turn back on now).

      Then you do the same thing again with the other half of the fuses, i.e. you switch off half of the fuses in that half and go check the wire.
      Now, let’s say the wire is dead, so now you know that the fuse you want is in this quarter.

      So, then you flick off half of the fuses in that quarter and check the wire again, and so on.

      With every step, you eliminate half of the remaining fuses, so for 60 fuses, you need at most 6 steps (which is the logarithm for base 2 of 60).

      • greenhorn@lemm.ee
        link
        fedilink
        English
        arrow-up
        4
        ·
        1 day ago

        Ah, obvious now, thank you. For some reason my his brain couldn’t get to actually turning off half the breakers in one go

        • intensely_human@lemm.ee
          link
          fedilink
          arrow-up
          2
          ·
          1 day ago

          Binary search requires splitting the search space into two halves, then asking “is it in that half?”

          Normally the “is it in that half?” check involves a numerical comparison: test value versus target value. “higher or lower” here gets you to “is it in that half?”

          So finding the midpoint seems like a core part of the process, but really that’s just a shortcut in the case of comparable values, that helps you split into two and check membership.

          I admit I couldn’t think of that either: just alter half the items and check for effect.

      • dan@upvote.au
        link
        fedilink
        arrow-up
        7
        ·
        2 days ago

        Once you figure out which one it is, label it! I labeled all the breakers in my panel when I moved in to my house, as half of the existing labels were wrong (no idea why).

          • dan@upvote.au
            link
            fedilink
            arrow-up
            6
            ·
            2 days ago

            Why are so many mislabeled though? It’s not like the loads are being changed every day. I had two breakers labeled “dishwasher” and neither of them were the dishwasher!

            • rumba@lemmy.zip
              link
              fedilink
              English
              arrow-up
              3
              ·
              2 days ago

              I had two breakers labeled “dishwasher”

              Electrical work is one of those things that’s not difficult to do as long as you don’t mind it being some level of wrong but relatively hard to do 100% to code right without training. With most of the wrong ways, the project still works, but it’s dangerous and/or hard to maintain. Professional work is expensive, so you end up with a LOT of handyman work that’s poorly labeled, poorly run, poorly designed or some combination of the three.

              My best guess would be that at some point, running the dishwasher tripped the breaker. They had space so they added a breaker below it and moved the line to the new breaker. Then it still tripped, so they moved the line at the dishwasher circuit that was already close by.

              Either the original line has a fault in it (old aluminum lines can have junction issues over time) or the dishwasher had a short in it, and they either replaced the dishwasher, or the new line they chose didn’t fail.

        • phughes@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          2 days ago

          I keep a spreadsheet with every outlet/light in every room on it and their corresponding breakers. Much easier since breakers often span multiple rooms, sometimes only powering one or two fixtures in each.

    • spongebue@lemmy.world
      link
      fedilink
      arrow-up
      30
      arrow-down
      2
      ·
      2 days ago

      Turn off half the breakers. See if you still have power where you need to go. That will tell you which half it’s on. Turn off half of those breakers, repeat.

    • PM_Your_Nudes_Please@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      1 day ago

      Turn off half the breakers. Now you know which half the outlet is on, based on whether or not it has power. Repeat.

      For instance, let’s say you have 100 breakers. You turn off the first 50. Your target outlet still has power. So now you have divided the potential number of breakers by half, and you know the breaker is somewhere in 51-100.

      So you cut that in half, and turn off 51-75. Your outlet is now dead, so you know it’s somewhere in the 51-75 range that you just turned off; if it were still on, it would be somewhere between 76-100.

      So now you reset 51-63, while leaving 64-75 off. It is still dead, so you know it is somewhere between 64-75.

      Maybe now you turn on all of the odd breakers, leaving the evens off. It is still dead, so you know it must be 64, 66, 68, 70, 72, or 74. Reset the first three. Your outlet has power now, so it must be one of the first three.

      Flip 64 and 66 off. If you get lucky, your outlet still has power and you know it is 68. But you get unlucky, and it is dead. So now you know it must be either 64 or 66.

      Flip 64 back on. If it has power, you know it’s 64. If it doesn’t, you know it’s 66.

      We just eliminated 99 breakers and found the correct one using only 7 tests. Because each test eliminated half of the potential values, it whittles things down very quickly. We went from 1-100, to 51-100, to 51-75, to 64-75, to the evens between 64-74, to only 64/66/68, to 64/66, and finally landed on 66 as the correct breaker. If we had gotten lucky earlier, we could have done it in 6 instead. If you had simply started with breaker 1 and worked subsequently, it would have taken 66 trips to the breaker box to figure out.

      Where binary search really excels is with large data sets. Even if it had been 1000 breakers instead of 100, it still would have only taken an extra three or four searches (1-1000 > 1-500 > 1-250 > 1-125 > 1-75… etc…) to narrow it down.