DEV Community

Somuya Khandelwal
Somuya Khandelwal

Posted on • Edited on

DAY 40 Heaps and Bits: Merging Logic with Creativity

Hello Everyone!

The last topic of Week 8 was about Heap Management and Bit Manipuration where we learned that efficient and creative thinking goes hand in hand. Solving modern challenges was as if one were trying to integrate reason into both the handling of the most general data and into calculations of on-off switchings.


Challenges of the Day

  1. Add Binary (Easy Level)

    • Write a function, which takes two arguments in form of binary strings and returns the sum of these binary numbers in form of binary string.
    • Approach:
      • Simulated binary addition using bit manipulation principles: Concatenated bits from the two strings beginning with the least signifying bit of the two strings. Carried over the remaining, handled it in the same way as to conventional addition, and it was done on a barter basis. Constructed the result up from scratch and reversed the result at the end in order to make it easier to work with.
    • Why It Was Fun: Using binary strings befuddled me – it was like solving simple addition, subtraction, division and multiplication but computer coding style. Carry simulation and the guarantee of the selected protocol’s accuracy was a very interesting endeavor.
  2. Median of a Data Stream (Hard Difficulty)

    A more practical use will be to constantly supply a data stream with numbers and calculate median instantly as the stream increases in length.

    • Approach:
      • Used two heaps: –A list that is a max-heap for the set of numbers less than the median for the sequence at hand. One min-heap for managing the larger half of unexamined data, one for the smaller half. – Always leveled the heaps after some additions so that they could be nearly of the same size. Invented the median depending upon the current state of heaps, such as the average of the tops or single middle value.
    • Why It Was Fun: Observation of the heap balance itself during numbers addition and subtraction make it touch the real-time system where every added or subtracted number is done in a way that the result is well balanced.

Highlights of the Day

  1. Bit-Level Arithmetic:

    Despite that Add Binary was a great exercise in understanding the process of how the addition of two binary numbers works on the most basic levels, it did help to make further observations about the process of carry propagation.

  2. Real-Time Data Management:

    In the Find Median from Data Stream, it was shown how heaps could be used to control and ordered data in environments that are constantly evolving.

  3. Adaptable Techniques:

    Both problems involved modifying logic flexibly – from spreading a carry between bits in the process of addition to balancing heaps for real-time median determination.


Key Takeaways

  • Bit Manipulation is a Core Skill:

    Challenges such as Add Binary demonstrate how important binary computations are especially for effective and or basic calculations.

  • Heaps Simplify Dynamic Problems:

    The two-heap solution of Find Median from Data Stream problem is conceivable to organize an efficient way in handling streaming data.

  • Think Step by Step:

    Both challenges focused on the issue of approaching problems as a sequence of subproblems, guaranteeing that each of them was solved effectively at every stage.


Reflections

The Add Binary problem was rather different and a great representation of how you can take something simple, like numbers in binary form, and turn it into a problem. On the other hand, Find Median from Data Stream was much more dynamic and was both accurate and adjusted to the current state of the stream. Together, these tasks proved the effectiveness of the union of concepts as a basis for creating efficient algorithms.


What’s Next?

The Week 8 is over and now it is time to proceed to the Week 9, which will be concentrated on Dynamic Programming, Graph Exploration, and Greedy Algorithms. I believe they will increase my usage of logical thinking and optimization to the next level.

It was my pleasure having you here with me, thank you for following me. They mean let’s move on with solving problems, with learning processes, and with personal development.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay