The first principle thinking

Karthick RamjeeKarthick Ramjee
3 min read

Breaking down complicated problems and generating original solutions.

Overview

  • In theory, first-principle thinking requires you to dig deeper and deeper until you are left with only the foundational truths of a situation.

    • It is a cycle of breaking a situation down into the core pieces and then putting them all back together in a more effective way. Deconstruct then reconstruct.
  • In practice, you don't have to simplify every problem down to the atomic level to get the benefits of first-principle thinking. You just need to go one or two levels deeper than most people.

    • One example that comes to my mind while writing this article (relating to computer science).

      • We do have many databases that we can choose from when building a product. We just need to go deeper as to why we need to choose A vs B.

        • Is it because of scalability issues?

        • Or is it because of some XYZ feature that's present in one (Say B) which is missing in the other (Say A)? If so, why A is missing that feature?

      • If we could think and conclude by choosing B, we could at that point understand the fundamentals and the limitations that one offers over the other.

      • Also, another way of thinking would be to do an in-house or open-source solution if we have all the resources and time to execute it (if and only if we understand the fundamentals).

  • First principles thinking sets you on a different trajectory.

    • "I tend to approach things from a physics framework and boils down to the most fundamental truth," Musk said in an interview.
  • The human tendency for imitation is a common roadblock to first-principle thinking.

  • If you want to enhance an existing process or belief, continuous improvement is a great option. If you want to learn how to think for yourself, reasoning from first principles is one of the best ways to do it.

References

The below video clearly explains what this thinking is all about from Elon Musk.

Bonus content

Question 3:

Explanation:

  • We can have odd ("aba") and even ("bb") palindromes.

  • We just need to expand around the centre to find the longest palindrome.

    • We iterate the array with (i, i) and (i, i+1) for odd and even cases and then we expand left-- and right++ to find the longest palindrome.

    • Once we get the maximum length from the above cases, we just need to compute the start and end with the current i-th index.

Solution:

class Solution {

    /**
        We ultimately get the maximum length at which we can expand around the center
     */
    private int expandPalindrome(String s, int left, int right) {
        while(left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            left--;
            right++;
        }
        // Since the last iteration would have crossed the boundary we added -1
        return right - left - 1;
    }

    public String longestPalindrome(String s) {
        int len = s.length();
        int start = 0, end = 0;
        for(int i=0;i<len;i++) {
            // odd palindromes
            int point1 = expandPalindrome(s, i, i);
            // even palindromes
            int point2 = expandPalindrome(s, i, i+1);
            int maxLength = Math.max(point1, point2);
            if(maxLength > (end - start)) {
                // Left max
                start = i - (maxLength - 1) /2;
                // Right max
                end = i + maxLength / 2;
            }
        }
        return s.substring(start, end + 1);
    }
}

Next problem:

In the next post, I will cover the below problem.

0
Subscribe to my newsletter

Read articles from Karthick Ramjee directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Karthick Ramjee
Karthick Ramjee

Software developer from India!