Found 26504 Articles for Server Side Programming

Golang program to find the diameter of a tree

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

317 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

392 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

270 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

2K+ 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

375 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

152 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

Swift Program to Sort Dictionary by keys

Ankita Saini
Updated on 10-May-2023 11:13:21

1K+ Views

Swift supports a sorted() method to sort all the elements present in the given dictionary. This method sorts the key-value pairs of the dictionary according to their keys. Syntax func sorted(by:) Here, the value of by parameters are − Greater than(>) − To sort the elements into descending order. Less than(

Swift Program to sort an array in descending order using insertion sort

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

1K+ Views

In Swift, insertion sort is a sorting technique in which the given array is virtually divided into two parts that are the sorted and the unsorted part. Then the array is searched sequentially, compares two elements from the unsorted part, and moves them into the right place in the sorted part. Using insertion sort, we can easily sort the array elements in ascending or descending order. So in this article, we will learn how to sort an array in descending order using insertion sort. Working of insertion sort Given unsorted array To sort the array in descending order, compare ... Read More

Advertisements