Java Program to Traverse a Graph using BFS

This is the Java Program to do a Breadth First Search/Traversal on a graph non-recursively. Problem Description Given a graph in the form of an adjacency matrix and a source vertex, write a program to perform a breadth-first search of the graph. In breadth-first search traversal, nodes are traversed level by level. Problem Solution The … Read more

advertisement

Java Program to Check the Connectivity of Directed Graph using DFS

This Java program,performs the DFS traversal on the given directed graph represented by a adjacency matrix to check connectivity.the DFS traversal makes use of an stack. Here is the source code of the Java program to check the connectivity of a directed graph. The Java program is successfully compiled and run on a Linux system. … Read more

advertisement

Java Program to Check the Connectivity of Undirected Graph using DFS

This Java program,performs the DFS traversal on the given undirected graph represented by a adjacency matrix to check connectivity.the DFS traversal makes use of an stack. Here is the source code of the Java program to check the connectivity of a undirected graph. The Java program is successfully compiled and run on a Linux system. … Read more

advertisement

Java Program to Traverse a Graph using DFS

This is the Java Program to do a Depth First Search/Traversal on a graph non-recursively. Problem Description Given a graph in the form of an adjacency matrix and a source vertex, write a program to perform a depth-first search of the graph. In depth-first search traversal, neighbours of a node are traversed first. Problem Solution … Read more

advertisement

Java Program to Count Number of Occurrences of a Given Number using Binary Search

This is a Java Program to find number of occurences of a given number using binary search approach. The time complexity of the following program is O (log n). Here is the source code of the Java program to find number of occurences of a given number using binary search approach. The Java program is … Read more

advertisement

Java Program to Find the Median of Two Sorted Arrays using Binary Search

This is a Java Program to find median of two sorted arrays using binary search approach. In probability theory and statistics, a median is described as the number separating the higher half of a sample, a population, or a probability distribution, from the lower half. The median of a finite list of numbers can be … Read more

advertisement

Java Program to Find the Maximum Subarray Sum using Divide and Conquer

This is the Java Program to Find the Maximum Sum in a Contiguous Sub-Array. Problem Description Given an array of integers, find the contiguous subarray, whose sum of the elements, is maximum. Example: Array = [2 1 3 5 -2 1 -3 8] Output: Subarray = [2 1 3 5 -2 1 -3 8] Sum … Read more

advertisement

Java Program to Find the Maximum Subarray Sum using Naive Method

This is a Java Program to find maximum subarray sum of an array. A subarray is a continuous portion of an array. The time complexity of the following program is O (n2). Here is the source code of the Java program to find maximum subarray sum. The Java program is successfully compiled and run on … Read more

advertisement

Java Program to Find Peak Element of an Array using Binary Search

This is a Java Program to find peak element of an array. A peak element of an array is that element which is greater than its neighbors. The following program uses binary search approach to find a peak element. The time complexity of the following program is O (log n). Here is the source code … Read more

advertisement

Java Program to Find Peak Element of an Array using Naive Method

This is a Java Program to find peak element of an array. A peak element of an array is that element which is not smaller than its neighbors. Consider only one neighbour for corner elements. The time complexity of the following program is O (n). Brute Force Algorithm is as follows : for i in … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.