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

  Create a binary search tree program

Creating a Binary Search Tree program - Finding the largest and smallest values in the tree Add two class methods

  Insertion sort and merged using standard merging mechanism

Using "insertion sort" and then merged using standard merging mechanism, where k is value to be determined. How must be we select k in practice?

  Write algorithm which divides n objects of u into k clusters

Suggest the algorithm which divides n objects of U into k clusters, making use of MST of a graph. Give a simple argument of correctness and bound on the running time of the algorithm you are proposing.

  Transmitting image using raster scan order

If we were to transmit this image using raster scan order, after 15 seconds how many rows of the image will the user have received?

  Design a linked list structure

Design a linked list structure Music that contains data fields Name, Artist, Number_of_Songs, and a pointer to the list. Design the structure with three members and fill in data for each member.

  Describe a computation of the timer-based protocol

Describe a computation of the timer-based protocol in which the receiver opens a connection upon receipt of a packet with a sequence number greater than zero.

  Creating a table of xml documents

Make a table of XML documents with a type of XML. Use a primary key so add a field of type INT that is an identity. Insert many records into XML field in this new table.

  B+-tree

For the B+-tree where M=3 and L=5 shown below, show how an insert of value 80 is handled.

  Question about unix commands

Assume you have a document called records.txt having the list of employee id and workers names. Every line contains a single employee id immediately followed by the employee name in the format Last name, First name.

  Create algorithm to count of integers less than average

Create the algorithm which will prompt for and get 10 integers from the operator at terminal, and then count number of integers whose value is less than average value of integers.

  Which algorithm should be most efficient

the test conditions are equal for both algorithms, which algorithm should be most efficient when N is arbitrarily large (i.e., you can select N to be as large as you want it to be)?

  Determine expected number of collisions use hash function

Assume we use hash function h to hash n distinct keys into the array T of length m. Suppose simple uniform hashing, determine the expected number of collisions?

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