Page faults in LRU algorithm - lru

I'm having trouble with understanding something from my programming lecture. I know that page replacement algorithms have page faults.
In the LRU algorithm, when does a page fault occur? Is it when there are no more free frames left? Is it when a frame is already there, but already used too?
I have this picture in my lecture presentations (I cropped just the important part since the original is in another language):
The question in this picture is "Having only 4 frames, when will a page fault occur if the LRU algorithm is used?" And as I can see there is an x on the first 3 lines. That's why I'm asking if a page fault occurs when there are free frames left? Or does a page fault occur only in the red X's, when we need to "kick out" a frame?

A page fault occurs when the page isn't already in one of the frames.
So if there are some free frames left and we need to enter a new page - a page fault will occur because the page isn't already in one of the frames.
This means a page fault will keep occuring until we come across the same page (number) that is already in one of the frames. That's why there is an 'x' in the first 3 lines of the picture. And there is no 'x' on the fourth line because the page was already in one of the frames.
AND a page fault occurs if all of the frames are already with pages and the new page we are entering isn't already in one of the frames, we need to "kick out" a frame in order to free up one frame for the new page. This can be done in different algorithms, like Least Recently Used, First-In First-Out etc. That's why in the picture, some of the 'X's are red, because a page fault occured AND we kicked out a frame.
Thanks to #Blorgbeard for helping with my answer.

Related

Google Form - New Row

I already saw other questions from other users and I still couldnt help myself on this problem.
Im using google form on my job to help my team mates to simulate some jobs and im using forms to make it easier without using the sheet in itself. Im using one page for the form and one page for the calculations based on the replies from that form.
The problem, as you know it, everytime I complete a form it makes a new row, and it doenst go to my calculation page. It jumps ahead 1 row.
Any suggestion on how I can make it block the jumping row?
I apologise if I am not understanding your problem fully, but I think you mean you're trying to add a calculated column in Google Sheets based on responses in Google Forms?
Let's say, for example, on the form there is a question for length and a question for width and you want Sheets to automatically calculate the area by multiplying the values in the Responses sheet.
You can't drag the formula down the column because when a new response is submitted in Google Forms, Google Sheets adds it as a new row, and the formula is not included.
You've done the right thing by having a separate sheet that deals with calculations but you should use an Array Formula that will refer to the whole column of the Responses sheet, and it would need an IF statement to account for the first row, which has the headers.
I think this video explains everything better than I could:
https://www.youtube.com/watch?v=0v-hQ3EecdE

SCORM to xAPI sessions and re-answering Activity + changing Score

I'm coming from a SCORM end and trying to figure out two related issues with how to do update and find the most recent data (ie, looking for best practices).
In SCORM I'd have a set of activities that would all store their answers and scores (easily understandable from the docs etc). The "how" I'm after is specifically related to resuming the set of activities multiple times, and hitting "reset" and submitting a different answer to a single activity after a statement has been sent in.
From what I read with xAPI it states that statements are immutable - so how would I go about this.
My first thought was that I'd make the statement id generated from the activity id and void the old answer when it changes - but that sounds wrong (not least because it reads like you can't re-use the id even with voiding).
So it looks like the Statement id needs to be unique, which would mean that multiple identical Objects would be found - so would I have to look through every attempt and check for the latest one?
I'm currently looking at using xAPIWrapper in the middle.
Moving from SCORM to xAPI requires a change of mindset. SCORM deals with statuses which get updated; xAPI logs events like a journal.
You can think of it like Facebook. You post a photo of your new cat; a month later you post a photo of your cat 1 month older. There's no need to go back and delete the old post. If you want the latest photo of your cat you just go and get the most recent photo tagged "Ryochet's cat". You can also look at older photos to see how your cat developed. xAPI is like that activity stream on Facebook.
So, if somebody scores 10 points on their first attempt, then 20 points on their second attempt, you'd simply send a second set of statements about the 2nd attempt. There's no need to get rid of the statements about the old attempt, that happened and is useful data to see how the learner developed.

ASP.Net grid with frozen headers, columns and lots of data

I am in need of a control that will give me input functionality where the user will get a few locked columns on the left and will be able to enter some values into text boxes to the right (for example a row value may be a name, and the columns would be each day of a month). As the user inputs values and scrolls to the right, the first couple of columns on the left would say locked (i.e. in view) and as the user scrolls down the list the headers would stay in view.
I have done exhaustive analysis of JQuery fixed header/column plugins, and while many of them were promising, none of them worked well once there were many rows (> 100) and many columns (> 15 or so). They would all start to freeze the browser (especially in IE).
I am more than happy to buy a commercial control that meets my needs, but I haven't been able to find any.
Does anyone have any recommendations?

How can I determine the "correct" number of steps in a questionnaire where branching is used?

I have a potential maths / formula / algorithm question which I would like help on.
I've written a questionnaire application in ASP.Net that takes people through a series of pages. I've introduced conditional processing, or branching, so that some pages can be skipped dependent on an answer, e.g. if you're over a certain age, you will skip the page that has Teen Music Choice and go straight to the Golden Oldies page.
I wish to display how far along the questionnaire someone is (as a percentage). Let's say I have 10 pages to go through and my first answer takes me straight to page 9. Technically, I'm now 90% of the way through the questionnaire, but the user can think of themselves as being on page 2 of 3: the start page (with the branching question), page 9, then the end page (page 10).
How can I show that I'm on 66% and not 90% when I'm on page 9 of 10?
For further information, each Page can have a number of questions on that can have one or more conditions on them that will send the user to another page. By default, the next page will be the next one in the collection, but that can be over-ridden (e.g. entire sets of pages can be skipped).
Any thoughts? :-s
Simple answer is you can't. From what you have said you won't know until you have reached the end how many pages the user is going to see so you can't actually display an accurate result.
What you could do to get a better result as in your example is to assume they are going through all the remaining pages. In this case you would on any page have:
Number of pages gone through so far including current (visited_pages)
Number of the current page (page_position)
Total number of pages (total_pages)
The maximum number of pages is now:
max_pages = total_pages - page_position + visited_pages
You can think of total_pages-page_position as being the number of pages left to visit which makes the max_pages quite intuitive.
So in the 10 page example you gave visited_pages = 2 (page 1 and page 9), page_position = 9 and total_pages = 10.
so max_pages = 10-9+2 = 3.
then to work out the distance through you just do
progress = visited_pages/max_pages*100
One thing to note is that if you were to go to pages 1,2,3,4,9,10 then your progress would be 10%,20%,30%,40%,83%,100% so you would still get a strange jump that may confuse people. This is pretty much inevitable though.
Logically unless the user's question graph is predetermined, you can not predetermine their percentage complete.
That being said.
What you can do is build a full graph of the users expected path based on what information you know: what questions they have completed, and what questions they have to take, and simply calculate a percentage.
This will probably involve a data structure such as a linked list to calculate where they have been, and what the user has left to complete, this implementation is up to you.
The major caveat here is you have to accept that if the users question graph changes, so will their percent completed. Theoretically they could display 90% and then it changes and they will display 50%.

ASP.NET Variable issues

I have some terribly written ASP.NET code that is just not working right (go figure).
I'm charged with maintaining and bug fixing this code, but I can barely make head or high water of it
Unfortunately I don't have the time to rewrite it.
If someone could help this would be great:
(the code): given to you here (some minimal obfuscation necessary):
http://mastergeektheater.com/issues.txt
What it's supposed to do:
Receives an order from a shopping cart application, and creates a table of textboxes based on the quantity of said object ordered.
Once the whole thing is validated (submit_Click()), then it reveals a div with further instructions and grays out the input fields so you can still see what was entered, but can't affect anymore. Emails are sent to each inputted email address.
What it actually does:
Receives the order, and correctly displays the inputs. On Submit, all of the "required field validators fire - if they are Vaild, then the comparison validators fire. SOMEWHERE AROUND HERE, it all goes south."
All of the input areas in the table except the first user disappear. if the comparisons success, then it postsback, and the first user is there (greyed out) and the other users are gone. if the comparisons fail, then it doesn't successfully postback, and stays on the input form, but all of the input fields except the first user still disappear
I know this is a little too specific to be a really well formed Stack Overflow question, but I've tried to break it down to things I think were wrong and I asked other questions that were more specific to try to fix it. Unfortunately, it hasn't worked. The code got better, but the whole thing is still broken. At this point I'm desperate.
If anyone could help, it would be a huge lifesaver. Thanks in advance for all of you who pour through this terrible code (and terrible question) for even a minute...
I guess the problem could be due to this line.
Session["quantity"] =(null != Request["quantity1"]) ? Request["quantity1"].ToString() : "1";
Do you have a field (hidden/input) named quantity1 on the form?
Is it being passed to querystring or as part of form item collection?
It will be 1 (when the form posts back to itself) & hence the loop will only run once.

Resources