DSA Unit-1 Data Structure
DSA Unit-1 Data Structure
Employee name get divided into three subitems as first name, middle
name and last name.
ii) Elementary items :- Data items that are not divided into
subitems are called elementary item.
Ex.: 14 – 03 – 2022.
Social security number is treated as a single item.
(c) Organization of data :-
Collection of data are frequently organized into hierarchy of fields,
records and files.
- The above concept can be more cleared using following additional
terminology i.e. attribute, entity and entity set.
i) Attribute :- A attribute is a specified memory area used to store
data.
ii) Entity :- A entity is something that has retain attributes or
properties which may be assigned values. Here assigned values may
be either numeric or non-numeric.
Ex.: Attributes: Roll No. Name Grade
Values: 01 Ajay A
iii) Entity Set :- Entities with similar attributes form an entity set.
Each attribute of an entity set as a range of values, the set of all possible
values that could be assigned to the particular attribute.
Ex.: All the employees in an organization.
(d) Information :- A meaningful or processed data at particular attribute
is called as “information”.
The way that data are organized into the hierarchy of fields, records and files,
shows the relationship between attributes, entities and entity set as:
i) Field :- A field is a single elementary unit of information
representing an attribute of an entity.
1. By:Chimle Mahesh 2 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 3 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
Linked list
[A] Primitive Data Structure :-
Primitive data structure are basic data types i.e. int, real, character,
Boolean, float. These data types are primitive because they are directly
understand by the machine.
1. By:Chimle Mahesh 4 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
Using a linear array, a list of finite number ‘n’ of similar data elements
referenced respectively by the set of ‘n’ consecutive (serially)
numbers, usually 1, 2, 3, ……….. n.
The elements of an array A may be denoted by the notation :
1. Subscript notation as A1, A2, A3, ……, An.
2. Parenthesis notation as A(1), A(2), A(3), …….., A(n).
3. By the bracket notation as A[1], A[2], A[3], ……., A[n]
Regardless of the notation, the number K in A[K] is called a
subscript and A[K]is called a subscripted variable.
II) Stacks :-
A stack, also called a last-in-first-out (LIFO) system, is a linear list in
which insertions and deletions place only at one end, called the Top.
This structure is similar in its operation to a stack of dishes on a spring
system as shown in following figure.
TOP
Disk
Sprig Container
As container is open at top side, new dishes are interested only at the
top of the stack and dishes can be deleted only from the top of the
stack.
III) Queue :-
A queue, also called a first-in first-out (FIFO) system, is a linear list in
which deletions can take place only at one end of the list, the ‘front’ of
By:Chimle Mahesh 5 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
the list, and insertions can take place only at other end of the list, the
‘rear’ of the list.
The structure operates in a same way as line of people waiting for bus
at bus-stop as Bus Stop shown in
figure.
Front -End
Rear-End
Fig: Queue of People
START
1. By:Chimle Mahesh 6 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
- It is clear that, in above fig. each node is pictured with two fields.
- The left field use the actual information, and right field use store
the address of the next node.
- Arrow shows the order of the nodes.
- The next pointer or LINK field of the last node contains a invalid
address called ‘null pointer’.
- The null pointer (X) is used to shows the end of the list.
- The linked list has also a list pointer variable called START which
contains address of first node in the list.
- The starting address o the list which is stored in START is used
to traverse the whole linked list.
- Here if the linked list has no any node then such a list is called
‘null list’ or ‘empty list’ and it is denoted by the null pointer
assigning to START i.e. START = NULL.
❖ Non – Linear Data Structure :-
Tree and graph are the non – linear data structure.
a) Tree :- data frequently contain a hierarchy relationship between
various elements, the data structure which shows such relationship is
called ‘Tree’.
Getting more about trees consider the following two examples.
i) Record structure. ii) Algebraic
expression.
i) Record Structure :- An employee personal record may contain
following data items.
Ex.: Social_security_no Name Address Age Salary.
By:Chimle Mahesh 7 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
- In above data items, name and address may be group items with
sub item i.e.
Name :- F_Name, M_Name, L_Name.
Address :- Street Address & Area Address.
- Further are its may be group item having sub item city, state and
pin code number.
- The hierarchical structure of above data element is in term of
tree’s is as follows,
Employee
F_Name Street
M_Name Area
L_Name
City
State
Pin Code
1. By:Chimle Mahesh 8 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
(3) F_Name
(3) M_Name
(3) L_Name
(2) Address
(3) Street
(3) Area
(4) City
(4) State
(4) Pin Code
(2) Age
(2) Salary.
By:Chimle Mahesh 9 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
Delhi
Mumbai Kolkatta
Aurangabad Pune
1. By:Chimle Mahesh 10 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
7. Copying.
8. Concatenation.
1. Traversing :-
- This operations is used to accessing each record exactly once of
process certain items in the records.
- Ex.: We have 1, 5, 10, 7 items into data structure.
- Then access (visit) all items means read one five, seven, ten in
certain manner called as ‘Traversing’.
2. Searching :-
- This operation is used to finding the location of the record with
the given key value.
- Ex.: If we have data 1, 5, 10, 7 stored sequentially.
- We want to find location of data 10, it is located ‘3 rd’ location is
called as, ‘Searching’.
3. Inserting :-
- This operation is used to adding a new record to the structure.
- Ex.: Data as 1, 5, 10, 7.
- We want to insert ‘20’ at ‘4th’ location after that output is 1, 5, 10,
20, 7.
4. Deleting :-
- This operation is used to removing a record from the structure.
- Ex.: Data as 1, 5, 10, 20, 7
- We want to delete data on ‘3rd’ location after delete output is 1,
5, 20, 7.
By:Chimle Mahesh 11 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
5. Sorting :-
- This operation is used to arrange the records in same logical
order.
6. Merging :-
- This operation is used to combining the records in two different
sorted fields into a single a sorted file.
7. Copying :-
- This operation is used to make the duplication of the record.
8. Concatenation :-
- This operation is used to combine any two records into single
record.
1. By:Chimle Mahesh 12 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 13 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
If Condition, Then :
1. By:Chimle Mahesh 14 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
[Module A]
[End of If structure]
ii) Double Alternative :- This structure has a form:
If Condition(1), Then :
[Module A]
Else :
[Module B]
[End of If structure]
iii) Multiple Alternative :- This structure has the form:
If condition(1), Then :
[Module A]
Else if condition (2),Then:
[Module A2]
. .
. .
Else if condition (n), Then:
[Module An]
Else [Module B]
[End of If structure]
By:Chimle Mahesh 15 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 16 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 17 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
- The time and space are two important measurements which are
used to calculate the efficiency of an algorithm.
- The complexity of an algorithm is the function which gives the
running time and/or memory space used by the input size.
- There are two case usually investigates to find complexity.
1. Worst Case.
2. Average Case.
1. Worst Case :-
- The maximum value of F(n) for any possible input.
- C(n) = n is complexity of linear search algorithm.
2. Average Case :-
- The excepted value of F(n).
1. By:Chimle Mahesh 18 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 19 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 20 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. Linear Search :-
- It is clear that time required execute the algorithm is
proportional to the number of comparisons performed by the
linearly.
- In this method each name of the file is get compared so the
average number of comparisons for the file with ‘n’ records is
equal to
- Hence, the complexity of linear search algorithm is
2. Binary Search :-
- In this method the name are stored in sorting order
alphabetically.
- This algorithm compare a given name with the name in the
middle of the list : This tells which half of the list the name
contain.
- Then compare name with the name in the middle of the correct
half to determine which quarter of the list contains name.
- Continue the process until finding name in the list. - Hence, the
complexity of the binary search method is c(n) = log 2n
By:Chimle Mahesh 21 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
Here ‘UB’ is the largest index called upper bound and ‘LB’ is the lower bound
i.e. smallest index of an array.
DATA 30 15 35 40 50
LB 30 10 1 2 3
4 15
2 35
3 40
4 50
UB 5
length = UB – LB + 1
length =5–1+1 length= 4 – 0 + 1
=4+1 =4+1
=5 =5
- The element of an array may be denoted by the notation :
4. Subscript notation as :
A1, A2, A3, ……, An.
5. Parenthesis notation as:
1. By:Chimle Mahesh 22 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1000
1001
1002
1003
1004
Fig. Computer
Memory
By:Chimle Mahesh 23 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 24 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
set k LB
Step 2. :
Repeat step 3 & 4 while
(k <= UB)
By:Chimle Mahesh 25 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 26 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 27 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 28 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
test weather LA[1] = ITEM. Then last weather LA[2] = ITEM and
so on.
- The method which traverses LA sequentially to search ITEM is
called ‘Linear Search’ or ‘Sequential Search’.
- In this search, first the ITEM is stored at LA (N + 1) location as =
LA (N + 1) = ITEM.
- Then searching is started from the first element of the list, here
if ITEM is present at that time this search method display a
message successful search and if ITEM is not present in the list
then this search method display a message unsuccessful search
and reset the location variable LOC to Null or Zero.
- Following is a algorithm to find the location LOC of given
element ITEM for an array LA.
Step 1. :
[Insert ITEM at the end of the LA] set
LA (N + 1) ITEM
Step 2. : [Initialize counter location]
Set LOC 1
Step 3. : [Search for ITEM in LA]
Repeat step 4
while (LA [LOC] ITEM)
By:Chimle Mahesh 29 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 30 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 31 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1.
10 11 20 22 30 33 40 44 50 55 60 66 70 77
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1. By:Chimle Mahesh 32 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
8 9 10
Let, START = 8 & END = 10
By:Chimle Mahesh 33 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
1. By:Chimle Mahesh 34 / 35
Class: BCASY(Sem IV) COCSIT, Latur Sub: Data Structure and algorithm
By:Chimle Mahesh 35 / 35