Found 26504 Articles for Server Side Programming

How do you create unidirectional channels in Golang?

Akhil Sharma
Updated on 05-Jul-2023 17:37:50

403 Views

When working with go language channels there must be cases such as clear communication intent, enhanced safety in communication, encapsulation and more where you need to create unidirectional channels. In this go language article we are going to learn to create unidirectional channels using send only channel method, receive only channel method, using interfaces as well as type conversion methods. Bidirection channels enables the channel data to be transferred and received. There may be times when you want to impose unidirectional communication, limiting either sending or receiving actions. Syntax ch := make(chan

How do you declare an interface in Golang?

Akhil Sharma
Updated on 05-Jul-2023 17:31:12

267 Views

Declaring an interface in go language means creating a new named type that defines a collection of method signatures. In go-language we can declare an interface using single method interface, multiple method interface as well as embedded interface. In this article we are going to understand these methods and declare an interface in go language with the help of various examples. Method 1: Single Method Interface The first method involves a single interface, in this approach we describe an interface that all implementing types must fulfill. Algorithm Create the interface with a single method called CreateSound(). Now, create ... Read More

Golang program to check if a priority queue is empty

Akhil Sharma
Updated on 05-Jul-2023 17:28:40

228 Views

A priority queue is a queue in which elements are stored along with their priority values. The functions supported by priority queue are − enqueue and dequeue where enqueue implies adding elements to the queue along with their priorities and dequeue implies removing elements from the queue along with their priorities. In this article, we will write a Go language program to check if a priority queue is empty. 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 size ... Read More

Golang program to insert a new node into a Red Black Tree

Akhil Sharma
Updated on 05-Jul-2023 17:25:28

230 Views

In this article, we will write a Go language program to insert a node into a Red Black tree. A Red Black tree. It is a self-balancing Binary search tree having the following properties − Every node is either red or black The root node is always black All leaves are taken as black If a node is red, both its children will be black Every path from a node to its descendant leaves contains the same number of black nodes Algorithm Create a "Node" struct with four fields: "key" of type int, "colour" of type string, ... Read More

Golang program to implement N queens problem

Akhil Sharma
Updated on 05-Jul-2023 17:23:29

511 Views

N queen problem is a puzzle in which N queens are to be placed on a NXN chessboard, so that the two queens don’t share the same row, column and diagonal or attack each other. A queen in chess can move in any direction, horizontally, vertically and diagonally so it is a challenge to find places where no two queens can attack each other. In this article, we will write a Go language program to implement the N queens problem. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map ... Read More

Golang program to search for a node in a Red Black Tree

Akhil Sharma
Updated on 05-Jul-2023 17:20:10

150 Views

Searching a node in a red black tree is to find a node with a specific key or value. The search in the red black tree is similar to searching in a standard binary tree. In this article, we will write Go language programs to search for a node in a Red Black tree. It is a self-balancing Binary search tree with coloring properties where the root node is always black and other nodes are red or black as per the properties. This tree uses rotations to maintain the balance during insertions and deletions. Properties Every node is either ... Read More

Golang program to insert an element into a binary heap

Akhil Sharma
Updated on 05-Jul-2023 17:00:47

244 Views

Inserting an element in a binary heap means to add an extra element to the heap and maintain the heap property at the same time.In this Go language article, we will write a program to insert an element into a binary heap. It is a binary tree-based data structure which follows the heap properties. Heaps are of two types: min heap and max heap. In the min heap the value of the parent node is less than the value of its children and in the max heap the value of the parent node is more than the value of ... Read More

Golang program to represent a Binary Heap

Akhil Sharma
Updated on 05-Jul-2023 16:57:52

488 Views

A Binary heap is a binary tree-based data structure which is used to implement priority queues and sorting algorithms. In this article, we will write a Go language program to represent a Binary Heap. There are two types of heaps: max and min heap. In max heap the value of nodes is greater or equal to their children and in min heap the value of nodes is less than its children. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is ... Read More

Golang program to define a Red Black tree

Akhil Sharma
Updated on 05-Jul-2023 16:51:54

441 Views

In go language we can create a red black tree by providing proper structures and methods. In this article we will write Go language programs to define a Red Black tree. Here, the root node is always black and other nodes can be red or black based on the properties it possess. It is used for various operations like efficient search, insertions and deletions. Algorithm Step 1 − imports fmt and “main” as necessary packages Step 2 − Create a RedBlackTree struct, which contains a field that provides reference to the root node. Step 3 − Then, create a ... Read More

Golang program to implement Bellman ford algorithm

Akhil Sharma
Updated on 05-Jul-2023 16:49:13

370 Views

The bellman ford algorithm is a graph traversal method that is used to find the shortest distance in a weighted network from a particular vertex to all the vertices. In this article, we will write a Go language program to implement Bellman ford algorithm. This algorithm is used to handle the situations where you need to find the shortest path from the source vertex to other vertices in a weighted directed graph. It works by updating the distance value of the vertices if the shortest path is found. Syntax func make ([] type, size, capacity) The make function ... Read More

Advertisements