![]() |
CPSC 110-08: Computing on Mobile Phones
|
Do the following exercises and add your answers to your Portfolio page for today's homework.
For each of the following problems, decide whether it can be solved by a linear algorithm and explain briefly why or why not.
If we don't use all those buckets, this problem can be solved by a quadratic time algorithm: For each number in the list, go through all the other numbers to see if it has a duplicated. So, each of n numbers in the list is compared to n-1 other numbers. That would be n × (n-1) = n2 - n comparisons, which is quadratic. As the size of the list doubles, the amount of time this would take would increase by 22.
For each of the following problems, decide whether it can be solved by a logarithmic algorithm and explain briefly why or why not.
For each of the following problems, decide whether or not it is intractable and explain briefly why or why not.
To see this more clearly, let's count the subsets. There are 4 (22) subsets of {1, 2}: {}, {1,2}, {1}, {2}.
There are 8 (23) subsets of {1,2,3}: {}, {1,2,3}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}.
And there are 16 (24) subsets of {1,2,3,4}: {}, {1,2,3,4}, {1}, {2},{3},{4},{1,2}, {1,3},{1,4},{2,3},{2,4},{3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}.
In general, the the number of subsets of a set of N things is 2N, which is exponential.