Complexities of the recursive and the iterative algorithms

Assignment Help Programming Languages
Reference no: EM132699926

Question 1) Consider the following pseudocode:

Input: An array A = (a1, a2, ..., an) of n numbers.
1. For i = 1 to n
2. For j = 2 to A[i] / 2
3. If A[i] % j = 0
4. Then Print false.
5. Go to step 1.
6. Print true.

a. Show the iterations step-by-step of the pseudocode for the in- stance A = (4, 5, 6, 7).
b. Describe the inputs, outputs and the computational problem that the pseudocode solves.
c. What is the computational complexity of the pseudocode? Is it an efficient algorithm or not? Discuss in detail.

Question 2) Assume we have n sensors and a master sensor S0 located in 2- dimensional space. The master sensor S0 knows the (x, y)-coordinates of the other sensors and can calculate the distance of the sensor Si from itself with the following formula:

d(S0, Si) = |x0 - xi| + |y0 - yi| (1)
Given a radius R, the master sensor S0 categorizes the sensor Si according to the distance as following:
• Si is category 1 if d(S0, Si) < R
• Si is category 2 if R ≤ d(S0, Si) < 2R
• Si is category 3 if 2R ≤ d(S0, Si)
As an example, the master sensor S0 is at location (5, 4) and the sensor S1 is at location (2, 2) in Figure 1. Assuming R = 2, the sensor S1 is category 3 since d(S0, S1) = |5 - 2| + |4 - 2| = 5 ≥ 2R = 4.

Figure 1: The master sensor S0 and the other sensors Consider the Category Detection Problem:
Input: The (x, y) coordinates of the sensors S0, S1, ..., Sn, a radius R, and a category value v.
Output: The sensors having category v.
a. Design an algorithm, say Categorization algorithm, that solves
Category Detection Problem. Give the pseudocode of your algorithm.
b. Show the iterations step-by-step of your algorithm for v = 3 on the instance in Figure 1.
c. What is the computational complexity of your algorithm? Is it an efficient algorithm or not? Discuss in detail.

Question 3) Consider the Deviation Sorting Problem:

Input: An array A = a1, a2, ..., an of n numbers.
Output: The sorted absolute deviations (in nondecreasing order) of the numbers from the array average.
Ex: Let A = 3, 5, 8, 10, 9 , then the array average A¯ = 3+5+8+10+9 = 7.
The absolute deviation di of ai from the array average A¯ can be calculated as di = ai A¯ .
Then, the unsorted absolute deviations array can be given as D = 4, 2, 1, 3, 2 .
We obtain the output as 1, 2, 2, 3, 4 after sorting the array D in nondecreas- ing order.

a. Design an algorithm, say Deviation Sorting algorithm, that solves Deviation Sorting Problem. Give the pseudocode of your algo- rithm. (Hint: You may use a sorting algorithm from the lecture.)
b. Show the iterations step-by-step of your algorithm on the in- stance in the example.
c. What is the computational complexity of your algorithm? Is it an efficient algorithm or not? Discuss in detail.

Question 4) Consider the Even Number Problem:

Input: A positive integer k.
Output: kth even natural number (the first even number is 0).

a. Design a recursive algorithm, say Recursive Even algorithm, that solves Even Number Problem. Give the pseudocode of your algo- rithm. Show the iterations step-by-step of your algorithm for k = 4.

b. Alternatively, design an iterative algorithm, say Iterative Even algorithm, that solves Even Number Problem. Give the pseudocode of your algorithm.

c. What are the computational complexities of the recursive and the iterative algorithms? Are they efficient algorithms or not? Discuss in detail.

Attachment:- iterative algorithms.rar

Reference no: EM132699926

Questions Cloud

How groups make good decisions in a new group : After watching the Ted Talk how would you integrate the new knowledge of how groups make good decisions in a new group that you might encounter?
Legal or ethical aspects of contract administration : Students are required to read and provide analysis of Legal or ethical aspects of contract administration related articles from a professional journal,
Compute good estimate of nonvalue-added costs : Suppose that a company is spending $60,000 per year for inspecting, $30,000 for purchasing, Compute good estimate of nonvalue-added costs
Understanding the court system : The U.S. Court System is a complex system that includes both federal and state-level courts. Summarize the seminal facts of the case that you chose.
Complexities of the recursive and the iterative algorithms : Design a recursive algorithm, say Recursive Even algorithm, that solves Even Number Problem. Give the pseudocode of your algo- rithm. Show the iterations
How would you describe yourself during adolescence : How would you describe yourself during adolescence? Were you an early maturer or a late maturer? What positive qualities came out of this?
Compute the amount of shipping cost assigned to the customer : Lambert Company will ship 1,500,000 pounds of goods to customers at a cost of $1,200,000. Compute the amount of shipping cost assigned to the customer
Discuss the effects of media on depression in females : Research depression among women and the role society plays. Discuss the effects of media on depression in females and include various types such as TV, movies.
Compute the best activity rate for moving : Expected direct labor hours are 20,000, and expected number of moves is 40,000. Compute the best activity rate for moving

Reviews

Write a Review

Programming Languages Questions & Answers

  Develop at least one wireframe layout design

ICTICT514 -Identify and manage the implementation of current industry specific technologies-Victoria University-Australia-design and develop a website.

  Method to pass string argument and returns first line

Write a method, getFirstLine, that is passed a String argument and that returns the first line.

  Write a program that reads the coordinates

Write a program that reads the (x,y) coordinates of a point in the Cartesian plane and prints a message telling in which quadrant, or on which axis (or axes) the point lies. The quadrants are labeled as follows:

  Design a program to amount save for budgeted

Design a program that asks the user to enter the amount that he or she has budgeted for a month. (For example: $2,000.00). A loop should then prompt the user to enter each of his or her expenses for the month

  Develop pseudo-code for program to retrieve bytes

Develop the pseudo-code for a program that will retrieve 2 bytes (NUM1 and NUM2) from memory, determine which is closest to the numeric value 50.

  Design a grade average program by using raptor which will

design a grade average program using raptor that will produce the numerical grade average of test scores input by a

  Write program that lets user enter charge account number

Write a program that lets the user enter a charge account number. The program should determine if the number is valid by checking for it in the following list.

  Building instruction set simulators

Building Instruction Set Simulators

  Explore a little untyped functional programming using elisp

The goal of this homework is to explore a little untyped functional programming using elisp, the version of the LISP programming language supported by the emacs text editor

  Php code to add-delete product using ajax programming

PHP Code to add a new product and delete a existing product Implement AJAX Programming based solutions to write code to add a new product to the database.

  Create a program that reads position and velocity data

For this project, you will create a program that reads position, velocity, and acceleration data from a file, and determines if two objects will collide.

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