Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Solutions for Data Structures And Algorithm Analysis In C++ 4th Edition by Mark A. Weiss, Chapters 1-12

Rating
5.0
(1)
Sold
2
Pages
151
Grade
A+
Uploaded on
22-12-2024
Written in
2024/2025

Solutions for Data Structures And Algorithm Analysis In C++ 4th Edition by Mark A. Weiss, Chapters 1-12. Chapter 1 Programming: A General Overview, Chapter 2 Algorithm Analysis, Chapter 3 Lists, Stacks, and Queues, Chapter 4 Trees, Chapter 5 Hashing, Chapter 6 Priority Queues (Heaps), Chapter 7 Sorting, Chapter 8 The Disjoint Sets Class, Chapter 9 Graph Algorithms, Chapter 10 Algorithm Design Techniques, Chapter 11 Amortized Analysis, Chapter 12 Advanced Data Structures and Implementation

Show more Read less
Institution
Data Structures And Algorithm Analysis In C++, 4e
Course
Data Structures And Algorithm Analysis In C++, 4e

Content preview

Data Structures and Algorithm Analysis in C++, 4th edition




SOLUTIONS
ST
UV

Data Structures and
IA

Algorithm Analysis in
.A

C++, 4th edition
PP
RO

Authors:
Mark A. Weiss
VE

◊ ALL CHAPTERS

◊ INSTANT PDF DOWNLOAD💯💯💯
D?

◊ ORIGINAL FROM PUBLISHER
??

MEDCONNOISSEUR

, CHAPTER 1


Introduction
ST
1.1
/*
Exercise 1.1
Selection of integers with k = N/2
UV
select1 => sorting and selecting
select2 => keeping top k
*/

#include <iostream>
#include <ctime>
#include <cmath>
IA
#include <vector>
#include <algorithm>
using namespace std;
.A
void sort(vector<int> & vec)
{ // bubble sort ascending
bool sorted = false;
PP
while (!sorted)
{
sorted = true;
for (auto i = 1; i < vec.size(); i++)
{
RO
if (vec[i-1]> vec[i])
{
swap(vec[i],vec[i-1]);
sorted = false;
}
}
VE
}
}

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

, int select1(vector<int> nums)
{
int k = (nums.size()+1)/2;
sort(nums);
return nums[k];
}
ST
int select2(const vector<int> &nums)
{
int k = nums.size()/2;
UV
vector<int> topK(nums.begin(), nums.begin() + k);

sortDec(topK);
for (auto i = k; i < nums.size(); i++)
{
if (nums[i] > topK[k-1])
{
IA
for (auto j = k-2; j >=0 ; j--)
if (nums[i] < topK[j])
{topK[j+1] = nums[i]; break;}
else
.A
topK[j+1] = topK[j];
if (topK[0] < nums[i])
topK[0] = nums[i];
}
PP
}
return topK[k-1];
}

int main()
{
RO
vector<int> nums;
int selected;
time_t start, end;

srand(time(NULL));
for (auto numInts = 1000; numInts<=10000; numInts+=1000)
VE
// 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
D?
{
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
ST
100
Time of Select1
80
Time of Select2
60
UV
40

20

0
IA
0 2000 4000 6000 8000 10000 12000


2. /*
Word Puzzle problem
.A
from the example in figure 1.1
*/

#include<iostream>
#include<fstream>
PP
#include<string>
#include<vector>
#include "matrix.h"
#include<algorithm>
RO
using namespace std;

const int MAXROWS = 4;
const int MAXCOLS = 4;

struct Orientation
VE
{
Orientation() : delRow(0), delCol(0) {}
Orientation operator() (int direction)
{
switch (direction)
{
D?
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;

Written for

Institution
Data Structures And Algorithm Analysis In C++, 4e
Course
Data Structures And Algorithm Analysis In C++, 4e

Document information

Uploaded on
December 22, 2024
Number of pages
151
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$20.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Reviews from verified buyers

Showing all reviews
1 year ago

1 year ago

Thank you for shopping with us. We really appreciate your review. If you're Looking for Any Study Materials (exams, test bank, ATI, Hesi etc.) email us on We’re looking forward to hear from you soon!

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

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.
MedConnoisseur West Virgina University
View profile
Follow You need to be logged in order to follow users or courses
Sold
2783
Member since
4 year
Number of followers
1739
Documents
2934
Last sold
1 day ago
MedConnoisseur Study Hub – Verified Step-by-Step Solutions Manual, Test Banks &amp; Guides for Medical, Nursing, Business, Engineering, Accounting, Chemistry, Biology &amp; Other Subjects

Welcome to Your Ultimate Study Resource Hub! Looking for high-quality, reliable, and exam-ready study materials? You’re in the right place. Our shop specializes in original publisher content, including solutions manuals, test banks, and comprehensive study guides that are ideal for university and college students across various subjects. Every document is in PDF format and available for instant download—no waiting, no hassle. These materials are especially effective for exam preparation, offering step-by-step solutions, real test formats, and well-organized study guides that align with your coursework and textbooks. Love what you get? Share it! Help your mates and classmates succeed too by referring them to our shop. More learners, more success for all.

Read more Read less
4.0

199 reviews

5
106
4
36
3
26
2
11
1
20

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right 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 aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions