Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Python program to insert a new node at the middle of the Doubly Linked List
When it is required to insert a new node in the middle of a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Exampleclass Node: def __init__(self, my_data): self.previous = None self.data = my_data self.next = None class double_list: def __init__(self): self.head = ...
Read MoreGolang Program to count the set bits in an integer.
ExamplesFor example, 101, 11, 11011 and 1001001 set bits count 2, 2, 4 and 3 respectively.Approach to solve this problemStep 1 − Convert number into binary representation.Step 2 − Count the number of 1s; return count.Examplepackage main import ( "fmt" "strconv" ) func NumOfSetBits(n int) int{ count := 0 for n !=0{ count += n &1 n >>= 1 } return count } func main(){ n := 20 fmt.Printf("Binary representation of %d is: %s.", n, strconv.FormatInt(int64(n), 2)) fmt.Printf("The total number of set bits in %d is %d.", n, NumOfSetBits(n)) }OutputBinary representation of 20 is: 10100. The total number of set bits in 20 is 2.
Read MoreHow to create a frequency table in data frame format in R?
To create a frequency table in R, we can simply use table function but the output of table function returns a horizontal table. If we want to read the table in data frame format then we would need to read the table as a data frame using as.data.frame function. For example, if we have a table called T then to convert it into a data frame format we can use the command as.data.frame(T).Example1> x1 x1Output[1] 2 0 2 3 2 3 1 2 1 4 0 0 4 4 1 3 1 2 1 3 2 3 2 1 4 ...
Read MorePython program to remove duplicate elements from a Doubly Linked List\\n
When it is required to remove the duplicate elements in a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Exampleclass Node: def __init__(self, my_data): self.previous = None self.data = my_data self.next = None class double_list: def __init__(self): self.head = None ...
Read MoreGolang Program to find the minimum and maximum number, using binary operations.
ExamplesFor example, x = 12, y = 15 => Maximum number is 15.For example, x = 13, y = 17 => Minimum number is 13.Approach to solve this problemStep 1 − Define method, findMax and findMin, that accept two integer x and y.Step 2 − Return integer according to defined method.Examplepackage main import "fmt" func FindMax(x, y int){ fmt.Printf("Maximum element in %d, and %d is: %d", x, y, x - ((x - y) & ((x - y) >> 31))) } func FindMin(x, y int) { fmt.Printf("Minimum element in %d, and %d is: %d", x, y, y + ...
Read MorePython program to rotate doubly linked list by N nodes
When it is required to rotate a doubly linked list by a specific number of nodes, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Exampleclass Node: def __init__(self, my_data): self.previous = None self.data = my_data self.next = None class double_list: def __init__(self): self.head = None ...
Read MoreGolang Program to round up the next highest power of 2.
ExamplesFor example, n = 12 => Next number power of 2 is 16.For example, n = 20 => Next number power of 2 is 32.Approach to solve this problemStep 1 − Define method, that accepts a number n.Step 2 − Iterate k := 1 until k < n.Step 3 − In a loop, calculate k
Read MorePython program to search an element in a doubly linked list
When it is required to search for an element in a doubly linked list, a ‘Node’ class needs to be created. In this class, there are three attributes, the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list.Another class needs to be created that would have an initialization function, and the head of the node would be initialized to ‘None’ inside this.Multiple methods are defined by the user to add node to the linked list, to display the nodes it and ...
Read MoreGolang Program to round up the next previous power of 2.
ExamplesFor example, n = 12 => Previous number power of 2 is 8.For example, n = 20 => Previous number power of 2 is 16.Approach to solve this problemStep 1 − Define a method that accepts a number n.Step 2 − Perform n | (n >> k), where k is 1, 2, 4, 8, 16.Step 3 − At the end, return n - (n >> 1).Examplepackage main import "fmt" func PreviousPowOf2(n int) int{ n = n | (n >> 1) n = n | (n >> 2) n = n | (n >> 4) n = ...
Read MorePython Program to Print an Identity Matrix
When it is required to print an identity matrix, nested loops can be used.Below is a demonstration for the same −Examplen = 4 print("The value of n has been initialized to " +str(n)) for i in range(0, n): for j in range(0, n): if(i==j): print("1", sep=" ", end=" ") else: print("0", sep=" ", end=" ") print()OutputThe value of n has been initialized to 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1ExplanationThe value of ‘n’ is ...
Read More