# Basic CS-Algorithms [3i Infotech Placement]: Sample Questions 6 - 7 of 12

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

## Question 6

## Question 7

Algorithms

### Explanation

Assuming sorting of n elements in the entire array.

Step 1:

- The divide step takes constant time, regardless of the sub array size.
- Divide step computes the midpoint q of the indices p and r.
- We indicate constant time by .

Step 2:

- The conquer step, recursively sorts two subarrays of approximately elements.
- Account for that time when considering the subprograms.

Step 3:

- The combine step merges a total of n elements, taking time.
- The running time of two recursive calls on element- depends on the running merge sort on element array

- Each of sub problem size recursively sorts two subarrays of
- Now the problem is to find total merging time for all subproblems of size

- We now get down to subprograms of size 1: the base case.
- Spend time to sort subarrays of size 1.
- Each base takes time.

- We know how long merging takes for each subproblem size.
- For example, tree with 8 elements has 3 levels n = 4,2, 1.
- Total time for merge sort is the sum of merging times for all the levels.
- Now this ties would be same as binary search,
- When we use big notation to describe this running time.
- Low order term (+ 1) and the constant coefficient can be discarded.
- Thus running time is the efficiency of merge sort.