Sie sind auf Seite 1von 65

Department of Information Science &

​ SKB Campus, 1​st ​Main, AG’s Colony,


Engineering A
Anandnagar, Bengaluru-24.

6​th ​Semester

FILE STRUCTURES LAB


15ISL68

ACADEMIC YEAR
2017 ​- ​2018

LABORATORY MANUAL

Name of the Student

USN

Section / Batch
www.atria.edu

Department of Information Science &


Engineering

6​th ​Semester

FILE STRUCTURES LAB


15ISL68

ACADEMIC YEAR
​ ​2018
2017 –

Name of the Student


USN

Section / Batch

Prepared by

PROF. SUHAS A BHYRATAE

PROF. OM PRAKASH B

Department of Information Science &


Engineering

LABORATORY CERTIFICATE

This is to certify that Mr.


/Ms.___________________________________
bearing USN____________________of ________semester and
________

section has satisfactorily completed the course of experiments in

FILE STRUCTURES LABORATORY ​subject code 15ISL68

prescribed by the Visvesvaraya Technological University, Belagavi of


this

Institute for the academic year 2017 -


2018.

MARKS ​Maximum Marks Marks Obtained

Signature of Faculty-In-Charge Head of the Department

Date:
File Structures Laboratory ​15ISL68

PREFACE

The idea of this manual is to make students aware of programs in the File

Structures techniques on Searching, Sorting, Indexing, Sequential processing,


Co-

sequential processing and Hashing. This manual is therefore an attempt to fill the
gap

in the knowledge of the students. The most important feature of this lab manual
is

given the coding part of each technique of File structures along with the suitable

sample inputs and outputs. It is also suggests various Object oriented concepts
using

C++. Written in with proper indentation, students find this manual extremely
useful

and handy. An incline of the questions for their viva is given at the end of this
book.

Though all the efforts have been made to make this manual error free, yet
some

errors might have crept in inadvertently. Suggestions from the teachers and
students

for the improvement of the manual are most


welcome.

Hoping that this manual will help the students develop a new perspective
about

the choosing appropriate file structure for storage representation, Identify a


suitable

sorting technique to arrange the data and Select suitable indexing and hashing

techniques for better performance to a given


problem.

We wish our students a knowledgeable and a more enjoyable File


Structure Lab

experience.

Prof. SUHAS A BHYRATAE

Prof. OMPRAKASH B

“We measure our success by our students


success”

i Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

SYLLABUS

SEMESTER – VI Subject Code 15ISL68 IA


Marks 20 Exam Marks 80 Exam Hours 03

PART A

1. Write a program to read series of names, one per line, from standard input and
write these names spelled in reverse order to the standard output using I/O
redirection and pipes. Repeat the exercise using an input file specified by the
user instead of the standard input and using an output file specified by the user
instead of the standard output.
2. Write a program to read and write student objects with fixed-length records
and the fields delimited by “|”. Implement pack ( ), unpack ( ), modify ( ) and
search ( ) methods

3. Write a program to read and write student objects with Variable - Length
records using any suitable record structure. Implement pack ( ), unpack ( ),
modify ( ) and search ( ) methods.

4. Write a program to write student objects with Variable - Length records using
any suitable record structure and to read from this file a student record using
RRN.

5. Write a program to implement simple index on primary key for a file of student
objects. Implement add ( ), search ( ), delete ( ) using the index.

6. Write a program to implement index on secondary key, the name, for a file of
student objects. Implement add ( ), search ( ), delete ( ) using the secondary
index.

7. Write a program to read two lists of names and then match the names in the
two lists using Consequential Match based on a single loop. Output the names
common to both the lists.

8. Write a program to read k Lists of names and merge them using k-way merge
algorithm with k = 8.

Part B

Mini Project ​-- Student should develop mini project on the topics mentioned
below or similar applications Document processing, transaction management,
indexing and hashing, buffer management, configuration management. Not
limited to these.

ii Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

CONTENTS

Sl.No Experiments Page No.

1 I/O Redirection 1

2 Fixed-Length Records 7

3 Variable-Length Records 15

4 RRN(Relative Record Number) 22

5 Implement Simple Index On Primary Key 28

6 Implement Index On Secondary Key 36

7 Consequential Match Based On A Single Loop 45

8 K-Way Merge 49

9 VIVA VOCE QUESTIONS 54


iii Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

1) Write a program to read a series of names, one per line, from standard
input and write these names spelled in reverse order to the standard output
using I/O redirection and pipes. Repeat the exercise using an input file
specified by the user instead of the standard input and using an output file
specified by the user instead of the standard output.

I/O redirection ​Operating systems provide shortcuts for switching between


standard I/O (stdin and stdout) and regular file I/O. I/O redirection is used to
change a program so it writes its output to a regular file rather than to stdout.
• In both DOS and UNIX, the standard output of a program can be redirected to
a file with the > symbol.
• In both DOS and UNIX, the standard input of a program can be redirected to a
file with the < symbol.
• The notations for input and output redirection on the command line in
Unix are
<file redirect stdin to “file”
>file redirect stdout to “file”
• ​Example: ​List.exe > myfile The output of the executable file is
redirected to a file called “myfile” ​Pipe
• Piping: using the output of one program as input to another program. A
connection between standard output of one process and standard input of a
second process.
• In both DOS and UNIX, the standard output of one program can be piped
(connected) to the standard input of another program with the | symbol.
• ​Example: ​program1 | program2
• Output of program1 is used as input for program2 ​File
I/O: ​perform output and input of characters to or from files
Standerd I/O:
• standard streams are preconnected input and output channels between a
computer program and its environment (typically a text terminal) when it begins
execution. The three I/O connections are called standard input (stdin), standard
output (stdout) and standard error (stderr). ​Fstream
• fstream provides an interface to read and write data from files as input/output
streams. The file to be associated with the stream can be specified either as a
parameter in the constructor or by calling member open.
• After all necessary operations on a file have been performed, it can be closed
(or disassociated) by calling member close. Once closed, the same file stream
object may be used to open another file.

1 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68
Function to open a file: ​The first operation generally performed on an object of
one of these classes is to associate it to a real file. This procedure is known as to
open a file. An open file is represented within a program by a stream object (an
instantiation of one of these classes, in the previous example this was myfile)
and any input or output operation performed on this stream object will be applied
to the physical file associated to it. In order to open a file with a stream object we
use its member function open(): ​open (filename, mode); ​Where filename is a
null-terminated character sequence of type const char * (the same type that
string literals have) representing the name of the file to be opened, and mode is
an optional parameter with a combination of the following flags: ios::in Open for
input operations. ios::out Open for output operations. ios::binary Open in binary
mode.
Set the initial position at the end of the file. ios::ate If this flag is not set to any
value, the initial position is the
beginning of the file. ios::app All output operations are performed at the end of
the file, appending the content to the current content of the file. This flag can only
be used in streams open for output-only operations. ios::trunc If the file opened
for output operations already existed before, its
previous content is deleted and replaced by the new
one. ​Function to Closing the Files ​To disassociate a logical program
file from a physical system file.
• Prototypes: ​int
close (int Handle);
• Example: ​close (Input); ​Getline Function: ​Extracts characters from specified
location and stores them into str until the delimitation character delim is found or
length equal to size.
• prototype ​fstream str; Str.getline
(istream& is, int size, char delim);
2 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

Program:

#include<iostream>
#include<fstream>
#include<string.h>
#include<stdlib.h>
using namespace
std; class names {
public:

char name[255]; }; ​void

revr(ofstream &out, char name[255]) {​


char *rev;
rev=name+strlen(name)-1;
while(rev>=name) {

out<<*rev; rev--; } } ​void

revs(char name[255]) {​
char *rev;
rev=name+strlen(name)-1;
while(rev>=name) {
cout<<*rev; rev--; } }

3 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

int main() {

names n[10]; ofstream outf; ifstream in; int choice; while(1) {


cout<<"Enter: 1. For standard I/P, O/P \n 2. To read from file \n 3.
Exit\n"; cin>>choice; switch(choice) {
case 1: {
int m; cout<<"enter no. of
names\n"; cin>>m; for(int
i=0;i<m;i++) {
cout<<"\nenter the names\n";
cin>>n[i].name; revs(n[i].name);
cout<<"\n"; }
cout<<"\n";

break; } case 2: {
ofstream o; ifstream in; char
sfile[10], dfile[10]; char
ch[10]; cout<<"Enter the
input file :";
4 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

cin>>sfile; cout<<"Enter the


outut file :"; cin>>dfile;
o.open(sfile,ios::out); int m;
cout<<"enter no. of names\n";
cin>>m; for(int i=0;i<m;i++) {
cout<<"\nenter the names\n";
cin>>n[i].name;
o<<n[i].name<<endl; } o.close();
in.open(sfile,ios::in); ofstream
outf(dfile,ios::out); while(in) {
in.getline(ch,255); if(in)
revr(outf,ch); outf<<"\n";
}
cout<<"\n"; in.close(); break; } case
3: exit(0); } // End of Switch } //End
of While } //End of Main

5 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Output: ​[root@localhost
~]# ./a.out Enter 1. For
standard i/p o/p 2. To read

from file 3. Exit 1 ​Enter no.

​ ​enter the names


of names 2
yasmin nimsay

enter the names


manjula alujnam
Enter 1. For standard i/p o/p
2. To read from file 3. Exit 2

Enter the input file: input


Enter the output file: output

Enter no. of names 1 ​Enter

the names xyz


Enter 1. For standard i/p o/p


2. To read from file 3. Exit

6 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

2) Write a program to read and write student objects with fixed-length


records and the fields delimited by “|”. Implement pack(), unpack(),
modify() and search() methods.

Fixed length record ​A record which is predetermined to be the same length as


the other records in the file.

Record 1 Record 2 Record 3 Record 4 Record 5

• The file is divided into records of equal


size.
• All records within a file have the same
size.
• Different files can have different length
records.
• Programs which access the file must know the record
length.
• Offset, or position, of the nth record of a file can be
calculated.
• There is no external overhead for record
separation.
• There may be internal fragmentation (unused space within
records.)
• There will be no external fragmentation (unused space outside of records)
except for deleted records.
• Individual records can always be updated in
place

Delimited Variable Length Fields


Record 1 | Record 2 | Record 3 | Record 4 | Record 5

• The fields within a record are followed by a delimiting byte or series of


bytes.
• Fields within a record can have different
sizes.
• Different records can have different length
fields.
• Programs which access the record must know the
delimiter.
• The delimiter cannot occur within the
data.
• If used with delimited records, the field delimiter must be different from the
record delimiter.
• There is external overhead for field separation equal to the size of the
delimiter per field.
• There should be no internal fragmentation (unused space within
fields.)

Pack(): ​This method is used to group all the related field values of particular
record taken by the application in buffer.

Unpack(): ​This method is used to ungroup all the related field values of
particular record taken from the file in buffer.

7 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Program:
#include<iostream>
#include<fstream>
#include<string.h>
#define SIZE 55 using
namespace std; char
buffer[SIZE + 1];

class Student {
char usn[15]; char name[20];
char sem[5]; char marks[10];
public: void getData(); void
putData(); void pack(); void
unpack(); void insert(); void
display(); void modify(char
*key); void search(char *key);

}; ​void Student::getData() {

cout << "Enter usn, name, sem, marks: \n"; cin


>> usn >> name >> sem >> marks; } ​void

Student::putData() {
cout << usn << "\t" << name << "\t\t" << sem << "\t" << marks <<

endl; } ​void Student::pack() {

8 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

strcpy(buffer, usn); strcat(buffer, "|");


strcat(buffer, name); strcat(buffer, "|");
strcat(buffer, sem); strcat(buffer, "|");
strcat(buffer, marks); while(strlen(buffer)
< SIZE - 1) {
strcat(buffer, "#"); } //here len of buffer is SIZE - 1
strcat(buffer, "\n"); //now len of buffer becomes = SIZE }

void Student::unpack() {
char *p; p = strtok(buffer, "|"); strcpy(usn, p); p =
strtok(NULL, "|"); strcpy(name, p); p = strtok(NULL,
"|"); strcpy(sem, p); p = strtok(NULL, "#");

strcpy(marks, p); } ​void Student::insert() { getData();



pack(); //packs the data into buffer ofstream
fout("record.txt", ios::app); fout << buffer;

fout.close(); } ​void Student::display() {

ifstream fin("record.txt");
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n');
if(fin.fail()) break; unpack(); putData();
}
9 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

fin.close(); } ​void

Student::search(char *key) {
ifstream fin("record.txt");
int count = 0;
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n');
if(fin.fail()) break; unpack();
if(strcmp(usn, key) == 0) {
putData(); count++; } } cout << "Total records found: "

<< count << endl; fin.close(); } ​void

Student::modify(char *key) {
ifstream fin("record.txt");
ofstream fout("temp.txt");
int count = 0;
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n');
if(fin.fail()) break; unpack();
if(strcmp(usn, key) == 0) {
getData(); count++; }
pack(); fout << buffer; }
10 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68
if(count == 0)
cout << "USN not found." << endl; else
cout << "Modified. " << endl;

fin.close(); fout.close();
remove("record.txt");

rename("temp.txt", "record.txt"); } ​int

main() {
int choice; Student
s; char key[15]; //
clrscr();

while(1) {
cout << "1.Insert\n"
<< "2.Display\n" <<
"3.Search\n" << "4.Modify\n"
<< "5.Exit\n" << endl; cin >>
choice; switch(choice) {
case 1:
s.insert(); cout << "Done!" <<
endl; break; case 2:
cout << "The contents are: " <<
endl; s.display(); cout << "Done!" <<
endl; break;
11 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68
case 3:
cout << "Enter the key USN: "; cin
>> key; s.search(key); cout <<
"Done!" << endl; break; case 4:
cout << "Enter the USN to modify: "; cin
>> key; s.modify(key); cout << "Done!" <<
endl; break; default:

return 0; } } } ​Output:
[root@localhost ~]# ./a.out
1.Insert 2.Display 3.Search
4.Modify 5.Exit

1 ​Enter usn, name, sem,

marks: 1at08is01
​ ajay 5 ​25

Done! 1.Insert
​ 2.Display

12 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

3.Search
4.Modify
5.Exit

2 ​The contents are: 1at08is01



ajay 5 25 Done! 1.Insert 2.Display
3.Search 4.Modify 5.Exit
3 ​Enter the key USN: 1at08is01
1at08is01 ajay 5 25 Total records
found: 1 Done! 1.Insert 2.Display

3.Search 4.Modify 5.Exit 4 ​Enter

the USN to modify: 1at08is01


Enter usn, name, sem, marks:

1at08is01 ajit 5 ​25 Modified. Done!



1.Insert
13 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

2.Display
3.Search
4.Modify
5.Exit

2 ​The contents are: 1at08is01


​ ajit
5 25 Done! 1.Insert 2.Display
3.Search 4.Modify 5.Exit
14 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

3) Write a program to read and write student objects with Variable-Length


records using any suitable record structure. Implement pack(), unpack(),
modify() and search() methods.

Variable length record ​A record which can differ in length from


the other records of the file.
• delimited record ​A variable length record which is terminated by a special
character or sequence of characters.
• delimiter ​A special character or group of characters stored after a field or
record, which indicates the end of the preceding unit.
• The records within a file are followed by a delimiting byte or series of
bytes.
• The delimiter cannot occur within the
records.
• Records within a file can have different
sizes.
• Different files can have different length
records.
• Programs which access the file must know the
delimiter.
• Offset, or position, of the nth record of a file cannot be
calculated.
• There is external overhead for record separation equal to the size of the
delimiter per record.
• There should be no internal fragmentation (unused space within
records.)
• There may be no external fragmentation (unused space outside of records)
after file updating.
• Individual records cannot always be updated in
place. ​Program: ​#include<iostream>
#include<fstream> #include<string.h> #define SIZE
55 using namespace std; char buffer[SIZE + 1];

class Student {
char usn[15];
char name[20];
char sem[5];
char marks[10];
public: void
getData();
15 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

void putData();
void pack(); void
unpack();

void insert(); void display();


void modify(char *key); void

search(char *key); }; ​void

Student::getData() {
cout << "Enter usn, name, sem, marks: \n"; cin

>> usn >> name >> sem >> marks; } ​void

Student::putData() {
cout << usn << "\t" << name << "\t\t" << sem << "\t" << marks <<

endl; } ​void Student::pack() {

strcpy(buffer, usn); strcat(buffer, "|");


strcat(buffer, name); strcat(buffer, "|");
strcat(buffer, sem); strcat(buffer, "|");

strcat(buffer, marks); strcat(buffer, "\n"); } ​void

Student::unpack() {
char *p; p = strtok(buffer, "|"); strcpy(usn, p); p
= strtok(NULL, "|"); strcpy(name, p); p =
strtok(NULL, "|"); strcpy(sem, p); p =
strtok(NULL, "\n"); strcpy(marks, p); }
16 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

void Student::insert() { getData(); pack();


//packs the data into buffer ofstream
fout("record.txt", ios::app); fout << buffer;

fout.close(); } ​void Student::display() {

ifstream fin("record.txt");
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n'); if(fin.fail())
break; unpack(); putData(); } fin.close(); }

void Student::search(char *key) {


ifstream fin("record.txt");
int count = 0;
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n');
if(fin.fail()) break; unpack();
if(strcmp(usn, key) == 0) {
putData(); count++; } } cout << "Total records found: "
<< count << endl; fin.close(); }
17 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

void Student::modify(char *key) {


ifstream fin("record.txt");
ofstream fout("temp.txt");
int count = 0;
while(!fin.eof()) {
fin.getline(buffer, SIZE + 1, '\n');
if(fin.fail()) break; unpack();
if(strcmp(usn, key) == 0) {
getData(); count++; }
pack(); fout << buffer; }
if(count == 0)
cout << "USN not found." << endl; else
cout << "Modified. " << endl;

fin.close(); fout.close();
remove("record.txt");

rename("temp.txt", "record.txt"); } ​int

main() {
int choice;
Student s;
char key[15];
while(1) {
cout << "1.Insert\n"
<< "2.Display\n"
<< "3.Search\n"
18 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

<< "4.Modify\n" << "5.Exit\n"


<< endl; cin >> choice;
switch(choice) {
case 1:
s.insert(); cout << "Done!" <<
endl; break; case 2:
cout << "The contents are: " << endl;
s.display(); cout << "Done!" << endl;
break; case 3:
cout << "Enter the key USN: "; cin
>> key; s.search(key); cout <<
"Done!" << endl; break; case 4:
cout << "Enter the USN to modify: "; cin
>> key; s.modify(key); cout << "Done!" <<
endl; break; default:
return 0; } } }

19 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Output: ​[root@localhost
~]# ./a.out 1.Insert
2.Display 3.Search
4.Modify 5.Exit

1 ​Enter usn, name, sem,

marks: 1at08is059
​ vimala 5

25 Done! 1.Insert
​ 2.Display
3.Search 4.Modify 5.Exit
2 ​The contents are: 1at08is059
​ vimala
5 25 Done! 1.Insert 2.Display 3.Search

4.Modify 5.Exit 3 ​Enter the key USN:

1at08is059 1at08is059
​ vimala 5 25
Total records found: 1
20 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

Done! 1.Insert 2.Display 3.Search


4.Modify 5.Exit 4 ​Enter the USN to

modify: 1at08is059 Enter


​ usn,
name, sem, marks: 1at08is059 vijay

5 ​25 Modified. Done!


​ 1.Insert
2.Display 3.Search 4.Modify 5.Exit 2

The contents are: 1at08is059


​ vijay 5
25 Done! 1.Insert 2.Display
3.Search 4.Modify 5.Exit

21 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68
4) Write a program to write student objects with Variable-Length records
using any suitable record structure and to read from this file a student
record using RRN.

RRN(relative record number)


• RRN is an ordinary number that gives the distance of current record from first
record. Using RRN, Direct access allows individual records to be read from
different locations in the file without reading intervening records.
• When we are using fixed length record, we can calculate the byte offset of
each record using the fallowing formula
• ByteOffset = (RRN - 1) × RecLen o RRN: relative record
number(starts fron 0) o RecLen: size of fixed length record ​Direct
Access ​Record 1 Record 2 Record 3 Record 4 Record 5 Record 6 Record 7

Program: ​#include
<iostream> #include
<fstream> #include
<string> #include
<sstream> using
namespace std; class
student {
public:
string USN;
string Name;
string Branch;
int Semester;
string buffer; int
count;
int rrn_list[100];

void read_data();
void pack();
22 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

void write_to_file(); void


unpack(); void create_rrn();
void search_by_rrn(int); };

void student::read_data() {​
cout<<"\nUsn:";
cin>>USN;
cout<<"\nName:";
cin>>Name;
cout<<"\nBranch:";
cin>>Branch;
cout<<"\semester:";

cin>>Semester; } ​void

student::pack() {​
string sem; stringstream out; out << Semester; sem =
out.str(); buffer.erase();
buffer=USN+'|'+Name+'|'+Branch+'|'+sem+'$'+'\n'; }

void student::write_to_file() {​
int pos; fstream file;
file.open("1.txt",ios::out|ios::app);
pos=file.tellp(); file<<buffer;
23 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

file.close();
rrn_list[++count]=pos; } ​void

student::unpack() {​
string sem; int
ch=1,i=0;
USN.erase(); while
(buffer[i]!='|')
USN+=buffer[i++];

Name.erase(); i++;
while (buffer[i]!='|')
Name+=buffer[i++];

Branch.erase(); i++;
while (buffer[i]!='|')
Branch+=buffer[i++];

sem.erase(); i++; while


(buffer[i]!='$')
sem+=buffer[i++];
istringstream out(sem);
out>>Semester;

} ​void
student::create_rrn() {​
ifstream file;
24 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

int pos; count=-1;


file.open("1.txt",ios::in);
while (!file.eof()) {
pos=file.tellg(); buffer.erase();
getline(file,buffer);
rrn_list[++count]=pos; } file.close();

} ​void student::search_by_rrn(int

rrn) {​
int pos=-1; fstream file; if (rrn>count) cout<<"\n
Not Found"; else{ buffer.erase();
file.open("1.txt"); pos=rrn_list[rrn];
file.seekp(pos,ios::beg); getline(file,buffer);

cout<<"\n"<<buffer<<"\n" ; } } ​int main() {​

int choice,rrn;
student s1;

s1.create_rrn();
25 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

while(1){ cout <<"\nMain Menu\n 1.Add \n\n 2.Search 3.EXIT\n\nEnter


the choice:"; cin>>choice; switch (choice) {
case 1: cout<<"Data\n";
s1.read_data(); s1.pack();
s1.write_to_file(); break; case 2:
cout <<"\n\nEnter the RRN";
cin>>rrn; s1.search_by_rrn(rrn);
break; case 3: return 0; default:
cout<<"\n\nWrong Choice";

break; } ​} }​

Output: [root@localhost

~]# ./a.out Main Menu

1.Add ​2.Search 3.EXIT


Enter the choice:1


Usn:1at08is058
Name:varsha
Branch:ISE
Semester:6 Main
Menu
26 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

1.Add

2.Search
3.EXIT

Enter the choice:2 Enter


the RRN: 0
1at08is059|Vimala|ISE|6

Main Menu
1.Add

2.Search
3.EXIT

Enter the choice: 3


27 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

5) Write a program to implement simple index on primary key for a file of


students objects. Implement add(), search(), delete() using the index.

Index ​A structure containing a set of entries, each consisting of a key field and a
reference field, Which is used to locate records in a data file. ​Key field ​The part
of an index which contains keys. ​Reference field ​The part of an index which
contains information to locate records.
• An index imposes order on a file without rearranging the
file.
• Indexing works by indirection. ​Simple
Index for Entry-Sequenced Files
Simple index
• An index in which the entries are a key ordered linear list. Simple indexing can
be useful when the entire index can be held in memory. Changes (additions and
deletions) require both the index and the data file to be changed.
• Updates affect the index if the key field is changed, or if the record is moved.
An update which moves a record can be handled as a deletion followed by an
addition.

Primary key ​A primary key is a special relational database table column (or
combination of columns) designated to uniquely identify all table records. A
primary key's main features are: It must contain a unique value for each row of
data. It cannot contain null values. ​Program: ​#include<iostream>
#include<fstream> #include<string> #include<sstream> using namespace std;
class primary_index {
public:

28 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

string usn_list[100]; int address_list[100]; int


count; void create_primary_index(); void
insert(); void remove(string); void
search(string); int
search_primary_index(string); string
extract_usn(string); void

sort_primary_index(); }; ​void

primary_index::create_primary_index() {​
fstream file; int pos; string
buffer,usn; count=-1;
file.open("hi1.txt",ios::in);
while(!file.eof()) {
pos=file.tellg(); buffer.erase();
getline(file,buffer); if(buffer.empty()) break;
usn=extract_usn(buffer);
usn_list[++count]=usn;
address_list[count]=pos; } file.close();

sort_primary_index(); } ​string

primary_index::extract_usn(string buffer) {​
string usn;
29 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

int i=0; usn.erase();


while(buffer[i]!='|')

usn+=buffer[i++]; return usn; } ​void

primary_index::sort_primary_index() {​
int i,j,temp_address;
string temp_usn;
for(i=0;i<=count;i++) {
for(j=i+1;j<=count;j++) {
if(usn_list[i]>usn_list[j]) {
temp_usn=usn_list[i]; usn_list[i]=usn_list[j];
usn_list[j]=temp_usn; temp_address=address_list[i];
address_list[i]=address_list[j];

address_list[j]=temp_address; } } } } ​void

primary_index::insert() {​
string
usn,name,branch,sem,buffer; int
semester,address,pos; fstream
file; cout<<"\nUSN:"; cin>>usn;
cout<<"\nNAME:";
30 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

cin>>name; cout<<"\n BrANCH:"; cin>>branch;


cout<<"\nSEMESTER:"; cin>>semester;
stringstream out; out<<semester; sem=out.str();
buffer.erase();
buffer=usn+'|'+name+'|'+branch+'|'+sem+'$'+'\n';
file.open("hi1.txt",ios::out|ios::app); pos=file.tellp();
file<<buffer; file.close(); usn_list[++count]=usn;

address_list[count]=pos; sort_primary_index(); } ​int

primary_index::search_primary_index(string key) {​
int low=0,high=count,mid=0,flag=0,pos;
while(low<=high) {
mid=(low+high)/2;
if(usn_list[mid]==key) {
flag=1; break; }
if(usn_list[mid]>key)
high=mid-1;
if(usn_list[mid]<key)
low=mid+1; }
31 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

if(flag) return mid; else return -1; }

void primary_index::search(string

key) {​
int pos=0,address; string buffer;
fstream file; buffer.erase();
pos=search_primary_index(key)
; if(pos>=0) {
file.open("hi1.txt");
address=address_list[pos];
file.seekp(address,ios::beg);
getline(file,buffer); cout<<"\nFound the
record"<<buffer; file.close(); } else
cout<<"\nNot found."; }

void primary_index::remove(string key)


{
int pos=0; int address,i; char
del_ch='*'; fstream file;
pos=search_primary_index(key)
; if(pos>=0) {
file.open("hi1.txt");
address=address_list[pos];
file.seekp(address,ios::beg)
;
32 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

file.put(del_ch);
cout<<"\nRecord deleted.";
file.close();
for(i=pos;i<count;i++) {
usn_list[i]=usn_list[i+1];
address_list[i]=address_list[i+1]; } count--; }
else
cout<<"Not found.\n"; }

int main() {​
int choice; string key;
primary_index i1;
i1.create_primary_index();
while(1) {
cout<<"\nMAin menu\n1.ADD\n2.SEARCH\n";
cout<<"3.Delete\n4.Exit\nEnter your choice\n";
cin>>choice; switch(choice) {
case 1:
cout<<"Data\n";
i1.insert(); break; case
2:
cout<<"Enter the usn to be
searched\n"; cin>>key; i1.search(key);
33 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

break; case 3:
cout<<"Enter the usn to delete\n";
cin>>key; i1.remove(key); break; case
4:
return 0; default:
cout<<"Wrong choice\n"; } } return 0;

} ​Output:

[root@localhost ~]# ./a.out


Main menu 1.ADD
2.SEARCH 3.Delete 4.Exit

Enter your choice 1 ​Data

USN:1at08is045
NAME:ashwini
Branch: ise
SEMESTER:6

Main menu 1.ADD


2.SEARCH 3.Delete 4.Exit

Enter your choice 2 ​Enter

the usn to be searched


1at08is045
34 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68
Found the
record1at08is045|ashwini|ise|6 Main
menu 1.ADD 2.SEARCH 3.Delete

4.Exit Enter your choice 3 ​Enter the usn

to delete 1at08is045

Record deleted.
Main menu 1.ADD
2.SEARCH 3.Delete
4.Exit Enter your
choice: 4
35 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

6) Write a program to implement index on secondary key, the name, for a


file of student objects. Implement add(), search(), delete() using the
secondary index.

Index ​A structure containing a set of entries, each consisting of a key field and a
reference field, Which is used to locate records in a data file. ​Key field ​The part
of an index which contains keys. ​Reference field ​The part of an index which
contains information to locate records.
• An index imposes order on a file without rearranging the
file.
• Indexing works by indirection. ​Simple
Index for Entry-Sequenced Files
Simple index
• An index in which the entries are a key ordered linear list. Simple indexing can
be useful when the entire index can be held in memory. Changes (additions and
deletions) require both the index and the data file to be changed.
• Updates affect the index if the key field is changed, or if the record is moved.
An update which moves a record can be handled as a deletion followed by an
addition.

Secondary key ​A secondary key is made on a field that you would like to be
indexed for faster searches. A table can have more than one secondary key
Program: ​#include<iostream> #include<fstream> #include<sstream>
#include<string> using namespace std; class secondary_index{

public:
string Name_list[100];
int Address_list[100];
int count;
36 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

void create_index(); void insert() ; void


remove(string); void
delete_from_file(int); void
search(string); int search_index(string);
void read_from_file(int); string
extract_Name(string); void sort_index();

}; ​void secondary_index::create_index()
{
fstream file; int pos;
string buffer,name;
count=-1;
file.open("1.txt",ios::in);
while(!file.eof()) {
pos=file.tellg(); buffer.erase();
getline(file,buffer); if(buffer.empty() ) break;
if(buffer[0]=='*') continue; //imp since it leads
the last \n and goes to new line
name=extract_Name(buffer);
Name_list[++count]=name;
Address_list[count]=pos; }
file.close();
sort_index();
37 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

buffer.erase(); } ​string

secondary_index::extract_Name(string buffer) {​
string USN,Name; int i=0;
USN.erase(); while(buffer[i]!='|')
USN+=buffer[i++]; Name.erase();
i++; while(buffer[i]!='|')
Name+=buffer[i++]; return Name; }

void

secondary_index::sort_index() {​
int i,j,temp_Address;
string temp_Name;
for(int i=0;i<count;i++) {
for(int j=i+1;j<=count;j++) {
if(Name_list[i]>Name_list[j]) {
temp_Name=Name_list[i];
Name_list[i]=Name_list[j];
Name_list[j]=temp_Name;
temp_Address=Address_list[i];
Address_list[i]=Address_list[j];
Address_list[j]=temp_Address; }
//End of if
38 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

} //End of Inner for } //End


of outer for } //End of function

void secondary_index::insert()
{
string USN,Name,Branch,sem,buffer; int
semester,pos; fstream file ; cout<< "\n USN:";
cin>>USN; cout<< "\n Name:"; cin>>Name; cout<<
"\nBranch:" ; cin>>Branch; cout<< "\nSEMESTER:";
cin>>semester; stringstream out; out<<semester;
sem=out.str();
buffer=USN+'|'+Name+'|'+Branch+'|'+sem+'$'+'\n';
file.open("1.txt",ios::out|ios::app); pos=file.tellp();
file<<buffer; file.close(); Name_list[++count]=Name;

Address_list[count]=pos; sort_index(); } ​int

secondary_index::search_index(string key){ int



low=0,high=count,mid=0,flag=0; while(low<=high){
mid=(low+high)/2;
39 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

if(Name_list[mid]==key){
flag=1; break; }
if(Name_list[mid]>key)
high=mid-1; else
low=mid+1; }
if(flag){
return mid; } else

return -1; } ​void

secondary_index::search(string key){
int pos=0,t; string buffer;
buffer.erase();
pos=search_index(key);
if(pos>=0){
read_from_file(pos); t=pos;
while(Name_list[++t]==key)
read_from_file(t); t=pos;
while(Name_list[--t]==key)
read_from_file(t); } else

cout<<"\n"<<"Not found"; } ​void

secondary_index::read_from_file(int pos){
int address;
40 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

string buffer; fstream file; file.open("1.txt");


address=Address_list[pos];
file.seekp(address,ios::beg); getline(file,buffer);
cout<<endl<<"Found the record:"<<buffer;

file.close(); } ​void

secondary_index::remove(string key){
int pos=0,t; string buffer;
buffer.erase();
pos=search_index(key);
if(pos>=0){
read_from_file(pos);
delete_from_file(pos); t=pos;
while(Name_list[++t]==key){
read_from_file(t);
delete_from_file(t); }
t=pos; while(Name_list[--t]==key){
read_from_file(t);
delete_from_file(t); } } else

cout<<"\n\nNot found\n"; } ​void

secondary_index::delete_from_file(int pos){
char del_ch='*';
int i,address;
41 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

if(pos>=0){ fstream file;


file.open("1.txt");
address=Address_list[pos];
file.seekp(address,ios::beg);
file.put(del_ch);
cout<<endl<<"\n\nRecord
deleted:"; file.close(); } for(int
i=pos;i<count;i++){
Name_list[i]=Name_list[i+1];
Address_list[i]=Address_list[i+1]; }
count--; }

int main(){
int ch; string key;
secondary_index i1;
i1.create_index();
while(1){
cout<<"\nMain Menu\n1:Add\n2:Search\n3:Delete\n4:Exit\nEnter
the choice";
cin>>ch;
switch(ch){
case 1:cout<<"Data \n";
i1.insert(); break; case
2:cout<<"Enter the name\n";
cin>>key; i1.search(key);
break; case 3:cout<<"Enter the
Name";
cin>>key;
42 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

i1.remove(key); break; case 4: return 0;


default:cout<<"Wrong Choice!!!!!!!\n\n"; } } } ​Output:
[root@localhost ~]# ./a.out Main Menu 1:Add 2:Search
3:Delete 4:Exit Enter the choice1 Data USN:1at08is059
Name:varsha Branch:ise SEMESTER:5

Main Menu 1:Add


2:Search 3:Delete
4:Exit Enter the
choice2 Enter the
name varsha

Found the
record:1at08is059|varsha|ise|5$ Main
Menu 1:Add 2:Search
43 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

3:Delete 4:Exit Enter


the choice3 Enter the
Name: varsha

Found the
record:1at08is059|varsha|ise|5$ Record
deleted: Main Menu 1:Add 2:Search
3:Delete 4:Exit Enter the choice: 4

44 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68
7) Write a program to read two lists of names and then match the names in
the two lists using Consequential Match based on a single loop. Output the
names common to both the lists.

Consequential operations ​Operations which involve accessing two or more


input files sequentially and in parallel, resulting in one or more output files
produced by the combination of the input data. ​Considerations for
Consequential Algorithms
•Initialization - What has to be set up for the main loop to work
correctly?
•Getting the next item on each list - This should be simple and easy, from the
main algorithm.
•Synchronization - Progress of access in the lists should be
coordinated.
•Handling End-Of-File conditions - For a match, processing can stop when the
end of any list is reached.
•Recognizing Errors - Items out of sequence can "break" the
synchronization. ​Matching Names in Two Lists Match ​The process of
forming a list containing all items common to two or more lists.
Consequential Match Algorithm
•Initialize (open the input and output
files.)
•Get the first item from each list.
•While there is more to do: Compare the current
items from each list. If the items are equal, Process
the item. Get the next item from each list. Set more
to true iff none of these lists is at end of file. If the
item from list A is less than the item from list B, Get
the next item from list A. Set more to true iff list A is
not at end-of-file. If the item from list A is more than
the item from list B, Get the next item from list B. Set
more to true iff list B is not at end-of-file.
• Finalize (close the files.)

45 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Program:
#include<iostream>
#include<fstream>
#include<string.h>
//#include<conio.h>
using namespace
std;

int main() {

int i, n; char name[20],


name2[20]; ofstream fout;
ifstream fin1, fin2; // clrscr();

fout.open("record1.txt");
cout << "Enter the no of names to enter in record1: ";
cin >> n; cout << "Enter " << n << " names in
ascending order: \n"; for(i=0; i<n; i++) { cin >> name;
fout << name << endl; } fout.close();
fout.open("record2.txt"); cout << "Enter the no of
names to enter in record2: "; cin >> n; cout << "Enter "
<< n << " names in ascending order: \n"; for(i=0; i<n;
i++) { cin >> name; fout << name << endl; }

fout.close();

46 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

fin1.open("record1.txt");
fin2.open("record2.txt");
fout.open("output.txt");
fin1 >> name; fin2 >>
name2;

while(!fin1.eof() && !fin2.eof()) {

if(strcmp(name, name2) == 0) {
fout << name << endl;
cout <<name <<endl;
fin1 >> name; fin2 >>
name2;

} else if(strcmp(name, name2) < 0) {


fin1 >> name;

} else {
fin2 >> name2; } }

fin1.close(); fin2.close();
fout.close(); cout <<
"Done!"; // getch();
return 0;

47 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Output​: [root@localhost ~]# ./a.out Enter


the no of names to enter in record1: 2
Enter 2 names in ascending order: sindhu
yasmin Enter the no of names to enter in
record2: 2 Enter 2 names in ascending
order: manjula yasmin yasmin
48 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

8) Write a program to read k lists of names and merge them using k-way
merge algorithm with k=8.

Merge ​The process of forming a list containing all items in any of two or
more lists. ​K-way merge ​A merge of order k ​Order of a merge ​The
number of input lists being merged.
• If the distribution phase creates k runs, a single k-way merge can be
used to produce the final sorted file.
• A significant amount of seeking is used by a k-way merge, assuming
the input runs are on the same disk. ​Program: ​#include<iostream>
#include<fstream> #include<string.h> using namespace std; // Record
specification class record {
public: char name[20]; char usn[20]; }rec[20]; int no; fstream file[8]; //The
first 8 files char fname[8][8] =
{"l.txt","2.txt","3.txt","4.txt","5.txt","6.txt","7.txt","8.txt"}; void
merge_file(char* file1, char* file2, char* filename) {
record recrd[20]; int k; k=0; fstream f1,f2;
f1.open(file1,ios::in); //open the first file
f2.open(file2,ios::in); //open the second file

49 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

while(!f1.eof()) //Unpack and retrieve first file


{
f1.getline(recrd[k].name,20,'|');
f1.getline(recrd[k++].usn,20,'\n'); }

while(!f2.eof()) //Unpack and retrieve second

file {​
f2.getline(recrd[k].name,20,'|');

f2.getline(recrd [k++].usn, 20,'\n'); } ​record


temp; int
​ t,y; for(t=0;t<k-2;t++) //Sort the
retrieved records for(y=0;y<k-t-2;y++)
if(strcmp(recrd[y].name,recrd[y+1].name)>0
){

temp=recrd[y]; recrd[y]=recrd[y+1]; recrd[y+1]=temp; } ​fstream temp1;


temp1.open(filename,ios::out); //Open the file to be packed into
for(t=1;t<k-1;t++) //Pack the sorted records onto the file
temp1<<recrd[t].name<<"|"<<recrd[t].usn<<"\n"; f1.close(); f2.close();

temp1.close(); return; } ​void kwaymerge() ​{ ​char

filename[7][20]={"ll.txt","22.txt","33.txt","44.txt","lll.txt","222.txt","llll.txt"}; int
​ i; int
k;
50 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

k=0; for(i=0;i<8;i+=2) //Merge and sort the 8 original


files onto { //the four files indicated {ll.txt,22.txt....}

merge_file(fname[i],fname[i+1],filename[k++]); } ​k=4;
for(i=0;i<4;i+=2) //Merge and sort the four files onto lll.txt and
222.txt {
merge_file(filename[i],filename[i+1],filename[k++]);
}
//Merge and sort the two files onto the llll.txt file
merge_file(filename[4],filename[5],filename[6]);

return; } ​int main() {​

int i; cout<<"Enter the no. of records : "; cin>>no;


cout<<"\nEnter the details : \n"; for(i=0;i<8;i++)
//Create 8 files to store the split data
file[i].open(fname[i],ios::out); for(i=0;i<no;i++)
//Split and pack data onto the files {
cout<<"Name :"; cin>>rec[i].name; cout<<"USN :
";cin>>rec[i].usn;
file[i%8]<<rec[i].name<<'|'<<rec[i].usn<<"\n"; }

for(i=0;i<8;i++) file[i].close();
​ kwaymerge(); //Merge
fstream result; result.open("llll.txt",ios::in);
cout<<"\nSorted Records : \n";
51 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

char name[20],usn[20]; for(i=0;i<no;i++) //Unpack the


sorted records and dispL {
result.getline(name,20,'|'); result.getline(usn,20,'\n');

cout<<"\nName : "<<name<<"\nUSN : "<<usn<<"\n"; } ​return 0; }​

Output: [root@localhost
​ ~]# ./a.out Enter the no. of records : 6

Enter the details :


Name :sindhu
USN : 23 Name
:yasmin USN : 25
Name :manjula
USN : 26 Name
:kala USN : 27
Name :vijetha
USN : 28 Name
:priya USN : 29
Sorted Records :
Name : kala USN
: 27 Name :
manjula USN : 26

52 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

Name : priya
USN : 29

Name : sindhu
USN : 23

Name : vijetha
USN : 28

Name : yasmin
USN : 25
53 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

VIVA QUESTIONS

1. What is FILE STRUCTURE? 2. What are the


main goals of FILE STRUCTURE? 3. What is a
physical file? 4. What is a logical file? 5. Difference
between physical and logical file? 6. What is the
syntax of open function? 7. Define Flags. 8. List
different types of flag and their operations. 9. What
do you mean by pmode? Explain. 10. Define read
function with syntax. 11. Define Write function with
syntax. 12. What do you mean by source file? 13.
What do you mean by destination file? 14. What are
source and destination addresses? 15. Define File
descriptor. 16. Explain seeking with its syntax. 17.
Difference between seekg and seekp. 18. Define
byte offset. 19. What is origin in seek function? 20.
Explain the following commands.
a)cat d)mv g)ls b)tail e)rm h)mkdir c)cp f)chmod i)rmdir 21.
Explain different field structures. 22. Explain different record
structures. 23. What is inheritance? 24. Explain primary key
with an Example. 25. Explain Secondary key with an
Example. 26. What do you mean by canonical form? 27.
What is Sequential search? 28. How can we improve the
sequential search performance? 29. What is the order of
sequential search? 30. When will you say that the sequential
search is good? 31. Give some unix tools for sequential
processing.

54 ​Department of Information Science & Engineering, Atria Institute Of


Technology
File Structures Laboratory ​15ISL68

32. What is Direct Access? 33. Explain the order of Direct


Access. 34. RRN stands for? 35. Define RRN. 36. How can we
Calculate byte offset using RRN? 37. What do you mean by
Standard I/O? 38. What are header records? 39. What is data
compression? 40. Advantages of data compression. 41. Different
techniques of data compression. 42. What is run-length
encoding? 43. What do you mean by reclaimation of unused
space? 44. What is linked-list? 45. What is need of using linked
list? 46. What is stack? 47. Explain the need of using stack? 48.
What do you mean by available list? 49. What “-1” indicates in
avail list? 50. How you can reclaim the unused space? 51. What
is storage fragmentation? 52. What do you mean by internal and
external Fragmentation? 53. What are the different placement
strategies? Explain. 54. Limitations of Binary search. 55. What is
keysorting? 56. What is tagsort? 57. Define pinned record. 58.
Define Redundancy Reduction. 59. What do you mean by
indexing? 60. What are the Operations required to maintain the
indexed file? 61. What are inverted lists? 62. Define selective
indexes. 63. Define Binding. 64. Define Co-sequential search. 65.
Explain the logic K-Way merge. 66. AVL stands for? 67. What do
you mean by paged Binary trees? 68. Define multilevel indexing.
55 ​Department of Information Science & Engineering, Atria Institute Of
Technology
File Structures Laboratory ​15ISL68

69. What are B-trees? 70. Explain Splitting. 71. Explain the logic of
redistribution. 72. Explain how you are deleting the nodes in B trees.
73. Explain the logic for merging the nodes in B trees. 74. Define B*
trees. 75. Explain Virtual B-trees. 76. What is LRU replacement? 77.
What do you mean by replacement based on page height? Explain.
78. What is order of a B-tree? 79. Define page index. 80. What are
blocks? 81. What are separators? 82. Define prefix. 83. Define B+
tree. 84. Define hashing. 85. Define hashing function. 86. Explain the
advantages and disadvantages of hashing. 87. Explain any simple
hashing algorithm. 88. Define Packing Density. 89. What is
Progressive overflow? 90. Define search length. 91. What are
buckets? 92. What are tombstones? 93. Define double hashing. 94.
Define chained progressive overflow. 95. What do you mean by
chaining with a separate overflow Area? 96. Define scatter tables. 97.
What is a pattern of record access? 98. What do you mean by home
address? 99. What is Mid-square method? 100. Define Extendible
hashing? 101. Define buddy buckets? 102. Define linear hashing.
103. Explain dynamic hashing.
56 ​Department of Information Science & Engineering, Atria Institute Of
Technology

Das könnte Ihnen auch gefallen