## How to Find Whether the given Number is PRIME or not using Recursion in Golang? Updated on 10-Jul-2023 16:48:16

27 Views

In mathematics, there are numbers that can be divisible by 1 or by itself, and such numbers are called Prime numbers. For example, 2, 3, 5, 7 … etc. In programming, we can create a program to check number is prime or not. In this article, we will use the concept of recursion which we call the function within the function to create a program to check number is prime or not. Example 1 In this example, we are going to create a recursive function with two parameters one is the number and another one is the divisor. The ... Read More

## How to find the Tangent of a given Radian Value in Golang? Updated on 10-Jul-2023 16:40:12

18 Views

The ratio of the radian’s adjacent side and the opposite side is known as the tangent of the given radian. Golang language has many packages with predefined functions that the developer can use without writing the complete logic. To perform the mathematical operations and logic we have a math package in Golang. We will use this package only to find the Tangent of a given radian value. We will also see how to import the package and also how to call a function this package consists of by writing a Golang code. Tangent Definition Tangent is a function that ... Read More

## How to Check Whether a Number is Even or Odd in Golang? Updated on 10-Jul-2023 16:08:51

341 Views

In this tutorial, we are going to learn how we can check whether the number is even or odd. The number that can be divisible by 2 is an even number and the number that is not divisible by two is an odd number. This tutorial includes three different ways to achieve this Moulous Operator − In the first method, we are using the modulus (%) operator. This operator is used to find the remainder of two numbers. In our case, we will do the modulus of the number with 2 and if it returns 0 then ... Read More

## How Does One Install Pip in a Docker Container using a Dockerfile? Updated on 10-Jul-2023 15:59:34

1K+ Views

In this tutorial, we are going to learn how we can install pip in a Docker container using a Dockerfile. This tutorial will cover the creation of the Dockerfile and then we will see the docker command to build a docker image from the Dockerfile, and in last we will see the docker command to run a container based on that image and see whether PIP is installed properly or not. Prerequisites There are some prerequisites to creating and building the Dockerfile as mentioned below. The stable version of Docker should be installed. Create a file in any folder ... Read More

## Golang Program to Sort an Array of 0’s, 1’s and 2’s Updated on 10-Jul-2023 15:49:33

28 Views

In Golang, like other programming languages, we can code the logic to sort an array that has 0’s, 1’s, and 2’s as elements. Sorting means assigning the data either in increasing order or in decreasing order. This is one of the famous questions on the array asked in interviews. There can be two approaches to achieve this that we are going to explore one by one. For example, we have an array 2, 1, 0, 0, 1, 2, and after sorting the array will look like 0, 0, 1, 1, 2, 2. Method 1 In this example, we are going ... Read More

## Golang Program to Implement Kaden's Algorithm Updated on 10-Jul-2023 17:34:03

41 Views

There is a famous maximum sum subarray problem, in which we have a 1 Dimensional array and must find the maximum sum in that subarray. To solve this problem, the most naive approach will be to find all the sub − arrays, sum their elements, and return the maximum, but the time complexity will be O(N*N). To reduce this there is an algorithm that will reduce the time complexity from O(N*N) to O(N) named as Kadens Algorithm. In programming, there are algorithms based on the Dynamic programming concept in which the problem is broken into sub − problems and the ... Read More

## Golang Program to Implement Linear Search Algorithm Updated on 10-Jul-2023 15:44:46

56 Views

In programming, to search for anything from an array, linked List, or from any other data structures we have a few search algorithms, one of which is Linear search. In the linear search, we iterate over the data structure from starting and search for the element till the last index. The advantage of a linear search algorithm is that we can perform this search of both sorted and unsorted data. The disadvantage is that for sorted or unsorted both kinds of data it will take the same amount of time to find an element. For example, we have an array ... Read More

## Golang Program to Implement Binary Search Algorithm Updated on 10-Jul-2023 17:26:38

52 Views

In programming, to search for anything from an array, linked List, or any other data structures we have a few search algorithms, one of which is binary search. In binary search, the prerequisite is that the data should be sorted. In binary search, we follow the divide and conquer approach in which we divide the data by applying some conditions and then perform the operation on that data only. In this way, we reduce the time complexity. For example, if we have an array of elements {20, 44, 45, 54, 67, 88, 91} and we want to find 44 then ... Read More

## Golang program to find the union of two arrays Updated on 10-Jul-2023 17:24:56

92 Views

In Golang, like other programming languages, we can find the union of two arrays. The union of two arrays is a list that consists of elements that lie in array A and the elements that lie in array B and common elements that lie in both arrays. For example, we have two arrays listed below A = {2, 9, 5, 7, 3} B = {5, 8, 7 2, 1} The union of the above arrays will be Union = {1, 2, 3, 5, 7, 8, 9} Method 1 In this method, we are going to find the union of two ... Read More

## Golang Program to Find Max No. of 1 in a Sorted Row of the Matrix Updated on 10-Jul-2023 17:23:48

27 Views

In programming languages, we can create 2−Dimensional Matrices and store elements in them. The 2−Dimensional metric is a data structure that has rows and columns. In this article, we are going to see the two different logic to find the maximum no. of ones in a sorted row of the matrix. For example, we have below the matrix {0, 1, 1, 1}, no. of 1s = 3 {0, 0, 1, 1}, no. of 1s = 2 {1, 1, 1, 1}, no. of 1s = 4 {0, 0, 0, 0}, no. of 1s = 0 In the ... Read More