Found 1082 Articles for Go Programming

Golang program to implement a binary indexed tree (Fenwick tree)

Akhil Sharma
Updated on 18-Oct-2023 15:36:02

63 Views

Binary Indexed Tree (also Fenwick Tree) is a data structure that efficiently handles range queries and point updates on an array. In this article, we are going to explore two different methods to implement a binary indexed tree in go, here implementation means we are performing main operations of a binary indexed tree that are creating a BIT(initialization), updation and prefix sum query. Explanation Fenwick Tree is a binary tree structure which efficiently maintains cumulative information about an array, specifically prefix sums and allows faster updates and queries on ranges. It has applications in various algorithms and problems like finding ... Read More

Golang program to implement a persistent data structure (a stack)

Akhil Sharma
Updated on 18-Oct-2023 15:29:58

90 Views

Persistent data structures, such as a stack, are of pivotal significance to programming for organising and chronologically managing data efficiently. This article showcases different examples to implement a persistent data structure in go, focusing on stack. In the first example we use immutable slices to perform the operation, while the second method employs a linked list, here implementation means we are going to demonstrate the operations like insertion, updation and deletion on a persistent data structure. Explanation A persistent data structure allows preserving previous versions when modifications are to occur. In this context, a stack as a data structure ... Read More

Golang program to implement a concurrent hash trie

Akhil Sharma
Updated on 18-Oct-2023 15:24:13

38 Views

Concurrency is crucial to modern programming for enabling efficient use of resources in multi-core systems. Hash tries are associative data structures which provide a scalable and thread-safe handling of large amounts of data concurrently. In this article, we are going to learn to implement a concurrent hash trie in go, implementation here means we are going to demonstrate the operations like insertion, updation and deletion on a hash trie data structure. Explanation A concurrent hash trie as a data structure combines the benefits of hash maps and tries to allow multiple threads simultaneous access and modification rights associated with ... Read More

Golang program to implement a concurrent hash map

Akhil Sharma
Updated on 18-Oct-2023 15:19:24

132 Views

Concurrent hash maps can be perceived as efficient data structures for ensuring smooth and parallel execution. Designed to handle concurrent read and write operations efficiently, it is a valuable tool for building highly performant multi-threaded applications. In this article, we learn to implement a concurrent hash map in go. Syntax func NewConcurrentMap(size int) *ConcurrentMap The syntax defines a function named NewConcurrentMap defined to create and return an instance of a customized concurrent hash map named ConcurrentMap. Taking a size parameter to determine internal bucket count for data distribution, it encapsulates the initialization process. Algorithm Start by ... Read More

Golang program to implement a Merkle tree

Akhil Sharma
Updated on 18-Oct-2023 15:17:22

181 Views

A merkle tree is used in cryptography and computer science to verify the authenticity of a data efficiently. Merkle trees are extremely crucial in the fields of cryptography and blockchain technology for ensuring data integrity and security. In this article, we will learn the significance of Merkle trees and to implement a merkle tree in go. Here we are going to use two different examples to perform this implementation in the first example we will build the Merkle tree recursively through the `MerkleNode` struct with hash, left, and right pointer, and in the second example we will employ an ... Read More

Golang program to implement a Skip List

Akhil Sharma
Updated on 18-Oct-2023 15:14:18

110 Views

Skip lists are a dynamic data structure which offer efficient insertion, search, and deletion operations. In this article, we will demonstrate the function and explore the algorithmic concepts to implement a Skip List in Go programming language. We are going to write two different examples for this demonstration. In the first example we are going to use a randomization approach and in the second example we will build the Skip List directly from randomised tower structures for quicker traversal. Explanation A Skip List as a data structure, maintains a sorted list of elements, to enable fast searching without the complexity ... Read More

Golang program to implement a Bloom filter

Akhil Sharma
Updated on 18-Oct-2023 15:12:12

109 Views

Bloom filters are a space-efficient data structure that find widespread use in various applications involving membership testing. In this article, we are going to explore how to create a Bloom filter in golanguage. Here we are going to write two different examples for this implementation, the first example includes the use hash functions from the FNV-1a algorithm, and in the second example we are going to use a a []bool array in order to determine element presence efficiently. Explanation A Bloom filter can be described as a probabilistic data structure that checks for the existence of an element in a ... Read More

Golang program to implement a red-black tree

Akhil Sharma
Updated on 18-Oct-2023 15:08:46

59 Views

Red-Black Trees are binary search trees with consistent structure and height balance, capable of self-balancing. They are beneficial in efficient insertion, deletion, and search operations. In this article, we will take an in-depth look at how to implement a red-black tree in golanguage, in the first example we are directly going to build the tree, while in the second example we are going to build the tree using structure. Explanation A red black tree is a self-balancing binary search tree that during insertion and deletion operations, ensures balance by making sure each node within the binary search tree is designated ... Read More

Golang program to find the cross product of two vectors

Akhil Sharma
Updated on 18-Oct-2023 12:48:21

47 Views

The cross product is an operation performed on two vectors in three-dimensional space that results in a third vector that is orthogonal (perpendicular) to the original vectors. In this article, we will see the Golang program to find the cross product of two vectors, here we will explore two different methods. Explanation Let us assume we have two vectors A and B. The cross product of the two vectors can be calculated by the formula: C = A X B. Components of a cross product vector can be calculated by formula: Cx =Ay ⋅Bz −Az ⋅By Cy ... Read More

Golang program to find the dot product of two vectors

Akhil Sharma
Updated on 18-Oct-2023 12:32:49

139 Views

The dot product is a measure of how closely two vectors are aligning in the direction that they are pointing towards. The dot product of two vectors is a fundamental operation in linear algebra that calculates the sum of the products of corresponding elements in two vectors. In this article, we will write a Golang program to find the dot product of two vectors using a loop as well as using the go languages range keyword. Explanation The dot product of two vector is calculated by the formula shown below: DOT PRODUCT = A⋅B =Ax ⋅Bx +Ay ⋅By +Az ... Read More

Advertisements