- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
328 Views
The quicksort technique is done by separating the list into two parts. Initially a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using same procedure.Here we are considering a large array (nearly 100 elements) to sort. We are taking some numbers then shuffling them in randomized order to make them unsorted. Then sort using quicksort technique.The complexity of Quicksort TechniqueTime Complexity − O(n log n) for best case and average case, O(n2) for worst case.Space ... Read More
240 Views
To sort some small numbers in linear time we can use the counting sort technique.Counting sort is a stable sorting technique, which is used to sort objects according the keys that are small numbers. It counts the number of keys whose key values are same. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity.The complexity of counting Sort TechniqueTime Complexity: O(n + r)Space Complexity: O(n + r)Input − A list of unsorted data: 2 5 6 2 3 10 3 6 7 8 Output − Array after Sorting: ... Read More
3K+ Views
The quicksort technique is done by separating the list into two parts. Initially a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using same procedure.In this case we are choosing the pivot element randomly. After choosing the pivot, we are doing the partitioning, then sort the array recursively.The complexity of Quicksort TechniqueTime Complexity − O(n log n) for best case and average case, O(n2) for worst case.Space Complexity − O(log n)Input − The unsorted list: 90 ... Read More
2K+ Views
The Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, i.e; each number is the sum of the two preceding ones, starting from 0 and 1. That is −F0 = 0 and F1 = 1 And Fn = Fn-1 + Fn-2 for n > 1.AlgorithmBegin Take two 2 dimensional array Create a function and Perform matrix multiplication Create another function to find out power of matrix Create a function then to find out the Fibonacci number Multiply(arr1[2][2], arr2[2][2]) Take ... Read More
669 Views
Fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Basically Fourier analysis converts time (or space) to frequency and vice versa. A FFT rapidly computes transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.AlgorithmBegin Declare the size of the array Take the elements of the array Declare three arrays Initialize height =size of array and width=size of array Create two outer loops to iterate on output data Create two outer loops to iterate on input data Compute real, img and ... Read More
3K+ Views
In discrete Fourier transform (DFT), a finite list is converted of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids. They ordered by their frequencies, that has those same sample values, to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.AlgorithmBegin Take a variable M and initialize it to some integer Declare an array function[M] For i = 0 to M-1 do function[i] = (((a * (double) i) + (b * (double) i)) - c) ... Read More
211 Views
In discrete Fourier transform (DFT), a finite list is converted of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids. They ordered by their frequencies, that has those same sample values, to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.AlgorithmBegin Declare three variables which are the coefficient of linear equation and max value Read the variables Define a class with two variables real, img Create a constructor and ... Read More
1K+ Views
The bin packing problem is a special type of cutting stock problem. In the bin packing problem, objects of different volumes must be packed into a finite number of containers or bins each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinational NP-hard problem.When the number of bins is restricted to 1 and each item is characterized by both a volume and a value, the problem of maximizing the value of items that can fit in the bin is known as the knapsack problem.AlgorithmBegin Binpacking(pointer, size, no ... Read More
691 Views
Here is a C++ Program to get all the unique partitions of a given integer such that addition of a partition results an integer. In this program, a positive integer n is given, and generate all possible unique ways to represent n as sum of positive integers.AlgorithmBegin function displayAllUniqueParts(int m): Declare an array to store a partition p[m]. Set Index of last element k in a partition to 0 Initialize first partition as number itself, p[k]=m Create a while loop which first prints current partition, then generates next partition. The loop stops when the current ... Read More
5K+ Views
In Fractional knapsack problem, a set of items are given, each with a weight and a value. We need to break items for maximizing the total value of knapsack and this can be done in greedy approach.AlgorithmBegin Take an array of structure Item Declare value, weight, knapsack weight and density Calculate density=value/weight for each item Sorting the items array on the order of decreasing density We add values from the top of the array to total value until the bag is full, i.e; total value