Question

In: Computer Science

1. When do we say an algorithm is optimal for a problem? Explain with a specific...

1. When do we say an algorithm is optimal for a problem? Explain with a specific problem and two concrete examples of algorithms, one of which is optimal and one which is not optimal for your chosen problem.

Solutions

Expert Solution

An optimal algorithm for a problem is the algorithm for which the objective function is maximized(or minimized) for a large random input. The objective function can be time complexity for searching and sorting or hit rate for page replacement algorithms.

We take the example of Page Replacement Algorithms here. In operating system, whenever a page is referred and is not present in the cache memory, page fault(or miss) occurs. There are a number of algorithms for page replacement. Any new referred page that is not present in the memory is considered a miss. Otherwise, it is a hit. Our aim is to maximize the hit to miss ratio.

First, we see the First-in-first-out(FIFO) algorithm in which when a page fault occurs, the page in the memory which arrived the first is replaced with the new page.

Maximum no. of pages that can be stored in the cache = 3.

Input string : 1,2,3,4,1,4,5,2,3

When 4 arrives, the page that is oldest in the memory is 1. So, 1 is replaced with 4. Similarly, when 1 arrives for the 2nd time, the oldest page is 2. So, 2 is replaced by 1 and so on.

No. of miss = 8          No. of hit = 1        hit-to-miss ratio = 1/8

Now, we consider the optimal page replacement algorithm. In it, we replace the page which will not be used for the longest in the future. If there are two such pages in the memory that are never used in the future, we replace the page that arrived first in the memory.

Input string : 1,2,3,4,1,4,5,2,3

When 4 arrives, the page that will not be used in the future for the longest time is 3. So, 3 is replaced with 4. Similarly, when 5 arrives, the pages that will not be referred in the future is 1 and 4. Now, 1 is older than 4 i.e, 1 has been in the memory for a longer time than 4. So, 1 is replaced by 5 and so on.

No. of miss = 6        No. of hits = 3        hit-to-miss ratio = 3/6 = 1/2

So, you can see that the ratio is much higher in case of optimal page replacement algorithm as compared to FIFO algorithm. So, the 2nd algorithm is considered the optimized algorithm for the page replacement problem.


Related Solutions

            What do we mean when we say “a preferred size”? Explain and give an example.
            What do we mean when we say “a preferred size”? Explain and give an example.
1. What do we mean when we say to solve a two-player strategy game in a...
1. What do we mean when we say to solve a two-player strategy game in a a. ultra weak sense b. weak sense c. strong sense 2. Compare Depth-First Iterative Deepening method with Depth-First Search and Breadth- First Search. What are the pros and cons for each of these methods
What do we mean when we say that a histogram is skewed to the left? To...
What do we mean when we say that a histogram is skewed to the left? To the right? What is a bimodal histogram? Discuss the following statement: “A bimodal histogram usually results if we draw a sample from two populations at once.” Suppose you took a sample of weights of college football players and with this sample you included the weights of cheerleaders. Do you think a histogram made from the combined weights would be bimodal? Explain. write in your...
1.What do we mean when we say the triplet code is universal? 2.If a mutation causes...
1.What do we mean when we say the triplet code is universal? 2.If a mutation causes a permanent change in the DNA sequence, how is it that most mutations are “silent” mutations 3.Suppose a young woman is exposed to a chemical mutagen and some permanent changes arise in the DNA (mutations) of some of her germ line cells. Will those mutations be passed down to her children? Why or why not 4. humans, attached earlobes (A) are dominant to free...
Question 1: (a) What do we mean when we say money is neutral? (b) Bill Clinton...
Question 1: (a) What do we mean when we say money is neutral? (b) Bill Clinton believed in working with the Fed to use Monetary Policy to help the economy grow while he was President in the early 1990s. That is, he believed that money had real effects (on output and the interest rate). Show that Bill Clinton was right, and money is non-neutral in the short run. (Guide: Draw the IS-LM graph only). (c) Ronald Reagan believed that Monetary...
When we say the media is a business, what do we mean by that? How does...
When we say the media is a business, what do we mean by that? How does that affect the way the media cover politics?
Why do we say that ex post moral hazard is more of a problem if the...
Why do we say that ex post moral hazard is more of a problem if the demand for health care is more price elastic ( quantity is quite responsive to changes in price( that if is very inelastic? ( A graph is not required but might be useful.)
Question 1.) What is natural rate of unemployment? When do we say an economy has full...
Question 1.) What is natural rate of unemployment? When do we say an economy has full employment? Identify what type of unemployment will result from the following scenarios 1.) Jane has completed college and quit her job at Tim Horton so she can work full-time in her marketing field: 2.) The clothing store George used to work for was shut down as the clothing brand is now selling all its collection through its online website: 3.) The business Hank was...
1)   Explain why we never say “accept” the null hypothesis (but we rather say “fail to...
1)   Explain why we never say “accept” the null hypothesis (but we rather say “fail to reject” the null hypothesis).   2)   State the requirements that must be satisfied to test a hypothesis regarding a population mean with either the population standard deviation know or unknown. 3)   Explain two graphs/figures/plots that you can use to assess whether the sample data is normally distributed? Make sure to explain how to assess normality using these graphs; that is, what to look for in...
What do we mean when we say we have a “distribution of mean differences”? Theoretically, how...
What do we mean when we say we have a “distribution of mean differences”? Theoretically, how would you construct a “distribution of mean differences”?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT