ListMap Random Numbers Write a program that will insert rand
List/Map Random Numbers
Write a program that will insert random integers between 0 and 150 into a list and perform some calculations. You will prompt the user to ask them the number of elements in your list. You will then get that many random numbers between 0 and 150 and put them in the list.
You want to number your random list numbers, so use an iterator to put the list numbers into a map (but keep the list). The key will be the number the random number was generated in starting at 1 (ex. 1, 2, 3, etc., since these are not just index numbers). The value will be the random number. Use an iterator to print the two fields lined up on the right with field widths in two columns with the numbers labeled with centered column headings of Key and Value.
Since the list is easier to work with, lets work with the list to perform some calculations. You will sort the numbers in your list. Then use iterators, algorithms, and list functions (not the user\'s input variable) to find the sum, mean (average), median (middle value - find the size and move up half way), range (difference between highest and lowest), and a random number from a random spot from your list of random number (get a random number (in the proper range) with rand() and move up that many spots in your list). Then print the labeled values (with the mean to three decimal places).
Now, use your iterator to put the now sorted list numbers back into the map (which will change the original map\'s order). The key will still be numbers starting at 1. The value will now be the random number in their sorted order. Again, use an iterator to print the two fields lined up on the right with field widths in two columns with the numbers labeled with column headings of Key and Value.
Output:
Map of original List numbers in two columns Key and Value.
The sum, average, median, range, and a value from a random spot.
Map of sorted List numbers in two columns Key and Value.
Document your program with at least 4 lines of comments at the top and at least 5 comments throughout the code for all of the not easily understandable lines of code. Run your program twice using the following number of elements. Submit your main program and submit the output text file of results.
1st run: 5 numbers
2nd run: 25 numbers
Solution
NP-complete issues area unit in NP, the set of all call issues whose solutions may be verified in polynomial time; NP could also be equivalently outlined because the set of call issues which will be resolved in polynomial time on a non-deterministic Turing machine. drawback|a drag|a haul|a retardant|a tangle} p in NP is NP-complete if each different problem in NP may be remodeled (or reduced) into p in polynomial time.
NP-complete issues area unit studied as a result of the flexibility to quickly verify solutions to drawback|a drag|a haul|a retardant|a tangle} (NP) appears to correlate with the flexibility to quickly solve that problem (P). it\'s not better-known whether or not each drawback in NP may be quickly solved—this is termed the P versus NP drawback. however if any NP-complete drawback may be resolved quickly, then each drawback in NP will, as a result of the definition of AN NP-complete drawback states that each drawback in NP should be quickly reducible to each NP-complete drawback (that is, it may be reduced in polynomial time). attributable to this, it\'s typically aforesaid that NP-complete issues area unit more durable or harder than NP issues generally.
 To the correct could be a diagram of a number of the issues and therefore the reductions generally wont to prove their NP-completeness. during this diagram, AN arrow from one drawback to a different indicates the direction of the reduction. Note that this diagram is deceptive as an outline of the mathematical relationship between these issues, as there exists a polynomial-time reduction between any 2 NP-complete problems; however it indicates wherever demonstrating this polynomial-time reduction has been best.
There is typically solely atiny low distinction between drawback|a drag|a haul|a retardant|a tangle} in P ANd an NP-complete problem. as an example, the 3-satisfiability drawback, a restriction of the Boolean satisfiability drawback, remains NP-complete, whereas the marginally a lot of restricted 2-satisfiability drawback is in P (specifically, NL-complete), and therefore the slightly a lot of general Georgia home boy. 2-sat. drawback is once more NP-complete. determinative whether or not a graph may be coloured with two colours is in P, however with three colours is NP-complete, even once restricted to tabular graphs. determinative if a graph could be a cycle or is bipartite is incredibly simple (in L), however finding a most bipartite or a most cycle subgraph is NP-complete. answer|an answer} of the packsack drawback among any mounted proportion of the best solution may be computed in polynomial time, however finding the best resolution is NP-complete.


