Provide the algorithmic efficiency for the following tasks J

Provide the algorithmic efficiency for the following tasks. Justify your answer, often with a small piece of pseudocode or a drawing to help with your analysis. Determining whether a provided number is odd or even Determining whether or not a number exists in a list Finding the smallest number in a list Determining whether or not two unsorted lists of the same length contain all of the same values (assume no duplicate values) Determining whether or not two sorted lists contain all of the same values (assume no duplicate values) Determining whether a number is in a BST

Solution

A.

In this pseudo code only once a condition is checked, so this will take constant time irrespective of value of n. SO the time complexity T(n)=O(1).

B.

Suppose the size of the list is n, then the loop will run n number of times to search the element linearly, so the time taken in searching the element will be dependent on n and in worst case considering that the element will be found at last. It will take order of n time to search the element. So time complexity T(n)= O(n)

C.

Suppose the size of the list is n, then the loop will run n number of times to compare smalll with every element linearly, so the time taken in finding the smallest element will be dependent on n. It will take order of n time to find the smallest element. So time complexity T(n)= O(n)

D.

In this program if the length is same of both the lists, suppose n is the length then the time complexity T(n)=O(n).

 Provide the algorithmic efficiency for the following tasks. Justify your answer, often with a small piece of pseudocode or a drawing to help with your analysis

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site