Found 34472 Articles for Programming

IntStream sum() method in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

156 Views

The sum() method of the IntStream class is used in Java to return the sum of elements in this stream.The syntax is as follows −int sum()To work with the IntStream class in Java, import the following package −import java.util.stream.IntStream;Create IntStream and add some elements −IntStream intStream = IntStream.of(50, 100, 150, 200, 250, 300);Now, return the sum of elements in the IntStream added above −int sumVal = intStream.sum();The following is an example to implement IntStream sum() method in Java −Example Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(50, ... Read More

C++ Program to Check the Connectivity of Undirected Graph Using BFS

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the undirected graph, we will select one node and traverse from it.In this case the traversal algorithm is recursive BFS traversal.Input − Adjacency matrix of a graph0110010110110110110100110Output − The Graph is connected.Algorithmtraverse(s, visited)Input − The start node s and the visited node to mark which node is visited.Output − Traverse all connected vertices.Begin mark s as visited insert ... Read More

C++ Program to Represent Graph Using Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

The incidence matrix of a graph is another representation of a graph to store into the memory. This matrix is not a square matrix. The order of the incidence matrix is V x E. Where V is the number of vertices and E is the number of edges in the graph.In each row of this matrix we are placing the vertices, and in each column the edges are placed. In this representation for an edge e {u, v}, it will be marked by 1 for the place u and v of column e.The complexity of Adjacency Matrix representationThe incidence matrix ... Read More

C++ Program to Represent Graph Using Adjacency List

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

The adjacency list representation of a graph is linked list representation. In this representation we have an array of lists The array size is V. Here V is the number of vertices. In other words, we can say that we have an array to store V number of different lists. If a list header is vertex u, then it signifies that it will hold all of the adjacent vertices of u.The complexity of Adjacency List representationThis representation takes O(V+2E) for undirected graph, and O(V+E) for directed graph. If the number of edges are increased, then the required space will also ... Read More

C++ Program to Represent Graph Using Incidence Matrix

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

The incidence matrix of a graph is another representation of a graph to store into the memory. This matrix is not a square matrix. The order of the incidence matrix is V x E. Where V is the number of vertices and E is the number of edges in the graph.In each row of this matrix we are placing the vertices, and in each column the edges are placed. In this representation for an edge e {u, v}, it will be marked by 1 for the place u and v of column e.The complexity of Adjacency Matrix representationThe incidence matrix ... Read More

C++ Program to Represent Graph Using Adjacency Matrix

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

The adjacency matrix of a graph is a square matrix of size V x V. The V is the number of vertices of the graph G. In this matrix in each side V vertices are marked. If the graph has some edges from i to j vertices, then in the adjacency matrix at ith row and jth column it will be 1 (or some non-zero value for weighted graph), otherwise that place will hold 0.The complexity of Adjacency Matrix representationThe adjacency matrix representation takes O(V2) amount of space while it is computed. When graph has maximum number of edges and ... Read More

Period negated() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

47 Views

An immutable copy of a Period where all the Period elements are negated can be obtained using the method negated() in the Period class in Java. This method requires no parameters and it returns the Period elements after negating them.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; import java.time.LocalDate; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p = Period.parse(period);       System.out.println("The Period is: " + p);       System.out.println("The Period with elements negated is: " + p.negated());    } ... Read More

C++ Program to Implement Merge Sort Algorithm on Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

The merge sort technique is based on divide and conquer technique. We divide the while data set into smaller parts and merge them into a larger piece in sorted order. It is also very effective for worst cases because this algorithm has lower time complexity for worst case also.Linked list can be sorted using merge-sort very efficiently. For the linked list the merging task is very simple. We can simply update the links to merge them. In this section we will see how to sort the linked list using this approach.The complexity of Merge Sort TechniqueTime Complexity − O(n log ... Read More

Period between() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

3K+ Views

The Period between two dates can be obtained using the between() method in the Period class in Java. This method requires two parameters i.e. the start date and the end date and it returns the Period between these two dates.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; import java.time.LocalDate; public class Demo {    public static void main(String[] args) {       LocalDate startDate = LocalDate.parse("2015-03-15");       LocalDate endDate = LocalDate.parse("2019-05-20");       System.out.println("The start date is: " + startDate);       System.out.println("The end date is: " + endDate);       ... Read More

Period multipliedBy() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

49 Views

An immutable copy of a Period where all the Period elements are multiplied by a value can be obtained using the method multipliedBy() in the Period class in Java. This method requires a single parameter i.e. the value which is to be multiplied and it returns the immutable copy of the Period which is multiplied by a value.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y9M4D";       Period p = Period.parse(period);       System.out.println("The Period is: " ... Read More

Advertisements