Found 26504 Articles for Server Side Programming

Selection Sort in Go Lang

Dev Prakash Sharma
Updated on 23-Feb-2021 18:27:34

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

Find the Nth Ugly Number in Java

Dev Prakash Sharma
Updated on 23-Feb-2021 18:37:00

1K+ Views

A number whose prime factors are either 2, 3 or 5 is called an Ugly Number.  Some of the ugly numbers are: 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, etc.We have a number N and the task is to find the Nth Ugly number in the sequence of Ugly numbers.For Example:Input-1:N = 5Output:5Explanation:The 5th ugly number in the sequence of ugly numbers [1, 2, 3, 4, 5, 6, 8, 10, 12, 15] is 5.Input-2:N = 7Output:8Explanation:The 7th ugly number in the sequence of ugly numbers [1, 2, 3, 4, 5, 6, 8, 10, 12, 15] is 8.Approach ... Read More

Find the Intersection Point of Two Linked Lists in Java

Dev Prakash Sharma
Updated on 23-Feb-2021 18:42:34

635 Views

A Linked List is a linear data structure in which each node has two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to the other nodes in the list. The task is to find the node at which two linked lists intersect each other. If they don’t intersect, then return NULL or empty as output.For ExampleInput-1:Output:2Explanation: Since the given linked list intersects at the node with ... Read More

Significance of regex match() and regex search() function in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 05:50:24

630 Views

There are two types of operations that can be performed using regex, (a) search and (b) match. In order to use regex efficiently while finding the pattern and matching with the pattern, we can use these two functions.Let us consider that we have a string. regex match() checks the pattern only at the beginning of the string, while regex search() checks the pattern anywhere in the string. The match() function returns the match object if a pattern is found, otherwise none.match() – Finds the pattern only at the beginning of the string and returns the matched object.search() – Checks for ... Read More

Python Program to Construct an Expression Tree of a given Expression

Dev Prakash Sharma
Updated on 23-Feb-2021 18:49:16

3K+ Views

Expression trees are those in which the leaf nodes have the values to be operated, and the internal nodes contain the operator on which the leaf node will be performed.Example: 4 + ((7 + 9) * 2) will have an expression tree like -Approach to solve this ProblemIn order to construct an Expression Tree for a given expression, we generally use Stack Data Structure. Initially we Iterate over the given postfix expression and follow the steps as given below -If we get an operand in the given expression, then push it in the stack. It will become the root of the ... Read More

Make three numbers Zero in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 18:56:04

319 Views

Let us suppose we have three numbers. The task is to count the total number of optimal steps to make all these numbers '0'.For ExampleInput-1:a = 4 b = 4 c = 6Output:7Explanation:The total number of optimal steps to make all the numbers '0' is, (4, 4, 6)Removing '1' from 1st and 2nd number = (3, 3, 6)Removing '1' from 1st and 3rd number = (2, 3, 5)Removing '1' from 1st and 3rd number = (1 ,3, 4)Removing '1' from 1st and 3rd number = (0 ,3 ,3)Removing '1' from 2nd and 3rd number = (0 ,2, 2)Removing '1' from ... Read More

Largest Merge of Two Strings in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 19:01:14

299 Views

Let us suppose we have two strings 'a' and 'b' and a string 'merge'. The task is to fill the string 'merge' with the characters from 'a' and 'b' in such a way that, If the string 'a' is non-empty, then remove the first character from the string 'a' and copy it into string 'merge'.If the string 'b' is non-empty, then remove the first character from the string 'b' and copy it into string 'merge'.If the strings 'a' and 'b' are non-empty, then remove the first characters from string 'a' and copy it into string 'merge' and then remove the ... Read More

Explain pointers and one-dimensional array in C language

Bhanu Priya
Updated on 17-Mar-2021 10:21:38

8K+ Views

Pointer is a variable that stores the address of another variable.FeaturesThe features of pointer are explained below −Pointer saves the memory space.Execution time of pointer is faster because of direct access to the memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used with data structures.Pointer declaration, initialization and accessingConsider the following statement −int qty = 179;In memory, the variable can be represented as follows −Declaring a pointerIt means ‘p’ is a pointer variable which holds the address of another integer variable, as mentioned in the statement below −Int *p;Initialization ... Read More

How to send individual elements as an argument in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:02:07

205 Views

The array is a group of related items that is stored with a common name.Declaring arrayThe syntax used for declaring an array is as follows −datatype array_name [size];InitializationAn array can be initialized in two ways, which are as follows −Compile time initializationRuntime initializationAn array can also be initialized at the time of declaration as follows −int a[5] = {100, 200, 300, 400, 500};FunctionA function is a self-contained block that carries out a specific well-defined task. The two ways of passing the arrays as arguments to functions are as follows −Sending an entire array as argument to function.Sending the individual elements ... Read More

Explain the scope rules related to the statement blocks in C language

Bhanu Priya
Updated on 15-Mar-2021 15:21:54

194 Views

The scope rules are related to the following factors −Accessibility of a variables.Period of existence of a variable.Boundary of usage of variables.Scope rules related to statement blocks are given below −Block is enclosed in curly braces which consists of set of statements.Variables declared in a block are accessible and usable within that block and does not exist outside it.Example 1Following is the C program for scope rules related to statement blocks − Live Demo#include main ( ){    {       int i = 1;       printf ("%d", i);    }    {       int j=2;   ... Read More

Advertisements