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

  Using our stack data structure for storing disk objects

Using our Stack Data Structure for storing Disk objects (see attached zip file), implement the game The Towers of Hanoi for 3 disks and 3 columns (as simulated at: http://www.mathsisfun.com/games/towerofhanoi.html).

  Creating dataflow diagram

Think about the level of detail involved with creating a dataflow diagram, why should the narrative be prepared? Explain why do we need the questionnaire?

  Making visual studio.net web application

Make a Visual Studio.NET 2005 web application with 2-aspx forms. Add a Menu control and a Label control to form. Populate the Menu control with data stored in the "Font" column and show your name in the Label control.

  Question related to sequential files

In spite of the fact that sequential files lack direct targeted addressing of each of the records and fields, they are the most widely used.

  Question about binomial tree

A binomial tree of height O, Bo is a one node tree. A binomial tree of height k, Bk is formed through attaching a binomial tree, Bk-1 to root of another binomial tree another binomial tree Bk-1.

  Arrays & more loops practice

Write a program ArraysAndLoops and implement the following in the main method:

  Analyzing the use of database in an organization

Examine the use of databases in your company. Include what database applications are used. Conclude through proposing improvements.

  Construct the weight vector of the maximum margin hyperplane

Construct the weight vector of the maximum margin hyperplane by inspection and identify the support vectors - how many leaf nodes can a decision tree have if it is consistent with a training set containing 100 examples?

  The set of students studying discrete mathematics the set

for each of these pairs of sets determine whether the first is a subset of the second the second is a subset of the

  What does a computer know about a declared array?

What does a computer know about a declared array?

  Develop the flow diagram of the information

Develop the flow diagram of the information and any control elements needed to ensure proper access for the information. A diagram of the information flow and any elements controlling proper access to the information it uses

  How to sort an array using insertion sort

How to sort an array using insertion sort and track teh number of swaps during the sorting - Can someone provide the answer with reference to data structure?

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