The Greedy Gardener: A Simple Tale of Algorithms
ved a gardener named Prashant. He had two ways of planting flowers in his garden Greedy and Non-Greedy.1. The Non-Greedy WayOne day, Prashant wanted to count all the even-numbered
Written by Prashant Basnet
More from the writer
ved a gardener named Prashant. He had two ways of planting flowers in his garden Greedy and Non-Greedy.1. The Non-Greedy WayOne day, Prashant wanted to count all the even-numbered
ht arborescence (MWA) problem is a fundamental problem in graph theory with applications in:Network design: Finding optimal broadcast trees (e.g., in telecommunication networks).Transportation &a
f the LCA problem and how to solve each one with slight modifications to the core algorithm.1. Basic LCA Problem Problem: Find the LCA of two nodes p and q in a binary tree (both nodes guaranteed to e
e locally optimal choices at each step with the hope that these choices will lead to a globally optimal solution. They are particularly useful for optimization problems where you want to find the best
ms. In one operation, you must:Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.Subtract x from every
nbsp;is a problem where we need to find a subsequence of three numbers in an array (nums[i], nums[j], nums[k]) such that:Indices are in order: i < j < k Values satisfy: nums[
f integers where every element appears exactly twice, except for one element that appears only once. Find and return the single element that does not have a duplicate.Input: [1, 1, 2, 3, 3,
some problems are deceptively simple to describe but incredibly challenging to solve.One such problem is the Hamiltonian Cycle Problem, a classic puzzle that has fascinated researchers for decade
problem.Greedy algorithm makes the decision at every point choosing the local minimum or maximum depending on the optimization type.Here we want to find shortest path from S to E This is how the greed
dream company. The interviewer slides you a problem about scheduling meetings or merging overlapping intervals. Your heart skips a beat this is one of the most common and trickiest topics i
recommended for you
that focuses on speed, memory safety, and parallelism. It was developed by Mozilla and has been gaining popularity for its ability to provide memory safety without using a garbage collector.Why Shoul
numbers using lambda calculus. a foundational framework in mathematical logic and computer science. In essence, they encode numbers using functions rather than conventional numeric symbols.Why study C
straction applied to an argumentReduction replaces a redex with the result of applying the function.Beta Reduction:The process of applying the function to its argument. The process of replacing the bo
& how they interact through application & abstraction. It's a foundational mathematical framework that models computation in its purest form.Key concepts:Variables represents data or valuesFu
irs types. For example:+ is mapped to the type , Int -> Int -> Int y is mapped to the type Int Lambda Expressions & Types:Each lambda expression can be typed based on it's structure. The ty
relation that describes when one type can be used in place of another type. It's more like flexible version of type equality.Y -> XY -> X <: XY -> X -> XY The notation we are seeing is
s first understand the tools to solve it:Constraint Solving in type inference involves finding a way to make different type expressions agree with each other according to a set of rules.What are const
maps variables names to theirs types. For example:+ is mapped to the type , Int -> Int -> Int y is mapped to the type Int Lambda Expressions & Types:Each lambda expression can be typed bas
ages, type checking is done at compile time. This means that the types of all variables must be known before the program runs.Advantages:Early detection of type errors.Potential for optimizations duri
ess, particularly in the context of type checking and type inference, we can use analogies to make them easier to grasp.Soundness and completeness are two properties that describe the reliability of a
You are given a non-negative integer array nums. In one operation, you must:
Example 1:
Example 2:
First Approach:
Analysis:
The quadratic complexity comes from:
Why Unique Elements = Operations:
Key Point: