Maxing Out Your Code: Unleashing the Power of Best Conceivable Runtime (BCR)

Siddharth S
7 min readMay 12, 2024

Have you ever found yourself, whether in a coding interview or staring down the abyss of your latest project, wondering, “Is this the fastest my code could possibly run?

I’ve been there — sweating bullets over whether my algorithm could be faster, or just less embarrassing. Honestly, I can easily imagine screwing up my chances in an interview as soon as someone leans in and asks, “Can you do better?”

Can you do better?

How far will you go?

Well, fear not! Enter the hero of our story: the “Best Conceivable Runtime (BCR).” This isn’t just any metric; it’s your coding career’s fairy godmother, ensuring you never have to mutter “I guess that’s as good as it gets.”

What is Best Conceivable Runtime?

Simply put, Best Conceivable Runtime (BCR) is the superhero version of your algorithm — this is it at its theoretical best, under ideal conditions. It’s like dreaming of a perfect day where everything you do is super smooth and fast — BCR is that, but for your code. Going beyond this point? Not happening. Your tweaks and optimizations might hit BCR or get close, but they won’t surpass it.

BCR is like the high score in a video game that’s incredibly hard to beat. It serves as a benchmark for gauging the efficiency of algorithms by considering all the rules and limits you have to work with. This is super important in areas like sorting things, finding stuff, or navigating complex paths, where there are many ways to solve the problem, and picking the fastest one really matters.

It’s like BCR is telling you, “You’ve done what you can — it’s time to let go and move on!”

Meme of Captain america saying — Some people move on, but not us.

Shaping up your code with BCR

Here’s how you can use BCR to whip your algorithms into shape:

  1. Identifying the Lower Bound: Think of BCR as your magical map that shows the minimum number of moves needed to solve the problem. It doesn’t matter if you’re working with old-school tech like a Turing machine or something snazzier; this map points to the treasure marked ‘Fastest Possible Route’.
  2. Algorithm Design: When you’re crafting your algorithm, hitting close to the BCR is like hitting a bullseye. It means your algorithm is in top form! If your algorithm is lagging way behind the BCR, it’s a sign it might need a bit of a workout to catch up.
  3. Algorithm Comparison: BCR also works like a leaderboard. It sets the standard for comparing different algorithms that tackle the same problem. The closer an algorithm gets to the BCR, the more it’s considered a top contender.

To figure out the BCR, you usually have to dive deep into what the problem’s really about and the bare minimum processing needed to crack it. For instance, in sorting, think of the BCR as being influenced by the logarithmic factor — like in those comparison-based sorting algorithms that have a proven lower bound of 𝑂(𝑛log⁡𝑛).

Big Bang Theory GIF — Well, with that sorted out

Let’s work an example

Let’s look at interesting problem that can benefit from a BCR analysis:

Given two sorted arrays, find the number of elements in common. The arrays are the same length and each has all distinct elements.

Brute Force Approach

The brute force approach would involve checking each element against every other element, which leads to a quadratic time complexity, 𝑂(𝑛²).

function findCommonElements(array1, array2) {
let commonElements = 0;
for(const a1 of array1) {
for(const a2 of array2) {
if(a1 == a2) commonElements++;
}
}
return commonElements;
}

Achieving Best Conceivable Runtime (BCR)

Identifying Lower Bounds
Since we have to give each element at least a quick glance to check if it’s common or not, the best time complexity we can hope for is 𝑂(𝑛). It’s like making sure every guest at a party gets a hello — you can’t skip anyone! Now, let’s not forget that both arrays are sorted and perfectly matched in length. This is like having two dance lines moving in sync.

This setup screams for something slick like the Two Pointer approach. It’s like having a pair of skilled dancers moving down the lines — no need for everyone to dance with everyone else! With this smart move, we can steer clear of that clunky n² complexity and streamline it down to n. Efficient, right?

function findCommonElements(array1, array2) {
let i = 0;
let j = 0;
let commonCount = 0;

while (i < array1.length && j < array2.length) {
if (array1[i] === array2[j]) {
commonCount++;
i++;
j++;
} else if (arr1[i] < arr2[j]) {
i++;
} else {
j++;
}
}
return commonCount;
}

Space Complexity
The two-pointer method is like the ultimate dance duo of the coding world — slick, quick, and only needs a bit of room to show off its moves. Operating with just 𝑂(1) extra space, it doesn’t pack much more than a couple of pointers and a counter.

Why is this technique a champion for our problem? Because it’s not just playing around — it seriously uses the natural order of arrays to zip through and find matches without missing a beat. This method is a star when it comes to BCR, acing both time and space efficiency.

Here’s the clever bit: by smartly advancing the pointers — think of it as skipping over all the bad dance partners — you ensure each element gets its moment in the spotlight exactly once. This makes the two-pointer method not just a savvy choice but a practical one, especially when you’re dealing with big, bulky datasets.

Getting Good at BCR and Identifying Patterns

If you’re looking to boost your algorithm game — whether for nail-biting coding competitions, snagging that dream job interview, or just crafting sleeker software — getting a grip on Best Conceivable Runtime (BCR) analysis and spotting patterns is your golden ticket. Here’s how you can level up:

Understand the Problem Deeply

Before diving in, make sure you really get what the problem’s about. This means:

  1. Pinning down exactly what you’re dealing with — inputs, outputs, the whole shebang.
  2. Grasping any limitations or quirks of the data you’re working with.
  3. Thinking about those tricky edge cases and their sneaky impacts on potential solutions.

Study the Intrinsic Properties of the Problem

To nail the BCR, you need to:

  1. Figure out the bare minimum effort required. For example, in sorting, you won’t beat O(nlogn) with comparison-based methods — just like you can’t skip leg day and expect ripped quads.
  2. Consider any absolute limits on how fast or light your solution can be, given the nature of the beast.

Learn Common Algorithmic Patterns

Some patterns are just classic hits for tackling problems:

  1. Two-pointers: Your go-to for array or linked list shenanigans.
  2. Binary Search: When you need to find things in a sorted mess.
  3. Dynamic Programming: Saving past work to make future tasks a breeze.
  4. Backtracking: For when you need to try every flavor before choosing your ice cream.
  5. Divide and Conquer: Breaking big problems into cute, manageable chunks.
  6. Graph Algorithms: For all your networky, pathy needs.

Practice Regularly

  1. Hit up platforms like LeetCode or HackerRank. Start easy, then crank it up.
  2. Jump into coding contests. They’re like the sprint workouts of coding — fast, furious, and full of adrenaline.

Review and Analyze Solutions

After you solve a problem:

  1. Peek at what others did. It’s like checking the answers in the back of a math book but more socially acceptable.
  2. Break down why some solutions are sleeker, quicker, or just plain cleverer.

Learn from Mistakes

When things go south:

  1. Dig into what went wrong — no shame, it’s all part of the game.
  2. Study the champion solutions. There’s always a next time to shine.
  3. Circle back to similar puzzles to make sure the lesson sticks.

Teach Others or Write About Your Solutions

Nothing cements knowledge like teaching it. Whether you’re blogging your brilliance or tutoring a buddy, it’s all good. (Shameless plug)

Stay Updated

The world of algorithms never stands still:

  1. Devour the latest research, blogs, and breakthroughs. (Subscribe to my blog if you must)
  2. Keep an eye on the new cool kids on the algorithm block.

Conclusion

To wrap it up, getting cozy with Best Conceivable Runtime (BCR) and recognizing slick patterns is like having a secret weapon in the world of algorithm design — super handy for those edge-of-your-seat coding competitions and brain-busting tech interviews. It all starts with getting to the heart of the problem, throwing some classic algorithmic moves, and learning like it’s going out of style.

Hitting the coding platforms regularly, mixing it up in discussions, and sharing your coding conquests can seriously amp up your code-fu. These strategies aren’t just about getting good — they make you a coding ninja, ready to tackle the gnarliest of challenges and stay sharp in the tech world that just won’t quit evolving.

So, keep practicing, stay curious, and maybe teach a thing or two. Your future self — and your impressed peers — will thank you.

--

--

Siddharth S

Engineer, Nerd, Spiritual, life long learner & explorer.