Upload
shiva-bandaru
View
221
Download
0
Embed Size (px)
Citation preview
8/11/2019 student data base full pdf
1/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
DATA STRUCTURES AND ALGORITHMS
ASSIGNMENT
Centre Name: CSN
Course Name: M.Sc (Engg) in Computer Science And Ne tworking
Name of the Student : P. V K P Sasidhar
Student Registration No : CJB0910010
Module Leader at MSRSAS : N D Gangadhar
FULL TIME 2010 BATCH
M. S. Ramaiah School of Advanced StudiesNew BEL Road, Gnanagangothri Campus, MSR Nagar, Bangalore-560 054
Tel: 23605539 / 23601983 / 2360 4759. Fax: 2360 1923 website : http://www.msrsas.org
P O S T G R A D U A T E E N G I N E E R I N G A N D M A N A G E M E N T P R O G R A M M E ( P E M P )
8/11/2019 student data base full pdf
2/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
8/11/2019 student data base full pdf
3/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 1
Declaration Sheet
Student Name P. V K P Sasidhar
Reg. No CJB0910010
CourseM. Sc (Engg.) Computer Science And
NetworkingBatch FULL TIME 10
Module Code CSN501
Module Title Data Structures And Algorithms
Module Start Date 02.11.2010 Submission Date 29.11.2010
Module Leader N D Gangadhar
Submission Arrangements This assignment must be submitted to Academic Records Office (ARO) by the submission date before 1730hours for both Full-Time and Part-Time students.
Extension requestsExtensions can only be granted by the Head of the Department / Course Manager. Extensions granted by anyother person will not be accepted and hence the assignment will incur a penalty. A copy of the extensionapproval must be attached to the assignment submitted.
Late submission PenaltiesUnless you have submitted proof of Mitigating Circumstances or have been granted an extension, the penaltiesfor a late submission of an assignment shall be as follows:
Up to one week late: Penalty of one grade (5 marks) One-Two weeks late: Penalty of two grades (10 marks) More than Two weeks late: Fail - 0% recorded (F 2)All late assignments must be submitted to Academic Records Office (ARO). It is your responsibility toensure that the receipt of a late assignment is recorded in the ARO. If an extension was agreed, theauthorization should be submitted to ARO during the submission of assignment.
To ensure assignments are written concisely, the length should be restricted a limit indicated in theassignment questions. Each participant is required to retain a copy of the assignment in his or her record incase of any loss.
Declaration
The assignment submitted herewith is a result of my own investigations and that I have conformed to the
guidelines against plagiarism as laid out in the PEMP Student Handbook. All sections of the text and results,
which have been obtained from other sources, are fully referenced. I understand that cheating and plagiarism
constitute a breach of University regulations and will be dealt with accordingly.
Signature ofDelegate Date
Date Stamp fromARO
Signature of AROStaff
Signature ofModule Leader
Signature ofCourse Manager
8/11/2019 student data base full pdf
4/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 2
M. S. Ramaiah School of Advanced StudiesPostgraduate Engineering and Management Programme- Coventry University (UK)
Assessment Sheet
Department ESDC
Course Computer Science And Networking Batch Full-Time 2010
Module Code CSN501 Module Title Data Structures And AlgorithmsModule Leader N D Gangadhar Module Completion
Date29.11.2010
Student Name P. V K P Sasidhar ID Number CJB0910010
Attendance Details Theory Laboratory Fine Paid(if any for shortage of attendance)
Remarks
Written Examination Marks Sheet (Assessor to Fill)
Q. No a b C d Total Remarks
1
2
3
4
5
6
Marks Scored for 100 Marks Scored out of 50
Result PASS FAILAssignment Marks-Sheet (Assessor to Fill)
Part a b C d Total Remarks
A
B
C
Marks Scored for 100 Marks Scored out of 50Result PASS FAIL
PMAR- form completed for student feedback (Assessor has to mark) Yes NoOverall-Result
Components Assessor Reviewer
Written Examination (Max 50) Pass / Fail
Assignment (Max 50) Pass / Fail
Total Marks (Max 100) (Before Late Penalty) Grade
Total Marks (Max 100) (After Late Penalty) Grade
IMPORTANT1. The assignment and examination marks have to be rounded off to the nearest integer and entered in the respective fields2. A minimum of 40% required for a pass in both assignment and written test individually3. A student cannot fail on application of late penalty (i.e. on application of late penalty if the marks are below 40, cap at 40 marks)
Signature of Reviewer with date Signature of Module Leader with date
8/11/2019 student data base full pdf
5/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 3
Index
Abstract. 4
Introduction....... 5
Position based list ADT..6
Unification by sequence ADT7
Conclusion..7
File operations8
Pseudo code8-9
Implementation.9-18
Testing and validation18-20
Conclusion...20
Logging sub-system.21
Implementation...21-28
Testing and validation.28
Conclusion...28
References29
8/11/2019 student data base full pdf
6/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 4
Abstract
In an array the objects are systematically arranged, usually in rows and columns.Anarray is most fundamental Abstract Data Type. An array is a finite sequence of storage cells.The data storage in most computers can be regarded as an array, so array ADT provides theultimate implementation for other Abstract Data TypeIn c arrays are error prone i.e., beforestarting of the array the element can be accessed means v[-1] and past the ending of the arraythe element can be accessed means v[n] and Modify the variable that keeps track of size(e.g., n )The List ADT is one of the most basic data structures. List ADT have more complexdata types like Trees, Stacks, Queues, etc.
Pointer has been declared in file operations. The file structure is defined ininput output library. In this file operations 3 modes are available they are read and write andappend modes. In read mode, if file doesnt exist then error is returned. In write mode, if filedoesnt exist then file is created. If file is exist then file is erased. In append mode, if filedoesnt exist then file is created. fclose () is used for close a file. fopen() is used for open afile
Administrators of UNIX system are familiar about syslog daemon. But Unlessa problem is reported by someone the information that is collected remains unprocessed. Fora site that has more machines, no time is devoted by people to log in and check multiple logfiles each day or month.
8/11/2019 student data base full pdf
7/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 5
IFor organising and storing the data specialized format called data structures is
used. Some of the data structure types are file, table, array and so on. In order to suit a
specific purpose a data structure is designed so that it can be worked and also can be accessed
within appropriate ways. Data structures are used in computer programming for data storing
for the purpose of working on it with various algorithms.
A mathematical model for a certain group of data structures
having same behavior or having similar semantics for one or more programming languages iscalled abstract data type. In order to build data structures it is important to have ADTs.
Array ADT:
Array is a collection of homogeneous elements. Array is a static like data
type but array list is the list of array is not a like data type. An array is a basic Abstract Data
Type, it can show reasonable response to consider others. An array is a finite sequence of
storage cells. It collects data elements that is same type of elements have sequence of fixed
size. It can access each element directly in the array by specifying its position so that positionvalues can be retrieved from or stored.
There are different types of arrays differentiated based on the number of
indexes are used
One dimensional array: In this one index is used.
Two dimensional array: In this two indexes are used.
Multi dimensional array: In this more than one index is used.
Static array: The allocation of memory for the array is determined by the compiler.
Dynamic array: The allocation of memory in dynamic array will takes place during
execution.
8/11/2019 student data base full pdf
8/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 6
List ADT is the collection of heterogeneous elements. The List ADT is also
one of the fundamental data structures. This concept is used for more complex data types like
stack, queues, trees etc. The List ADT is also known as a recursive ADT . The operations on
an ADT are constructors, interrogators, manipulators, and destructors.
A list is a collection of items which are accessible one after another. List ADT operations are
based on positions. List ADT position is generic.
Comparative use of array and list ADT:
List ADT:
In this list ADT list is a sequential data structure it collects the items one after another
starting at head and ending with tail.
Size of list[0] is called as null list.
In this list insertion and deletion operations are can be made at any position.
Sequential data structure is widely used in numerous applications it do not have
random access.
In Array list:
List can be stored in this Array list.
In this insertion element time in certain position depending on list size. In this insertion element time does not depend on the list.
In this array position of each element is given in the form of indices from 0 to n-1.
In list ADT:
Insertion element time with node pointer is depends upon the node pointer.
In this each element position of the list is given in the form of node.
Insertion element time at any position does not depend on the list size.
Critical appraisal of position based list ADT:
Position ADT is intuitive notation of place of an elment. Each element of the list can be stored at position and these elements are arranged
in a linear order.
8/11/2019 student data base full pdf
9/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 7
Wherever a single object is stored the position ADT is the notion of a place
within a data structure.
In position ADT null position refers to no object and defined in terms of its
neighbors.
It gives different ways of storing data, such as A cell of an array. A node of a linked list.
It have only one method i.e., element(): returns the element stored at the
position.
Critical appraisal of unification sequence ADT:
Sequence ADT is a collection of sequential arranged elements and it
provides arbitrary elements method. Sequence ADT is the set of vector and list ADTs and it can be implemented
in linked list or array.
In this, elements can be ordered in a sequence manner is described about the
ADT operations and not by elements values.
Conclusion:
Arrays cannot allocate memory dynamically. Suppose we wanna add
more elements than the array size it is not possible. Array and lists are most basic types of
data structure. Linked list are create any number of nodes and adding them at any position. In
this all operations of elements in middle also easier. Sequence ADT is used to send the
sequence of packets of network and these packets represent the relationship between their
neighbors.
8/11/2019 student data base full pdf
10/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 8
File operations:
A file is a collection of related data. computer will treat file as a single unit. Files are
secondary storage of the computers. so whenever a computer switch off then file
contents remain intact. When a computer reads a file, it copies the file from the
storage device to memory; when it writes to a file, it transfers data from memory to
the storage device.
The file open function (fopen) serves two purposes: In this connection between the physical file and the stream is available. It creates a program file structure to store the information C needs to
process the file.
Syntax: fopen(filename, mode);
Whenever finish a mode, we need to close the file before ending the program or
beginning another mode with that same file. we use fclose and the pointer variable for
file.
Syntax: fclose(spData);
Pseudo code:
Append:
()
= ("I . ", " +");
( == LL)
("F C F !");
("E . I : ");
("% ", & );
( =0; < ; ++)
("E I : ");
("% ", & . );
8/11/2019 student data base full pdf
11/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 9
List:
()
= ("I . ", " +");
( == LL)
(" F !!! AGAI ");
(( (& , ( ), 1, ))==1)
++;
(" I : % ", . );
(" : % ", );
( );
Implementation:
# < . >
# < . >
();
();
();
();
();
8/11/2019 student data base full pdf
12/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 10
, ;
, 20 ;
;
()
;
1 ;
(" E L EE DA ABA E ");
("1.A E 2.L E 3. E 4.DE 5. E E C : ");
("% ",& );
( )
1:
();
;
2:
();
;
3:
();
;
4:
();
;
8/11/2019 student data base full pdf
13/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 11
5:
();
;
:
("I C !");
(" A ? ( / ) :");
( );
("% ", );
( ( ," ")==0);
()
, ;
;
FILE * ;
= ("E . ", " +");
( == LL)
("F C F !");
(0);
("E . : ");
("% ", & );
( =0; < ; ++)
("E E : ");
8/11/2019 student data base full pdf
14/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 12
("% ", & . );
("E E : ");
("% ", & . );
// ( );
();
("E E : ");
("% ", & . );
(" E : ");
("% ", . );
// ( );
// ( . );
(" ");
(& , ( ), 1, );
( );
()
=0;
;
FILE * ;
= ("E . ", " +");
( == LL)
(" F !!! AGAI ");
(0);
8/11/2019 student data base full pdf
15/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 13
(( (& , ( ), 1, ))==1)
++;
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" ");
(" : % ", );
( );
()
, =0;
;
;
FILE * ;
= ("E . ", " +");
("E E : ");
("% ", & );
(( (( *)& , ( ), 1, ))==1)
++;
( . == )
(" E : % ", . );
8/11/2019 student data base full pdf
16/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 14
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" ");
("D : ? ( / )");
( );
("% ", & );
( , (( 1)* ( )), 0);
( ==' ' ==' ')
("E E : ");
("% ", & . );
("E E : ");
( );
("% ", & . );
("E E : ");
( );
// ( . );
(( *)& , ( ), 1, );
(" ");
(" ");
( );
8/11/2019 student data base full pdf
17/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 15
()
;
;
;
FILE * , * ;
= ("E . ", " ");
= (" . "," ");
("E E : ");
("% ", & );
(( (( *)& , ( ), 1, ))==1)
( . == )
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" ");
("D : ? ( / )");
( );
("% ", & );
( ==' ' ==' ')
( );
8/11/2019 student data base full pdf
18/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 16
(( (( *)& , ( ), 1, ))==1)
( != . )
(( *)& , ( ), 1, );
(" ");
( );
( );
("E . ");
(" . ", "E . ");
()
, ;
20 ;
;
FILE * ;
= ("E . ", " ");
(" 1. 2. E . E : ");
("% ", & );
( )
1:
8/11/2019 student data base full pdf
19/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 17
("E E : ");
( );
// ( );
(( (( *)& , ( ), 1, ))==1)
( ( , . )==0)
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" ");
(" % ", );
;
;
2:
("E E : ");
("% ", & );
(( (( *)& , ( ), 1, ))==1)
( . == )
8/11/2019 student data base full pdf
20/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software En ineerin 18
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
(" E : % ", . );
;
Test and validation:
8/11/2019 student data base full pdf
21/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software En ineerin 19
8/11/2019 student data base full pdf
22/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software En ineerin 20
Conclusion:
File operations are easy to understand the users. In these file operationsthree modes are available. They are write mode, read mode, append mode. Pointer has beendeclared in file operations. Stream pointer is used in fprintf and fscanf statements. These fileoperations are accessing the files randomly.
8/11/2019 student data base full pdf
23/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 21
Logging sub-system:
It is difficult for automated scripts to correlate data across machinesbecause they have to access individually for each machine. In order to reduce the burden ofautomatic and manual data processing, many sites are considering the implementation of acentral log server that gathers data for all the machines on a network. It also includes UNIXservers, windows and Mac desktops, and also networking equipment like routers andswitches. With most stock UNIX syslog daemons the centralized logging is fairly trivial, butfrom early incarnations the syslogd is little changed and it has some shortcomings
Implementation:
#include
#include
void append();
void list();
void search();
void modify();
void del();
struct log
{
int pid[10];
char process[20];
};
void main()
{ int a;
char ch[1];
do {
printf( "\n log DATABASE\n\n" );
printf( "1.Append log Record\n2.List log Record\n3.Modify logRecord\n4.Delete log Record\n5.Search log Record\n Enter Choice : " );
scanf( "%d" ,&a);
switch (a)
8/11/2019 student data base full pdf
24/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 22
{
case 1:
append();
break ;
case 2:
list();
break ;
case 3:
modify();
break ;
case 4:
del();
break ;
case 5:
search();
break ;
default :
printf( "Invalid Choice!" );
}
printf( "\n More Actions ? (Y/N) :" );
fflush(stdin);
scanf( "%s" , ch);
} while (strcmp(ch, "y" )==0);
}
void append()
{ int i,n;
struct log;
FILE *fp;
fp=fopen( "log.dat" , "ab+" );
if (fp==NULL)
8/11/2019 student data base full pdf
25/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 23
{
printf( "File Creation Failed!" );
exit(0);
}
printf( "Enter the nos. of logs : " );
scanf( "%d" , &n);
for (i=0;i
8/11/2019 student data base full pdf
26/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 24
{ nofrec++;
printf( "\n log pid : %d" , l.pid);
printf( "\n log process : %s" ,l.process);
printf( "\n\n" );
}
printf( "Total number of records present are : %d" , nofrec);
fclose(fp);
}
void modify()
{ int recno, nofrec=0;
char ch;
struct log l;
FILE *fp;
fp=fopen( "log.dat" , "rb+" );
printf( "Enter the log pid to modify : " );
scanf( "%d" , &recno);
while ((fread(( char *)&l, sizeof (l), 1, fp))==1)
{ nofrec++;
if (l.pid==recno)
{
printf( "\nlog pid : %d" , l.pid);
printf( "\nlog process : %s" ,l.process);
printf( "\n" );
printf( "Do you want to modify this record : ? (Y/N)" );
fflush(stdin);
scanf( "%c" , &ch);
fseek(fp, ((nofrec-1)* sizeof (l)), 0);
if (ch== 'Y' || ch== 'y' )
{
printf( "Enter the log process : " );
8/11/2019 student data base full pdf
27/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 25
fflush(stdin);
//gets(l.process);
fwrite(( char *)&l, sizeof (l), 1, fp);
printf( "Record Modified" );
}
else
printf( "No modifications were made" );
fclose(fp);
}
}
}
void del()
{
int recno;
char ch;
struct log l;
FILE *fp, *ft;
fp=fopen( "log.dat" , "rb" );
ft=fopen( "Temp.dat" , "wb" );
printf( "Enter the log Number to delete : " );
scanf( "%d" , &recno);
while ((fread(( char *)&l, sizeof (l), 1, fp))==1)
{
if (l.no==recno)
{
printf( "\nlog pid : %d" , l.pid);
printf( "\nlog process : %s" ,l.process);
printf( "\n" );
printf( "Do you want to delete this record : ? (Y/N)" );
fflush(stdin);
scanf( "%c" , &ch);
8/11/2019 student data base full pdf
28/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software Engineering 26
}
}
if (ch== 'y' ||ch== 'Y' )
{
rewind(fp);
while ((fread(( char *)&l, sizeof (l), 1, fp))==1)
{
if (recno!=e.no)
{
fwrite(( char *)&l, sizeof (l), 1, ft);
}
}
}
else
printf( "No Record was deleted" );
fclose(fp);
fclose(ft);
remove( "log.dat" );
rename( "Temp.dat" , "log.dat" );
}
void search()
{ int s,recno;
char sname[20];
struct log l;
FILE *fp;
fp=fopen( "log.dat" , "rb" );
printf( "\n1.Search by log process\n2.Search by log pid\n Enter choice : " );
scanf( "%d" , &s);
switch (s)
{
8/11/2019 student data base full pdf
29/31
8/11/2019 student data base full pdf
30/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
Real-Time Software En ineerin 28
}
}
Testing and validation:
Conclusion:
It is an alternative file system design. It is mainly used for system logfiles for th operating system. Generally it is text message its stores a detailed functionalitywhich happens in the previous programming. It mainly uses at the time of system crash.
8/11/2019 student data base full pdf
31/31
M.S Ramaiah School of Advanced Studies Postgraduate Engineering and Management Programme (PEMP)
References:
[1] M.T. Goodrich and R. Tamassia, Algorithm Design: Foundations, Analysis, and
Internet Examples , John Wiley & Sons, Inc., 2002. 2 Anonymous, Data structures
http://www.idevelopment.info/data/Programming/data_structures/overview/Data_Stru
ctures_Algorithms_Introduction.shtml, retrieved on 25/11/10
3 Anonymous, List ADT http://www.darronschall.com/weblog/2003/09/the-list-adt.cfm
retrieved on 25/11/10
4 F , B & G
C : 2007
5