
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1082 Articles for Go Programming

162 Views
ExampleConsider n = 20(00010100), k = 3 The result after turning off the 3rd bit => 00010000 & ^(1 16sApproach to solve this problemStep 1 − Define a method, where n and k would be the arguments, return type is int.Step 2 − Perform AND operation with n & ^(1

637 Views
Example − In the given tree, the root node is 1, the root of its left sub tree is 2, and the root of its right sub tree is 3, ... so on.Preorder Tree Traversal Output: 1, 2, 4, 5, 3, 6, 7.Approach to solve this problemStep 1 − First, we’ll define the node structure.Step 2 − In the main method, we would create the above tree.Step 3 − Finally, we will perform the Preorder Tree Traversal.Example Live Demopackage main import "fmt" type Node struct { data int left *Node right *Node } func (root *Node)PreOrderTraversal(){ if ... Read More

2K+ Views
Selection sort is a sorting algorithm that is used to sort the elements by repeatedly finding the minimum element and placing it at the first in the unsorted part of the array. After placing the minimum element in one end of the array, the array is then divided into two subparts which can be again sorted using the algorithm.For ExampleInputarr[ ] = {2, 9, 4, 3, 5, 1}Output1 2 3 4 5 9ExplanationAfter sorting the given array, it becomes 1, 2, 3, 4, 5, 9Algorithm:Take an array of integers as the input.Find the index of the minimum element by iterating ... Read More

237 Views
Catalan Numbers are sequences of natural numbers that gives the number of BST (Binary Search Tree) possible with n Values. So, the Catalan number is a full binary tree with n+1 leaves.Some applications of Catalan Numbers are counting the pairs of nested parentheses, valid mountain ranges etc.For n = 5, C = (C(0) * C(4)) + (C(1) * C(3)) + (C(2) * C(2)) + (C(3) * C(1)) + (C(4)* C(0))Thus, we can see that Catalan numbers are in the form of a recursive relation, i.e., for the nth term, the Catalan number Cn is, ... Read More

536 Views
ExamplesInput num = 5 => 101 & 1 = 001 => True, i.e., Odd; else num would be Even.Approach to solve this problemStep 1: Define a method that accepts a number.Step 2: Perform & operation with that number.Step 3: If the & operator returns a non-zero value, then that number would be odd.Step 4: Else, the number would be even.ProgramLive Demopackage main import "fmt" func oddEven(num int){ if num & 1 != 0 { fmt.Println("ODD") } else { fmt.Println("EVEN") } } func main(){ oddEven(13) oddEven(50) oddEven(0) }OutputODD EVEN EVEN

630 Views
We can solve this problem in two different ways. Let’s check the first method.Method 1: ExamplesInput Array = [1, 2, 3, 4, 4] => Range is from 1 to 5 but 4 is a duplicate element in this range.Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Declare a visited map.Step 3: Iterate the given array. If the element exists in the visited map, then return that element.Step 4: Else, return -1.ProgramLive Demopackage main import "fmt" func duplicateInArray(arr []int) int{ visited := make(map[int]bool, 0) for i:=0; i Range is from 1 to 5 but 4 ... Read More

6K+ Views
ExamplesInput Array = [1, 3, 5, 6, 1] => Duplicate element is 1;Input Array = [1, 3, 5, 6, 7] => return -1Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Declare a visited map.Step 3: Iterate the given array. If the element exists in the visited map, then return that element.Step 4: Else, return -1.ProgramLive Demopackage main import "fmt" func duplicateInArray(arr []int) int{ visited := make(map[int]bool, 0) for i:=0; i

331 Views
There are two methods in which we can solve this problem. Let’s check the first method.Method 1ExamplesInput Array = [1, 0, 1, 0, 1, 0, 0, 1] => [0, 0, 0, 0, 1, 1, 1, 1]Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Count number of 0.Step 3: Store 0 till count becomes 0 and store 1 at the remaining indexes.Step 4: At the end, return the array.ProgramLive Demopackage main import "fmt" func binarySort(arr []int) []int{ count := 0 for i:=0; i