Found 26504 Articles for Server Side Programming

How to Check Whether a Number is Even or Odd in Golang?

Aman Sharma
Updated on 10-Jul-2023 16:08:51

5K+ 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?

Aman Sharma
Updated on 10-Jul-2023 15:59:34

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

Aman Sharma
Updated on 10-Jul-2023 15:49:33

150 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

Aman Sharma
Updated on 10-Jul-2023 17:34:03

206 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

Aman Sharma
Updated on 10-Jul-2023 15:44:46

508 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

Aman Sharma
Updated on 10-Jul-2023 17:26:38

645 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

Aman Sharma
Updated on 10-Jul-2023 17:24:56

876 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

Aman Sharma
Updated on 10-Jul-2023 17:23:48

145 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

Golang program to find duplicates in N+1 array

Aman Sharma
Updated on 10-Jul-2023 17:22:26

2K+ Views

In programming, there is a problem statement asked in interviews to find the duplicate number in an array of size N + 1. Also, there will be only one duplicate element in the array. The elements will be between 1 to N. For example, Array = {1, 3, 2, 1, 4} 1 is the duplicate element in the above array. Algorithm Step 1: Import the required packages at the top using the import keyword. Step 2: Then the main function will get run first. First, we are declaring and initialize the array. Now, we are calling the function to ... Read More

Golang Program Right View of Binary Tree

Aman Sharma
Updated on 10-Jul-2023 15:12:35

197 Views

In programming, there is a coding problem of binary tree that gets asked very frequently in interviews and the problem statement is to find the right view of a binary tree. If we try to understand the problem statement more than what exactly the right view is then we can explain it in a way that all the nodes are visible when you see them by standing on the right side of the tree. Illustration Let us understand more with the help of an example. Suppose we have a below tree and if we stand on the right side ... Read More

Advertisements