Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 668 of 719
4K+ Views
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. Our task is to implement the counting sort algorithm to sort the given unsorted array in C++. Example Here is an example of ... Read More
2K+ Views
The shell sorting technique is based on the insertion sort. In the insertion sort, sometimes we need to shift a large block to insert an item in the correct position. In shell sort, we avoid large number of shifting. The sorting is done with specific interval. After each pass, the interval is reduced to make smaller interval. We call also say we use gapped insertion sort in shell sort as we compare elements separated by a gap. In this article, we have an unsorted array. Our task is to sort the given unsorted array by implementing the shell sort in ... Read More
19K+ Views
The insertion sort technique is an in-place comparison-based sorting algorithm used to sort the numbers in an ascending or descending order. It is similar to the card sorting technique. In this technique, we pick up one element from the data set and shift the data elements to make a place to insert the picked-up element into the data set. In this article, we have an array of integers. Our task is to implement insertion sort in C++ to sort the given array. Example Here is an example of an array before sorting and after sorting using insertion sort: ... Read More
22K+ Views
The selection sort is an in-place comparison-based simple sorting algorithm. In the selection sort technique, the list is divided into two parts: sorted and unsorted. The minimum element from the unsorted part is selected and swapped with the element at the beginning of the list. Similarly, the next minimum value from the unsorted list is placed at the next position in the sorted list, and this keeps repeating until the whole array is sorted. In this article, we have an unsorted array. Our task is to sort this array using selection sort in C++. Here is an example of selection ... Read More
46K+ 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. In this article, we have an unsorted array of integers and our task is to implement the merge sort to sort the unsorted array. Steps to to Implement Merge Sort We will be using the steps mentioned below to implement the merge sort algorithm: ... Read More
1K+ Views
The Heap Sort is a comparison-based sorting algorithm that sorts the numbers using a binary heap. It is an in-place sorting method, that means it sorts the array without needing any extra space. In this article, we have been given an unsorted array and our task is to implement the heap sort in C++. What is Heap Sort? The heap sort is an efficient sorting technique that first constructs the heap ADT and then removes the root element to swap it with the node having minimum value at the leaf position. Then we use the heapify method ... Read More
17K+ Views
Bubble sort is comparison based sorting algorithm. It works by going through the list, comparing each pair of numbers, and swapping them if they are in the wrong order. This process is repeated until the list is sorted. The name "bubble sort" comes from the way smaller numbers move to the front of the list, like bubbles rising to the top. While bubble sort is easy to understand, it is not the most efficient way to sort numbers. Other sorting methods, like insertion sort, tend to work faster and handle larger lists better. One good thing about bubble ... Read More
2K+ Views
In the Bucket Sorting technique, the data items are distributed of a set of buckets. Each bucket can hold similar type of data. After distributing, each bucket is sorted using another sorting algorithm. After that all elements are gathered into the main list to get the sorted form.The complexity of Bucket Sort TechniqueTime Complexity: O(n + k) for best case and average case and O(n2 ) for worst case.Space Complexity: O(nk) for worst caseInput − A list of unsorted data: 0.25 0.36 0.58 0.41 0.29 0.22 0.45 0.79 0.01 0.69 Output − Array after Sorting: 0.01 0.22 0.25 0.29 0.36 ... Read More
4K+ Views
The radix sort is a non-comparative sorting algorithm that sorts the individual digits of the given numbers in the list. It sorts the numbers digit by digit, starting from the least significant digit to the most significant digit. The radix sort assumes that all the input elements are k-digit numbers. So, if the elements do not have the same number of digits, find the maximum number of digits in an input element and prepend zeroes to the elements having less number of digits. In this article, we have an unsorted array of integers and our task is to implement the ... Read More
5K+ Views
In this article, we will learn how to calculate Fibonacci numbers efficiently using dynamic programming in C++. The Fibonacci sequence starts with 0 and 1, and each next number is the sum of the two preceding ones. The basic recursive method works but becomes very slow for larger numbers because it repeats the same calculations many times. Dynamic programming solves this by storing the results of previous calculations, which makes the process much faster and more efficient. For example, if we want to find the 6th Fibonacci number, the sequence will look like this: F(0) = 0 ... Read More