Answered step by step
Verified Expert Solution
Question
1 Approved Answer
lab08_functions.h #ifndef COLLATZ_MAP #define COLLATZ_MAP #include using std::vector; #include using std::string; #include using std::map; #include using std::pair; using Collatz = pair >; /* input is
lab08_functions.h
#ifndef COLLATZ_MAP
#define COLLATZ_MAP #includeThe Problem You remember the Collatz sequence, don't ya? Here is a little reminder in case you didn't. http://en.wikipedia.org/wiki/Collatz conjecture One of the problems is that, by doing the calculation over from the beginning for every number, you waste a lot of time redoing work that already has been done. Look at the first 6 sequences: 2 2,1 33,10, 5, 16, 8, 4, 2,1 4 4,2,1 55, 16, 8, 4, 2,'1 6 6, 3, 10, 5,16, 8,4, 2,1 Subsequences, whose value we already know, are recalculated. For example, the entire sequence of3 is already known, but we recalculate the entire sequence when starting from 6 Memoization Memoization (note the spelling, no "r") is a simple optimization technique used in algorithms where repeat calculations occur (http://en.wikipedia.org/wiki/Memoization) The idea is simple. We remember a sequence when we first calculate it. Subsequently, for any value we calculate we check first to see if we already know the remaining sequence. If so, we stop the calculation and just copy the known sequence in. For this lab, we will use a map to memorize Collatz sequences. Pay attention to this technique, it comes up in many guises and is very useful! Programming Task Make a new project directory called lab08. Copy lab08 functions.h to your directory. You need to write both lab08_functions.cpp and lab08_main.cpp. You will turn in lab08 functions. cpp to Mimir for testing Data structure, map of lona to vectorusing std::vector; #include using std::string; #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started