Write the function definition as a recursive search

Assignment Help Data Structure & Algorithms
Reference no: EM13963253

1. A sequential search member function of Sorted Type has the following prototype: void Sorted Type::Search( int value, bool & found);

a. Write the function definition as a recursive search, assuming a linked list implementation.

b. Write the function definition as a recursive search, assuming an array based implementation.

2. We want to count the number of possible paths to move from row 1, column 1 to row N, column N in a two-dimensional grid. Steps are restricted to going up or to the right, but not diagonally. The illustration that follows shows three of many paths, if N = 10:

a. The following function, NumPaths, is supposed to count the number of paths, but it has some problems. Debug the function.
int NumPaths(int row, int col, int n)

{
if (row == n)
return 1;
else
if (col == n)
return NumPaths + 1;
else
return NumPaths(row + 1, col) * NumPaths(row, col + 1);
}

b. After you have corrected the function, trace the execution of NumPaths with n = 4 by hand. Why is this algorithm inefficient?

c. You can improve the efficiency of this operation by keeping intermediate values of NumPaths in a two-dimensional array of integer values. This approach keeps the function from having to recalculate values that it has already figured out. Design and code a version of NumPaths that uses this approach.

d. Show an invocation of the version of NumPaths you developed in part (c), including any array initialization necessary.

e. How do the two versions of NumPaths compare in terms of time efficiency? Space efficiency?

Reference no: EM13963253

Questions Cloud

What angle should the boad head : A ferryboat sails between two towns directly opposite each other on a river. if the boat sails at 15 km/h relative to the water, and if the current flows at 6.3 km/h, at what angle should the boad head?
How incident response protocols will mitigate the threats : Justify how the incident response protocols will mitigate the threats to and vulnerabilities of the organization. Support your justification with information assurance research and best practices
Speech on role of students in nation building : Speech on role of students in nation building
Cost of capital for the division : The return on capital in the division is 15 percent, and the corporate tax rate is 40 percent. If the cost of capital for the division is 9 percent, estimate the following:
Write the function definition as a recursive search : Write the function definition as a recursive search, assuming a linked list implementation. After you have corrected the function, trace the execution of NumPaths with n = 4 by hand. Why is this algorithm inefficient?
Relative details of the firms in the drugstore industry : You have been asked to assess whether Walgreen, a drugstore chain, is correctly priced relative to its competitors in the drugstore industry. The following are the price/sales ratios, profit margins, and other relative details of the firms in the ..
Find the rrns voltage across the capacitor. : Find the time averaged output power of the generator in this circuit.
Explain why the bullet acquires a high velocity : When the spring is released, the rod pushes against one cart with a given force. This cart pushes back with an equal force. Explain why this means that the total force on the system of the two carts is zero.
How many distinct exams can she give : A chemistry professor at ASU has 36 questions that she uses on her exams. Her exams always have 11 questions. How many distinct exams can she give? The order of the questions does not matter.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Question about designing a database

As we start designing a database for implementation should we use the latest and greatest technology? Does the user need a flat-file or object-oriented database?

  Circular linked list to implement the queue

Use a circular linked list to implement the queue data structure as explained in java. Write unit test with various test cases to test your implementation.

  Query this database for several types of information & sort

The steps for the queries are listed in the textbook alphabetically. Use this alphabetic list for naming your queries as you save them. For instance, name the query created in step a as Query A, and so forth.

  Show steps needed to look up ann arbor using binary search

Show steps needed to look up Ann Arbor using binary search on the following list: Ann Arbor, Berkeley, Cambridge, Eugene, Madison, New Haven, Pasadena, Santa Cruz, Stony Brook, Westwood, and Yellow Springs.

  How to implement a class called hugeinteger

Using your own Linked List implementation (see attached), implement a class called HugeInteger that represents arbitrary sized integers and supports addition only. You may only use the tools we have introduced in class, and you MAY NOT use Java's ..

  Advantage of fast running time of insertion sort

Running time of quicksort can be enhanced in practice by taking advantage of fast running time of insertion sort when its input is "nearly" sorted.

  Scaled and unscaled value of solution that algorithm finds

For each value of ε, give items included and scaled and unscaled value of solution that algorithm finds. For tables, you only require to show those rows which correspond to values less than or equal to scaled value of this solution.

  Comparison of the applicability of array

Data structures include: 1. a linked list, 2. an ordered, one dimensional array, and three. a binary tree. Assume the list of letters R, A, N, B, C, F, X and G are stored in a list.

  Create an asp.net project with visual studio.net

CpCreate an MS Access database called "Members.mdb." Add a table called "tblScores" with the following columns.

  Calculate a three quarter moving average forecast

The Fastgro Fertilizer Corporation distributes fertilizer to various lawn and garden shops. Calculate a three-quarter moving average forecast for quarters 4 through 13 and calculate the forecast for each quarter.

  Basic algorithm and pseudocode help

An area is calculated by multiplying the length by the width. The pseudocode program below should ask the user for the length and width of a rectangular room in order to calculate the area, and display the room's area.

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