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.
- Measuring script execution time in PHP
- Measure execution time with high precision in C/C++
- Find time taken to execute the tasks in A based on the order of execution in B
- Time Complexities of all Sorting Algorithms
- Case-specific sorting of Strings in O(n) time and O(1) space
- Program for sorting variables of any data type
- time.h header file in C with Examples
- What is data type of FILE in C ?
- How to delete data from file in Python
- 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
- 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
- Sorting a Map by value in C++ STL
- Pancake sorting
- Sorting Terminology
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.