Home About My Portfolio Privacy Policy Terms

Tuesday, 30 August 2022

toastKing.js : A new JavaScript library!





toastKing.js is a light-weight JavaScript library for creating non-blocking, beautiful notification messages. 
I am very fond of beautiful notification or toast messages. They are often used in web applications. I searched the internet for such libraries and found some, but the problem was that they are very mediocre in looks or a kind of boring. Then I decided to make a library for notification cum toast messages that will be very beautiful in terms of graphics and will have some interactive features. Before developing the library, I made a layout of it, which looks like this:



After completing the design, I started the coding part. All the CSS and HTML is dynamic. User need not to including any additional CSS or HTML in his program.
For docs, please visit the github page of toastKing : https://rudraworks.github.io/toastKing/

Monday, 8 August 2022

Optimal String Search Using Genetic Algorithm


Optimal String Search Using Genetic Algorithm

About Genetic Algorithms (GA)

In Computer Science and Operations Research, Genetic Algorithms are often used for find the optimal solution of a optimization problem, more formally, GAs are heuristic algorithms. 
GAs are based on Darwin's theory of natural selection. i.e. survival of the fittest.

Heuristic Algorithms: In mathematical optimization and computer science, heuristic is a technique designed for solving a problem more quickly when classic methods are too slow or for finding an approximate solution when classic methods fail to find any exact solution.


Steps followed in designing a genetic algorithm 




What I have made?

I have made a simulation of GA in which the algorithm goes on computing until it founds the optimal string. 


Wednesday, 18 May 2022

Flood Fill Algorithm

 Flood Fill Algorithm

Flood fill algorithm helps in visiting each and every point in a given area. It determines the area connected to a given cell in a multi-dimensional array. Following are some famous implementations of flood fill algorithm:

Bucket Fill in Paint:
Clicking in an area with this tool selected fills that area with the selected color.

Solving a Maze:
Given a matrix with some starting point, and some destination with some obstacles in between, this algorithm helps to find out the path from source to destination

Minesweeper:
When a blank cell is discovered, this algorithm helps in revealing neighboring cells. This step is done recursively till cells having numbers are discovered.

Flood fill algorithm can be simply modeled as graph traversal problem, representing the given area as a matrix and considering every cell of that matrix as a vertex that is connected to points above it, below it, to right of it, and to left of it and in case of 8-connections, to the points at both diagonals also. For example, consider the image given below.


It clearly shows how the cell in the middle is connected to cells around it. For instance, there are 8-connections like there are in Minesweeper (clicking on any cell that turns out to be blank reveals 8 cells around it which contains a number or are blank). The cell (1,1) is connected in (2,1), (1,2), (1,0), (0,0), (0,2), (2,0), (2,2) and (0,1). 

ie Each (x,y) cell is connected to (x-1,y), (x+1,y), (x,y+1), (x,y-1), (x+1,y+1), (x+1,y-1), (x-1,y+1) and (x-1,y-1).

Algorithm

function DFS(x, y, visited, n, m)
    if (x  n OR y  m)
        return
    if(x < 0 OR y < 0)
        return
    if(visisted[x][y] == True)
        return
    visited[x][y] = True
    DFS(x-1, y-1, visited, n, m)
    DFS(x-1, y, visited, n, m)
    DFS(x-1, y+1, visited, n, m)
    DFS(x, y-1, visited, n, m)
    DFS(x, y+1, visited, n, m)
    DFS(x+1, y-1, visited, n, m)
    DFS(x+1, y, visited, n, m)
    DFS(x+1, y+1, visited, n, m)

The above code visits each and every cell of a matrix of size n×m starting with some source cell. Time Complexity of above algorithm is O(m*n).

Click here to see the demonstration of Flood Fill Algorithm


Friday, 15 April 2022

HeapSort as a combine subroutine of MergeSort


This article is taken from my ResearchGate profile. Link . This article is under Creative Commons Licence By (cc-by).

Wednesday, 13 April 2022

Divide and Conquer Algorithm for Linear Search

Divide and Conquer Algorithm for Linear Search


We have seen the Binary Search Algorithm which searches for an element in a sorted array in logarithmic time. Time complexity associated with it is 

Recurrence relation of Binary Search: 


Using the same principle of Divide, Conquer, and Combine, we can also utilize this algorithm to find an element in an unsorted array, though the time complexity will be linear .

Recurrence relation of Linear Search: 



#include<iostream>
#include<vector>
using namespace std;

int linear_search(vector<int>&v,int s,int e,int x)
{
    if(s>e)return -1;

    int m=s+(e-s)/2;
    if(v[m]==x)return m;

    int left=linear_search(v,s,m-1,x);
    int right=linear_search(v,m+1,e,x);

    if(left==-1 && right==-1)return -1;
    if(left!=-1)return left;
    else if(right!=-1)return right;
}

int main()
{
    vector<int>v={4,2,6,8,1,2,9,4};
    cout<<linear_search(v,0,v.size()-1,8);

    return 0;
}

Output: 3

Analysis of time complexity: