“The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to last rod, obeying the following simple rules:
It is a well-known Algorithm used to find the shortest distance and shortest path from a single source node to all other nodes in a graph. This algorithm only works on graphs, where there are no negative cycles in them (i.e. a cycle whose edges sum to a negative value).
Today, we will learn how to implement a Typing Effect in React from scratch.
A working Example can be found here.
Start by creating a starter react app using npx create-react-app my-app
or follow the procedure from here.
Go to App.js, remove all redundant Elements, and add a h1
tag where the typing effect will take place.
Now import to add additional hooks using import {useEfect, useState} from "react";
Create an array of words that will be type one by one.
Now we have to keep track of the index of the word array for typing a specific word, so we…
Pythagorean Triplets are set of three ordered positive integers (x,y,z) such that
x^2 + y^2 = z^2 --- (1)
where,
x < y < z <= N
There are several techniques for generating Pythagorean Triplets for example using Gaussian Integers and using Euclid’s formula. They can be used to generate all primitive Pythagorean Triplets, which again can be used to generate all non-primitive Pythagorean triplets by using the fact that the non Primitive Pythagorean triples are a positive integer multiple of primitive Pythagorean Triplets.
Generating Pythagorean triplets simply using two loops by iterating over x and y for all possible…
“A Mandelbrot set marks the set of points in the complex plane such that the corresponding Julia set is connected and not computable. The Mandelbrot set is the set obtained from the recurrence relation, Z_(n) = Z²_(n-1) + c, where, Z_(0) = c. where c is a complex number” — Wolfram Mathworld.
The colors in a Mandelbrot set represents the iterations at which that complex number diverges to infinity (we can use here some threshold instead of infinity). …
Breadth-first search (BFS) is a common search technique on graphs. BFS is a companion of depth-first search (DFS). While DFS traverses the graph depth-wise, BFS does it breadth-wise. It’s used to find a node in a graph. It may also be used to get the path to that node from a given node or to just traverse all the nodes and edges in a graph.
Let’s say we want to find a node in a tree where we know in advance the tree is not bushy (higher diameter) and the node lies somewhere in the middle of the tree. …
Depth-First Search (DFS) is a common search technique on graphs. It is used to find a node in a graph and may also be used to get the path to that node from a given node or to just traverse all the nodes and edges in a graph.
It can also be augmented to do many more interesting things such as finding connected components, strongly connected components, minimum spanning tree, cycles in graphs, topological sort, etc.
For a refresher and basic concepts on graphs visit my previous post, graph theory algorithms simplified.
Graph theory is a very broad branch of mathematics and it is highly applicable in real-world problems. Originally, graph theory was “invented” to solve real-world problems and after that, it was hijacked by abstract mathematicians like all other branches of mathematics.
In this tutorial and subsequent tutorials, we will look at some graph theory algorithms and their implementations in Python. Now, back to the meat of the subject.
In a nutshell, a graph is a set of vertices/nodes and edges. If you are not comfortable with “set” replace it with collection.