• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Sequential files (1 Viewer)

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
So a sequential file uses delimiters and a sentinel value to show when its the eof.
a question from 2006 trial 2006.
We are reading a sequential file which has an array of records on it. Records in the array are sorted on surname of students.
Now, i was under the impression that a sequential file would store the array of records as like a stream with the delimiter (i.e. TAB if TAB delimited separating them). i.e.
sof----record1 TAB record2 TAB record 3 TAB----eof
we had to justify why we would use an array of record for the student's details. I understand how to justify this. The answer was:
"we need an array of records as it is necessary to read in every record from the file and allow the searching to be done quickly in RAM rather than by having to read the sequential file multiple times to access the required records as part of the binary search"
now, to me this implies with the "binary search" that the records are indexed.
im confused
a) i thought sequential files couldnt index and so thats what disallow their ability to random access
Could some1 please help

Also quickly
b) can you have a sequential file which has multiple array of records where inside these array of records their are indexes allowing the binary search, however between the 2 array of records their are only delimiters
i.e. sof-----array of records 1 TAB AOR2--------eof
and inside each AOR their are indexes for the records. So basically when wanting to find a student the program could linear search the sequential file for the student array, and then perform a binary search on that array using the indexes of the records (which are sorted in a logical order)
  • but then that means in a Random access file if there were multiple arrays of records in the file, there would be indexes for each of these AOR, and then another index for the records within the AOR?
So yeh you can see im reallyyyyyy confused and this is gonna cost me heaps of markssss
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
I think you may be reading too much into this question.

To be honest, you have completely lost me on your second question and a little in your first.

But I will try anyway.

A) They are indexed by the array, as it is an array of records.
The answer is saying that you then load this into RAM as random access and then perform a binary search.
I'm assuming it is saying that when it is loaded into RAM, it is automatically indexed, as they are already in order.

I hope that makes sense.

b) I am not quite sure what you are asking..?

but then that means in a Random access file if there were multiple arrays of records in the file, there would be indexes for each of these AOR, and then another index for the records within the AOR?
This is true. Ie Array[1, 2.Studentname]? Sorry I think I have missed what you are asking?
 

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
yeh i was afraid i would overwhelm or not be clear
basically was asking
a) how is it possible to perform a binary search on a sequential file if they arent indexed
b) is a sequential file just a file where all the structured data types (record, array of records etc) are delimited, but then within each of these data structures there are indexes.
c) does a random access file index each of the structured data types in it, and then inside these structured data types(if the structured data types was an array of records) are their another send of indexes just for that data structure.

i think thats alot more clearer without the scenario of the question.

and
d) if each structured data type in a sequential file is delimited and then inside these structured data types they have indexes, does the CPU read the file using a linear search considering delimiters to find the AOR within the file it wants, load that whole AOR into memory, and as inside this AOR there are indexes it can perform the binary search.

thanks for responding lol
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Ok, I can't answer them all fully and correctly, but here goes:

a) It isn't. Well, not without some crazy programming skills.

b) I think, but am not sure =S, a sequencial file would work like this:
it could be anyway, depending on how the individual program reads it, for example:

sof---array1 TAB studentname TAB studentage TAB array2 TAB studentname TAB studentage---eof

This way the file can then be read into a random access file, and stored in the appropriate data structures.

c) I would think so. No way to be sure, it might just vary based on how it is stored. Sorry not so sure about this one.

d) Depends on how the programmer programs it. I think my answer to b might help you understand that.

Not sure if I really answered your questions well, but hopefully that helps somewhat.
 

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
yeh you helped heaps.
i think i grasped this now
but yeh uncertainties with b
like if there can be many different structed data types in the one file, and inside these are other structured data types (i.e. an array of records and inside this there are records), if it stores the data structure like you said i.e. aray1 TAB student name TAB eof, isnt the student name part of that array i.e. a field of the records in that array lol
and yeh
i think the main question for me is how does the programme reading the file know if the record stored in the file is just a record or is part of an array of records, if it stores the files like you said.
the only way i could see this working if they declared where an array started and ended in a file. e.g.
sof----AOR(start) TAB record1 TAB record2 TAB---AOR(end)---NewARRAY(start)...
if you get my drift lol
thanks for all your help
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Yes! I can answer this properly.

Pretty much, the program reads the array however the programmer wants them to.
A sequencial file can be any way you want it to be, so long as it works with the program.
I think this algorithm will help you.

BEGIN
Array As Array (this is the random access array)
ArrayIndex As Integer = 0
Index As Integer //Index will just represent a place separated by spaces within the algorithm for simplicity
Open FILENAME
WHILE Index =/= eof
Array(ArrayIndex.Record1) = FILENAME.Index
Index = Index + 1
Array(ArrayIndex.Record2) = FILENAME.Index
Index = Index + 2
ArrayIndex = ArrayIndex + 1
ENDWHILE
END
Don't know if that algorithm will work, but yeah, gives a general idea hopefully. Ask me to explain anything I sucked at explaining there. :)

Hope it helps :)

EDIT: Note the sequencial file is not indexed, it should just say, Next index or whatever. I am just saying it reads the next area separated by spaces in the file. (saying they are delimiters)
 
Last edited:

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
WHILE Index =/= eof
Array(ArrayIndex.Record1) = FILENAME.Index
so if ArrayIndex is the index for each AOR in the file and index is for the index of each record in each AOR,
should it be WHILE Index=/= eoArray?
as it will be the last item in that AOR which after it has been processed will cause ArrayIndex to implement to the next AOR along the file?
to be pedantic you didnt set index to 0 before processing ArrayIndex + 1

but yeh that makes so much more sense to me thankyou so much lol
i guess i was right that the AOR inside a sequential have their own indexes for records, just that the file must read sequential till it gets to this AOR.

So if this file was a sequential file which contained AOR's would we just do:
get first AOR //using linear search
Read contents into program untill arrayindex= eoarray
CASEWHERE next item in file is
TAB : get next array
SENTINEL : cease processing
END CASEWHERE
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
Don't poke fun at my lazy algorithm :(

I don't think you have quite got it though =P

should it be WHILE Index=/= eoArray?
ArrayIndex handles which index of the ARRAY you are talking about.
The part of the record is then specifically referenced in the program. Remember the record has to be predefined.

So the program already knows there are going to be 2 records in this instance.
So it skips over the "array1" etc part (Index = Index + 2), and just adds one to the index of array.
It then just increments the array index each loop through and you end up with a stored array of records, just by reading linearly through the file.

o if this file was a sequential file which contained AOR's would we just do:
get first AOR //using linear search
Read contents into program untill arrayindex= eoarray
CASEWHERE next item in file is
TAB : get next array
SENTINEL : cease processing
END CASEWHERE
Yeah I couldn't be bothered going into that much detail.

Oh well, glad i could be of assistance :)
 

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
so are you saying the records are just stored in the sequential file using delimiters and are read by the programme into an array to create an array of indexed records?
cause if so, if the tAB is separating the records, whats separating each field in the record lol
cause this would explain why the whole sequential file must be read into RAM for searches to be conducted on it.

and for a Random Access file does it store the records already as an array of indexed records without the need for the program to read all records into RAM to create its own array of indexed records (As it has to with a sequential file)

lol this is pretty hard aha do u think we need to know this?
 

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
We don't need to know this much lol.. =D

But yeah, it depends on the programmer. You could make another seperator other than TAB to separate records. It doesn't really matter.

I'm not to sure about random access files. I would say it doesn't matter, as RAM is random access too.
You would only copy it into RAM from a random access file to increase speed. (as RAM is faster)

In saying that we don't need to know this, knowing it will help with some of the higher order thinking questions occassionally which lead you on to this sort of thing.
 

crammy90

Member
Joined
Mar 26, 2006
Messages
264
Gender
Male
HSC
2008
ah k kool
well thanks heaps
might do a past paper now
:)
good luck with ur exams
keep lurking this forum lol i may have other questions...
ahaha :)
oh wait
so when its reading the sequential file's records into an array in RAM for processing, if there are 2 arrays in the file does the programmer just define like a new symbol (say "*") which when the program reaches processing it it just starts putting the next set of records into a new array in RAM untill it reaches the sentinel or another *?
and just say it wants to get the records for one array in the file, when reading, does it have to process furthur along when it reaches this * to the end of file, or could the programmer define the file so that if it wants just say the first lot of records for the file array from the file, processessing ceases when the * is reached without having to read all the succeeding records in the file
and just say the programme did have to get the records for a particular array in the file, if this target array was say the 4th array in the sequential file, does the program read the first 3 arrays into memory before it reads the 4th target, where it then discards the first 3 from RAM? or can it linear search the file and start reading from the 4th (target) array without having to read the preceeding 3. Like basically is a sequential file in that to get to the 4th array in the file does it load the first 3 into RAM before it reaches the 4th (is this the sequential aspect) or is it that it just has to start from the start of the file and read along the file till it gets to the 4th file (the sequential part) but it doesnt have to actuall read them into memory
 
Last edited:

Graceofgod

Member
Joined
Feb 17, 2008
Messages
136
Location
Now? A computer.
Gender
Undisclosed
HSC
2008
so when its reading the sequential file's records into an array in RAM for processing, if there are 2 arrays in the file does the programmer just define like a new symbol (say "*") which when the program reaches processing it it just starts putting the next set of records into a new array in RAM untill it reaches the sentinel or another *?
Yes, again, its completely up to the programmer how they do it. But yeah, that would work.

and just say it wants to get the records for one array in the file, when reading, does it have to process furthur along when it reaches this * to the end of file, or could the programmer define the file so that if it wants just say the first lot of records for the file array from the file, processessing ceases when the * is reached without having to read all the succeeding records in the file
You could write a program to read it like this if you wanted.

and just say the programme did have to get the records for a particular array in the file, if this target array was say the 4th array in the sequential file, does the program read the first 3 arrays into memory before it reads the 4th target, where it then discards the first 3 from RAM? or can it linear search the file and start reading from the 4th (target) array without having to read the preceeding 3. Like basically is a sequential file in that to get to the 4th array in the file does it load the first 3 into RAM before it reaches the 4th (is this the sequential aspect) or is it that it just has to start from the start of the file and read along the file till it gets to the 4th file (the sequential part) but it doesnt have to actuall read them into memory
It doesn't have to read anything into memory to perform a linear search on a sequential file. So yes, you could just read through it until you found the part you wanted.
Really depends on exactly what you are trying to do.
If for some reason you need to find an array that contains a certain record value, then copy that whole index of the array, not just that record value to use for whatever reason, you would have to copy each array into RAM as you search through it, then delete it after seeing it is the incorrect one.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top