Server Side Programming Articles - Page 1980 of 2650

Product of lengths of all cycles in an undirected graph in C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:30:16

236 Views

We are given with the undirected as well as unweighted graph as an input and the task is to find the product of the cycles that are formed in the given and display the result.ExampleInputIn the given figure, there are 8 nodes and out of that 5 nodes are forming cycle including 1, 6, 3, 5, 8 and rest of the node are not included in the cycle. So, the length of the cycle is 5 as it includes 5 node therefore product is 5In the given figure, there are 12 nodes and out of that 11(5 +6) nodes are ... Read More

Priority Queue Introduction in C/C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:25:27

547 Views

A priority queue is a type of queue in which elements are inserted or deleted according to the priorities assigned to them where priority is an integer value that can range between 0-10 where 0 shows the element with the highest priority and 10 shows the element with the lowest priority. There are two rules that are followed for implementing priority queue −Data or element with the highest priority will get executed before the data or element with the lowest priority.If two elements have the same priority than they will be executed in the sequence they are added in the ... Read More

Convert a list to string in Python program

Pavitra
Updated on 23-Dec-2019 07:28:22

246 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list iterable, we need to convert it into a string type iterable.There are four approaches to solve the given problem. Let’s see them one by one−Brute-force ApproachExample Live Demodef listToString(s):    # initialize an empty string    str_ = ""    # traverse in the string    for ele in s:       str_ += ele    # return string    return str_ # main s = ['Tutorials', 'Point'] print(listToString(s))OutputTutorialsPointUsing Built-In join() methodExampledef listToString(s):    # initialize an empty string ... Read More

Probability of getting a sum on throwing 2 Dices N times in C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:24:49

358 Views

We are given with the sum and the number of times the pair of dice is thrown as an input and the task is to determine the probability of getting the given sum on throwing a pair of dice N times.Probability is the chances of getting the desired output from the set of data available. The range of probability lie between 0 and 1 where an integer 0 shows the chances of impossibility and 1 indicates certainty.ExampleInput-: sum = 12, N = 1 Output-: Probability = 1/36 Explanation-: if a pair of dice is thrown once then the combinations will ... Read More

Python program to check if the given string is vowel Palindrome

Pavitra
Updated on 23-Dec-2019 07:17:47

479 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given string (containing both vowel and consonant letters), remove all consonants, then check if the resulting string is a palindrome or not.Here we first remove all the consonants present in the string. A loop to calculate the divisors by computed by dividing each value from 1 to the minimum computedEach time the condition is evaluated to be true counter is incremented by one.Remove all the consonants in the string. Now we check whether the vowel string is a palindrome or not i.e. ... Read More

Priority Queue using Linked List in C

Sunidhi Bansal
Updated on 23-Dec-2019 07:15:27

4K+ Views

We are given with the data and the priority as an integer value and the task is to create a linked list as per the priority given and display the result.Queue is a FIFO data structure in which the element which is inserted first is the first one to get removed. A Priority Queue is a type of queue in which elements can be inserted or deleted depending upon the priority. It can be implemented using queue, stack or linked list data structure. Priority queue is implemented by following these rules −Data or element with the highest priority will get ... Read More

Priority Queue using doubly linked list in C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:10:39

754 Views

We are given with the data and the priority as an integer value and the task is to create a doubly linked list as per the priority given and display the result.Queue is a FIFO data structure in which the element which is inserted first is the first one to get removed. A Priority Queue is a type of queue in which elements can be inserted or deleted depending upon the priority. It can be implemented using queue, stack or linked list data structure. Priority queue is implemented by following these rules −Data or element with the highest priority will ... Read More

Python program to check if a given string is Keyword or not

Pavitra
Updated on 23-Dec-2019 07:13:45

511 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a number, we need to check that the number is a power of two or not.Keywords are the special words reserved by any language with specific usage and cannot be used as an identifier.To check whether the given string is a keyword we used the keyword module as discussed below.Example Live Demo# keyword module import keyword # Function def isKeyword(word) :    # list of all keywords    keyword_list = keyword.kwlist    # check the presence    if word in keyword_list : ... Read More

Minimum sum falling path in a NxN grid in C++

Narendra Kumar
Updated on 23-Dec-2019 07:05:13

235 Views

Problem statementGiven a matrix A of integers of size NxN. The task is to find the minimum sum of a falling path through A.A falling path will start at any element in the first row and ends in last row.It chooses one element from each next row. The next row’s choice must be in a column that is different from the previous row’s column by at most onesExampleIf N = 2 and matrix is: {    {5, 10},    {25, 15} } then output will be 20 as element 5 and 15 are selectedExample Live Demo#include #define MAX 2 using ... Read More

Python Program for Number of elements with odd factors in the given range

Pavitra
Updated on 23-Dec-2019 07:03:27

589 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a range, we need to find the number of odd factors in the range.ApproachAs we all know that all perfect squares have an odd number of factors in a range. So here we will compute a number of perfect squares.As m and n both are inclusive, so to avoid error in case of n being a perfect square we take n-1 in the formulae.Now let’s see the implementation below−Example Live Demo# count function def count(n, m):    return int(m**0.5) - int((n-1)**0.5) # ... Read More

Advertisements