<![CDATA[अमन Mehara]]>https://amanmehara.com/https://amanmehara.com/favicon.pngअमन Meharahttps://amanmehara.com/Ghost 6.12Fri, 24 Apr 2026 02:33:39 GMT60<![CDATA[सांख्यकारिका - कारिका ४]]>दृष्टमनुमानमाप्तवचनं च सर्वप्रमाणसिद्धत्वात्।
त्रिविध

]]>
https://amanmehara.com/saankhykaarikaa-kaarikaa-4/6976e9ee44fd0100017eb136Mon, 26 Jan 2026 04:21:00 GMTदृष्टमनुमानमाप्तवचनं च सर्वप्रमाणसिद्धत्वात्।
त्रिविधं प्रमाणमिष्टं प्रमेयसिद्धिः प्रमाणाद्धि॥४॥

]]>
<![CDATA[श्रीमद्भगवद्गीता - अध्याय २ - श्लोक ३३]]>अथ चैत्त्वमिमं धर्म्यं संग्रामं न करिष्यसि।
ततः स्वधर्मं क

]]>
https://amanmehara.com/shriimdbhgvdgiitaa-adhyaay-2-shlok-33/696cbeed8db5fa0001ece73eSun, 18 Jan 2026 11:26:43 GMTअथ चैत्त्वमिमं धर्म्यं संग्रामं न करिष्यसि।
ततः स्वधर्मं कीर्तिं च हित्वा पापमवाप्स्यसि॥२-३३॥

]]>
<![CDATA[Coming soon]]>This is अमन Mehara, a site by Aman Mehara that's just getting started. Things will be up and running here shortly.

]]>
https://amanmehara.com/coming-soon/6963b29880ed450001943224Sun, 11 Jan 2026 14:24:24 GMT

This is अमन Mehara, a site by Aman Mehara that's just getting started. Things will be up and running here shortly.

]]>
<![CDATA[Design Patterns]]>In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to

]]>
https://amanmehara.com/design-patterns/696cd06a8db5fa0001ece77eSat, 13 Jun 2020 12:30:00 GMTIn software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations.

Creational Patterns

  • Abstract Factory
    Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  • Builder
    Separete the construction of a complex object from its representation so that the same construction process can create different representations.
  • Factory Method
    Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses.
  • Prototype
    Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype.
  • Singleton
    Ensure a class only has one instance, and provide a global point of access to it.

Structural Patterns

  • Adapter
    Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
  • Bridge
    Decouple an abstraction from its implementation so that the two can vary independently.
  • Composite
    Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of the objects uniformly.
  • Decorator
    Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
  • Facade
    Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
  • Flyweight
    Use sharing to support large numbers of fine-grained objects efficiently.
  • Proxy
    Provide a surrogate or placeholder for another object to control access to it.

Behavioral Patterns

  • Chain of Responsibility
    Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
  • Command
    Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
  • Interpreter
    Given a language, define a representation for its grammer along with an interpreter that uses the representation to interpret sentences in the language.
  • Iterator
    Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  • Mediator
    Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
  • Memento
    Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.
  • Observer
    Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
  • State
    Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
  • Strategy
    Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
  • Template Method
    Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template methods lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
  • Visitor
    Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

Reference

  1. Design Patterns: Elements of Reusable Object-Oriented Software
]]>
<![CDATA[Disjoint Set]]>A disjoint-set data structure maintains a collection \(\mathcal{S} = \{S_{1}, S_{2}, \dots, S_{k}\}\) of disjoint dynamic sets.

A weighted-union heuristic

Theorem 1

Using linked-list representation of disjoint sets and the weighted union heuristic, a sequence of \(m\) MAKE-SET, UNION, and FIND-SET operations, \(n\) of which are MAKE-SET

]]>
https://amanmehara.com/disjoint-set/696e3e3f44fd0100017eafb8Tue, 17 Mar 2020 12:30:00 GMTA disjoint-set data structure maintains a collection \(\mathcal{S} = \{S_{1}, S_{2}, \dots, S_{k}\}\) of disjoint dynamic sets.

A weighted-union heuristic

Theorem 1

Using linked-list representation of disjoint sets and the weighted union heuristic, a sequence of \(m\) MAKE-SET, UNION, and FIND-SET operations, \(n\) of which are MAKE-SET operations, takes, \(O(m + n \lg{n})\) time.

References

  1. Introduction to Algorithms, MIT Press
]]>
<![CDATA[Graph]]>Breadth-first search

Lemma 1

Let \(G = (V, E)\) be a directed or undirected graph, and let \(s \in V\) be an arbitrary vertex. Then for any edge \((u, v) \in E\),\( \delta (s, v) \leq \delta (s, u) + 1\).

Lemma 2

Let \(G = (V, E)\) be a directed or undirected

]]>
https://amanmehara.com/graph/696e3f4c44fd0100017eafd1Wed, 11 Mar 2020 12:30:00 GMTBreadth-first search

Lemma 1

Let \(G = (V, E)\) be a directed or undirected graph, and let \(s \in V\) be an arbitrary vertex. Then for any edge \((u, v) \in E\),\( \delta (s, v) \leq \delta (s, u) + 1\).

Lemma 2

Let \(G = (V, E)\) be a directed or undirected graph, and suppose that BFS is run on \(G\) from a given source vertex \(s \in V\). Then upon termination for each vertex \(s \in V\), the value \(v.d\) computed by BFS satisfies \(v.d \geq \delta (s, v)\).

Lemma 3

Suppose that during the execution of BFS on a graph \(G = (V, E)\), the queue \(Q\) contains the vertices \(\langle v_{1}, v_{2}, \dots, v_{r} \rangle\), where \(v_{1}\) is the head of \(Q\) and \(v_{r}\) is the tail. Then \(v_{r}.d \leq v_{1}.d + 1\) and \(v_{i}.d \leq v_{i+1}.d\) for \(i = 1, 2, \dots, r-1\)

Corollary 4

Suppose that vertices \(v_{i}\) and \(v_{j}\) are enqueued during the execution of BFS, and that \(v_{i}\) is enqueued before \(v_{j}\). Then \(v_{i}.d \leq v_{j}.d\) at the time \(v_{j}\) is enqueued.

Let \(G = (V, E)\) be a directed or undirected graph, and suppose that BFS is run on \(G\) from a given vertex \(s \in V\). Then, during its execution, BFS discovrs every vertex \(v \in V\) that is reachable form the source \(s\), and upon termination, \(v.d = \delta (s, v)\) for all \(v \in V\). Moreover, for any vertex \(v \ne s\) that is reachable from \(s\), one of the shortest paths from \(s\) to \(v\) is a shortest path from \(s\) to \(v.\pi\) followed by the edge \(v.\pi, v\).

Lemma 6

When applied to a directed or undirected graph \(G = (V, E)\), procedure BFS constructs \(\pi\) so that the predecessor subgraph \(G_{\pi} = (V_{\pi}, E_{\pi})\) is a breadth-first tree.

Theorem 7 (Parenthesis theorem)

In any depth-first search of a (directed or undirected) graph \(G = (V, E)\), for any two vertices \(u\) and \(v\), exactly one of the following three conditions holds:

  • the intervals \([u.d, u.f]\) and \([v.d, v.f]\) are entirely disjoint and neither \(u\) nor \(v\) is a descendant of the other in the depth-first forest.
  • the interval \([u.d, u.f]\) is contained entirely within the interval \([v.d, v.f]\), and \(u\) is a descendant of \(v\) in a depth-first tree, or
  • the interval \([v.d, v.f]\) is contained entirely within the interval \([u.d, u.f]\), and \(v\) is a descendant of \(u\) in a depth-first tree.

Corollary 8 (Nesting of descendants' interval)

Vertex \(v\) is a proper descendant of vertex \(u\) in the depth-first forest for a (directed or undirected) graph \(G\) if and only if \(u.d < v.d < v.f < u.f\).

Theorem 9 (White-path theorem)

In a depth-first forest of a (directed or undirected) graph \(G = (V, E)\), vertex \(v\) is a descendant of vertex \(u\) if and only if at the time \(u.d\) that the search discovers \(u\), there is a path from \(u\)to \(v\) consisting entirely of white vertices.

Theorem 10

In a depth-first search of undirected graph \(G\), every edge of \(G\) is either a tree edge or a back edge.

Topological sort

Lemma 11

A directed graph \(G\) is acyclic if and only if a depth-first search of \(G\) yields no back edges.

Theorem 12

TOPOLOGICAL-SORT produces a topological sort of the directed acyclic graph provided as its input.

Strongly connected components

Lemma 13

Let \(C\) and \(C^{\prime}\) be distinct strongly connected components in a directed graph \(G = (V, E)\), let \(u, v \in C\), let \(u^{\prime}, v^{\prime} \in C^{\prime}\), then suppose that \(G\) contains a path \(u \leadsto u^{\prime}\). Then \(G\) also cannot contain a path \(v^{\prime} \leadsto v\).

Lemma 14

Let \(C\) and \(C^{\prime}\) be distinct strongly connected components in directed graph \(G = (V, E)\). Suppose that there is an edge \((u, v) \in E\), where \(u \in C\) and \(v \in C^{\prime}\). Then \(f(C) > f(C^{\prime})\).

Corollary 15

Let \(C\) and \(C^{\prime}\) be distinct strongly connected components in directed graph \(G = (V, E)\). Suppose that there is an edge \((u, v) \in E^{T}\), where \(u \in C\) and \(v \in C^{\prime}\). Then \(f(C) < f(C^{\prime}\).

Theorem 16

The STRONGLY-CONNECTED-COMPONENTS procedure correctly computes the strongly connected components of the directed graph provided as its input.

References

  1. Introduction to Algorithms, MIT Press
]]>
<![CDATA[Tree]]>Binary Tree

A binary tree \(T\) is a structure defined on a finite set of nodes that either

  • contains no nodes, or
  • is composed of three disjoint set of nodes: a root node, a binary tree called its left subtree, and a binary tree called its right subtree.

The binary

]]>
https://amanmehara.com/tree/696e3ee644fd0100017eafc5Tue, 10 Mar 2020 12:30:00 GMTBinary Tree

A binary tree \(T\) is a structure defined on a finite set of nodes that either

  • contains no nodes, or
  • is composed of three disjoint set of nodes: a root node, a binary tree called its left subtree, and a binary tree called its right subtree.

The binary tree that contains no nodes is called the empty tree or null tree, sometimes denoted NIL.

Binary Search Tree

The keys in a binary search tree are always stored in such a way as to satisfy the binary-search-tree property: Let \(x\) be a node in a binary search tree. If \(y\) is a node in the left subtree of \(x\), then \(y.key \geq x.key\). If \(y\) is a node in the right subtree of \(x\), then \(y.key \leq x.key\).

Theorem 1

If \(x\) is the root of an \(n\)-node subtree, then the call INORDER-TREE-WALK(\(x\)) takes \(\Theta(n)\) time.

Theorem 2

We can implement the dynamic-set operations SEARCH, MINIMUM, MAXIMUM, SUCCESSOR, and PREDECESSOR so that each one runs in \(O(h)\) time on a binary search tree of height \(h\).

Theorem 3

We can implement the dynamic-set operations INSERT and DELETE so that each one runs in \(O(h)\) time on a binary search tree of height \(h\).

Theorem 4

The expected height of a randomly built binary search tree on \(n\) distinct keys is \(O(\lg{n})\).

Red-Black Tree

A red-black tree is a binary search tree with one extra bit of storage per node: its color, which can be either RED or BLACK. A red-black tree is a binary tree that satisfies the following red-black properties:

  • Every node is either red or black.
  • The root is black.
  • Every leaf (NIL) is black.
  • If a node is red, then both its children are black.
  • For each node, all simple paths from the node to descendant leaves contain the same number of black nodes.

Lemma 1

A red-black tree with \(n\) internal nodes has height at most \(2 \lg{(n+1)}\).

References

  1. Introduction to Algorithms, MIT Press
]]>
<![CDATA[Divide-and-Conquer]]>Divide the problem into a number of sub-problems that are smaller instances of the same problem.

Conquer the sub-problems by solving them recursively. If the sub-problem sizes are small enough, however, just solve the sub-problems in a straightforward manner.

Combine the solutions to the sub-problems into a

]]>
https://amanmehara.com/divide-and-conquer/696e413b44fd0100017eaff1Thu, 30 Jan 2020 12:30:00 GMTDivide the problem into a number of sub-problems that are smaller instances of the same problem.

Conquer the sub-problems by solving them recursively. If the sub-problem sizes are small enough, however, just solve the sub-problems in a straightforward manner.

Combine the solutions to the sub-problems into a solution for the original problem.

]]>
<![CDATA[Curiously Recurring Template Pattern]]>The curiously recurring template pattern (CRTP) is an idiom in C++ in which a class X derives from a class template instantiation using X itself as template argument. It is a form of F-bounded Quantification.

// The Curiously Recurring Template Pattern (CRTP)
template <class T>
]]>
https://amanmehara.com/curiously-recurring-template-pattern/696cd2f28db5fa0001ece799Sun, 26 Jan 2020 12:30:00 GMTThe curiously recurring template pattern (CRTP) is an idiom in C++ in which a class X derives from a class template instantiation using X itself as template argument. It is a form of F-bounded Quantification.

// The Curiously Recurring Template Pattern (CRTP)
template <class T>
class Base
{
    // methods within Base can use template to access members of Derived
};

class Derived : public Base<Derived>
{
    // ...
};

Some use cases for this pattern are:

  1. Static polymorphism
  2. Template metaprogramming techniques
]]>
<![CDATA[Calculus]]>Limits

\[ \lim_{x \to c} f(x) = L \]

Discontinuity

  • Removable Discontinuity
  • Jump Discontinuity
  • Essential Discontinuity

Derivatives

]]>
https://amanmehara.com/calculus/696eef0b44fd0100017eb064Sat, 24 Aug 2019 12:30:00 GMTLimits

\[ \lim_{x \to c} f(x) = L \]

Discontinuity

  • Removable Discontinuity
  • Jump Discontinuity
  • Essential Discontinuity

Derivatives

]]>
<![CDATA[Category Theory]]>Category

A category is a collection of objects that are linked by arrows.

Morphisms

Universal Construction

Functor

functor is a map between categories.

Definition

Let C and D be categories. A functor F from C to D is a mapping that:

]]>
https://amanmehara.com/category-theory/696f00ca44fd0100017eb0f6Tue, 30 Jul 2019 12:30:00 GMTCategory

A category is a collection of objects that are linked by arrows.

Morphisms

Universal Construction

Functor

functor is a map between categories.

Definition

Let C and D be categories. A functor F from C to D is a mapping that:

  • associates to each object \(X\) in C an object \(F(X)\) in D,
  • associates to each morphism \(f \colon X \to Y\) in C a morphism \(F(f) \colon F(X) \to F(Y)\) in D such that the following two conditions hold:
    • \(F(id_{x}) = id_{F(x)}\) for every object  \(X\)  in C,
    • \(F(g \circ f) = F(g) \circ F(x)\) for all morphisms \(f \colon X \to Y\) and \(g \colon Y \to Z\) in C.

Natural Transformations

natural transformation provides a way of transforming one functor into another while respecting the internal structure of the categories involved.

Definition

If F and G are functors between the categories C and D, then a natural transformation  from F to G is a family of morphisms that satisfies two requirements.

  • The natural transformation must associate to every object \(X\) in C a morphism \(\eta_{X} \colon F(X) \to G(X)\) between objects of D. The morphism \(\eta_{X}\) is called the component of \(\eta\) at \(X\).
  • Components must be such that for every morphism \(f \colon X \to Y\) in C we have: \(\eta_{Y} \circ F(f) = G(f) \circ \eta_{X}\)

Monads

]]>
<![CDATA[Abstract Algebra]]>
  • Group
  • Field
  • Ring
  • Category
  • ]]>
    https://amanmehara.com/abstract-algebra/696e40a644fd0100017eafe3Sat, 20 Jul 2019 12:30:00 GMT
  • Group
  • Field
  • Ring
  • Category
  • ]]>
    <![CDATA[श्रीमद्भगवद्गीता - अध्याय ४ - श्लोक ७]]>यदा यदा हि धर्मस्य ग्लानिर्भवति भारत।
    अभ्युत्थानमधर्मस्य

    ]]>
    https://amanmehara.com/shriimdbhgvdgiitaa-adhyaay-4-shlok-7/696ef2d744fd0100017eb087Fri, 09 Nov 2018 03:18:00 GMTयदा यदा हि धर्मस्य ग्लानिर्भवति भारत।
    अभ्युत्थानमधर्मस्य तदात्मानं सृजाम्यहम्॥४-७॥

    ]]>
    <![CDATA[Functions]]>function \(f\) from a set \(D\) to a set \(Y\) is a rule that assigns a unique value \(f(x)\) in \(Y\) to each \(x\) in \(D\).

    The set \(D\) of all possible

    ]]>
    https://amanmehara.com/functions/696e508744fd0100017eb035Sat, 15 Sep 2018 12:30:00 GMTfunction \(f\) from a set \(D\) to a set \(Y\) is a rule that assigns a unique value \(f(x)\) in \(Y\) to each \(x\) in \(D\).

    The set \(D\) of all possible input values is called the domain of the function. The set of all output values of \(f(x)\) as \(x\) varies throughout \(D\) is called the range of the function. The range might not include every element in the set \(Y\).

    Even and odd functions

    A function \(y = f(x)\) is an
    even function of \(x\)  if \(f(-x) = f(x)\)
    odd function of \(x\)  if \(f(-x) = -f(x)\)
    for every \(x\) in the function's domain.

    The graph of an even function is symmetric about the y-axis.
    The graph of an odd function is symmetric about the origin.

    \(f(x) = 0\) is even and odd function

    Linear functions

    A function of the form \(f(x) = mx + b\), where \(m\) and \(b\) are fixed constants, is called a linear function.

    Power functions

    A function of the form \(f(x) = x^a\), where \(a\) is a constant is called a power function.

    Exponential functions

    A function of the form \(f(x) = a^x\), where \(a > 0\) and \(a \ne 1\), is called an exponential function (with base a). All exponential functions have domain \((-\infty, \infty)\) and range \((0, \infty)\).

    ]]>
    <![CDATA[Windows Subsystem for Linux (WSL)]]>https://amanmehara.com/windows-subsystem-for-linux-wsl/696e4fe944fd0100017eb02cSat, 25 Aug 2018 12:30:00 GMT