Homework on Data Structure Subject: Data Structure

download Homework on Data Structure Subject: Data Structure

If you can't read please download the document

Transcript of Homework on Data Structure Subject: Data Structure

HOMEWORK ON DATA STRUCTURE SUBJECT: DATA STRUCTURE

SUBJECT CODE: CAP 205

SUBMITTED BY: PARAMJIT KAUR

CLASS: MCA

SECTION: D3804

ROLL NO: D3804A03

REGD NO: 10803106

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 storing data 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-trees are particularly well-suited for implementation of databases, while routing tables rely on networks of machines to function. In the design of many types of programs, 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. Most languages feature some sort of module system, allowing data structures to be safely reused in different applications by hiding their verified implementation details behind controlled interfaces. Object-orientedHYPERLINK "http://www.search.com/reference/Programming" \o "Programming"programming languages such as C++ and Java in particular use classes for this purpose. 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

3. 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 Btrees 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 nonessential 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 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 pseudocode. 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 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 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 pseudocode. 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 QUES 5: Consider the array NAME i. 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. (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=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.

QUES 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 #include int main() { int st[60][7],b,c,d,avg; int total; clrscr(); cout