Topological Sorting

Ankith Reddy
Updated on 16-Jun-2020 14:05:13

8K+ Views

The topological sorting for a directed acyclic graph is the linear ordering of vertices. For every edge U-V of a directed graph, the vertex u will come before vertex v in the ordering.As we know that the source vertex will come after the destination vertex, so we need to use a stack to store previous elements. After completing all nodes, we can simply display them from the stack.Input and OutputInput: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 ... Read More

Ford Fulkerson Algorithm

Samual Sam
Updated on 16-Jun-2020 14:01:32

5K+ Views

The Ford-Fulkerson algorithm is used to detect maximum flow from start vertex to sink vertex in a given graph. In this graph, every edge has the capacity. Two vertices are provided named Source and Sink. The source vertex has all outward edge, no inward edge, and the sink will have all inward edge no outward edge.There are some constraints:Flow on an edge doesn’t exceed the given capacity of that graph.Incoming flow and outgoing flow will also equal for every edge, except the source and the sink.Input and OutputInput: The adjacency matrix: 0 10 0 10 0  0 0  0 4 ... Read More

Transitive Closure of a Graph

George John
Updated on 16-Jun-2020 13:54:00

20K+ Views

Transitive Closure it the reachability matrix to reach from vertex u to vertex v of a graph. One graph is given, we have to find a vertex v which is reachable from another vertex u, for all vertex pairs (u, v).The final matrix is the Boolean type. When there is a value 1 for vertex u to vertex v, it means that there is at least one path from u to v.Input and OutputInput: 1 1 0 1 0 1 1 0 0 0 1 1 0 0 0 1 Output: The matrix of transitive closure 1 1 1 ... Read More

Create JavaScript Objects Using Object Constructor

Jennifer Nicholas
Updated on 16-Jun-2020 13:53:02

380 Views

A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.The variable contains a reference to the new object. The properties assigned to the object are not variables and are not defined with the var keyword.ExampleYou can try to run the following code to learn how to work with JavaScript objects with object() constructor −Live Demo           User-defined objects                var book = new Object(); ... Read More

Print Message to Error Console using JavaScript

Ali
Ali
Updated on 16-Jun-2020 13:52:32

316 Views

To print a message to the error console, use the console object. Here’s an example −The following will show a red error message −console.error(message);The following gives you the default message −console.log(message);The following gives you the warning message −console.warn(message);The following gives an information message −console.info(message);Add CSS to the log message −console.log('%c Add message!, "background: green; color: white;");Use the following to print error. Consider “num” as the variable name −console.error('num=%d', num);For complete API reference, refer Console API Reference.

Layers of Canvas in Fabric.js

karthikeya Boyini
Updated on 16-Jun-2020 13:51:07

1K+ Views

FabricJS has the following API methods that change the z-index of objects:canvas.sendBackwards(myObject) canvas.sendToBack(myObject) canvas.bringForward(myObject) canvas.bringToFront(myObject)You can also use:fabric.Canvas.prototype.orderObjects = function(compare) {    this._objects.sort(compare);    this.renderAll(); }

Print Content of JavaScript Object

Johar Ali
Updated on 16-Jun-2020 13:50:35

270 Views

To print content of JavaScript object, you can try to run the following code. Here, the object is created using the new keyword −ExampleLive Demo                          var dept = new Object();          dept.employee = "Amit";          dept.department = "Technical";          dept.technology ="C++";          document.getElementById("test").innerHTML =          dept.employee + " is working on " + dept.technology + " technology.";          

Check For Star Graph

karthikeya Boyini
Updated on 16-Jun-2020 13:50:23

681 Views

A graph is given; we have to check the given graph is a star graph or not.By traversing the graph, we have to find the number of vertices has degree one, and number of vertices, whose degree is n-1. (Here n is the number of vertices in the given graph). When the number of vertices with degree 1 is n-1 and a number of vertices with a degree (n-1) is one, then it is a star graph.Input and OutputInput: The adjacency matrix: 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 Output: ... Read More

Bellman-Ford Algorithm for Shortest Paths

Ankith Reddy
Updated on 16-Jun-2020 13:41:56

5K+ Views

Bellman-Ford algorithm is used to find minimum distance from the source vertex to any other vertex. The main difference between this algorithm with Dijkstra’s the algorithm is, in Dijkstra’s algorithm we cannot handle the negative weight, but here we can handle it easily.Bellman-Ford algorithm finds the distance in a bottom-up manner. At first, it finds those distances which have only one edge in the path. After that increase the path length to find all possible solutions.Input and OutputInput: The cost matrix of the graph: 0  6  ∞ 7  ∞ ∞  0  5 8 -4 ∞ -2  0 ∞  ∞ ∞ ... Read More

Create JavaScript Objects Using New Operator

Krantik Chavan
Updated on 16-Jun-2020 13:39:41

323 Views

The new keyword in JavaScript is the new operator, which creates an instance of a user-defined object type.ExampleYou can try to run the following code to create JavaScript objects using new operator −Live Demo                          var dept = new Object();          dept.employee = "Amit";          dept.department = "Technical";          dept.technology ="Java";          document.getElementById("test").innerHTML =          dept.employee + " is working on " + dept.technology + " technology.";           OutputAmit is working on Java technology.

Advertisements