Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Assignment =1
CourseCode:CAP205
Submitted by
Priyanka
Sharma
Roll no rtb901a04
10902167
PART A
1. Q)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: - A data structure is a logical/mathematical model of organization of data. The choice of
data structure depends upon the various considerations such as:
1. The data structure should be simple so that it can be efficiently processed when
required.
2. Data structure must be capable to represent the relationship of the data in real world.
Example
The stack is a data structure that is used to perform the following operations: -
PUSH: For inserting new element in Data Structure.
POP: For deleting element from Data Structure.
TRAVERSE: For List out the elements of Data Structure.
If we want to place plates in a rack in then we have to use the stack data structure. The stack is
used because we have to pick the last item placed first. If we choose the wrong data structure
then the following problems must be faced: -
Ans: - Abstract Data Type: -To understand the notion Abstract data type, it is necessary to
understand the concept of abstract and data type separately. Abstract in our context stands for
considering apart from the detailed specification or implementation. Abstraction refers to the act
of representing the essential features without including the details. Data type is the set of values
and set of operations that are permissible on those values.
Abstract data types uses the following principles:
Encapsulation : Providing the data and operations on the data.
Abstraction: hiding the details e.g. a class in c++ or java language exhibits what it does
through its method but the detail of how methods work is hidden from the user.
The various abstract data types are stack ,queue, tree etc. the stack is an abstract data type
as two operations push and pop are performed on the stack without knowing the detail of
whether stack is implemented using array and linked list.
(i) Worst case: the maximum value of f(n) for any possible input.
The various data structures are used to solve a problem. So, the choice of data structure
depends on many things including the type of data and the frequency with which various data
operations are applied. Sometimes, the choice of data structure involves a time-space tradeoff:
By increasing the amount of space for storing the data, one may be able to reduce the time
needed for processing the data or vice-versa.
Example with algorithm notations
O(1) Push and Pop Operations
O(n) Linear Search, Factorial
O(log2n) Binary Search, Insertion in a Tree
O(nlog2n) Quick Sort, Merge Sort, Heap Sort
O(n2) Bubble Sort, Selection Sort, Insertion Sort
O(n3) Multiplication of Square Matrix
O(an) Recursion, Towers of Hanoi
Complexity notations: a function f(n) is defined to be O (g(n)), that is
f(n)=O(g(n))
and is read as order of g(n)’,if there exists positive constants n0 and k such that
Mar
y
Jane (i)Write the Algorithm to delete an
element from an array and also delete
Dian
jane from the array NAME.
a
(ii) Write the algorithm to INSERT an
Susa
element in an algorithm and also add
n
‘ABC’ into the array NAME.
Kare
n
Edit
h
Ans: - Algorithm to delete an element from an array
Let NAME is an array with N elements and K is the position from where we want to
delete an element.
1. Start
2. Input array, item
3. Set item=NAME[K]
4. Repeat for I = K to N-1
a. NAME[I] = NAME[I+1]
[end of loop]
5. Set N = N-1
6. Exit
Ans)- Algorithm to the number of students who have failed whose grade is less than 40
1. Start
2. Input n, array
3. Repeat steps for i= 1 to n
count= count+1
Endif
Endfor
5. Write “ count”
6. Exit
=========================================================