Saturday, 20 January 2018

Basics of Tree data structure

Tree data structure simulates a hierarchical tree structure, with root and subtrees represented by linked nodes.

Some Terminology

Root : Top node in tree.
Child : Node directly connected to parent node.
Siblings : Child nodes with same parent.
Ancestor : A node reachable by repeated proceeding from child to parent.
Leaf : A node with no children.




Sunday, 14 May 2017

Topological sorting in Graph data structure

Topological sorting in directed graph is linear ordering of vertices, such that for every directed edge from u to v, vertex u will come before vertex v.

Applications

1. Executing task based on dependency, like our build system.
2. Scheduling tasks.

Topological sort will only work on directed acyclic graphs.

Algorithm

1. Pick one vertex, mark it visited and look for its adjacent vertices.
2. Push just found adjacent vertex into the main stack, and then look for its adjacent vertices  ( DFS of graph ).
3. Once no more adjacent vertex is found for the current vertex, pop it out from the main stack and push it into another stack (result stack).
4. Now, pick other vertex which is not visited yet and repeat steps 1, 2 and 3.

Consider this example

Let's say you are given 6 vertices with 6 edges :-
5, 0, 5, 2, 2, 3, 3, 1, 4, 1, 4, 0

These are 6 pairs, where integer u,v represents edge from u to v.



Topological order for the same will be 5, 4, 2, 3, 1, 0

Remember, there can be multiple topological sort order of a graph.

We will use Dictionary ( HashMap ) to store adjacent vertices and boolean array to keep track of visited vertices.



To find adjacent vertices of any given vertex.

Perform toplogical sort. You can then pop out resultStack values, to get topological sort order.

















Closures in Javascript

Depth First Search in Graph

DFS involves following a path from source vertex to adjacent vertices until there are no other vertex is left to visit.

Objective

  • Start with source vertex, push it into stack, mark it visited and display it
  • Now peek the stack and look for adjacent vertices.
  • If found push it into stack, mark it visited and display it.
  • If not, then pop up from stack and again repeat step 2.
  • Repeat till stack is empty.

Saturday, 13 May 2017

Basics of Graph data structure

  • Graph consist of vertices and edges.
  • They are used to model many realworld examples ( likes cities, network…)


Graph



Implementing a graph with 4 vertices (A,B,C,D) and 4 edges.

Saturday, 20 June 2015

Reflection at rescue

Few days back , i found some codebase which handled so many if conditions based on some input parameter. This thing made particular method to be 100 lines long. The code works fine , but was too ugly.

Monday, 11 August 2014

Starting with AngularJS for beginners

AngularJS framework is used for making dynamics views in web applications.It makes the front end of web applications more expressive & readable.For more information you can visit AngularJS website.
You can also learn some basics from this site AngularJS Tutorial

In this post i m going to guide you about creating basic applications using AngularJS , which will help in understanding small details more clearly. Then we will create a little big application which involves server side code too.

First some basics

AngularJS is MVC framework for front end of web applications.
Data = Models
Web page = Views
Navigation = Controllers


Wednesday, 16 July 2014

Validating your model before inserting into database in Asp.net MVC

We all are aware that when we take any model from view(user input) into the controller , we always tend to
use ModelState.IsValid to check if model is valid , then only we will proceed for further processing


But the same is not applicable when we are doing same in class file which does not inherit controller class.


Friday, 25 October 2013

Lucene for beginners

In this tutorial I will guide you brief about lucene search to get you started with it. Lucene library is an open source project under apache meant for searching full text.

It is really powerful & used by many companies.

What is the prerequiste for understanding lucene ?
a) should know what indexing means
b) you should have built basic search algorithm for searching strings
c) understand vector space model algorithm (optional)
d) should have passion for search & how it works

Is lucene scalable ?
Yes , lucene is high-performance , scalable search library.


Thursday, 3 October 2013

Starting with basic machine learning algorithms

Machine learning algorithms are used to understand the text & categorise them by computer programs itself . It involves some training data given to your program which help it in understanding the text more better & hence categorise them more effectively.

I will start with basic machine learning algorithm 

Vector Space Model
It is used for information filtering , information retrieval , indexing & relevancy ranking system.



Wednesday, 18 September 2013

Hashing in detail

Hashing is a technique of saving data in key/value form. So accessing data with help of key is quite fast , it has around O(1) Time complexity which is equivalent  to constant time.
Example :
• Input ["key"] = value , accessing value with help of key.
• Hashing technique used in cache system of our computer for 
   Fast data accessing between ram & cpu ( registers ).


Thursday, 5 September 2013

Making facebook like plugins

In this tutorial i will show you how we can make facebook like plugins , so that others can use our service by just embeding a piece of code on there website.


Friday, 30 August 2013

HTML5 database creation

HTML5 has some exciting features & one of them is database storage on your browser itself. In this tutorial i will guide you brief about creation of HTML5 database & start working with it. HTML5 database is created on SQLLite(open source db software) of browser .We have 3 types of ways to store data on browser :
  • localStorage , sessionStorage
  • Web SQL
  • IndexDB

Understanding Polymorphism

My first post on MB Coding starts with this small piece of code which tries to explain polymorphism concept.






























As you can see display function is in both classes , so when we call it from object of type father()
it invokes display function of father() & when that object tries to get assigned to children() , it
still invoke display function from father() . Why ? because father is father & children is children.

Children is a derived class hence when display function is called it calls display function of father only.
So if you want to call display function check this code below :

class father
{
   public father()
   {
      Console.WriteLine("In Father Constructor");
   }

   public virtual void display()
   {
      Console.WriteLine("In Father Class");
   }
}


class children : father
{
   public children()
   {
      Console.WriteLine("In Children Constructor");
   }

   public override void display()
   {
      Console.WriteLine("In Children Class");
   }

}

Polymorphism is just like eye , it observe or sees what is shown to it...or say it can understand
or interpret different objects.



Basics of Tree data structure

Tree data structure simulates a  hierarchical tree structure, with root and subtrees represented by linked nodes. Some Terminology Root...