Found 34475 Articles for Programming

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

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

74 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

137 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

300 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

270 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

196 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

157 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

Java Program to Find a Good Feedback Edge Set in a Graph

Rushi Javiya
Updated on 04-Jul-2023 16:00:27

159 Views

A feedback edge set in a graph refers to a set of edges that, when removed from the graph, eliminates all cycles or feedback loops. In other words, it is a subset of edges that, when deleted, transforms the original graph into a directed acyclic graph (DAG). A good feedback edge set is a feedback edge set that has the minimum possible number of edges. In this tutorial, we will learn to find a Good Feedback Edge Set in a Graph. Problem Statement Write a Java program that identifies and removes feedback edges in a graph to construct a Good ... Read More

Java Program to Extract Digits from A Given Integer

Rushi Javiya
Updated on 31-May-2024 14:02:14

10K+ Views

In Java programming, there are scenarios where we need to extract individual digits from an integer for further manipulation or analysis. This tutorial will guide you through the process of extracting digits from a given integer using Java. Syntax while (num > 0) { int digit = num % 10; System.out.println(digit); num = num / 10; } The above is the syntax to extract digits from an integer in Java. We keep extracting the last digit by taking the remainder of the number with 10. We divide the number by 10 until it ... Read More

Java Program to Implement Zhu-Takaoka String Matching Algorithm

Rushi Javiya
Updated on 04-Jul-2023 15:53:46

121 Views

The Zhu-Takaoka algorithm is one of the best algorithms for pattern matching. It is developed using the combination of the Boyer-Moore and KMP string-matching algorithms. The Zhu-Takaoka algorithm utilizes the good character shift and bad character shift techniques to solve the problem. Problem statement − We have given two strings. We need to implement the Zhu-Takaoka algorithm for pattern matching. Sample Examples Input str = "PQRDPQRSSE"; patt = "PQRS"; Output 5 Explanation The ‘PQRS’ pattern exists at position 5. So, it prints 5. Input str = "PQRDPQRSSE"; patt = "PRQS"; Output -1 Explanation ... Read More

Advertisements