Server Side Programming Articles - Page 2332 of 2650

C++ Program to Implement Selection Sort

Ravi Ranjan
Updated on 17-Apr-2025 16:53:03

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

C++ Program to Implement Merge Sort

Ravi Ranjan
Updated on 15-Apr-2025 15:26:32

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

C++ Program to Implement Heap Sort

Nishu Kumari
Updated on 17-Apr-2025 16:55:01

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

C++ Program to Implement Bubble Sort

Nancy Den
Updated on 21-Feb-2025 16:27:56

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

C++ Program to Implement Bucket Sort

Nancy Den
Updated on 30-Jul-2019 22:30:25

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

C++ Program to Implement Radix Sort

Ravi Ranjan
Updated on 16-Apr-2025 19:01:43

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

C++ Program to Find Fibonacci Numbers using Dynamic Programming

Nancy Den
Updated on 21-Feb-2025 16:30:27

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

C++ program to convert Fahrenheit to Celsius

Ravi Ranjan
Updated on 11-Apr-2025 17:17:03

4K+ Views

To convert fahrenheit to celsius, use a simple mathematical formula. In this article, we are going to discuss the conversion formula, a simple example, and an easy example code. We have been given a temperature in fahrenheit and our task is to convert the given temperature into celsius using C++. Understanding Fahrenheit to Celsius Formula The formula for converting the given temperature from fahrenheit to celsius is as follows: celsius = (fahrenheit - 32.0) * 5.0 / 9.0; Let's see an example to convert the temperature given in fahrenheit to celsius using the above formula: Input: Temperature in ... Read More

C++ program to generate random number

Ravi Ranjan
Updated on 11-Apr-2025 17:14:54

4K+ Views

Random numbers are the numbers that are unpredictable and we do not use any pattern or algorithm for choosing them. They are used to bring randomness such as while shuffling data or used in games. To generate a random number in C++, the built-in functions from different libraries such as or can be used. In this article, we will understand four different approaches for generating a random number. The approaches are listed below. Using rand() with srand() Functions Using rand() with Range Limit Using random_device ... Read More

C++ Program that will fill whole memory

George John
Updated on 30-Jul-2019 22:30:25

347 Views

In this article we will see how to fill the whole memory by writing a simple C++ program. Here the logic is very simple. We shall create new integer variables by using the dynamic memory allocation. If we create some variables again and again, it will fill the entire primary memory.In C++ to dynamically allocate a memory space we can use the new keyword.The basic syntax of the new operator is like below.pointer_var = new data_typeTo deallocate the memory space, we can use the delete keyword. The syntax isdelete pointer_varNote After running this program it may slow down the performance ... Read More

Advertisements