Академический Документы
Профессиональный Документы
Культура Документы
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 acknowledgement is made explicitly in the text, nor has any part been
written for me by another person.
Sol:- It is the ability of a computer to fetch and store data at any place in its memory,
specified by an address is called Data structures. A bit string that can be itself stored in
memory and manipulated by the program. Thus the record and array data structures are based
on computing the addresses of data items with arithmetic operations; while the linked data
structures are based on storing addresses of data items within the structure itself. Structuring
of data is required to save our memory space and to have fast access on the data.
In organization or in databases we don’t have to deal with small numbers of data there can be
million and billion of data records.
Let us consider an example where we have to find the maximum value in a set of 100
numbers. In this we can either use 100 variables or a data structure, such as an array of size
100, to store the numbers. When 100 different variables are used to store the numbers, the
algorithm to determine the maximum value among the numbers can be written as:
step 1. Accept 100 numbers and store them in num1, num2, num3, .. num100
step 2. Set maximum = num1
step 3. If num2 > maximum then: maximum = num2
step 4. If num3 > maximum then: maximum = num3:
.
.
step 102. If num100 > maximum then maximum = num100
step 103. Display maximum
Now look at the diference On the other hand, when an array of size 100 is used, the algorithm
can be written as:-
step1. Set maximum = num[0]
step 2. Repeat step3 varying i from 1 to 99
step 3. If numimum [i] > maximum then: maximum = num[i]
step 4. Display maximum
It is clear from the above two algorithms, that the algorithm using an array manipulates
memory much more efficiently than the algorithm using 100 variables. Also, the algorithm
using an array involves few steps (4 to 5) and is therefore, easier to understand and implement
as compared to the algorithm that uses 100 variables.
Space complexity :- Space complexity is the measure of the amount of space, excluding the
original data passed in, that it takes an algorithm to execute on an input. Any algorithm that
must always store at least all of the data at a time runs in &O(n) of space complexity. If
however an algorithm only needed to store a counter of some kind its space complexity would
be log(n) where n is the final value of the counter. This is the reason as it only takes log2 bits
to store a number.
Complexity Notation :- The symbol O is used to describe an asymptotic upper bound for the
magnitude of a function in terms of another, simpler function. This means that for x > k, when
x tends to infinity, the value f(x) will always be inferior to C *g(x) (with C a constant).
Insertion sort belongs to the O(n2) sorting algorithms. Unlike many sorting algorithms with
quadratic complexity, it is actually applied in practice for sorting small arrays of data. For
instance, it is used to improve quick sort. Some sources notice, that people use same
algorithm ordering items, for example, hand of cards.
Part-B
4. An array A contain 20 positive integers .Write algorithm which find the number
of elements of A which are even ,and the number of elements of array which are
odd.
sol:- [SCE(sequence counter of even no.), SCO(sequence counter of odd no.)]
step 1. start
step 2. Set a[20] read values and set SCE=0 && SCO=0.
step 3. repeat step 3 while i is 1 to 20
step 4. if a[i]%2==0 SCE=SEC+1
i. Else SCO=SCO+1
step 5. end if
step 6. end while
step 7. display SCE and SCO
step 8. end stop and exit
5. 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
Sol:- {array ar[30][6],item=0,sum=0,avg(average)=0}
step 1. Start
step 2. Set ar[30][6]
step 3. Repeat step 3 and 4 for i 1 to 30
step 4. Read marks for student i :
i. Repeat step (i-ii-iii) For j 1 to 6
ii. Read marks of the test j : i.e. ar[i][j]=item
iii. End for
step 5. End for
step 6. Repeat step 6 and 7 for i 1 to 30
step 7. Display marks for student i :
i. Repeat step (i-ii-iii) For j 1 to 6
ii. display marks of the test j : i.e. ar[i][j]=item
iii. if ar[i]j]<40 display GRADE:F
iv. else if ar[i][j]>=40 && ar[i][j]<60 display GRADE:D
v. else if ar[i][j]>=60 && ar[i][j]<70 display GRADE:C
vi. else if ar[i][j]>=70 && ar[i][j]<80 display GRADE:B
vii. else if ar[i][j]>=80 && ar[i][j]<90 display GRADE:A
viii. else if ar[i][j]>=90 && ar[i][j]<100 display GRADE:A+
ix. end if
x. End for
step 8. End for
step 9. Stop and exit
6. An array A contain 20 positive integers .Write algorithm which find the number
of elements of A which divisible by 2.
Sol:-