Programming Articles - Page 339 of 3363

Golang program to find floor and ceil in binary search tree

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

287 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

245 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

Golang program to find the diameter of a tree

Akhil Sharma
Updated on 10-May-2023 12:41:07

353 Views

In this Golang article, we are going to find the diameter of a tree by using recursion and iterative method. The diameter of a tree is the number of nodes on the longest path between any two leaves in the tree. Syntax func diameter(root *node) int{…} The diameter() function is used to find the diameter of a tree. It takes pointer to the root 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 tree named, node. It contains ... Read More

Golang program to delete duplicate value nodes from a sorted linked list

Akhil Sharma
Updated on 10-May-2023 12:39:48

426 Views

In this Golang article, we are going to delete duplicate value nodes from a sorted linked list by using recursion and iterative method. 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. Syntax func deleteDuplicates(head *Node) *Node{…} The deleteDuplicates() function is used to delete duplicate value nodes from a sorted linked list. It takes pointer to the head node as its argument. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, ... Read More

Golang program to print left pascals triangle

Akhil Sharma
Updated on 10-May-2023 12:36:56

310 Views

In this Golang article, we will learn how to print left Pascal’s triangle by using recursion and iterative method. Pascal's triangle is a triangular array of binomial coefficients. The left pascal's triangle is a variant of Pascal's triangle that is obtained by reflecting Pascal's triangle along a vertical axis. Syntax func leftPascal(n, k int) int{…} The leftPascal() function is used to print left Pascal’s triangle. It takes two arguments as input. func leftPascal(n int){…} The leftPascal() function is used to print left Pascal’s triangle. It takes one argument, number of rows as input. Algorithm Step 1 − ... Read More

Golang program to find maximum element in array using linear search

Akhil Sharma
Updated on 10-May-2023 12:17:27

3K+ Views

In this Golang article, we will learn how to find maximum element in array using linear search by using recursion and iterative method. Syntax func findMax(arr []int) int {…} The findMax() function is used to find maximum element in array using linear search iteratively. It takes an integer array as argument to it. func findMax(arr []int, n int) int {…} The findMax() function is used to find maximum element in array using linear search recursively. It takes an integer array and the size of the array as arguments to it. Algorithm Step 1 − First, ... Read More

Golang program to find the first occurrence of a specific element in array using linear search

Akhil Sharma
Updated on 10-May-2023 12:13:09

438 Views

In this Golang article, we will find the first occurrence of a specific element in array using linear search by using recursion and iterative method. Linear search is a simple search algorithm that checks every element in a list or array one by one, starting from the beginning, until a target value is found or the entire list has been searched. It is also known as sequential search. Syntax func firstOcc(arr []int, target int) int {…} The firstOcc() function is used to find the first occurrence of a specific element in array using linear search iteratively. It takes an ... Read More

Golang program to find minimum element in array using linear search

Akhil Sharma
Updated on 10-May-2023 11:59:28

1K+ Views

In this Golang article, we will learn how to find the minimum element in an array using linear search by using recursion and iterative method. An array is a collection of elements of the same data type, arranged in a contiguous block of memory, and accessed using an index or a subscript. Linear search is a simple search algorithm that checks every element in a list or array one by one, starting from the beginning, until a target value is found or the entire list has been searched. It is also known as sequential search. Syntax func minFind(arr []int) int ... Read More

Golang program to reverse a circular linked list

Akhil Sharma
Updated on 14-Jul-2023 16:44:56

204 Views

In this article, we will learn how to create a golang program to reverse a circular linked list using recursion and iterative method. A circular linked list is a type of linked list where the last node in the list points back to the first node, forming a loop. It could be used to implement a circular buffer or a round-robin scheduling algorithm. Syntax func reverseList(head **Node){…} The reverseList() function is used to reverse a circular linked list. It takes an argument as value to the pointer to the address of the head node. func reverseList(current, prev, head *Node) ... Read More

Swift Program to Update value of Dictionary using key

Ankita Saini
Updated on 10-May-2023 11:18:05

1K+ Views

Swift provides a method named as updateValue() method to update the value of the dictionary using a specified key. If the specified key does not exist, then this method will add that key along with its value in the dictionary. Syntax dict.updateValue(nvalue, forKey: nkey) Here, nvalue represents the new value and nkey represents the key to which we want to update or add value. If the given key exists in the dictionary, then its value is replaced by the new value. If the given key does not exist, then it will add the nkey and nvalue in the dictionary. ... Read More

Advertisements