Found 34494 Articles for Programming

Golang program to implement a Merkle tree

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

333 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

151 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

142 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

77 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

103 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

249 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

Merging two list of dictionaries in Python

Dr Ruqaiya Khanam
Updated on 18-Oct-2023 11:45:21

1K+ Views

Problematic data structures include Python lists and dictionaries, these two structures being ordered collections that allow changes, while an unordered dictionary stores values like maps. Dictionaries provide more efficient use by holding key-value pairs; unlike other data types which hold single values at a time as elements in them. In this article, merging two lists involve compiling all dictionaries from both lists into one large list, their order in this merged list will mirror how they appeared in their respective original lists, initially the order may contain only those from one original list followed by others from both original lists. ... Read More

Merging two strings with Suffix and Prefix using Python

Dr Ruqaiya Khanam
Updated on 18-Oct-2023 14:25:58

266 Views

String manipulation often necessitates merging two strings based on shared suffix and prefix sequences; suffices to be at the end, prefixes being at its beginning. This article will show how to merge two strings with suffixes and prefixes using Python language. We are considering two examples where we have two strings and their beginning and ending strings overlapped, the goal is to merge these by appending both strings together without creating redundant overlapped sections. As a result, there will be one string that contains all characters from both original strings without unnecessary duplication or repetition. In the second example, we ... Read More

Merging duplicates to list of lists

Dr Ruqaiya Khanam
Updated on 18-Oct-2023 14:22:46

99 Views

At hand is the challenge of Python lists - an incredibly flexible data structure capable of holding various kinds of information when dealing with lists within lists (where multiple duplicate entries could exist) duplication is likely. Therefore a Pythonic solution must exist that removes duplicated sublists to ensure each sublist in a main list is unique. In this article, we illustrate how to merge duplicates to a list of lists with detailed examples using different approaches. Merging Duplicates to a List of Lists by Using for Loop Code Explanation and Design Steps − Step 1 − Open Jupyter Notebook ... Read More

Merging nested lists in Python

Dr Ruqaiya Khanam
Updated on 18-Oct-2023 12:48:51

361 Views

Nesting lists in Python refers to multiple lists within one another that can be useful when performing data manipulation tasks; however, occasionally we may wish to change or flatten this nested structure by "flattening a list", in Python terminology meaning changing from multiple hierarchical structures into one single (non-nested) structure where all elements belong under equal scope without hierarchy or hierarchies present. In this article, we will illustrate how to merge nested lists in python using different approaches. Merging Nested Lists in Python Using Recursion Method Code Explanation and Design Steps − Step 1 − Import required module: we ... Read More

Advertisements