Programming Articles

Page 2514 of 2547

C++ Program to Implement Dijkstra's Algorithm Using Set

Nancy Den
Nancy Den
Updated on 30-Jul-2019 720 Views

This is a C++ Program to Implement Dijkstra’s Algorithm using Set. Here we need to have two sets. We generate a shortest path tree with given source node as root. One set contains vertices included in shortest path tree and other set includes vertices not yet included in shortest path tree. At every step, we find a vertex which is in the other set (set of not yet included) and has minimum distance from source.Algorithm:Begin    function dijkstra() to find minimum distance:    1) Create a set Set that keeps track of vertices included in shortest    path tree, Initially, ...

Read More

C++ Program to Perform Greedy Coloring

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 900 Views

Here is a C++ Program to Perform Greedy ColoringAlgorithm:Begin    Take the number of vertices and edges as input.    Create function greedyColoring() to assign color to vertices:    A) Assign the first color to first vertex.    B) Initialize the remaining vertices.    C) Declare a temporary array to store the available colors.    D) Assign color to the remaining vertices.    Print the solution. EndExample Code#include #include using namespace std; int n,e,i,j; vector g; vector col; bool visit[1001]; void greedyColoring() {    col[0] = 0;    for (i=1;i

Read More

Add a value to Quartet class in JavaTuples

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 186 Views

To add a value to the Quartet Tuple, use the addAtX() method. The index can be set here with the X i.e. the place where the value gets added.Let us first see what we need to work with JavaTuples. To work with Quartet class in JavaTuples, you need to import the following package −import org.javatuples.Quartet;We will use Quintet class; therefore, we will import the following package −import org.javatuples.Quintet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Quartet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add ...

Read More

What is difference between int and const int& in C/C++?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 4K+ Views

Here we will see what are the differences between int and const_int& in C or C++.The int is basically the type of integer type data. And const is used to make something constant. If there is int& constant, then it indicates that this will hold the reference of some int type data. This reference value is constant itself. So the const is redundant. The compiler may return warning or some error.The const int& is same as int const&. So this refers to a constant integer. The integer cannot be modified through the reference.

Read More

Create Octet Tuple from another collection in Java

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 178 Views

You can create Octel Tuple from another collection i.e. List or arrays. For List, use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package −import org.javatuples.Octet;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples −Steps: How to run JavaTuples program in EclipseThe following is an ...

Read More

C++ Program to Perform Operations in a BST

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 3K+ Views

         A Binary Search Tree is a sorted binary tree in which all the nodes will have following properties−The right sub-tree of a node has a key greater than to its parent node's key.The left sub-tree of a node has a key lesser than to its parent node's key.All key values are distinct.Each node cannot have more than two children.Class Descriptions:Begin    class BST to declare following functions:       search() = To search an item in BST.       initialize temp = root;       while(temp != NULL)          Increase ...

Read More

C++ Program to Implement Network_Flow Problem

Daniol Thomas
Daniol Thomas
Updated on 30-Jul-2019 677 Views

This is a C++ Program to implement Network_Flow problem using Ford Fulkerson algorithm.Algorithms:Begin    function bfs() returns true if there is path from source s to sink t in    the residual graph which indicates additional possible flow in the graph. End Begin    function fordfulkarson() return maximum flow in given graph:    A) initiate flow as 0.    B) If there is an augmenting path from source to sink, add the path to flow.    C) Return flow. EndExample Code#include #include #include #include #define n 7 using namespace std; bool bfs(int g[n][n], int s, int ...

Read More

Transpose a matrix in Python?

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 4K+ Views

Transpose a matrix means we’re turning its columns into its rows. Let’s understand it by an example what if looks like after the transpose.Let’s say you have original matrix something like -x = [[1, 2][3, 4][5, 6]]In above matrix “x” we have two columns, containing 1, 3, 5 and 2, 4, 6.So when we transpose above matrix “x”, the columns becomes the rows. So the transposed version of the matrix above would look something like -x1 = [[1, 3, 5][2, 4, 6]]So the we have another matrix ‘x1’, which is organized differently with different values in different places.Below are couple ...

Read More

Iterate through Quartet class in JavaTuples

Samual Sam
Samual Sam
Updated on 30-Jul-2019 189 Views

You can also iterate through Quartet class like Arrays using a loop.Let us first see what we need to work with JavaTuples. To work with Quartet class in JavaTuples, you need to import the following package −import org.javatuples.Quartet;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Quartet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Quartet; public class Demo { public static void main(String[] args) { ...

Read More

What do the id and scope attribute mean in the action elements in JSP?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 519 Views

These are two attributes that are common to all Action elements: the id attribute and the scope attribute.Id attributeThe id attribute uniquely identifies the Action element and allows the action to be referenced inside the JSP page. If the Action creates an instance of an object, the id value can be used to reference it through the implicit object PageContext.Scope attributeThis attribute identifies the lifecycle of the Action element. The id attribute and the scope attribute are directly related, as the scope attribute determines the lifespan of the object associated with the id. The scope attribute has four possible values:(a) ...

Read More
Showing 25131–25140 of 25,467 articles
Advertisements