Prerequisite: Selection Sort
In this article, we are going to apply selection sort algorithm, in which the source of input is A FILE CONTAINING 10000 INTEGERS and output will be the total time taken to sort.
Important functions to be used:
- rand(): Used to generate random numbers.
- fopen(): Used to open file .
- fscanf(): Used to scan data from file .
- clock(): Return the number of clock cycle
Program to generate random number in a file “random.txt”
- clock_t or Clock ticks are units of time of a constant but system-specific length, as those returned by function clock.
Algorithm for this program:
- Open the file using fopen().
- Scan the file and copy it to the array using fscanf().
- Apply any sorting algorithm that you want.
- Print to console.
Below are the implementation of above algorithm.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Measure execution time with high precision in C/C++
- Measuring script execution time in PHP
- Find time taken to execute the tasks in A based on the order of execution in B
- Know Your Sorting Algorithm | Set 1 (Sorting Weapons used by Programming Languages)
- Know Your Sorting Algorithm | Set 2 (Introsort- C++’s Sorting Weapon)
- Sorting objects using In-Place sorting algorithm
- Manufacturing Execution Systems
- Case-specific sorting of Strings in O(n) time and O(1) space
- Time Complexities of all Sorting Algorithms
- Program for sorting variables of any data type
- Python program to reverse the content of a file and store it in another file
- C program to check whether the file is JPEG file or not
- Difference between Data Scientist, Data Engineer, Data Analyst
- time.h header file in C with Examples
- Sorting 2D Vector in C++ | Set 2 (In descending order by row and column)
- Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
- Sorting Vector of Pairs in C++ | Set 2 (Sort in descending order by first and second)
- Asymptotic Analysis and comparison of sorting algorithms
- Merging and Sorting Two Unsorted Stacks
- What is data type of FILE in C ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.