A static C++ library contatining basic algorithms.
Content:
- How to compile the library
- How to add AlgoLib library in a project using Visual Studio
- SearchingAlgos
- SortingAlgos
You can clone this github repo to your local system using Visual Studio and open the .sln
file there. Thus you will be able to compile and build AlgoLib project to .lib
file.
You can copy the required .h
and .lib
files to a folder inside the project you want this library to serve for and give both the file's relative paths in project properties at respective locations.
#include "../include/SearchingAlgos.h"
when it is placed inside a folder, say include
in the project directory.
Function : LinearSearch
Parameters : (4) - array, length of array, element to be searched,
reference to duration to complete algorithm
Retrun type: Position of element to be searched in the given array
Note : If the given elemet to be searched is not found, method
will return -1. Array and elemnt to be searched should
be of integers.
To use this method:
int position = AlgoLib::SearchingAlgos::LinearSearch(array, length, elementToBeSearched, duration);
Note: duration
is passed as reference and can be used further down the code when it have the time taken to complete the algorithm, in milli seconds.
Time complexity | : O(n) |
---|---|
Auxiliary Space | : O(1) |
Function : BinarySearch
Parameters : (4) - array, length of array, element to be searched,
reference to duration to complete algorithm.
Retrun type: Position of element to be searched in the given array
Note : If the given elemet to be searched is not found, method
will return -1. Array and elemnt to be searched should
be of integers and array should be sorted.
To use this method:
int position = AlgoLib::SearchingAlgos::BinarySearch(array, length, elementToBeSearched, duration);
Note: duration
is passed as reference and can be used further down the code when it have the time taken to complete the algorithm, in milli seconds.
Time complexity | : O(logn) |
---|---|
Auxiliary Space | : O(1) |
1. SelectionSort
Function : SelectionSort
Parameters : (3) - array, length of array,
reference to duration for
sorting.
Retrun type: void
Note : Array should be of integers.
To use this method:
int position = AlgoLib::SortingAlgos::SelectionSort(array, length, duration);
Time complexity | : O( |
---|---|
Auxiliary Space | : O(1) |