Go Programming Articles

Page 48 of 86

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

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 423 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 728 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 842 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 529 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 545 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 277 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 582 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

Implement tower of hanoi in Golang

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

In this article we are going to learn how to use recursion method and iteration to implement tower of hanoi in golang. The Tower of Hanoi is a puzzle in which we move a set of disks from one page to another by moving one disk at a time. There are certain set of rules that need to be obeyed in this puzzle. Using Recursion Approach In this method, we will write a go language program to implement tower of Hanoi by using the method of recursion. If n is 1, we can move the disk from from to ...

Read More

Golang program to find all paths in a graph

Akhil Sharma
Akhil Sharma
Updated on 05-Apr-2023 1K+ Views

In this article we are going to learn how to use DFS Algorithm and breath-first searh method in golang to find all the paths in the a graph. In a graph, the nodes are depicted by the entities while the edges depict the relation between those entities. Finding all paths in a graph is a common task in graph theory and can be useful in a variety of applications. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then create different structs and functions and define properties to them. Step 3 − Now, ...

Read More

Golang program to convert the local time to GMT

Akhil Sharma
Akhil Sharma
Updated on 04-Apr-2023 2K+ Views

In this article, we will learn to write a Go language program to convert the local time to GMT using internal functions like Now() Time, LoadLocation()and time.In(). Local time is the time of a particular region which is calculated using position of the sun at noon. The local time is obtained using Now function from the time package whereas the local time is converted to GMT using ln function from the time package. Syntax func Now() Time The Now() function is defined in time package. This function generates the current local time.To use this function, we have to first ...

Read More
Showing 471–480 of 852 articles
« Prev 1 46 47 48 49 50 86 Next »
Advertisements