Found 7197 Articles for C++

C++ Program to Represent Graph Using Linked List

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

2K+ Views

What is Linked List? A linked list is a linear data structure which can store a collection of "nodes" connected together via links i.e. pointers. Linked lists nodes are not stored at a contiguous location, rather they are linked using pointers to the different memory locations. A linked list can be used for graph representations. In the graph representation: Each vertex has its own linked list that stores its adjacent vertices. This forms an adjacency list using linked lists instead of vectors or arrays. Graph The image below ... Read More

C++ Program to Represent Graph Using Adjacency List

Farhan Muhamed
Updated on 15-Apr-2025 18:23:30

4K+ Views

What is Adjacency List? An adjacency list is a collection of unordered lists that are used to represent a finite graph. Each list in the collection represents one of the vertex of the graph and it will store the adjacent vertices of that vertex. Let's see an example: Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Adjacency List The adjacency list of the above graph is shown below. Algorithm The following are the steps to create (represent) a graph using an adjacency list: ... Read More

C++ Program to Represent Graph Using Incidence Matrix

Farhan Muhamed
Updated on 15-Apr-2025 18:20:09

2K+ Views

What is incidence matrix? An incidence matrix is a mathematical representation of a graph that shows the relationship between vertices and edges. In other words, it is a matrix M of size v x e, where v = number of vertices and e = number of edges. For example, if the graph has an edge number n from vertex i to vertex j, then in the incidence matrix at ith row and nth column it will be 1. Graph The image below represent a simple undirected graph with 6 vertices and 8 edges. Incidence Matrix The incidence ... Read More

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

451 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

351 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

912 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

Advertisements