You are on page 1of 9

Homework Title / No.

: ______1________________________Course Code : __ Cse2050______

Course Instructor : __Miss Manki___________ Course Tutor (if applicable) : ____________

Date of Allotment : ___25/8/10____________Date of submission : __9/9/2010_________________

Student’s Roll No.: c6803A11

Section: c6803

Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgment is made explicitly in the text, nor has any
part been written for me by another person.

Student’s Signature :

Jitender kumar___________

Evaluator’s comments:
_____________________________________________________________________

Marks obtained : ___________ out of _____7_________________

Content of Homework should start from this page only:

Part-A
Ques1 : Why structuring of data is required .Take one example problem and discuss
various problems that can be faced if wrong choice has been made in selecting data
structure for the problem.
ANS: In computer science, a data structure is a way of in a computer so that it can be used
efficiently. Often a carefully chosen data structure will allow the most efficient algorithm to
be used. The choice of the data structure often begins from the choice of an abstract data
type. A well-designed data structure allows a variety of critical operations to be performed,
using as few resources, both execution time and memory space, as possible. Data structures
are implemented using the data types,references and operations on them provided by a
programming language.
Different kinds of data structures are suited to different kinds of applications, and some are
highly specialized to certain tasks. For
example,B- tr ees are particularly well-suited for implementation of databases, while routing
tables rely on networks of machines to function. In the design of many types ofpr ogr ams,
the choice of data structures is a primary design consideration, as experience in building large
systems has shown that the difficulty of implementation and the quality and performance of
the final result depends heavily on choosing the best data structure. After the data structures
are chosen, the algorithms to be used often become relatively obvious. Sometimes things
work in the opposite direction – data structures are chosen because certain key tasks have
algorithms that work best with particular data structures. In either case, the choice of
appropriate data structures is crucial.
This insight has given rise to many formalised design methods and programming languages
in which data structures, rather than algorithms, are the key organising factor. Mostlanguages
feature some sort ofmodule system, allowing data structures to be safely reused in different
applications by hiding their verified implementation details behind controlled interfaces.

Consider an example where you have to find the maximum value in a set of 50 numbers; in
this we can either use 50 variables or a data structure, such as an array of size 50, to store the
numbers. When 50 different variables are used to store the numbers, the algorithm to
determine the maximum value among the numbers can be written as:
1. Accept 50 numbers and store them in num1, num2, num3,---- num50
2. Set max = num1
. If num2 > max then: max = num2
4. If num3 > max then: max = num3:
..
5. If num50 > max then max = num50
6. Display max
On the other hand, when an array of size 50 is used, the algorithm can be
written as:-
1. Set max = num[0]
2. Repeat step3 varying i from 1 to 49
3. If num[i] > max then: max = num[i]
4. Display max
From the preceding two algorithms, it can be seen that the algorithm using
an array manipulates memory much more efficiently than the algorithm
using 50 variables. Also, the algorithm using an array involves few steps and
is therefore, easier to understand and implement as compared to the
algorithm that uses 50 variables.

QUES 2: Delineate the concept of abstract data type in data structures?

ANS: The implementation of a data structure usually requires writing a set of procedures that
create and manipulate instances of that structure. The efficiency of a data structure cannot be
analyzed separately from those operations.This observation motivates the theoretical concept
of an abstract data type, a data structure that is defined indirectly by the operations that may
be performed on it, and the mathematical properties of those operations (including their space
and time cost).

QUES 3 : In which Applications areas data structure is extensively used.

ANS:A data structure is used for the storage of data in computer so that data can be used
efficiently. For the organization of mathematical and logical concepts data structure provides
a methodology. With the proper selection of data structure you can also get efficient
algorithm. With very few resources like memory space and time critical operations can be
carried out with a well designed data structure. The major use of data structure is its
implementation in the programming language.

Moreover, there are different kinds of data structures and they have
different uses. Some data structures are used for specialized tasks like B-
trees are used for the implementation of databases and networks of
machines use routing tables.
Area in which data structures are applied is given below:

1)Compiler Design
2)Operating System,
3) Database Management System,
4)Statistical analysis package,
5)Numerical Analysis,
6)Graphics,
7)Artificial Intelligence,
8) Simulation

QUES 4 : Elaborate the concept of “Algorithm complexity” and Complexity notations


with suitable examples.

ANS:In the study of complexity of algorithm,most attention has been given to bounding the
number of primitive operations(for examples
comparons) needed to solve a problem.
However, when working with data materials so large that they will not fil into internal
memory, the amount of time neeed to transfer data between the intenam memoer and the
external storage(the number of I/O operation) can easily dominate the overall execution time.

In Computer Science, it is important to In Computer Science, it is important to measure the


quality of algorithms, especially the specific amount of a certain resource an algorithm needs.
Examples of such resourceswould be time or memory storage. Nowadays, memory storage is
almost a non- essential factor when designing algorithms but be aware that several systems
still have memory constraints, such as Digital Signal Processors in embedded systems.
Different algorithms may complete the same task with a different set of instructions in less or
more time, space or effort than other. The analysis and study of algorithms is a discipline in
Computer Science which has a strong mathematical background. It oftenrelies on theoretical
analysis of pseudo-code.
To compare the efficiency of algorithms, we don't rely on abstract measures such as thetime
difference in running speed, since it too heavily relies on the processor power and other tasks
running in parallel. The most common way of qualifying an algorithm is theAsymptotic
Notation, also called Big O .
specific amount of a certain resource an algorithm needs. Examples of such resources would
be time or memory storage. Nowadays, memory storage is almost a non-essential factor when
designing algorithms but be aware that several systems still have memoryconstraints, such as
Digital Signal Processors in embedded systems.
Different algorithms may complete the same task with a different set of instructions inless or
more time, space or effort than other. The analysis and study of algorithms is a discipline in
Computer Science which has a strong mathematical background. It oftenrelies on theoretical
analysis of pseudo- code.
To compare the efficiency of algorithms, we don't rely on abstract measures such as thetime
difference in running speed, since it too heavily relies on the processor power and other tasks
running in parallel. The most common way of qualifying an algorithm is the Complexity
Notation, also called Big O.

Complexity Notation: The symbol O is used to describe an asymptotic upper


bound for the magnitude of afunction in terms of another, simpler
function.This means that for x > k, when x tends to infinity, the value f(x)
will always be inferiorto C *g(x) (with C a constant).

The idea behind this notation is that it allows us to qualify to efficiency of an algorithm by
telling us how often a certain algorithm will execute operations before terminating.

Part-B
1. Consider the array NAME
1.NAME
Mar
y

Jane

Dia
na

Sus
an

Kar
en

Edit
h

(i)Write the Algorithm to delete an element from an array and


also delete jane from the array NAME.

(ii) Write the algorithm to INSERT an element in an algorithm and


also add ‘ABC’ into the array NAME.

Ans.(1)Algorithm to delete an element from an array:-

(Deleting an item from an Array) DELETE (LA,n,k,ele).


Here LA is an linear array with n elements and k is an positive integer
such that k<=n.This algorithm deletes the kth itemfrom LA.
1. Set item=LA[k].
2. Repeat for J= k to n-1 :
[Move J+1st itemupward] Set A[J] := A[J+1].
[End Of Loop.]
3.[Reset the number n of elements in A] Set n := n-1.
4. Exit.
Delete jane from the array NAME.
HereName[0]=Marry,Name[1]=jane,Name[2]=Diana,Name[3]=Susan,Name[4]=Karen,Name
[5]=Edith.
Steps of algorithm to delete jane from Name array:-
1. Set item=jane.
2. Repeat for J=1 to 5.
[Move J+1st item Upward] Set A[J]:=A[J+1].
[End Of Loop.]
3.[Reset the number of element in A] set n=5.
4.Exit.

(ii) Write the algorithm to INSERT an element in an algorithm and


also add ‘ABC’ into the array NAME.

ANS: (1)Algorithm to delete an element from an array:-


(Deleting an item from an Array) DELETE (LA,n,k,ele).
Here LA is an linear array with n elements and k is an positive integer such that k<=n.This
algorithm deletes the kth itemfrom LA.
1. Set item=LA[k].
2. Repeat for J= k to n-1 :
[Move J+1st itemupward] Set A[J] := A[J+1].
[End Of Loop.]
3.[Reset the number n of elements in A] Set n := n-1.
4. Exit.
Algorithm to insert ABC in Array at 7th Position.

1.[Initialize counter] Set J:= 6 and item=ABC.


2.Repeat Steps 3 and 4 while J>=6.
3.[Move Jth element downward] Set A[J+1] := A[J].

4. [Decrease Counter.] Set J := 5.

[end of Step 2 Loop].


5.[Insert Element.] Set A[k]=item.
6.[Reset n.] Set n=7.
7.Exit.

Q. 6: Each student of a class of 30 students takes 6 test in which scores ranges from 0 to
100 .Suppose the test Scores are stored in 30*6 array test. Find the average grade for
each test

ANS: #include<iostream.h>
#include<conio.h>
int main()
{
int st[60][7],b,c,d,avg;
int total;
clrscr();
cout<<"\nenter marks of students:";
for(b=1;b<=60;b++)
{cout<<"\n enter marks for student : "<<s;
for(c=1;c<=6;c++)
{
cout<<"\nenter marks of test "<<t<<":";
cin>>D[b][c];
}
}
for(b=1;b<=60;b++)
{
cout<<"\nStudent:"<<s;
total=0;
for(c=1;c<=6;c++)
{
cout<<"\nTest:"<<t<<"\n";
if(st[s][t]<33)
{cout<<"Grade:F";
}
else if(st[b][c]>=33 && st[b][c]<60)
{cout<<"Grade:C";
}
else if(st[b][c]>=60 && st[b][c]<70)
{cout<<"Grade:B";
}
else if(st[b][c]>=70 && st[b][c]<80)
{cout<<"Grade:A";
}
else if(st[b][c]>=80 && st[b][c]<=90)
{cout<<"Grade:A+";
}
else if(st[b][c]>90)
{cout<<"Distintion";
}
}
cout<<"\n";
getch();
return 0;
}

Q.7: Find the final grade for each student where the final grade is average of the
student’s five highest test scores
ANS:
#include<iostream.h>
#include<conio.h>
int main()
{
int st[30][30],a,m,sc,total,avg;
int total;
clrscr();
cout<<"\nenter marks of students:";
for(a=1;a<=60;a++)
{cout<<"\n enter marks for student : "<<s;
for(m=1;m<=6;m++)
{
cout<<"\nenter marks of test "<<t<<":";
cin>>st[a][m];
}
}
for(a=1;a<=60;a++)
{
cout<<"\nStudent:"<<s;
total=0;
for(m=1;m<=6;m++)
{total=total+st[a][m];
}cout<<"\n";
cout<<"\nTotal score:"<<total<<"\n";
if(total<200)
{
cout<<"Grade:F";
}else if ( total>=200 && total<360)
{
cout<<"Grade:C";
}else if(total>=360 && total<420)
{
cout<<"Grade:B";
}else if(total>=420 && total<480)
{
cout<<"Grade:A";
}else if(total>=480 && total<=540)
{
cout<<"Grade:A+";
}else if(total>540)
{cout<<"Distintion";
}}
getch();
return 0;
}

Q. 8: For Q6 Write a module which finds the number of students who have fail that is
whose final grade is less than 60.
ANS:
#include<iostream.h>
#include<conio.h>
int main()
{
int st[30][30],a,m,sc,avg,ctr=0;
int total;
clrscr();
cout<<"\nenter marks of students:";
for(a=1;a<=5;a++)
{
cout<<"\n enter marks for student : "<<s;
for(m=1;m<=6;m++)
{
cout<<"\nenter marks of test "<<t<<":";
cin>>st[a][m];
}
}
for(a=1;a<=5;a++)
{
cout<<"\nStudent:"<<s;
total=0;
for(m=1;m<=6;m++)
{
total=total+st[a][m];
}if(total<60)
{
ctr++;
}
cout<<"\nTotal score:"<<total<<"\n";
}
cout<<"\n"<<ctr;
getch();
return 0;
}

Q.9: For Q6 find the average of final grades .

ANS:
#include<iostream.h>
#include<conio.h>
int main()
{
int st[30][30],a,m,sc,avg,ctr=0;
int total;
clrscr();
cout<<"\nenter marks of students:";
for(a=1;a<=5;a++)
{
cout<<"\n enter marks for student : "<<s;
for(m=1;m<=6;m++)
{
cout<<"\nenter marks of test "<<t<<":";
cin>>st[a][m];
}
}
for(a=1;a<=5;a++)
{
cout<<"\nStudent:"<<s;
total=0;
for(m=1;m<=6;m++)
{
total=total+st[a][m];
avg=total/6;
}
cout<<"\nTotal score:"<<total<<"\n";
cout<<"\nAVG:"<<avg;
}
getch();
return 0;
}

You might also like