Found 1082 Articles for Go Programming

Golang program to find the minimum number of edges in a weighted directed graph that connects all nodes

Akhil Sharma
Updated on 06-Jul-2023 12:24:12

89 Views

In this article, we will write Go language programs to find the minimum no. of edges in a weighted directed graph that connects all nodes. We will use Prim’s algorithm to perform this operation. It is a greedy algorithm which is used to find the minimum spanning tree for a graph. Syntax func range(variable) Any data type may be iterated over using the range function. This may be used by first writing the range keyword, then the data type to which we wish to iterate func make ([] type, size, capacity) The go language's make function is used ... Read More

Golang program to find the shortest path from a source node to a target node using the Bellman-Ford algorithm

Akhil Sharma
Updated on 06-Jul-2023 12:22:17

100 Views

Bellman-ford algorithm is used to find the shortest distance from the source node to the other nodes in a weighted directed graph. This algorithm also predicts the negative weight cycles in the graph. It has a time complexity of O(V*E) where V stands for vertices and E stands for edges.In this Golang article, we will write programs to find the shortest path from source node to a target node using the Bellman-ford algorithm. Syntax func range(variable) The range function iterates through any data type. To utilise this, first type the range keyword followed by the data type to which ... Read More

Golang program to implement radix sort for sorting floating-point numbers

Akhil Sharma
Updated on 06-Jul-2023 12:15:36

225 Views

In this article, we will write Go language programs to implement radix sort for sorting floating-point numbers. Radix sort is usually used for sorting the integers, it can also be used to sort floating point numbers. It sorts items based on their particular bits or digits. This article provides an effective approach to sort the floating point numbers using the representation of floating point numbers. Algorithm Step 1 − Convert the floating-point numbers to a sortable format Step 2 − Perform a Radix Sort for each digit position Step 3 − Sort the integers based on the current ... Read More

Golang program to implement radix sort for sorting strings

Akhil Sharma
Updated on 06-Jul-2023 12:11:33

123 Views

Radix sort is efficient for sorting strings because of its inherent structure of string data type.In this article, we will write a Go language program to implement radix sort for sorting strings. We start working on an unsorted array string and demonstrate how radix sort can be applied to sort it. A string is a character array or combination of characters. Syntax func make ([] type, size, capacity) The make function in Go is used to build an array/map. It receives as arguments the kind of variable to be generated, as well as its size and capacity. func range(variable) ... Read More

Golang program to implement radix sort using bucket sort as a subroutine

Akhil Sharma
Updated on 06-Jul-2023 12:09:31

65 Views

A subroutine is a part of a program which performs a specific task and can be called repeatedly based on the purpose and use. When a subroutine is called, the program shifts to that routine and executes the instructions inside that routine.Radix sort is an algorithm that sorts elements from their digits. It has a linear time complexity and is used for sorting large amounts of data. It uses counting sort to calculate the frequencies of digits.In this Golang article, we will write programs to implement radix sort using bucket sort as a subroutine. Syntax func len(v Type) int ... Read More

Golang program to implement radix sort using counting sort as a subroutine

Akhil Sharma
Updated on 06-Jul-2023 12:07:11

103 Views

Radix sort is an algorithm that sorts elements from their digits. It has a linear time complexity and is used for sorting large amounts of data. It uses counting sort to calculate the frequencies of digits. Counting Sort is an algorithm that is efficient in sorting when the input is integer within a particular range. It counts the occurrence of each unique element from the input and uses that information to get the correct position of each element. A subroutine is a function of the program which performs a specific task and can be used when and repeatedly called in ... Read More

Golang program to perform a left rotation in a Red Black Tree

Akhil Sharma
Updated on 06-Jul-2023 12:02:59

49 Views

A red black tree is a self balancing binary search tree. Rotation is one of the fundamental operations of a self balancing tree. It is performed to maintain the tree's properties while inserting and deleting nodes to the tree. In this article we are going to write a language program to perform left rotation in a Red Black tree using pointers as well as using node value. Properties of Red Black tree Every node is either red or black The root node is always black Every leaf node is considered black If a node is red, both its children ... Read More

Golang program to find total bonus paid to a particular employee

Akhil Sharma
Updated on 06-Jul-2023 12:00:03

55 Views

There can be some situations in which you have a list of employees and you need to find out the bonus paid to a particular employee. Go language allows you to perform the task easily, in this article we are going to find out the total bonus paid to a particular employee using a fixed bonus amount as well as calculating individual bonus percentage. Algorithm Create a struct Employee with the attributes Name and BonusPercent. Calculate the total bonus using the function calculateTotalBonus, float64: Set the variable totalBonus to 0.0. Iterate through the employees array, one ... Read More

Golang program to find which Employees should get bonus

Akhil Sharma
Updated on 06-Jul-2023 11:57:35

45 Views

In corporate office there may be some cases in which you have a list of employees and you need to provide them extra bonus based on the work or experience or a particular property. In this article we are going to explore a way to calculate bonus using performance based calculations and tenure based calculations. Method 1: Performance Based Calculations Performance is the common base to determine the employee’s bonus, in this method we are going to calculate the bonus depending on the performance of the employee. Algorithm Create the Employee struct, which has the values Name, Salary, and ... Read More

Golang program to sort Employee by Name

Akhil Sharma
Updated on 06-Jul-2023 11:51:08

87 Views

There may be scenarios in which you need a list of employees and you need to display them in a particular order based on their name initials. In this Golang article, we are going to sort employee names using bubble sort, insertion sort as well as using go sort package. Algorithm Create a field called “Name” in the Employee struct. Use the array of Employee objects as input for the “BubbleSortByEmployeeName” method. Obtain the employees array's length and save it in the variable n. Start the outer loop from i = 0 to n-1 and Start the ... Read More

Advertisements