Found 26504 Articles for Server Side Programming

Priority Queue using doubly linked list in C++

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

732 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

503 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

221 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

574 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

Minimum steps to remove substring 010 from a binary string in C++

Narendra Kumar
Updated on 23-Dec-2019 07:02:29

204 Views

Problem statementGiven a binary string, the task is to count the minimum steps to remove substring 010 from this binary stringExampleIf input string is 010010 then 2 steps are requiredConvert first 0 to 1. Now string becomes 110010Convert last 0 to 1. Now final string becomes 110011Algorithm1. Iterate the string from index 0 sto n-2 2. If in binary string has consecutive three characters ‘0’, ‘1’, ‘0’ then any one character can be changed Increase the loop counter by 2Example Live Demo#include using namespace std; int getMinSteps(string str) {    int cnt = 0;    for (int i = ... Read More

Python Program for nth multiple of a number in Fibonacci Series

Pavitra
Updated on 23-Dec-2019 07:00:09

1K+ 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 find the nth multiple of a number k in Fibonacci number.The solution to the problem is discussed below−Example Live Demo# find function def find(k, n):    f1 = 0    f2 = 1    i =2;    #fibonacci recursion    while i!=0:       f3 = f1 + f2;       f1 = f2;       f2 = f3;       if f2%k == 0:          return n*i     ... Read More

C++ Program for Shortest Job First (SJF) scheduling(preemptive)

Sunidhi Bansal
Updated on 23-Dec-2019 07:02:50

19K+ Views

Given process, the burst time of a process respectively and a quantum limit; the task is to find and print the waiting time, turnaround time and their respective average time using Shortest Job First Scheduling preemptive method.What is the shortest job first scheduling?Shortest job first scheduling is the job or process scheduling algorithm that follows the nonpreemptive scheduling discipline. In this, scheduler selects the process from the waiting queue with the least completion time and allocate the CPU to that job or process. Shortest Job First is more desirable than FIFO algorithm because SJF is more optimal as it reduces ... Read More

Minimum steps to make all the elements of the array divisible by 4 in C++

Narendra Kumar
Updated on 23-Dec-2019 06:57:29

473 Views

Problem statementGiven an array of size n, the task iss to find the minimum number of steps required to make all the elements of the array divisible by 4. A step is defined as removal of any two elements from the array and adding the sum of these elements to the arrayExampleIf input array is {1, 2, 0, 2, 4, 3} then 3 operations are required −1 + 3 = 4 2 + 2 = 4 0 + 4 = 4Algorithm1. Sum of all the elements of the array should be divisible by If not, this task is not possible ... Read More

Minimum steps to delete a string after repeated deletion of palindrome substrings in C++

Narendra Kumar
Updated on 23-Dec-2019 06:52:26

939 Views

Problem statementGiven a string containing characters as integers only. We need to delete all character of this string in a minimum number of steps where in one step we can delete the substring which is a palindrome. After deleting a substring remaining parts are concatenated.ExampleIf input string is 3441213 then minimum 2 steps requiredFirst remove 121 from string. Now remaining string is 3443Remove remaining string as it’s palindromeAlgorithmWe can use dynamic programming to solve this problem1. Let dp[i][j] denotes the number of steps it takes to delete the substring s[i, j] 2. Each character will be deleted alone or as ... Read More

Find sum of even factors of a number in Python Program

Utkarsha Naithani
Updated on 23-Aug-2022 14:01:49

641 Views

Let’s start our article with an explanation of how to find the sum of even factors of a number but what are factors? Factors are the numbers which completely divide the given number leaving zero as remainder or we can say factors are the multiples of the number. Example 1 − If we are given a number 60 Factors of 60 (6*10=2*3*2*5) are 2, 5 and 3 But according to the question, we must find out the sum of even factors so, in the above given example, the even factor will be only 2. Also, if the given number is an ... Read More

Advertisements