Get Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Edition : 013284737X free all chapters
Get Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Edition : 013284737X free all chapters
http://testbankbell.com/product/solution-manual-for-data-structures-
and-algorithm-analysis-in-c-2-e-2nd-edition-0201498405/
http://testbankbell.com/product/solution-manual-for-data-structures-
and-other-objects-using-c-4-e-michael-main-walter-savitch/
http://testbankbell.com/product/solution-manual-for-data-structures-
and-problem-solving-using-java-4-e-4th-edition-0321541405/
http://testbankbell.com/product/solution-manual-for-elementary-survey-
sampling-7th-edition/
http://testbankbell.com/product/solution-manual-for-engineering-
economics-financial-decision-making-for-engineers-5th-edition-by-
fraser/
http://testbankbell.com/product/solution-manual-for-introduction-to-
mechatronic-design-by-carryer/
http://testbankbell.com/product/numerical-methods-in-engineering-with-
matlab-3rd-kiusalaas-solution-manual/
http://testbankbell.com/product/solution-manual-for-south-western-
federal-taxation-2019-individual-income-taxes-42nd-edition-james-c-
young/
Test Bank for Principles and Practice of Radiation
Therapy, 4th Edition Charles M. Washington Dennis T.
Leaver
http://testbankbell.com/product/test-bank-for-principles-and-practice-
of-radiation-therapy-4th-edition-charles-m-washington-dennis-t-leaver/
Solution Manual for Data Structures and Algorithm Analysis in
structures-and-algorithm-analysis-in-c-4-e-4th-edition-013284737x/
CHAPTER 1
Introduction
1.1
/*
Exercise 1.1
Selection of integers with k = N/2
select1 => sorting and selecting
select2 => keeping top k
*/
#include <iostream>
#include <ctime>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
sortDec(topK);
for (auto i = k; i < nums.size(); i++)
{
if (nums[i] > topK[k-1])
{
for (auto j = k-2; j >=0 ; j--)
if (nums[i] < topK[j])
{topK[j+1] = nums[i]; break;}
else
topK[j+1] = topK[j];
if (topK[0] < nums[i])
topK[0] = nums[i];
}
}
return topK[k-1];
}
int main()
{
vector<int> nums;
int selected;
time_t start, end;
srand(time(NULL));
for (auto numInts = 1000; numInts<=10000; numInts+=1000)
// sizes 1,000, 2,000, 3,000, ...10,000
{
nums.resize(numInts);
start = time(NULL);
for (auto i = 0; i < 10; i++) // run 10 times
{
for (auto j = 0; j < numInts; j++)
nums[j] = rand()%(2*numInts);
selected = select1(nums); // or selected = select2(nums);
}
end = time(NULL);
cout<<numInts<<"\t"<<difftime(end,start)<<endl;
}
return 0;
}
180
160
140
120
100
Time of Select1
80
Time of Select2
60
40
20
0
0 2000 4000 6000 8000 10000 12000
2. /*
Word Puzzle problem
from the example in figure 1.1
*/
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include "matrix.h"
#include<algorithm>
struct Orientation
{
Orientation() : delRow(0), delCol(0) {}
Orientation operator() (int direction)
{
switch (direction)
{
case 0 : delRow = -1; delCol = -1; break;
case 1 : delRow = -1; delCol = 0; break;
case 2 : delRow = -1; delCol = 1; break;
case 3 : delRow = 0; delCol = -1; break;
case 4 : delRow = 0; delCol = 1; break;
case 5 : delRow = 1; delCol = -1; break;
case 6 : delRow = 1; delCol = 0; break;
case 7 : delRow = 1; delCol = 1; break;
}
return *this;
}
int delRow;
int delCol;
};
class Puzzle
{
public:
Puzzle(int numRows, int numCols )
{
matrix<char> temp(numRows,numCols);
puzzle= temp;
initPuzzle();
}
Puzzle(int numRows , int numCols , vector<string> wordList) : dictionary(wordList)
{
matrix<char> temp(numRows,numCols);
puzzle= temp;
initPuzzle();
}
void solvePuzzle();
void findWords(int startRow, int startCol, Orientation orient);
private:
void initPuzzle();
matrix<char> puzzle;
vector<string> dictionary;
};
void Puzzle::initPuzzle()
{
puzzle[0][0] = 't';
puzzle[0][1] = 'h';
puzzle[0][2] = 'i';
puzzle[0][3] = 's';
puzzle[1][0] = 'w';
puzzle[1][1] = 'a';
puzzle[1][2] = 't';
puzzle[1][3] = 's';
puzzle[2][0] = 'o';
puzzle[2][1] = 'a';
puzzle[2][2] = 'h';
puzzle[2][3] = 'g';
puzzle[3][0] = 'f';
puzzle[3][1] = 'g';
puzzle[3][2] = 'd';
puzzle[3][3] = 't';
}
void Puzzle::solvePuzzle()
{
Orientation orient;
for ( auto startRow = 0; startRow < puzzle.numrows(); startRow++)
for ( auto startCol=0; startCol < puzzle.numcols(); startCol++)
for (auto i = 0; i < 8 ; i++)
findWords(startRow,startCol,orient(i));
}
int main()
{
string diction[] = {"this", "two", "fat", "fats", "at", "wad", "ad", "hat", "that",
"his","is","it","ah"} ;
vector<string> dictionary(diction,diction+ 12);
Puzzle puzzle(MAXROWS, MAXCOLS, dictionary);
puzzle.solvePuzzle();
return 0;
}
1.3
void printDouble(double x)
{
if (x < 0)
{
cout<<"-";
x = -x;
}
int intPart = floor(x);
double fract = x - intPart;
printOut(intPart);
cout<<".";
while (fract<1 && fract > 0.0000000001)// 0.0000000001 is machine accuracy.
{
fract *= 10;
printDigit(floor(fract));
fract = fract - floor(fract);
}
}
1.4
which opens f il eNa me, does whatever processing is needed, and then closes it. If a line of the form
#include SomeFile
processFile( SomeFile );
is made recursively. Self-referential includes can be detected by keeping a list of files for which a call to
p ro ce s sF ile has not yet terminated, and checking this list before making a new call to p ro ce s sF ile .
1.5
1.6
void permute(const string & str, int low, int high)
{
char letter;
string tmp = str;
if (low >= high)
cout<<str<<endl;
else
{
for (auto i= low; i < str.size(); i++)
{
swap(tmp[0], tmp[i]);
permute(tmp, low+1, high);
}
}
}
1.7 (a) The proof is by induction. The theorem is clearly true for 0 < X 1, since it is true for X = 1, and for X
< 1, log X is negative. It is also easy to see that the theorem holds for 1 < X 2, since it is true for X = 2,
and for X < 2, log X is at most 1. Suppose the theorem is true for p < X 2 p (where p is a positive integer),
and consider any 2p < Y 4p (p 1). Then log Y = 1 + log( Y /2 ) < 1 + Y/2 < Y/2 + Y/2 Y, where the
(b) Let 2X = A. Then A B = ( 2 X ) B = 2 X B . Thus log A B = XB. Since X = log A, the theorem is proved.
1.8 (a) The sum is 4/3 and follows directly from the formula.
S 14 2
3
L . 4S 1 2
3
L .
(b) 42 43 4 42 Subtracting the first equation from the second gives
3S 1 1
2
L .
4 42 By part (a), 3S = 4/3 so S = 4/9.
S 14 4
9
L . 4S 1 4
9
163 L .
(c) 42 43 4 42 4 Subtracting the first equation from the second gives
3S 2 i
1i .
3S 1 3
5
7
L . 4i 4
4 42 43 Rewriting, we get i 0 i 0 Thus 3S = 2(4/9) + 4/3 = 20/9. Thus S =
20/27.
i4 .
N
i
(d) Let S N = i 0 Follow the same method as in parts (a) – (c) to obtain a formula for S N in terms of SN–1,
SN–2,..., S0 and solve the recurrence. Solving the recurrence is very difficult.
N N N / 2 1
1
i
1i 1
i
ln N ln N /2 ln 2.
i N / 2 i 1 i 1
1.9
1.10 24 = 16 1 (mod 5). (24)25 125 (mod 5). Thus 2100 1 (mod 5).
1.11 (a) Proof is by induction. The statement is clearly true for N = 1 and N = 2. Assume true for N = 1, 2, ... , k.
k 1 k
Fi Fi Fk 1.
Then i 1 i 1 By the induction hypothesis, the value of the sum on the right is Fk+2 – 2 + Fk+1 =
Fk+3 – 2, where the latter equality follows from the definition of the Fibonacci numbers. This proves the claim
and N = 2, the statement is true. Assume the claim is true for N = 1, 2, ... , k.
Fk 1 Fk Fk 1
by the definition, and we can use the inductive hypothesis on the right-hand side, obtaining
Fk 1 k k 1
1 k 1 2 k 1
Fk 1 ( 1 2 ) k 1 k 1
(c) See any of the advanced math references at the end of the chapter. The derivation involves the use of
generating functions.
N N N
(2i 1) 2 i 1
1.12 (a) i 1 i 1 i 1 = N( N + 1) – N = N2.
(b) The easiest way to prove this is by induction. The case N = 1 is trivial. Otherwise,
N 1 N
i3 ( N 1)3 i3
i 1 i 1
N 2 ( N 1) 2
( N 1)3
4
N2
( N 1) 2 ( N 1)
4
N 4N 4
2
( N 1) 2
4
( N 1) 2 ( N 2) 2
22
2
( N 1) ( N 2)
2
2
N 1
i
i 1
1.15
class EmployeeLastNameCompare
{
public:
bool operator () (const Employee & lhs, const Employee & rhs) const
{ return getLast(lhs.getName())< getLast(rhs.getName());}
};
1.16
matrix() : array(10)
{for( auto & thisRow : array )
thisRow.resize( 10 );
}
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
testbankbell.com