Question 1a for n 0 what is the time complexity of the

Assignment Help Data Structure & Algorithms
Reference no: EM13380116

Question 1a: For n ? 0 , what is the time complexity of the method q(1, n). Show the details of your calculation of O(q(1, n) ˜ O(?).

public int q (int i, int n)
{
  return i+(i >= n ? 0 : q(i+i, n));
}

Answer: Linear time. O(n)

Question 1b: For n ? 0 , what is the time complexity of the r(n) method. Show the details of you calculation of O(r(n)) ˜ O(?).

public int r(int n)
{
    int sum = 0;
    for (int i=1; i <= n+n; i++)
    sum+=i + q(1,n);
    return sum;
}

Answer: Linear time. O(n)


Question 1c: For n ? 0 , what is the time complexity of the algorithm_1(int n) method. Show the details of you calculation of O(algorithm_1(n)) ˜ O(?).

public void algorithm_1(int n)
{
    if (n < 1) return; System.out.println(q(1, n)*n);
    System.out.println(r(n));
    System.out.println(q(1, n+n) + r(n+n));
}

Answer: Linear time. O(n)

Bonus:-

public int t(int n)
{
    for (int i=1; i <= n+n; i++)
{
    for (int j=1; j < i; j++)
    sum+=i + q(1,n);
}

Answer: Quadratic time. O(n^2)


Question 2:
n ? 0 , what is the time complexity of the binarySearch(array[n], key) algorithm. Show the details of you calculation of O(binarySearch(array[n], key)) ˜ O(?).

time = O(log n)

2^t -1 = n
2^t = n + 1
log2(2^t) = log2(n+1)
t = log2 n + 1

The time is logarithmic in the number of elements. Or proportional to the logarithm of # of elements.

Reference no: EM13380116

Questions Cloud

Describe the network management software components side : describe the network management software components. side server components middleware components and northbound
As part of the auditing team in capacity of a digital : as part of the auditing team in capacity of a digital forensics expert your task is to prepare a report explaining the
You have been asked to be the project manager for the : you have been asked to be the project manager for the development of an information technology it project. the system
You have been asked to be the project manager for the : you have been asked to be the project manager for the development of an information technology it project. the system
Question 1a for n 0 what is the time complexity of the : question 1a for n ? 0 what is the time complexity of the method q1 n. show the details of your calculation of oq1 n
You have been asked to be the project manager for the : you have been asked to be the project manager for the development of an information technology project. the system to
Write a two to three 2-3 page paper in which yourecommend : write a two to three 2-3 page paper in which yourecommend at least three 3 specific tasks that could be performed to
Regional gardens ltd is a company that runs a number of : regional gardens ltd is a company that runs a number of related gardening enterprises. it has a large display garden
Question 1the management of your employer wants to find out : question 1.the management of your employer wants to find out about desktop virtualisation and how it works. they think

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd