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
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Binary Search in C++ Standard Template Library (STL)
A binary search known as logarithmic search is a search algorithm that searches for an element in a sorted array. The algorithm recursively divides the array into two halves, if the element is found at the mid position then return otherwise call the divide and check again until the element is found.WorkingThe algorithm works by comparing the middle element of the sorted array with the element that is to be searched.If the search element is equal to the middle element, then return the index of the element.If the search element is greater than the middle element, search in the left ...
Read MorePython Program for Gnome Sort
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using gnome sort.Algorithm1. Firstly we traverse the array from left to right. 2. Now, if the current element is larger or equal to the previous element then we traverse one step ahead 3. otherwise, if the current element is smaller than the previous element then swap these two elements and traverse one step back. 4. Repeat steps given above till we reach the end of the arrayNow let’s observe the solution in the ...
Read MoreNested list comprehension in python
A nested list is a list within a list. Python provides features to handle nested list gracefully and apply common functions to manipulate the nested lists. In this article we will see how to use list comprehension to create and use nested lists in python.Creating a MatrixCreating a matrix involves creating series of rows and columns. We can use for loop for creating the matrix rows and columns by putting one python list with for loop inside another python list with for loop.Examplematrix = [[m for m in range(4)] for n in range(3)] print(matrix)Running the above code gives us the ...
Read MorePython Program for Heap Sort
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using the concept of heapsort.Here we place the maximum element at the end. This is repeated until the array is sorted.Now let’s observe the solution in the implementation below−Example# heapify def heapify(arr, n, i): largest = i # largest value l = 2 * i + 1 # left r = 2 * i + 2 # right # if left child exists if l < n and arr[i] ...
Read MoreJava regular expression program to validate an email including blank field valid as well
Following regular expression matches given e-mail id including the blank input −^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2, 6})?$Where, ^ matches the starting of the sentence.[a-zA-Z0-9._%+-] matches one character from English alphabet (both cases), digits, "+", "_", ".", "" and, "-" before the @ symbol.+ indicates the repetition of the above mentioned set of characters one or more times.@ matches itself[a-zA-Z0-9.-] matches one character from English alphabet (both cases), digits, "." and "-" after the @ symbol\.[a-zA-Z]{2, 6} two to 6 letter for email domain after "."$ indicates the end of the sentenceExample 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SampleTest { public static ...
Read MoreFind minimum of each index in list of lists in Python
In some problems we need to identify the minimum of each element in a list. But in solving the matrix operations, we need to find the minimum of each column in the matrix. That needs us to find the minimum value from list of lists. Because each column of a matrix is a list of lists.Using min() and zip()In the below example we use the min() and zip(). Here the zip() function organizes the elements at the same index from multiple lists into a single list. Then we apply the min() function to the result of zip function using a ...
Read MoreList.replaceAll(UnaryOperator operator) method in Java
The replaceAll() method of the List interface accept an object of the UnaryOperator representing a particular operation, performs the specified operation on all the elements of the current list and replaces the existing values in the list with their respective results.Exampleimport java.util.ArrayList; import java.util.function.UnaryOperator; class Op implements UnaryOperator { public String apply(String str) { return str.toUpperCase(); } } public class Test { public static void main(String[] args) throws CloneNotSupportedException { ArrayList list = new ArrayList(); list.add("Java"); list.add("JavaScript"); list.add("CoffeeScript"); list.add("HBase"); ...
Read MorePrint all the levels with odd and even number of nodes in it in C++
In this problem, we are given a tree. And we have to print all the levels with even number of nodes and odd number of nodes in it.Let’s take an example to understand the concept betterOutput −Levels with odd number of nodes: 1, 3, 4 Levels with even number of nodes: 2Explanation − The first level has only 1 element(odd), 2nd level contains two elements(even), 3rd level contains 3 elements(odd) and 4th level contains 1 element(even).Now, to solve this problem. We need to find the count of nodes at each level and print the even-odd levels accordingly.We will follow the ...
Read MorePython Program for Maximum height when coins are arranged in a triangle
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given N coins where we need to arrange them in form of a triangle, i.e. in the first row will have 1 coin, the second row will have 2 coins and so on, we need to display the maximum height that can be achieved by the help N coins.Now let’s observe the solution in the implementation below −Example# squareroot def squareRoot(n): # initial approximation x = n y = 1 e = 0.000001 # allowed error ...
Read MorePrint all the duplicates in the input string in C++
In this problem, we are given a string and we have to find all the characters that are duplicated along with their number of occurrences in the string.Let’s take an example to understand the problem −Input: TutorialsPoint Output: t (3) o (2) i (2)Explanation− The frequencies of occurrence of each character are t → 3; u → 1; o → 2; r → 1; i → 2; a → 1; s → 1; n → 1.Now, to solve this problem we will find the character count and store it in an array from the string. And then print the characters ...
Read More