100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Test Bank - Data Structures & Algorithm Analysis in C++ 4th Edition by Mark Weiss, Chapter 1-12

Rating
-
Sold
-
Pages
152
Grade
A+
Uploaded on
04-03-2025
Written in
2024/2025

Test Bank - Data Structures & Algorithm Analysis in C++ 4th Edition by Mark Weiss, Chapter 1-12

Institution
Data Structures & Algorithm Analysis In C++ 4th Ed
Module
Data Structures & Algorithm Analysis in C++ 4th Ed











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Data Structures & Algorithm Analysis in C++ 4th Ed
Module
Data Structures & Algorithm Analysis in C++ 4th Ed

Document information

Uploaded on
March 4, 2025
Number of pages
152
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

KLJHGFDSA




Test Bank for Data Structures & Algorithm
Analysis in C++ 4th Edition by Mark Weiss
N
U
R
All Chapters Included (1-12)
SE
D
♦️♦️♦️INSTANT DOWNLOAD
O
♦️♦️♦️COMPLETE CHAPTERS
C
♦️♦️♦️COMPLETE ANSWERS
S


kjhgfdsa

, KLJHGFDSA



CHAPTER 1


Introduction
1.1
/*
Exercise 1.1 All Chapters Included
Selection of integers with k = N/2
select1 => sorting and selecting
select2 => keeping top k
N
*/ All Answers Included
#include <iostream>
#include <ctime>
U
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
R

void sort(vector<int> & vec)
SE
{ // bubble sort ascending
bool sorted = false;
while (!sorted)
{
sorted = true;
for (auto i = 1; i < vec.size(); i++)
{
if (vec[i-1]> vec[i])
D
{
swap(vec[i],vec[i-1]);
sorted = false;
}
O
}
}
}
C
void sortDec(vector<int> & vec)
{ // bubble sort descending
bool sorted = false;
while (!sorted)
S
{
sorted = true;
for (auto i = 1; i < vec.size(); i++)
{
if (vec[i-1]< vec[i])
{
swap(vec[i],vec[i-1]);
sorted = false;
}
}
}
}




kjhgfdsa

, KLJHGFDSA



int select1(vector<int> nums)
{
int k = (nums.size()+1)/2;
sort(nums);
return nums[k];
}


int select2(const vector<int> &nums)
{
int k = nums.size()/2;
vector<int> topK(nums.begin(), nums.begin() + k);
N
sortDec(topK);
for (auto i = k; i < nums.size(); i++)
{
U
if (nums[i] > topK[k-1])
{
for (auto j = k-2; j >=0 ; j--)
if (nums[i] < topK[j])
R
{topK[j+1] = nums[i]; break;}
else
topK[j+1] = topK[j];
if (topK[0] < nums[i])
SE
topK[0] = nums[i];
}
}
return topK[k-1];
}

int main()
{
D
vector<int> nums;
int selected;
time_t start, end;
O
srand(time(NULL));
for (auto numInts = 1000; numInts<=10000; numInts+=1000)
// sizes 1,000, 2,000, 3,000, ...10,000
{
nums.resize(numInts);
C
start = time(NULL);
for (auto i = 0; i < 10; i++) // run 10 times
S
{
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;
}




kjhgfdsa

, KLJHGFDSA


180
160

140

120

100
Time of Select1
80 Time of Select2
60
N
40

20
U
0
0 2000 4000 6000 8000 10000 12000

2. /*
R
Word Puzzle problem
from the example in figure 1.1
*/
SE
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include "matrix.h"
#include<algorithm>

using namespace std;
D
const int MAXROWS = 4;
const int MAXCOLS = 4;
O
struct Orientation
{
Orientation() : delRow(0), delCol(0) {}
Orientation operator() (int direction)
C
{
switch (direction)
{
case 0 : delRow = -1; delCol = -1; break;
S
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;




kjhgfdsa

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ScoreGuides Chamberlain College Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
1326
Member since
2 year
Number of followers
776
Documents
2286
Last sold
10 hours ago
ScoreGuides – Study Smarter, Score Higher

ScoreGuides provides high-quality study guides, test banks, and solutions manuals across a wide range of subjects. Each document is carefully created and structured to help students master key concepts, practice effectively, and excel in exams. Trusted by thousands of learners worldwide — study smarter, score higher!

4.1

118 reviews

5
68
4
21
3
10
2
8
1
11

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions