Posts

Showing posts with the label Sorting

Top 10 Programming Language to learn in 2023

Are you a programming enthusiast looking to stay ahead of the curve in 2023? With the ever-evolving tech landscape, keeping up with the Best Programming Language to learn can be a daunting task. Fear not, as we have compiled a list of the top 10 Programming Languages that you should consider learning in 2023. Python: This versatile language continues to dominate in 2023, with its ease of use, readability, and a vast library of modules. JavaScript: As web development grows increasingly popular, JavaScript remains a crucial player, with its ability to create dynamic and interactive web pages. Java: This language has stood the test of time and remains a popular choice for enterprise software development. C++: A staple in the gaming and systems development industries, C++ offers exceptional performance and memory management. Swift: Apple's preferred language for iOS app development, Swift continues to grow in popularity with its simplicity and reliability. R: As data science and machin...

Selection Sort

Image
Selection Sort A selection sort is a sorting techniqlue in which successive elements are selected in order and paced into their proper sorted positions. By starting from the first element and using a nest of for loops, a pass through the array is made to locate the minimum value. Once this is found, it 1s placed in the first position of the array (position 0). Then the remaining elements is made to find the next smallest element, which is placed in the second position (position 1), and so on. Once the next to last element is compared with the last element, all the elements have been sorted into ascending order. The algorithm works as follows: Find the minimum value in the list. Swap it with the value in the first position. Repeat the above steps for the remainder of the list (starting at the second position and advancing each time). Algorithm for Selection Sort This algorithm sorts the array list with n elements Initialization, Set loc=o ...

Quick Sort

Image
Quick Sort It is also called partition exchange sort because it works by partitioning the array to be sorted. Basic Idea: Let x be an array and n be the number of elements in the array. Let us choose an element (called pivot) a from a specific position within the array (for example, a can be chosen as the first element so that a=x[o]). Now suppose that the elements of array x are partitioned in such a way that a is placed into position j of the array and the following conditions hold: Each of the elements in positions j through j-1 is less than or equal to a. Each of the elements in positions j+1 through n-1 is greater than or equal to a. If these two conditions hold for a particular a and j, a is the jth smallest element of array x, so that remains in position j when the array is completely sorted. lf the same process is repeated for sub-arrays x[o] through x[j-1] and x[j+1] through x[n-1] and any sub arrays created by the process in successive iterations, ...

C Program For Selection Sort | C Programming

C Program For Selection Sort by Generating Random Numbers and Using time.h Function #include <stdio.h> #include <time.h> #include <stdlib.h> void selection_sort ( int [], int ); int main () {     int list [ 100 ], n , i ;     time_t t ;     printf ( "Enter the max number \n " );     scanf ( " %d " , & n );     srand (( unsigned ) time (& t ));     for ( i = 0 ; i < n ; i ++)     {         list [ i ] = rand () % 100 ;     }     for ( i = 0 ; i < n ; i ++)     {         printf ( " %d \t " , list [ i ]);     }     selection_sort ( list , n );     printf ( " \n Time taken to complete the selectionsort %u " , clock () / CLOCKS_PER_SEC);     printf ( " \n The sorted list is: \n " );     for ( i = 0 ; i < n ; i ++)         printf ( " %d...

C Program For Merge Sort | C Programming

C Program For Merge Sort by Generating Random Numbers and Using time.h Function #include <stdio.h> #include <stdlib.h> #include <time.h> void mergesort ( int a [], int i , int j ); void merge ( int a [], int i1 , int j1 , int i2 , int j2 ); int main () {     int a [ 30 ], n , i ;     time_t t ;     printf ( "Enter the max number \n " );     scanf ( " %d " , & n );     srand (( unsigned ) time (& t ));     for ( i = 0 ; i < n ; i ++)     {         a [ i ] = rand () % 100 ;     }     for ( i = 0 ; i < n ; i ++)     {         printf ( " %d \t " , a [ i ]);     }     mergesort ( a , 0 , n - 1 );     printf ( " \n\n Time taken to complete the mergesort %u \n " , clock () / CLOCKS_PER_SEC);     printf ( " \n Sorted array is : \n " );     for (...

C Program For Quick Sort | C Programming

C Program For Quick Sort To Generate Random Number and Sort it #include <stdio.h> #include <stdlib.h> void quicksort ( int number [ 25 ], int first , int last ) {     int i , j , pivot , temp ;     if ( first < last )     {         pivot = first ;         i = first ;         j = last ;         while ( i < j )         {             while ( number [ i ] <= number [ pivot ] && i < last )                 i ++;             while ( number [ j ] > number [ pivot ])                 j --;             if ( i < j )             {                 temp = number [ i ]; ...

C Program for Insertion Sort | C Programming

C Program For Insertion Sort Using time.h Function and Generating Random Number #include <math.h> #include <time.h> #include <stdlib.h> #include <stdio.h> void insertionSort ( int arr [], int n ) {     int i , key , j ;     for ( i = 1 ; i < n ; i ++)     {         key = arr [ i ];         j = i - 1 ;         while ( j >= 0 && arr [ j ] > key )         {             arr [ j + 1 ] = arr [ j ];             j = j - 1 ;         }         arr [ j + 1 ] = key ;     } } void printArray ( int arr [], int n ) {     int i ;     for ( i = 0 ; i < n ; i ++)         printf ( " %d  " , arr [ i ]);     printf ( " \n " ); } int main () {     int ...

Popular posts from this blog

Eliminating Epsilon transition (ε-Transitions) | Conversion of Epsilon-NFA to DFA | Conversion of Epsilon-NFA to NFA | Theory Of Computation (TOC)

C program to Find Cartesian Product of Two Sets | C programming

Top 10 Programming Language to learn in 2023