DS _ unit-1
DS _ unit-1
- data is collection of facts & figures or set of values of specific format that refers to a single
set of items
- DS is a branch of CS
- study of DS allows us to understand the organisation of data & management of data flow in
order to increase efficiency of any process of program
- DS is the building block of any software
Classification of DS:
Primitive DS (PDS):
- PDS consisting of numbers & characters that come’s built in the program
- these DS can be manipulated operated directly by machine level instructions
- these data types are also called as simple data types as they contain char’s that
cannot be divided further
Non-Primitive DS (NPDS) :
- NPDS are DS that are derived from PDS
- these DS cannot be manipulated or operated directly by machine level instructions
- the main focus of these DS is on forming a set of data elements i.e. either
homogenous or heterogenous
- Based on the structures & arguments we can divide NPDS into 2 sub-categories i.e.
i) Linear DS & ii)Non-Linear DS
1.Linear DS :-
- arrangement of data is done linearly where each element consists of successors &
predecessors first & last data element
- based on memory allocation the linear DS is further classified into two types i.e.
i)Static & ii)Dynamic
Static DS
- the DS which is having fixed size is called as static DS
- the memory for this Ds is allocated at compiler line & their size cannot be
changed by user after being complied
- E.g., Array
Dynamic DS
- the dynamic DS which is having dynamic (changeable) size, more over the
user can change size as well as the data elements stored in the DS at
runtime of the program
- e.g., linked list, stack, queue, etc
- an ADT is an abstraction of DS that provides only the interface to which the DS must
depends
- ADT are the entities that are definitions of data & operation but do not have
implementation details
- in this case, we know the data that we’re storing & the operations that can be
performed on the data but we don’t know the implementation details
- ADT for objects whose behaviour is defined by set of values & set of operations
- it does not specify how data will be organised in memory & what algorithms will be
used for implementing the operations
- it is called abstract bcoz it gives an implementation independent view
- users only need to know what data types can do but not how it will be implemented
- e.g., a C DS is implemented using structures, while C++ DS is implemented using
objects & classes
Abstraction : it is technique of hiding the internal details from the user & only showing
necessary details to the user
Encapsulation : it is a technique combining data & member functions in the single unit
1.List ADT (LADT) :
- the data is generally stored in a key sequence in a list which has head structure
consisting of compare functions which need to compare data in a list
- the main functions of LADT are;
- get() : returns an element from the list at any given position
- insert() : inserts an element at any given position in a list
- remove() : removes the 1st occurrence of an element from a list
- removeAt() : removes the element from the given position from a list
- replace() : replaces an element by given element
- size() : returns the number of elements in the list
- isEmpty() : returns TRUE if the list is empty else returns FALSE
- isFull() : returns TRUE if the list is full else returns FALSE
Features of ADT:
1.Abstraction
- the user does not need to know the implementation of DS, only essential data is
provided
2.Encapsulation
- ADT hides the internal details of data & provide a public interface for users to interact
with data
3.Information Hiding
- ADT can protect integrate of the data by allowing access only to authorised user’s
4.Data Abstraction
- ADT provide level of abstraction from implementation details of that data
- users only need to know the operations that can be performed on that data, not how
those operations are implemented
Advantages of ADT:
1.Encapsulation
- ADT provide a way to encapsulate data & operations into a single unit working
making it easier to manage & modify DS
2.Abstraction
- ADT allow users to work with DS without having to know the implementation details
3.DS Independency
- ADT can be implemented using different DS which can make it easier to adapt
changing needs & requirement
4.Information Hiding
- ADT provides integrate of the data by allowing access to authorised users
5.Modularity
- ADT can be combined with other ADT to perform more complex DS which can
increase flexibility & modularity in our programming
Disadvantages of ADT:
- Overhead
- Complexity
- Learning curve
- Limited flexibility
- Cost
Algorithm:
- algorithm means set of finite rules or instructions to be followed in calculation or other
problem solving techniques
- algorithms are necessary for solving complex problem efficiently & effectively
- It also enables computer to perform task that would be difficult to humans to do
manually
Characteristics of Algorithm:
4.Finiteness
- algorithm must be finite i.e. it should terminate after finite time
5.Feasible
- algorithm must be simple, generic & practical, such that it can execute with the
available resource
6.Language Independent
- algorithm design must be language independent
7.Input
- algorithm has zero or more input
- each input contains fundamental operator
8.Output
- algorithm must produce at least one output
- each instructions contains fundamental operator
Array:
- an array is a collection of items of same DT that are stored in continuous memory
location
- there are two types of array i.e. i)One-Dimensional Array & ii) Multi-Dimentional Array
- 1D-Array = array stored in single row
- Multi-Dimentional Array = array stored in multiple row of elements
1D-Array:
- this is the simplest form of an array may be defined abstractly as a finite order which
is a set of homogenous & heterogenous elements
- we must also specify how the structure is accessed
- two basic operations of an array are extraction & storing
- the extraction operation is a function that accesses an array A & index (i) & returns
an element of the array at index[i]
- here is an example of an array A storing an element ‘x’ at index[i]