Samual Sam has Published 1776 Articles

Detect Cycle in a an Undirected Graph

Samual Sam

Samual Sam

Updated on 16-Jun-2020 11:27:25

8K+ Views

To detect if there is any cycle in the undirected graph or not, we will use the DFS traversal for the given graph. For every visited vertex v, when we have found any adjacent vertex u, such that u is already visited, and u is not the parent of vertex ... Read More

How to switch data from an array to array list in java?

Samual Sam

Samual Sam

Updated on 16-Jun-2020 11:14:27

330 Views

The Arrays class of the java.util package provides you a method named asList(). This method accepts an array (of objects) and converts them into a list and returns it.ExampleLive Demoimport java.util.Arrays; import java.util.List; public class ArrayToList {    public static void main(String args[]) {       Integer[] myArray ... Read More

Bridges in a Graph

Samual Sam

Samual Sam

Updated on 16-Jun-2020 10:48:32

2K+ Views

An edge in an undirected graph is said to be a bridge, if and only if by removing it, disconnects the graph, or make different components of the graph. In a practical approach, if some bridges are present in a network when the connection of bridges is broken, it can break ... Read More

Word Break Problem

Samual Sam

Samual Sam

Updated on 16-Jun-2020 09:42:44

520 Views

In the input of this problem, one sentence is given without spaces, another dictionary is also provided of some valid English words. We have to find the possible ways to break the sentence in individual dictionary words.We will try to search from the left of the string to find a ... Read More

Closest Pair of Points Problem

Samual Sam

Samual Sam

Updated on 16-Jun-2020 09:37:05

13K+ Views

In this problem, a set of n points are given on the 2D plane. In this problem, we have to find the pair of points, whose distance is minimum.To solve this problem, we have to divide points into two halves, after that smallest distance between two points is calculated in ... Read More

Count Inversions in an array

Samual Sam

Samual Sam

Updated on 16-Jun-2020 09:29:16

656 Views

The inversions of an array indicate; how many changes are required to convert the array into its sorted form. When an array is already sorted, it needs 0 inversions, and in another case, the number of inversions will be maximum, if the array is reversed.To solve this problem, we will ... Read More

Biconnected Graph

Samual Sam

Samual Sam

Updated on 16-Jun-2020 09:20:10

4K+ Views

An undirected graph is said to be a biconnected graph, if there are two vertex-disjoint paths between any two vertices are present. In other words, we can say that there is a cycle between any two vertices.We can say that a graph G is a bi-connected graph if it is ... Read More

How to count Java comments of a program that is stored in a text file?

Samual Sam

Samual Sam

Updated on 16-Jun-2020 08:49:25

573 Views

You can read the contents of a file using the Scanner class and You can find the comments in a particular line using contains() method.Exampleimport java.io.*; import java.util.Scanner; public class FindingComments {    public static void main(String[] args) throws IOException {       Scanner sc = new Scanner(new File("HelloWorld")); ... Read More

Adding an element in an array using Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 14:41:58

273 Views

Adding an element to an array can be done using different functions for different positions.Adding an element at the end of the arrayThis can be accomplished using the push method. For example, let veggies = ["Onion", "Raddish"]; veggies.push("Cabbage"); console.log(veggies);This will give the output −["Onion", "Raddish", "Cabbage"]You can also use this ... Read More

Dijkstra's algorithm in Javascript

Samual Sam

Samual Sam

Updated on 15-Jun-2020 12:14:29

6K+ Views

Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a weighted graph. We'll use the new addEdge and addDirectedEdge methods to add weights to the edges when creating a graph. Let us look at how this algorithm works −Create a distance collection and set all vertices ... Read More

Advertisements