C++ Program for Shortest Job First (SJF) Scheduling Non-Preemptive

Sunidhi Bansal
Updated on 23-Dec-2019 06:52:39

7K+ 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 non-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 Delete a String after Repeated Deletion of Palindrome Substrings in C++

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

993 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

Minimum Rotations Required to Get the Same String in C++

Narendra Kumar
Updated on 23-Dec-2019 06:45:35

333 Views

Problem statementGiven a string, we need to find the minimum number of rotations required to get the same stringExampleIf input string is “bbbbb” then minimum 1 rotation is requiredAlgorithm1. Initialize result = 0 2. Make a temporary string equals to original string concatenated with itself. 3. Take the substring of temporary string of size same as original string starting from second character i.e. index 1 4. Increment the counter 5. Check whether the substring becomes equal to original string. If yes, then break the loop. Else go to step 2 and repeat it from the next indexExample Live Demo#include using ... Read More

Efficient Program to Print All Prime Factors of a Given Number in Python

Pavitra
Updated on 23-Dec-2019 06:43:38

359 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 all the prime factors of a given number.The efficient solution to the problem is discussed below −Example Live Demo# Python program to print prime factors import math # prime def primeFactors(n):    # no of even divisibility    while n % 2 == 0:       print (2),       n = n / 2    # n reduces to become odd    for i in range(3, int(math.sqrt(n))+1, 2):       # while ... Read More

Common Divisors of Two Numbers in Python

Pavitra
Updated on 23-Dec-2019 06:40:33

542 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given two integers, we need to display the common divisors of two numbersHere we are computing the minimum of the two numbers we take as input. 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.Now let’s observe the concept in the implementation below−Example Live Demoa = 5 b = 45 count = 0 for i in range(1, min(a, b)+1):   ... Read More

Minimum Removals in a Number to be Divisible by 10^k in C++

Narendra Kumar
Updated on 23-Dec-2019 06:36:22

171 Views

Problem statementGiven two positive integers N and K. Find the minimum number of digits that can be removed from the number N such that after removals the number is divisible by 10K. Print -1 if it is impossible.ExampleIf N = 10203027 and K = 2 then we have to remove 3 digits. If we remove 3, 2 and 7 then number become 10200 which is divisible by 102Algorithm1. Start traversing number from end. If the current digit is not zero, increment the counter variable, otherwise decrement variable K 2. If K is zero, then return counter as answer 3. After ... Read More

C++ Program for Coefficient of Variation

Sunidhi Bansal
Updated on 23-Dec-2019 06:36:06

702 Views

We are given with an array of float values of size n and the task is to find the coefficient of variation and display the result.What is the coefficient of variation?In statistic measure, coefficient of variation is used to find the range of variability through the data given. In terms of finance, coefficient of variation is used to find the amount of risk involved with respect to the amount invested. If the ratio between standard deviation and mean is low then the risk involved in the investment is also low. Coefficient of variation is the ratio between standard deviation and ... Read More

C++ Program for Expressionless Face Pattern Printing

Sunidhi Bansal
Updated on 23-Dec-2019 06:33:07

342 Views

Given a number n; the task is to create the Expressionless face pattern upto n lines and display the results. Expressionless face is created using special characters, expressionless face using special character seems like: “*_*”.ExampleInput-: n = 6 Output-:Input-: n = 8 Output-: AlgorithmStart Step 1-> In function print_stars(int i)    Loop For j = 1 and j In function print_pattern(int rows)    Loop For i = 1 and i In function int main()    Declare and set rows = 8    Call print_pattern(rows) StopExample Live Demo#include using namespace std; //function to print stars void print_stars(int i) {    for (int j = 1; j

Minimum Removals from Array to Make Max-Min K in C++

Narendra Kumar
Updated on 23-Dec-2019 06:32:46

406 Views

Problem statementGiven N integers and K, find the minimum number of elements that should be removed such that Amax - Amin

Reverse a String Recursively in C++

Ajay yadav
Updated on 23-Dec-2019 06:30:31

1K+ Views

Recursion is simply the way toward rehashing things in a self-comparative way. In programming dialects, if a program enables you to call a capacity inside a similar capacity, at that point, it is known as a recursive call of the capacity. You can switch a string utilizing the recursive capacity as appeared in the accompanying project.Example Live Demo#include using namespace std; void reverse(string str){    if(str.size() == 0){       return;    }    reverse(str.substr(1));    cout

Advertisements