2. WHAT ARE FILES ? A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage
9. Sequential access is sometimes the only way of accessing the data, for example if it is on a tape. It may also be the access method of choice, for example if we simply want to process a sequence of data elements in order. 1 In data structures , a data structure is said to have sequential access if one can only visit the values it contains in one particular order. The canonical example is the linked list . Indexing into a list that has sequential access requires O ( k ) time, where k is the index. As a result, many algorithms such as quicksort and binary search degenerate into bad algorithms that are even less efficient than their naïve alternatives; these algorithms are impractical without random access . On the other hand, some algorithms, typically those that don't index, require only sequential access, such as mergesort , and face no penalty.
10. Example of Random Access File Storage How you use it is up to you- you could for example have a file full of equal size records. If these records have a size of 100 then record 0 occupies bytes 0-99, record 1 occupies bytes 100-199 etc. More generally record n starts at (n-1)*sizeof(record).
11. In data structures , Random access implies the ability to access any entry in a list of numbers in constant (i.e. independent of its position in the list and of list's size, i.e. ) time. Very few data structures can guarantee this, other than arrays (and related structures like dynamic arrays ). Random access is critical to many algorithms such as binary search , integer sorting or sieve of Eratosthenes . Other data structures, such as linked lists , sacrifice random access to make for efficient inserts, deletes, or reordering of data. Self-balancing binary search trees may provide an acceptable compromise, where access time is equal for any member of a collection and only grows logarithmically with its size.
12.
13.
14.
15.
16.
17. Value Rick Jim Bill jill Data file Rec num 1 2 3 4 Value 3 4 2 1 Index file Rec num 1 2 3 4
18. Index file is just made up of numbers, and the records in the index file are arranged such that they indicate the record of the data file that should hold this position. For instance, if we want to find the first person alphabetically in our data file we would go to the index file and get the first index record. We find the index value to be 3. So we then Get the 3rd record from the data file, and determine that the first record alphabetically is "Bill." The index record value 3 can be thought of as a pointer to the data file record.