Sorting Algorithms Time Complexities

Below is a table for time complexities of all the sorting algorithms that can be used as last minute revision notes for competitive exams as well as for placements. Time complexities of algorithms in best case, average case and worst case have been listed below.

Sorting AlgorithmsBest Case ComplexityAverage Case ComplexityWorst Case Complexity
Bubble SortΩ(n)θ(n^2)O(n^2)
Selection SortΩ(n^2)θ(n^2)O(n^2)
Insertion SortΩ(n)θ(n^2)O(n^2)
Merge SortΩ(nlogn)θ(nlogn)O(nlogn)
Quick SortΩ(nlogn)θ(nlogn)O(n^2)
Bucket SortΩ(n+k)θ(n+k)O(n^2)
Heap SortΩ(nlogn)θ(nlogn)O(nlogn)
Counting SortΩ(n+k)θ(n+k)O(n+k)

If you find any information mentioned above to be incorrect then please let us know in the comment box below.

Computer Science

System Calls for copying files in c

This article is fully dedicated to using system calls in c  so if you are new to system calls then you should first learn about system calls what they are and why they are used then only this article will be useful. For basics on system calls you must read Book named Operating System Principles by Galvin

//Program to copy content of one file to another file using system calls
//Author: Shubham Lashkan

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#define buffersize 10000
int main()
{
char source[25],destination[25]; //Source and destination filename
char buffer[buffersize]; //Character buffer
ssize_t read_in,write_out; //Number of bytes returned by single read and write operation
printf(“Enter source file name”);
scanf(“%s”,&source);
printf(“%s”,source);
int sourcefiledesc = open(source,O_RDONLY); //Source file open in read only mode
if(sourcefiledesc < 0 )
{
}
else
{
printf(“Enter destination file name”);
scanf(“%s”,&destination);
/* Destination file open in write mode and if not found then create*/
int destfiledesc = open(destination,O_WRONLY | O_CREAT);
{
}
close(sourcefiledesc);
close(destfiledesc);
}
return 0;
}

Description of above code of copying file using system calls

Now lets understand above code. We have used file system calls namely Create,open,close,read and write.

First thing we had included all the necessary header files. Now we have defined a constant that refer to size of buffer.Then we open our source file in read only mode and destination file in write only mode.

int sourcefiledesc = open(source,O_RDONLY);

int destfiledesc = open(destination,O_WRONLY | O_CREAT);

Here sourcefiledesc and destfiledesc are file descriptor that uniquely identifies opened file process.

{
}

From above code we start copying content of one file to other for that we had use while loop. Write system call is using number of bytes returned by read system call in that way write system call how much data is to be written in destination file.After copy operation is complete we close both the file descriptors.

Above code is very easy to understand if you have code for file handling in c. In case you have any doubt then let us know in the comment box below.