Create Hash Collection in Go

Akhil Sharma
Updated on 03-Apr-2023 13:18:29

246 Views

In this article, we will write a Golang programs to create hash collections with the help of make function and map function. Hashmap stores key value pairs that can be accessed via index. In this program we will create a hash collection with the help of two examples. 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 created, its size and capacity as arguments. Using Make Function In this method, we will create a hashmap with the help of a make ... Read More

Golang Program to Demonstrate a Simple Module

Akhil Sharma
Updated on 03-Apr-2023 13:17:34

220 Views

In this Go language article, we will write programs to demonstrate a simple module. A module in Go is called as the collection of packages namely we can call it packages and sub-packages where the root file will be called as go.mod. In this program we will demonstrate a module using three different examples. 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 created, its size and capacity as arguments Example1: Golang program to demonstrate a simple module using basic printing ... Read More

Binary Search on Slice of Custom Structs in Golang

Akhil Sharma
Updated on 03-Apr-2023 13:14:13

984 Views

In this Golang article, we are going to perform binary search on a slice of custom structs using iterative and recursive method. Binary search is a search algorithm used to find the position of a specific value within a sorted sequence of elements. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Create a custom Person structure with string type name and integer type age. Step 3 − Now, create a bSearch() function that is used to perform binary search on a slice of Person struct. Step 4 − It initializes the low ... Read More

Check if a Stack is Empty in Go

Akhil Sharma
Updated on 03-Apr-2023 13:13:45

302 Views

In this Golang article, we are going to check if a stack is empty using iterative and recursive method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop() and peek() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes the last ... Read More

Golang Program to Reverse a Stack

Akhil Sharma
Updated on 03-Apr-2023 13:13:14

262 Views

In this Golang article, we are going to reverse a stack using recursive and iterative method. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Algorithm Step 1 − First, we need to import the fmt and strconv package. Step 2 − Create a stack structure with an item slice to store the stack elements. Step 3 − Now, define the functions, push(), pop(), peek(), isEmpty() and print() to perform the basic operations with the stack. Step 4 − push() adds the item to the end of the stack while pop() removes ... Read More

Find Pair of Numbers That Add Up to Target Sum in Go

Akhil Sharma
Updated on 03-Apr-2023 13:12:40

557 Views

In this Golang article, we are going to find if there exists a pair of numbers in an array that add up to a given target sum using two pointer approach with iterative and optimized-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. Using Two Pointer Approach With Iterative Method In this method, we will define a pairWithGivenSum() function using iterative approach that is used to find if there exists a pair of numbers in an array that add up ... Read More

Find Longest Subarray with a Given Sum Using Two Pointer Approach in Go

Akhil Sharma
Updated on 03-Apr-2023 13:12:02

344 Views

In this Golang article, we are going to find longest subarray with a given sum using two-pointer approach with iterative and optimized-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. Using Two-Pointer Approach With Iterative Method In this method, we will define a longestSubarray() function using iterative approach that is used to find longest subarray with a given sum using two-pointer approach. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Start the ... Read More

Remove Duplicates from Sorted Array Using Two Pointer Approach in Go

Akhil Sharma
Updated on 03-Apr-2023 13:11:30

845 Views

In this Golang article, we are going to remove duplicates from a sorted array using two-pointer approach with iterative and optimized-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. A sorted array is an array in which the elements are arranged in a particular order, such as ascending or descending order. Using Two-Pointer Approach With Iterative Method In this method, we will define a duplicatesRemove() function using iterative approach that is used to remove duplicates from a sorted array using ... Read More

Find Maximum Product of Two Numbers in Array Using Two Pointer Approach

Akhil Sharma
Updated on 03-Apr-2023 13:10:58

523 Views

In this Golang article, we are going to find the maximum product of two numbers in an array using two pointer approach with iterative and optimized-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. Using Two Pointer Approach With Iterative Method In this method, we will define a productMax() function using iterative approach that is used to find the maximum product of two numbers in an array using two pointer approach. Algorithm Step 1 − First, we need to ... Read More

Find Subarray Existence Using Two Pointer Approach in Go

Akhil Sharma
Updated on 03-Apr-2023 13:10:09

512 Views

In this Golang article, we are going to find if a given subarray exists in a given array using two pointer approach with iterative and optimized-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. Syntax func isSubarrayPresent(arr []int, sub []int) bool {…} The isSubarrayPresent() function is used to find if a given subarray exists in a given array using two pointer approach. It takes array and sub-array as its argument. Algorithm Step 1 − First, we need to ... Read More

Advertisements