data structure and algorithms assignment
TRANSCRIPT
7/23/2019 Data Structure and Algorithms Assignment
http://slidepdf.com/reader/full/data-structure-and-algorithms-assignment 1/4
DATA STRUCTURE AND ALGORITHMS
ASSIGNMENT
QUESTION-01: DEFINE ARRAY
ANSWER:
In programming, a series of objects all of which are the same size and type.
Each object in an array is called an array element. For example, you could
have an array of integers or an array of characters or an array of anything
that has a dened data type. he important characteristics of an array are!
Each element has the same data type "although they may have di#erent
values$.
he entire array is stored contiguously in memory "that is, there are no gaps
between elements$.
%rrays can have more than one dimension. % one&dimensional array is called
a vector ' a two&dimensional array is called a matrix.
EXPLAIN ALGORITHM FOR INSERTING ELEMENTS IN AN ARRAY?
ARRAY Inser!"n
Inserting an element at end of linear array can be done easily if the array islarge enough to accommodate new item.
If the element is to be inserted in the middle of array then half members
must be moved downward to new location to accommodate new element by
(eeping the order of other elements
ARRAY INSERTION ALGORITHM
%lgorithm for Insertion: "Inserting into Linear Array $ I)*E+ "%, ), -, IE$
/. 0Initialize counter1 *et 2! 3 ).
4. +epeat *teps 5 and 6 while j 73 ('
5. 0ove jth element downward.1 *et % 02 8 /1! 3% 021.
6. 09ecrease counter1 *et 2! 3 2&/
7/23/2019 Data Structure and Algorithms Assignment
http://slidepdf.com/reader/full/data-structure-and-algorithms-assignment 2/4
0End of step 4 loop1
:. 0Insert element1 *et % 0-1!3IE.
;. 0+eset )1 *et )!3)8/
<. E=I.
QUESTION-0#: DEFINE DATA STRUCTURE AND EXPLAIN ALGORITHMIC
NOTATION IN DATA STRUCTURE?
In computer science, a data structure is a particular way of organizing data in
a computer so that it can be used e>ciently. 9ata structures can implement
one or more particular abstract data types "%9$, which are the means of
specifying the contract of operations and their complexity. In comparison, adata structure is a concrete implementation of the contract provided by an
%9.
9i#erent (inds of data structures are suited to di#erent (inds of applications,
and some are highly specialized to specic tas(s. For example, relational
databases most commonly use ?&tree indexes for data retrieval, while
compiler implementations usually use hash tables to loo( up identiers.
9ata structures provide a means to manage large amounts of data e>ciently
for uses such as large databases and internet indexing services. @sually,
e>cient data structures are (ey to designing e>cient algorithms. *ome
formal design methods and programming languages emphasize data
structures, rather than algorithms, as the (ey organizing factor in software
design. *toring and retrieving can be carried out on data stored in both main
memory and in secondary memory.
ALGORITHMIC NOTATION
%symptotic notation is a way of expressing the cost of an algorithm. Aoal of
%symptotic notation is to simplify %nalysis by getting rid of unneeded
information
Following are the asymptotic notation!
$!%&O' N"(!"n )O* :
77 B"g"n$$ 3 C f"n$ ! there exist positive constants c and nD such that D
f"n$ cg"n$ for all n 7 nD G.
7/23/2019 Data Structure and Algorithms Assignment
http://slidepdf.com/reader/full/data-structure-and-algorithms-assignment 3/4
77 It is asymptotic upper bound.
77he function f"n$ 3 B"g"n$$ i# there exist positive constants c and nD such
that f"n$ H c g"n$ for all n, n nD.
77 he statement f"n$ 3 B"g"n$$ states only that g"n$ is an upper bound onthe value of f"n$ for all n, n no.
O+e%( N"(!"n ),*
77 J "g "n$$ 3 C f"n$ ! there exist positive constants c and nD such that D c
g"n$ f"n$ for all n 7 nD G
77 %symptotic lower bound.
77 he function f"n$ 3 J"g"n$$ iff there exist positive constants c and nD
such that f"n$ c g"n$ for all n, n nD.
77 he statement f"n$ 3 J"g"n$$ states only that g"n$ is only a lower bound
on the value of f"n$ for all n, n no.
T'e( N"(!"n )*
77 K"g"n$$ 3 C f"n$ ! there exist positive constants c/ and c4 and nD such
that D c/ g"n$ f"n$ c4 g"n$ for all n 7 nD G
77 he function f"n$ 3 K"g"n$$ iff there exist positive constants L/, L4 and
nD such that L/ g"n$ H f"n$ H L4 g"n$ for all n, n nD.
L!.e "' N"(!"n )"*
77 o"g"n$$ 3 C f"n$ ! for any positive constant c7D , there exists a constant
nD such that D f"n$ c g"n$ for all n 7 nD G
77 Me use o notation to denote an upper bound that is not asymptotically
tight.
77 he denitions of B¬ation and o¬ation are similar. he main
di#erence is that in f"n$ 3B"g"n$$, the bound D f"n$ cg"n$ holds for some
constant c7D but in f"n$ 3B"g"n$$, the bound D f"n$ c g"n$ holds for all
constants c 7 D.
L!.e "+e%( N"(!"n )/*
7/23/2019 Data Structure and Algorithms Assignment
http://slidepdf.com/reader/full/data-structure-and-algorithms-assignment 4/4
77 w"g"n$$ 3 C f"n$ ! for any positive constant c7D , there exists a constant
nD such that D c g "n$ f"n$ for all n 7 nD G
77 Me use w notation to denote an lower bound that is not asymptotically
tight.