Posts

Dijkstra's Algorithm

Image
Dijkstra's algorithm is used to calculate the shortest path between the one node (our choice) and every other node in the graph. Let's start the algorithm part- We have a graph as shown in fig (1.a) Firstly we have to select one node for example we select node C as our source node. In the algorithm we will mark every node with its minimum distance to node C.For node C,this distance is 0.For the rest of nodes this distance will be infinity.(Fig 1.b). Secondly we are having a current node as C. Now, we check the neighbours of our current node i.e A,B,D in any order. Suppose we begin with B. We add the minimum distance of the current node in this case it is 0 with the weight of the edge which connects C(current node) and we obtain 0+7=7. We compare distance with the minimum distance of B(infinity) and we find that the minimum b/w infinity and 7 is 7.therefore 7 remains as the minimum distance of B.  (Fig 1.c) Now,let's check neighbour A. We add minimum distance

Let's talk about Array

Arrays  is a kind of data structure that can store a fixed size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring a variable of same type again and again you can simply create a array of that type for example int,char,etc.You can declare a one array of any of these type and use a[0],a[1].....to represent individual elements. We can declare a array as, datatype array_name[array_size]; We can also initialize array in c/c++ either one by one or using single statement.