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

Algorithms

Write in Short

Short Answer▾

Hexadecimal equivalent of

Explanation

Answer is achieved by diving by

Table of Division by 16
Division by QuotientRemainder (decimal)Remainder (hex)Digit

So,

Question 7

Algorithms
Edit

Describe in Detail

Essay▾

What is the efficiency of merge sort

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
Sub Problem Size in Diagram
  • Each of sub problem size recursively sorts two subarrays of
  • Now the problem is to find total merging time for all subproblems of size
Diagram of the Sub Problem 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.
Figure of the Sub Problem Size
  • 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.

Developed by: