Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 16 of 51

Go program to find the diameter of a graph using the Dijkstra Algorithm

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 393 Views

In this article we will write a go language program to find the diameter of a graph. The diameter of a graph is the maximum distance between any two vertices in the graph. There are several Algorithms that can be used to find the diameter of a graph, including Dijkstra's Algorithm, Floyd-Warshall Algorithm, and Breadth-First Search Algorithm. Since, dijkastra Algorithm finds the shortest distance between source vertex and other vertices. We can also use it to find the largest distance by comparing the length of vertices recieved. Syntax func len(v Type) int The len() function is used to get ...

Read More

Golang program to find the minimum number of coins needed to make a given amount of money

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 367 Views

In this golang article we are going to find the minimum number of coins needed to make a given amount of money if a list of coins with different denominations is given. We can use the Greedy Algorithm for this problem. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then create a function named minCoins() used to calculate the minimum number of coins. The function accepts two arguments one is the array of integers having number of coins and the amount that is to be formed. Step 3 − Inside this function ...

Read More

Golang program to find maximum sum of a subarray with length k

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 686 Views

In this article we are going to understand how to use methods naming brute-force, sliding window and prefix sum methods of golang to find the maximum sum of a subarray with length k. We will also discuss the Algorithm for each method and provide code Examples to demonstrate their implementation. Syntax func len(v Type) int The len() function is used to get the length of a any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value which is the length of the variable. Example 1 The first ...

Read More

Golang program to traverse a circular linked list and print its elements

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 394 Views

In this article we are going to understand how to creat a golang program to traverse a circular linked list and print it’s element using simple for and while loop. Circular linked lists are a type of data structure where the last element of the list is connected to the first element, forming a loop. Algorithm Step 1 − First, we need to import the fmt package. This struct contains a data variable to store data along with a pointer variable to store the address of the next node. Step 2 − Then create a function called Traverse() to ...

Read More

Golang program to implement bucket sort

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 690 Views

In this article we will learn to develop a go language program to implement the bucket sort through using custom sorting Algorithm. In Bucket sort we sort the unsorted array in different bucket every bucket contains a wide range of elements. The elements present in each bucket are then sorted by using a different sorting Algorithm, such as insertion sort or quicksort. Then the sorted buckets are merged back together. Algorithm Step 1 − First, we need to import the fmt package. Then create a function called bucketSort() which accepts the array to be sorted as an argument and ...

Read More

Implement circular linked list in Golang

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 804 Views

In this article we will learn how to write a go language program to implement circular linked list using struct and slice method. circular linked lists are created in such a way that each node of the linked list points to the next node and the last node points again to the starting node. Example 1 In this Example we will write a go language program to implement the circular linked lists by using a struct to store each node of the list. package main import "fmt" type Node struct { data int ...

Read More

Implement Prims Algorithm in Golang

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 498 Views

In this article we are going to learn how to use Binary Heap method and Priority queue method to implement prims Algorithm in golang. Prim's Algorithm is used to find the minimum spanning tree of a weighted undirected graph. Algorithm Step 1 − First, we need to import the fmt and heap package. Then create the required structs and functions and define properties to them. Step 2 − Further Initialize an empty visited set and a binary heap h with the minimum edge from the starting vertex s. Step 3 − Then create the main() function. Inside the function ...

Read More

Implement Kruskals Algorithm in Golang

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 517 Views

In this article we are going to understand how to develop a golang program to implement kruskals Algorithm with the help of union-find Algorithm and priority queue approach. Kruskal's Algorithm is used to find the minimum spanning tree of a graph. Algorithm Step 1 − First, we need to import the fmt and sort packages. Then create structures called Edge, graph and subset and assign properties to it. Step 2 − Then sort all the edges of the graph in non-decreasing order of their weight. Step 3 − Create a disjoint set data structure, where each set contains ...

Read More

Golang program to check a graph is bipartite using DFS

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 244 Views

The Depth-First Search (DFS) Algorithm is a classic Algorithm used to traverse and search graphs. In this article we are going to learn how to develop golang program where we can check if a graph is bipartie or not using DFS . Here we will use two different approaches to implement the result. Syntax func len(v Type) int The len() function is used to get the length of a any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value which is the length of the variable. ...

Read More

Golang program to implement radix sort

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 553 Views

In this article we are going to understand how to use least significant bit and the most significant bit to implement radix sort. Radix sort is a sorting Algorithm that sorts elements by grouping them based on their individual digits or by the position of their digits. It is a linear time sorting Algorithm that has a time complexity of O(nk). Using the Least Significant Bit In this method, we will write a go language program to implement the radix sort by using the least significant bit. LSD sorts the elements from right to left by comparing their individual ...

Read More
Showing 151–160 of 507 articles
« Prev 1 14 15 16 17 18 51 Next »
Advertisements