## What is Time Complexity?

Time complexity is a way of measuring the efficiency of algorithms. It is a measure of the amount of time an algorithm takes to complete its task as a function of the size of the input data. In simpler terms, it is a way of measuring how much time an algorithm takes to complete its task as the size of the input data increases.

## What is Big O Notation?

Big O notation is a mathematical notation used to describe the time complexity of algorithms. It is used to represent the upper bound of the time required by an algorithm to complete its task. Big O notation describes the behavior of an algorithm as the input size approaches infinity. In other words, it is a way of expressing how the algorithm performs as the input size increases.

## The Importance of Big O Notation

Big O notation is important because it allows us to analyze and compare the efficiency of different algorithms. When we compare the time complexities of two algorithms, we can determine which algorithm is more efficient for a particular problem. This is crucial because it allows us to choose the most efficient algorithm for a given problem, which in turn can save time and resources.

## Quick Sort Algorithm (QSA)

Quick Sort (QSA) is a popular sorting algorithm used to sort large sets of data efficiently. It works by selecting a pivot element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively.

## Understanding the Quick Sort Algorithm

The Quick Sort algorithm works as follows:

- Select a pivot element from the array.
- Partition the array into two sub-arrays, according to whether the elements are less than or greater than the pivot.
- Sort the sub-arrays recursively.

#include <iostream> #include <vector> using namespace std; void quick_sort(vector<int>& arr, int left, int right) { int i = left, j = right; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { swap(arr[i], arr[j]); i++; j--; } } if (left < j) quick_sort(arr, left, j); if (i < right) quick_sort(arr, i, right); } int main() { vector<int> arr = {5, 2, 4, 6, 1, 3}; quick_sort(arr, 0, arr.size() - 1); for (int i = 0; i < arr.size(); i++) { cout << arr[i] << " "; } cout << endl; return 0; }

The partitioning is done using a pivot element. The pivot element is usually selected as the first or last element of the array. The sub-arrays are then sorted recursively using the same process.

## Analysis of Quick Sort Time Complexity

The time complexity of the Quick Sort algorithm depends on the number of comparisons made during the sorting process. The best-case scenario for Quick Sort is when the array is already sorted. In this case, the time complexity is O(nlogn).

### Worst-case Scenario

The worst-case scenario for Quick Sort is when the pivot element is either the smallest or largest element in the array. In this case, the time complexity is O(n^2).

### Best-case Scenario

The best-case scenario for Quick Sort is when the pivot element is the median of the array. In this case, the time complexity is O(nlogn).

### Average-case Scenario

The average-case scenario for Quick Sort is when the pivot element is chosen randomly. In this case, the time complexity is also O(nlogn)

## DAA-2022

## Q-1.

(b) Discuss the concept of asymptotic notation and its properties.

## Q-2.

## Q-3

## Q-4

What is Huffman code ? discuss the greedy algorithm for constructing the Huffman code.

## Q-5

## Q-6

## Q-7

What is bitonic sequence ? discuss bitonic sort algorithm and it’s time complexity.

## Q-8

What is sorting Network ? Discuss the structure of bubble sorting network.