Found 1082 Articles for Go Programming

Golang program to find duplicates in N+1 array

Aman Sharma
Updated on 10-Jul-2023 17:22:26

479 Views

In programming, there is a problem statement asked in interviews to find the duplicate number in an array of size N + 1. Also, there will be only one duplicate element in the array. The elements will be between 1 to N. For example, Array = {1, 3, 2, 1, 4} 1 is the duplicate element in the above array. Algorithm Step 1: Import the required packages at the top using the import keyword. Step 2: Then the main function will get run first. First, we are declaring and initialize the array. Now, we are calling the function to ... Read More

Golang Program Right View of Binary Tree

Aman Sharma
Updated on 10-Jul-2023 15:12:35

73 Views

In programming, there is a coding problem of binary tree that gets asked very frequently in interviews and the problem statement is to find the right view of a binary tree. If we try to understand the problem statement more than what exactly the right view is then we can explain it in a way that all the nodes are visible when you see them by standing on the right side of the tree. Illustration Let us understand more with the help of an example. Suppose we have a below tree and if we stand on the right side ... Read More

Golang Program Level Order Traversal of Binary Tree

Aman Sharma
Updated on 10-Jul-2023 17:20:06

213 Views

In programming, there are different data structures to store data. There are two different types of data structures linear and non −linear. Array, stack, queue, and linked list are linear data structures. Binary trees, trie, etc are non − linear data structures. In this article, we are going to explore level order traversal on one of the non − linear data structures i.e. binary tree. Level Order Traversal In level order traversal, of a binary tree we start from the root node and then traverse the children nodes and move to the children of children nodes. In this way, ... Read More

Golang Program Left View of Binary Tree

Aman Sharma
Updated on 10-Jul-2023 17:17:31

93 Views

In programming, there is a coding problem of binary tree that gets asked very frequently in interviews and the problem statement is to find the left view of a binary tree. If we try to understand the problem statement more than what exactly the left view is then we can explain it in a way that all the nodes are visible when you see them by standing on the left side of the tree. Illustration Let us understand more with the help of an example. Suppose we have a below tree and if we stand on the left side ... Read More

Golang program Breadth-First Search graph

Aman Sharma
Updated on 10-Jul-2023 17:15:46

678 Views

Graph is a data structure that consists of edges or we can say nodes and vertices. Vertices are the lines between the nodes. To traverse all these nodes we have different traversal algorithms. In this article, we will discuss, Breadth − first search or we can say BFS. In Breadth − first search, we first start from one node and move to another till the dead end comes. Example If we start from node 1 then it will first visit node 2 and node 4 first. Then from node 2, we will visit node 3. In this way, the ... Read More

Golang program of two struct types with identical fields, with having one "JSON" tag on each field

Akhil Sharma
Updated on 06-Jul-2023 12:48:47

732 Views

Struct types are used to construct custom data structures consist of fields. These fields reflect the structure's characteristics or attributes. The ability to add tags to fields, such as "JSON" tags, which offer additional metadata about the field when serializing or deserializing the struct to/from JSON format, is a valuable feature of struct types. In this article, we will write Go language programs to represent structs with one JSON tag in each field. type StructName struct { Field1 DataType1 `Tag1:"Value1" Tag2:"Value2"` Field2 DataType2 `Tag3:"Value3" Tag4:"Value4"` // ... ... Read More

How do you compare two struct instances that have pointers as fields in Golang

Akhil Sharma
Updated on 06-Jul-2023 12:40:48

528 Views

In golang, Pointers are the variables which store the address of other variables. A struct is a counterpart to class in object-oriented programming where different fields can be placed in the struct, where these fields can be implemented later on and they have a type like int, float, string etc. In this article, we will write a Go language program to compare two struct instances that have pointers as fields. Mathematical representation for assigning the address of variable “b” to variable “a” − a = &b & denotes the address of operator, and receives the memory address of ... Read More

Golang program to compare two instances of this struct for equality, taking into account the values in the slice

Akhil Sharma
Updated on 06-Jul-2023 12:35:58

145 Views

A struct is a counterpart to class in object-oriented programming where different fields can be placed in the struct, where these fields can be implemented later on and they have a type like int, float, string etc.In this article, we will write a Go language program to compare the equality of two structs. Syntax func len(v Type) int The len() method returns the length of any parameter. It accepts one input, the data type variable whose length we want to know. func range(variable) The range function iterates through any data type. To utilize this, we must first put ... Read More

How to find the capacity of the pointers pointing at a map in Golang?

Akhil Sharma
Updated on 06-Jul-2023 12:32:23

50 Views

A pointer is a variable which holds the address of another variable and can be used to point to the content of another variable. A pointer does not have its capacity just like slices, it can be used to point to the map whose length of elements can be calculated.In this article, we will write a Go language program to find the capacity of a pointer pointing to a map. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its ... Read More

Golang program to find the longest path in a weighted directed acyclic graph using Bellman-Ford algorithm

Akhil Sharma
Updated on 06-Jul-2023 12:30:54

289 Views

In this article, we will write a Go language program to find the longest path in a weighted directed acyclic graph using Bellman-ford-algorithm. Bellman-Ford-Algorithm is a popular algorithm used to find the longest path from source vertex to other vertices in a weighted directed 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) When creating an array or map in the Go programming language, the ... Read More

Advertisements