C++ Articles - Page 663 of 719

C++ Program to Represent Graph Using Adjacency Matrix

Farhan Muhamed
Updated on 15-Apr-2025 18:18:25

4K+ Views

What is Adjacency Matrix? Adjacency matrix is a square matrix that represent a finite graph data structure using a 2D array. The each elements in the matrix represent the edges of the graph. For example, if the graph has some edges from i to j vertices, then in the adjacency matrix at ith row and jth column it will be 1 (or some non-zero value for weighted graph), otherwise that place will hold 0. Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Adjacency Matrix The adjacency matrix of the ... Read More

C++ Program to Implement Merge Sort Algorithm on Linked List

Ravi Ranjan
Updated on 08-May-2025 18:48:55

2K+ Views

The merge sort technique is based on the divide-and-conquer technique. We divide the whole data set into smaller parts and merge them into a larger piece in sorted order. It is also very effective for worst cases because this algorithm has lower time complexity for worst cases too. A linked list can be sorted using merge sort very efficiently. For the linked list, the merging task is very simple. We can simply update the links to merge them. In this article, we have an unsorted linked list. Our task is to sort the given unsorted list using the merge ... Read More

C++ Program to Perform Quick Sort on Large Number of Elements

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

464 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

C++ Program to Implement Sorting of Less than 100 Numbers in O(n) Complexity

Ravi Ranjan
Updated on 08-May-2025 18:49:07

380 Views

To sort less than 100 numbers in O(N) complexity, we can use the counting sort technique. The counting sort is a stable and non-comparison-based sorting technique, that is used to sort the objects according to the keys that are small integers. It counts the number of keys whose key values are same. It works by counting the occurrences of elements in the array. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity. In this article, we have an unsorted array containing twelve elements. Our task is to sort ... Read More

C++ Program to Implement Quick Sort Using Randomization

Vrundesha Joshi
Updated on 28-Apr-2025 17:12:34

4K+ Views

The quick sort technique is based on partitioning of array of data into smaller arrays. Initially, a pivot element is chosen by the partitioning algorithm. The left part of the pivot holds smaller values than the pivot, and the right part holds the larger value. In this case, we are choosing the pivot element randomly. After choosing the pivot, we do the partitioning and then sort the array recursively. In this article, we have an array having 100 elements. Our task is to implement quick sort on this array using randomization in C++. Here is an example of a quick ... Read More

C++ Program to Find Fibonacci Numbers using Matrix Exponentiation

Nancy Den
Updated on 25-Apr-2025 14:17:38

3K+ Views

The Fibonacci numbers, commonly denoted as F(n) forms a sequence, called the Fibonacci sequence. In Fibonacci series, each number is the sum of the two previous two numbers, starting from 0 and 1. It is represented as F(n) = F(n-1) + F(n-2). The matrix exponentiation method is used to calculate the powers of matrix efficiently with better time complexity. In this article, we provide a value of n. This n is the value up to which we want to find the Fibonacci numbers using the matrix exponentiation method in C++. Here is an example of the Fibonacci series up to ... Read More

C++ Perform to a 2D FFT Inplace Given a Complex 2D Array

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

935 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

C++ Program to Compute Discrete Fourier Transform Using Naive Approach

Ravi Ranjan
Updated on 26-May-2025 11:52:03

3K+ Views

DFT stands for Discrete Fourier Transform. DFT is a mathematical technique in which we convert the signals of the time domain to their respective signal in the frequency domain, i.e., converting into a list of numbers that tell us which frequencies are present in that signal. Here, by time signal, we mean signals such as audio, temperature, etc that changes over time. The frequency signal means the frequency of each signal present in the time signal. The numbers that tell us which frequencies are present in the signal are called the coefficients. In this article, our task is to compute ... Read More

C++ Program to Compute DFT Coefficients Directly

Ravi Ranjan
Updated on 26-May-2025 11:51:43

338 Views

DFT stands for Discrete Fourier Transform. DFT is a mathematical technique in which we convert the signals of the time domain to their respective signal in the frequency domain, i.e., converting into a list of numbers that tell us which frequencies are present in that signal. Here, by time signal, we mean signals such as audio, temperature, etc. that changes over time. The frequency signal means the frequency of each signal present in the time signal. The numbers that tell us which frequencies are present in the signal are called the coefficients. In this article, our task is to compute ... Read More

C++ Program to Implement the Bin Packing Algorithm

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

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

Advertisements