You are on page 1of 9

Assignment-1

Course Code:CAP205

Date:
08/09/10

Submitted to: Submitted by:

Sanjay Sir Manish Kr. Singh
10907108
D3912 A17

Ans: . Ans: In computer science.data structures are chosen because certain key tasks have algorithms that work best with particular data structures. The choice of the data structure often begins from the choice of an abstract data type.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. using as few resources. both execution time and memory space. A well-designed data structure allows a variety of critical operations to be performed.Why structuring of data is required . allowing data structures to be safely reused in different applications by hiding their verified implementation details behind controlled interfaces. the algorithms to be used often become relatively obvious. This insight has given rise to many formalized design methods and programming languages in which data structures. are the key organizing factor. Often a carefully chosen data structure will allow the most efficient algorithm to be used. the choice of data structures is a primary design consideration. After the data structures are chosen. the choice of appropriate data structures is crucial.trees are particularly well-suited for implementation of databases. In either case. B. Sometimes things work in the opposite direction . references and operations on them provided by a programming language. as possible. 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. 2. Most languages feature some sort of module system. while routing tables rely on networks of machines to function. In the design of many types of programs. Different kinds of data structures are suited to different kinds of applications.Delineate the concept of abstract data type in data structures.PART-A 1. a data structure is a way of storing data in a computer so that it can be used efficiently. For example. Data structures are implemented using the data types. and some are highly specialized to certain tasks. rather than algorithms.

6)Graphics. This observation motivates the theoretical concept of an abstract data type. With the proper selection of data structure you can also get efficient algorithm.List out Applications areas of various data structure. Ans: A data structure is used for the storage of data in computer so that data can be used efficiently. 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. 3. PART-B 4. . 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. The efficiency of a data structure cannot be analyzed separately from those operations. a data structure that is defined indirectly by the operations that may be performed on it. 8) Simulation. For the organization of mathematical and logical concepts data structure provides a methodology. Moreover. 4)Statistical analysis package. Areas in which data structures are applied is given below:- 1)Compiler Design 2)Operating System. 3) Database Management System.Elaborate the concept of “Algorithm complexity” and Complexity notations with suitable examples. 7)Artificial Intelligence. and the mathematical properties of those operations (including their space and time cost). 5)Numerical Analysis.The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure. there are different kinds of data structures and they have different uses.

However. when working with data materials so large that they will not fill into internal memory. Different algorithms may complete the same task with a different set of instructions unless or more time. memory storage is almost a non- essential factor when designing algorithms but be aware that several systems still have memory constraints. Nowadays. The most common way of qualifying an algorithm is the Asymptotic Notation. Different algorithms may complete the same task with a different set of . most attention has been given to bounding the number of primitive operations needed to solve a problem. The analysis and study of algorithms is a discipline in Computer Science which has a strong mathematical background. space or effort than other. Nowadays. it is important to measure the quality of algorithms. Examples of such resources would be time or memory storage. memory storage is almost a non-essential factor when designing algorithms but be aware that several systems still have memory constraints. we don't rely on abstract measures such as the time difference in running speed. such as Digital Signal Processors in embedded systems. It often relies on theoretical analysis of pseudo- code. especially the specific amount of a certain resource an algorithm needs.Ans: In the study of complexity of algorithm. To compare the efficiency of algorithms. In Computer Science. also called Big O specific amount of a certain resource an algorithm needs. since it too heavily relies on the processor power and other tasks running in parallel. the amount of time need to transfer data between the internal memoirs and the external storage(the number of I/O operation) can easily dominate the overall execution time. such as Digital Signal Processors in embedded systems. Examples of such resources would be time or memory storage. it is important to In Computer Science.

The most common way of qualifying an algorithm is the Complexity Notation. space or effort than other. To compare the efficiency of algorithms. simpler function. Complexity Notation: The symbol O is used to describe an asymptotic upper bound for the magnitude of a function in terms of another. Ans: (i) Algorithm to delete an element from an array:- Deleting an item from an Array) DELETE (LA.n. since it too heavily relies on the processor power and other tasks running in parallel. This means that for x > k. when x tends to infinity. The analysis and study of algorithms is a discipline in Computer Science which has a strong mathematical background.ele). Here LA is an linear array with n elements and k is an positive integer . the value f(x) will always be inferior to C *g(x) (with C a constant). 5.code. It often relies on theoretical analysis of pseudo. (ii) Write the algorithm to INSERT an element in an algorithm and also add ‘ABC’ into the array NAME. we don't rely on abstract measures such as the time difference in running speed.Consider the array NAME Mary Jane Diana Susan Karen Edith (i)Write the Algorithm to delete an element from an array and also delete jane from the array NAME. 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.k.instructions in less or more time. also called Big O.

Name[2]=Diana.Name[1]=jane.] 3. (ii) Algorithm to insert an element in Array:- (Inserting into a linear Array)INSERT (LA. [End Of Loop. This algo insert an element item into kth position in LA. [End Of Loop. Name[3]=Susan. Name[4]=Karen. Name[0]=Marry. LA is an Linear Array with n elements and k is an positive integer such that k<=n. This algorithm deletes the kth item from LA.[Reset the number n of elements in A] Set n := n-1.[Reset the number of element in A] set n=5. Name[5]=Edith. 1. 2.Exit. Set item=jane. 2.] 3. Exit. 4.k. Algorithm to Delete jane from Array Name :- Here. . Steps of algorithm to delete jane from Name array: 1. [Move J+1st item Upward] Set A[J]:=A[J+1]. Repeat for J=1 to 5.n. Repeat for J= k to n-1 : [Move J+1st item upward] Set A[J] := A[J+1]. Set item=LA[k].item) Here. 4.such that k<=n.

Repeat Steps 3 and 4 while J>=k. 6. 7.] Set LA[k]=item. else if(st[b][c]>=70 && st[b][c]<80) {cout<<"Grade:A".d.[Insert Element.Exit. . 6. [Move Jth element downward] Set LA[J+1] := LA[J].b<=60.b++) {cout<<"\n enter marks for student : "<<s. 2. int total. Ans: #include<iostr eam.Write algorithm which find all pair of elements whose sum is 25. [end of Step 2 Loop]. for(b=1. 1.c. 5. [Decrease Counter.[Initialize counter] Set J:= n.h> #include<conio. 4.An array A contain 30 positive integers .[Reset n. clrscr(). cout<<"\nenter marks of students:".] Set J := J-1.avg.] Set n=n+1.b.h> int main() { int st[60][7]. 3.

m<=6. } else if(st[b][c]>90) {cout<<"Distintion". getch(). Ans: #include<iostream. } } cout<<"\n".For Q5 Write a module which finds the number of students who have fail that is whose final grade is less than 60. return 0.avg.m. cout<<"\nenter marks of students:".ctr=0.h> int main() { int st[30][30].a.sc.a++) { cout<<"\n enter marks for student : "<<s. for(m=1. } 7.h> #include<conio. for(a=1.m++) . } else if(st[b][c]>=80 && st[b][c]<=90) {cout<<"Grade:A+".a<=5. clrscr(). int total.

m<=6.m++) { total=total +st[a][m]. getch().a<=5. cin>>st[a][m].{ cout<<"\n enter marks of test "<<t<<":". } } for(a=1. } cout<<"\n Total score:"<<total<<"\n". } . return 0. } cout<<"\n"<<ctr. total=0. for(m=1.a++) { cout<<"\n Student:"<<s. }if(total<60) { ctr++.