Found 26504 Articles for Server Side Programming

Extracting last element of a Priority Queue without traversing

Sonal Meenu Singh
Updated on 22-Feb-2023 11:55:01

2K+ Views

Introduction The Priority Queue in C++ is not similar to the normal Queue in the data structure, it has one difference: all its elements have priorities. We can extract its elements by traversing in the Queue. But, here in this tutorial, we are trying a method for extracting the last element of the Priority Queue without traversing. Let’s start… What is Priority Queue? In data structure, the abstract data type is the priority queue. It is a queue where all its elements have some associated priorities. All its elements are removed based on their priorities. Higher priority data are ... Read More

Golang Program to Perform the postorder tree traversal

Akhil Sharma
Updated on 22-Feb-2023 14:14:39

298 Views

In Go, postorder tree traversal is a technique in which the left child is visited first, then the right child, and finally the root node is the definition of the order. This order is frequently used to carry out certain activities on a tree, including releasing memory that the tree has consumed. We will implement postorder tree traversal using two methods the first one uses slices and the second one uses stacks. 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 ... Read More

Golang Program to Count number of leaf nodes in a tree

Akhil Sharma
Updated on 22-Feb-2023 14:02:39

489 Views

In Go programming language, a tree is a data structure in which each node has a value and zero to many nodes as children. The root node is the node without a parent, while the leaf node is the node without children. Trees can be employed for a variety of tasks, including data storage, sorting, and searching in hierarchical structures. We will use two methods to count no. of leaf nodes in a tree. In the first method TreeNode struct is used whereas queue is used in the second example to execute the program. Method 1: Using TreeNode Struct This ... Read More

Golang Program to Perform the preorder tree traversal

Akhil Sharma
Updated on 22-Feb-2023 14:01:05

1K+ Views

In Go programming language, pre-order traversal is a tree traversal technique in which the root node is visited first, then the left subtree, and finally the right subtree. A recursive function is used that calls itself on the root node, the left child node, the right child node, and finally the left child node again. When the node is nil, the recursion's basic case, occurs. We will execute pre-order traversal in this program using two methods- the TreeNode struct and the stacks. Method 1: Using TreeNode struct This method builds a tree node structure With a Value field, a pointer ... Read More

Golang program to implement binary tree data structure

Akhil Sharma
Updated on 22-Feb-2023 17:56:04

3K+ Views

In the Go, a binary tree is a tree data structure where each node has at most two children, as the left child and the right child. Go's built-in data structures and operations, like structs and pointers, can be used to create a binary tree. The tree's nodes can be visualized as structs with fields for the value kept at each node and pointers to any left or right children. There are three types of tree traversals- preorder, inorder and postorder. We will use two methods to implement the binary tree data structure. In the first method we executed pre-order ... Read More

Golang program to detect a loop in linked list

Akhil Sharma
Updated on 22-Feb-2023 13:56:08

670 Views

In Golang data structures, a linked list is the one that contains nodes which contains two fields: a next pointer and the data of the list. We will use two methods to detect a loop in linked list. In the first method two-pointer approach will be used and in the second example maps are used to execute the program. Let’s go through those examples to understand the execution. Method 1: Using two-pointer approach In this method, the linked list is traversed using a low pointer and a high pointer. While the high pointer advances two steps at a time, the ... Read More

Golang Program to Get the middle element of LinkedList in a single iteration

Akhil Sharma
Updated on 22-Feb-2023 13:54:59

316 Views

In golang data structures , a linked list has pointers connecting the items, and from the first node (head) to the last node, each node can be visited (tail) using next pointer. We will obtain the middle element of a linked list using two methods. The first approach depicts use of two-pointer approach and the second approach uses a counter variable to execute the program. Method 1: Using two-pointer approach In this method, the function navigates the linked list using two pointers, low and high. The high pointer takes two steps at a time, whereas the low pointer takes ... Read More

Golang program to implement linked list

Akhil Sharma
Updated on 22-Feb-2023 13:53:47

422 Views

In Go programming language, a linked list is a linear data structure made up of a series of nodes which are linked to each other via next pointer, which points to the next address. We will implement linked list in this program using two methods. In the first method struct will be used and in the second example list struct will be used. Method 1: Using Struct In this method, there are three nodes in this linked list, and each one has a value of 1, 2, or 3. Each node's next pointer points to the node after it in ... Read More

Golang Program to Iterate through Elements of Dictionary

Akhil Sharma
Updated on 22-Feb-2023 13:52:09

2K+ Views

In Golang, a dictionary is like a map which is a group of key-value pairs with a unique key for each value. The values can be of any type, and the keys can be of any type that is similar, such as strings or integers. We can build an empty map by using the built-in "make" function, and then add, retrieve, or update values. We will use two examples here to iterate through elements of a dictionary where in the first example loop will be used to iterate through the elements whereas in the next example slices will be used ... Read More

Basic Operations for Queue in Data Structure

Sonal Meenu Singh
Updated on 22-Feb-2023 11:23:18

970 Views

Queue is a collection of different data types and is an important part of data structure, following a particular order to insert and remove elements. In this tutorial, we will understand the basic operations of the queue. What is Queue in Data Structure? A Queue is a linear data structure that resembles a queue in real life. You all have been part of some queue in school, the billing counter, or any other place, where the one entered first will exit first in the queue. Similarly, a queue in data structure also follows the FIFO principle, which defines First In ... Read More

Advertisements