## Introduction

The Standard Template Library(STL) is a C++ library of container classes, algorithms, and iterators that contains many of computer science's fundamental algorithms and data structures. Since this STL is a generic library, its components are strongly parameterized: practically every component is a template.

STL provides a variety of algorithms that are implemented on any container. As a result, we no longer need to develop complicated algorithms and can instead rely on the built-in methods supplied by the STL algorithm library.

The use of these algorithms from STL saves time, effort, code and are very reliable. Hence, a single algorithm function is applied to every container type.

For example, To implement Binary Search in ** C++**, we will have to write the following function:

```
bool binary_search( int l , int r , int key ,int a[])
{
if(l > r)
return -1;
else
{
int mid=(l+r)/2;
if(a[mid] == key)
{
return true;
}
else if(a[mid] > key)
{
return binary_search(l, mid-1, key, a);
}
else if(a[mid] < key)
{
return binary_search(mid+1, r, key, a);
}
}
}
```

In STL, however, we can use the algorithm library's binary search() function to execute the binary search. The library already has a definition for it:

`return binary_search(a, a+a.size())`

Also see, __Literals in C____.__

**Commonly Used Algorithms in C++**

Algorithm | Description |
---|---|

Sorting Algorithms | |

- Quick Sort | Efficient sorting algorithm based on partitioning the array into smaller segments and recursively sorting them. |

- Merge Sort | Divides the array into smaller segments, sorts them individually, and merges them back together. Known for its stability and consistent performance. |

- Heap Sort | Builds a max-heap from the array, repeatedly extracts the maximum element, and rebuilds the heap until the array is sorted. |

Searching Algorithms | |

- Binary Search | Efficient search algorithm for sorted arrays, dividing the search interval in half each time until the target element is found or the interval is empty. |

Graph Algorithms | |

- Depth-First Search | Traverses a graph by exploring as far as possible along each branch before backtracking. Useful for topological sorting, cycle detection, and connected components. |

- Breadth-First Search | Explores a graph level by level, visiting all neighbors of a node before moving to the next level. Ideal for finding shortest paths and minimum spanning trees. |

Dynamic Programming | |

- Fibonacci Sequence | Solves the Fibonacci sequence efficiently using dynamic programming, storing previously computed values to avoid redundant calculations. |

- Longest Common Subsequence | Finds the longest subsequence common to two sequences by breaking down the problem into smaller subproblems and memoizing the results. |