Found 33676 Articles for Programming

Fill array with 1's using minimum iterations of filling neighbors in C++

sudhir sharma
Updated on 22-Jan-2021 13:45:26

199 Views

 In this problem, we are given an array arr consisting of n elements that are either 0 or 1. Our task is to fill array with 1’s using minimum iterations of filling neighbors. Let’s take an example to understand the problem, Input: arr[] = {0, 1, 1, 0, 0, 1}Output: 1Solution Approach −To solve the problem, we need to know the fact that if 1 is present in a position it can convert two neighbouring 0’s to 1.If,                arr[i] is 1.Then,           arr[i-1] and arr[i+1] will be converted to 1.Using this, the ... Read More

File opening modes(r versus r+) in C++

sudhir sharma
Updated on 22-Jan-2021 13:49:44

3K+ Views

File handling in programming languages is very important for the interaction of programming with the memory for accessing files and fetching data in it.Using a program, you can read data from a file as well as write data to the file and do a lot more functions.Here, we will see reading of data from a file.In programming, before performing any operation you need to open the file. And there are multiple modes to open a file in the programming language. The access to the file is based on the mode it is opened with.Here we will learn about the difference between ... Read More

File globbing in Linux in C++

sudhir sharma
Updated on 22-Jan-2021 13:45:44

709 Views

p>File globbing also known as Path Name Expansion. It is the method of recognizing wildcard patterns in linux and  then finding the file path expansion based on these patterns.Wildcard Patterns are strings that are used for selection of multiple files based on patterns.The character patterns like “?” , “[ ]” , “*” are used for pattern matching and multiselection of the files.Example of wildcard characters using in file globbing:Asterisk (*) : the * pattern is used when we need to match 0 or more character after the string in the filename.For example: file* will match all files with name file, files, file2, or with anything ... Read More

Fifth root of a number in C++

sudhir sharma
Updated on 22-Jan-2021 13:45:29

1K+ Views

In this problem, we are given a number N. Our task is to find the floor value of the fifth root of a number.Fifth Root of a number is the number which when multiplied to itself 5 times returns the number.If N1/5 = a then, a*a*a*a*a = N.Let’s take an example to understand the problem, Input: N = 325Output: 3Explanation:  The fifth root of 325 is 3.179 whose floor value is 3.Solution Approach: A simple solution to the problem is traversing from 1 to n. And finding the number which when multiplied to itself five times gives the number.Here, the exact value cannot be found ... Read More

Fermat's little theorem in C++

sudhir sharma
Updated on 22-Jan-2021 13:45:58

792 Views

Fermat’s little theorem −This theorem states that for any prime number p,           Ap - p is a multiple of p.This statement in modular arithmetic is denoted as,                  ap  ≡ a (mod p)If a is not divisible by p then,  ap - 1 ≡ 1 (mod p)In this problem, we are given two numbers a and p. Our task is to verify fermat’s little theorem on these values.We need to check if ap  ≡ a (mod p) or ap - 1 ≡ 1 (mod p)Holds true for the given values of a and p.Let’s take ... Read More

Fermat's Last Theorem in C++

sudhir sharma
Updated on 22-Jan-2021 13:33:04

232 Views

Fermat’s last theorem in number theory also known as Fermet’s conjecture is a theorem that states that for power n greater than 2. No three values a, b, c satisfy −          an + bn = cni.e.     if n 32 + 42 = 9 + 16 = 25 = 52. 5, 12, 13 => 25 + 49 = 169 = 132.In this problem, we are given three values, L, R, pow denoting range [L, R] and power. Our task is to verify the fermat’s last theorem for the given range and power.Let’s take an example to understand the problem, ... Read More

Federated database management system issues in C++

sudhir sharma
Updated on 22-Jan-2021 13:32:47

341 Views

Database Management System or DBMS in short refers to the technology of storing and retrieving usersí data with utmost efficiency along with appropriate security measures.Federated Database management system is a special type of DBMS in which transparently maps more that one autonomous database into one database which is federated database.The federated database management system is useful while working with multiple applications that uses federation of databases.There are some issues with the federated database management system. They are −Managing the difference in data models,  while working with federated databases multiple applications can have different type of data models and dealing with these ... Read More

Fast inverse square root in C++

sudhir sharma
Updated on 22-Jan-2021 13:32:33

2K+ Views

In this problem, we are given an integers x. Our task is to calculate Fast inverse square root () of a 32-bit floating point number.  The algorithm to find the inverse square root of the number is of great use in programming, such as vector normalization in video games,  in 3D graphics, etc.  Algorithm: Step 1: The algorithm converts the floating point value to integer. Step 2: Operate on the integer value and return approximate value of the inverse square root.Step 3: Convert the integer value back to floating point using the same method used in step 1.Step 4: The approximation is made for improving precision using ... Read More

Fast average of two numbers without division in C++

sudhir sharma
Updated on 22-Jan-2021 13:30:31

426 Views

In this problem, we are given two numbers A and B. Our task is to create a program to calculate the Fast average of two numbers without division. Let’s take an example to understand the problem, Input: A = 34       B = 54Output: 44Solution Approach: Normally, the average is calculated by adding two numbers and then divide it by 2. This requires division but we need to find the average without using division. This can be done using right shift operator >> and shift the binary expansion instead of using division operator.Program to illustrate the working of our solution, ExampleLive Demo#include ... Read More

External Sorting with Example in C++

sudhir sharma
Updated on 22-Jan-2021 13:30:46

3K+ Views

External Sorting is a category of sorting algorithm that is able to sort huge amounts of data. This type of sorting is applied on data set which acquire large memory which cannot be holded in main memory (RAM) and is stored in secondary memory ( hard disk).The idea of sorting used in external sort is quite similar to merge sort. In also possess two phases like in merge sort, In the sort phase,  small memory size data sets are sorted and then in merge phase, these are combined to a single dataset.External Sorting For a huge data set which cannot be processed in ... Read More

Advertisements