Found 1082 Articles for Go Programming

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

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

72 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

136 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

289 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

255 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

190 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

Golang program to insert an element into a priority queue

Akhil Sharma
Updated on 06-Jul-2023 16:05:15

151 Views

When working with go language there may be cases such as sorting, managing urgent events such as job scheduling, and more where you need to prioritize the element based on their urgency number. In this article, we will write a Go language program to insert an element into a priority queue. A priority queue is a type of queue in which every stored element has a priority. The elements are added in the priority queue using the enqueue operation and removed from the queue using the dequeue operation. Syntax func make ([] type, size, capacity) The make ... Read More

Golang program to create a priority queue

Akhil Sharma
Updated on 05-Jul-2023 16:39:44

2K+ Views

A priority queue is a type of queue in which priorities are assigned to the elements and the elements with higher priority are popped out first than the elements with lower priority. In this article, we will write Golang programs to create a priority queue. They can be implemented using heaps, slices, trees etc and are used to perform the operations such as pushing elements in queue and removing elements from queue. 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 ... Read More

Golang program to find minimum value in a stack

Akhil Sharma
Updated on 10-May-2023 12:46:25

194 Views

In Golang, we can find minimum value in a stack by using iterative method and optimized iterative method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Syntax func (s *Stack) getMin() int {…} The getMin() function is used to find the minimum value in a stack. It takes a address pointer to the stack as its argument. Algorithm Step 1 − First, we need to import the fmtpackage. Step 2 − Create a stack structure with an item slice to store the stack elements and a min slice to store the minimum ... Read More

Golang program to find floor and ceil in binary search tree

Akhil Sharma
Updated on 10-May-2023 12:44:21

146 Views

A binary search tree (BST) is a type of binary tree where every node has at most two children, commonly referred to as the left child and the right child. In this Golang article, we will learn how to find floor and ceil in binary search tree using recursion and iterative method. The binary search tree is a useful data structure for efficient searching, insertion, and deletion of elements. Syntax func ceil(root *Node, val int) int {…} The ceil() function is used to find the ceil value in the binary search tree. func floor(root *Node, val int) int {…} ... Read More

Golang program to reorder list using recursion

Akhil Sharma
Updated on 10-May-2023 12:43:12

121 Views

A linked list is a data structure consisting of a collection of nodes, where each node contains a value and a pointer to the next node in the list. In this Golang article, we will learn how to reorder list using recursion along with some helper functions. Syntax func reorderList(head *Node) {…} The reorderList() function is used to reorder list using recursion. It takes pointer to the head node as its argument. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, create a struct of a single node of the ... Read More

Advertisements