How Does a Sentinel Value Work in an Algorithm?

  • Thread starter Thread starter jackson6612
  • Start date Start date
  • Tags Tags
    Algorithm Value
AI Thread Summary
The discussion centers on understanding the use of a sentinel value in a programming context, specifically regarding a program that processes student data. The program reads student IDs and performs calculations until it encounters a sentinel value, which in this case is the ID "0000000." This sentinel value indicates that there is no more valid data to process. The input data file must be structured so that this sentinel appears as the last entry, allowing the program to function without needing to know the total amount of data in advance. The clarity of this explanation helped the original poster, Jackson, grasp the concept effectively.
jackson6612
Messages
334
Reaction score
1
Hi

Please have a look on this scanned page:
http://img257.imageshack.us/img257/8175/chap11page191.jpg

I humbly request you to be precise and to the point in your replies. I need you help and need to understand this as soon as possible. Thank a lot.

Suppose there were 100 students and once it has processed the percentage of the last student (100th) it writes output data and then goes back to first step "Read Input Data" as the 'arrow line' suggests. Well, there is any more Input Data so the program will keep on looking for the Input Data. How is it suppose to lead to the step "Is Roll no. = 0000000" - a sentinel value? I don't understand it.

Please help me.
 
Technology news on Phys.org
Using a sentinel or trailer value, the program doing the processing doesn't need to know how much data there is.

Basically the program reads a student ID. If the ID is 0000000, the program stops. If the ID is not 0000000, it reads in data about that student, does some calculations, and then goes back to read another student ID.
 
In order for the algorithm to work properly, the input data file must be constructed so that the last line or data set contains 0000000 in the position that normally contains the roll number. This last line is not intended to be used as "real data." It exists only as a "sentinel" which signals that there is no more "real data."
 
I understand it now. Thank you, both of you, Mark, JT. These are the answers I call concise and to the point. Or, as you say in English, don't give me what I ask for, give me what I need.

Best wishes
Jackson
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top