0% found this document useful (0 votes)
8 views35 pages

Data Structure

Uploaded by

semwalaakash19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views35 pages

Data Structure

Uploaded by

semwalaakash19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

DATA STRUCTURE

DEFINITIONS
TYPES
OPERATIONS ON DATA STRUCTURE
MCQS
IMPORTANT DEFINITIONS

 Data: It is simply values or set of values.


 Group Items : Data items which can be divided into sub items are called
group items eg. Date of birth can be divided in to three sub
items like day , month , year.
 Elementary Items : Data items which can not be divided into sub items eg.
Pincode number, roll number etc.
 Entity : An Entity is something that has certain attributes or properties ,
which may be assigned values. Eg .Bio data of student.

Attributes Name Address contact Marks

Values Manish Dahisar 12345 100


DEFINITIONS…….

 Field : Field is a single elementary unit of information representing an


attribute. [Board].
 Record : Record is a collection of field values of a given entity. [Board]
 File : File is a collection of records of the Entity in the given entity set.
[Board]

SR.NO NAME CONTACT GENDER


Record 1 XYZ 123 M
2 PQR 45 F

Field
File
Q) WHAT IS A DATA STRUCTURE?

Ans :
 It is a method of organizing and storing data inside the memory.
 The data structure should be simple and it should show relation between
the data elements.
TYPES :
1 . Linear Data structure : Data elements are stored in consecutive
memory location.
Eg. Array, Link list ,stack, Queue.
2 . Non Linear Data structure : Data elements are stored in a
hierarchical fashion.
Eg. Tree
Q) EXPLAIN IN BRIEF ANY SIX DATA
STRUCTURE OPERATION. (BOARD)
ANS:
1. Traversing :
Accessing each record or element exactly once, so that It can be processed is called
traversing.
2 .Inserting :
Adding new record to the existing data structure is called as inserting.
3. Deleting : Removing a record from an existing data structure is called as deleting.
4. Searching : Finding the location of the record which satisfied one or more
condition is called searching.
5.Sorting : Arranging records in some logical order is called as sorting.
6. Merging : Merging means combining the records from two different files.
Q) EXPLAIN WITH FLOW CHART THE
FOLLOWING CONTROL STRUCTURES.
I) SEQUENCE LOGIC , II) SELECTION LOGIC,
III) ITERATION LOGIC. [BOARD]
1. Sequence Logic : In Sequence logic modules are executed sequentially, one
after the another.

Module A

Module B

Module C

2. Selection Logic :
Selection Logic uses number of conditions , which cause selection of one out of
several alternative modules.
i) Single Alternative ii) Double Alternative
CONTINUE….

i) Single Alternative : If condition is satisfied then module A, which consist of


number of statements ,is executed otherwise module A is skipped. (Fig A)
ii) Double Alternative : If condition is satisfied then module A is executed otherwise
module B will be executed (Fig B)

IF
IF CONDITION?
CONDITION?
no
yes
Module A Module B
Module A

Fig A Fig B
CONTINUE…
 Iteration Logic : Here certain module is executed repeatedly until
condition satisfies.

CONDITION no
?

ye
s
Module
Q) WHAT ARE LINK LISTS? SHOW A LINK
LIST WITH SUITABLE EXAMPLE HAVING
SIX NODES.

10 inf lin
o k

A 13 B 19 C 14 D 12 E 18 F x
1 1 1
3 12 18
9 4

1. A link list is a linear collection of data elements, called nodes, where the linear
order is maintained with the help of pointer.
2. Link list is also called as one way list.
3. Each node in the link list is divided in to two parts. First part is called as INFO
part and second part is called as LINK part.
CONTINUE….

4. INFO part contains the information about actual elements and LINK part
contains address of the next node (pointer to the next node).

5. Starting address is stored in the variable called START variable(x,y,z).

6. An arrow is drawn from link part of one node to the next node to indicate
link.

7. The link part of the last node is null ,that indicates end of the link list.

8. To trace the link list we just required the address of the first node.
Q. HOW LINK LISTS ARE REPRESENTED IN
THE MEMORY ?
INFO LINK
1 D 0
D
5 A 9 B 4 C 1
X 2
start 5 9 4 1 3

4 C 1

5 A 9
5
6

9 B 4
Q) WHAT IS TREE? WHAT DO YOU MEAN
BY ROOT, LEAF, SIBLINGS AND CHILD
ABOUT TREE.
 Tree : Tree is a non linear hierarchical data structure which consists of finite set of one or
more nodes (i.e collected data items).
 There is specially designated node called the root.

B C

D E F G H

I J

 Root : The node which has no parent. Generally the first node is called as ‘root node’.
 Leaf : The node which has no child or children. Such nodes have degree zero. In
CONTINUE….

 Child : The node which are reachable from the above node through only one
vertex is called child.
 Sibling : Children of the same parent are said to be siblings. E.g The nodes D and
E are both children of node B. so D and E are siblings.
Q) EXPLAIN THE FOLLOWING TERMS :

1. Level of tree :

A Level 0

B C Level 1

D E F G
Level 2
Each node in a tree is assigned a level number. Generally, the level number of root R is zero.
2. Depth / height : Depth or height is defined as maximum level number + 1.
3. Degree of node : The number of subtree of a node is called degree of a node.
CONTINUE :
 Node Degree
A 2 A

B 2
B C
C 2
D,E,F,G 0 D E F G

Q ) What is a binary tree ?


H I
Ans :
1. Binary tree contains finite set of nodes where each node has either 0, 1
or 2 children.
2. It is non linear data structure.
CONTINUE…

 Basic terminology :
1. Left successor : B is left successor of node A.
2. Right successor : C is right successor of node A .
3. Left subtree : Left subtree consists of nodes B,D and E.
4. Right subtree : Right subtree consists of nodes C,F,G,H
and I.
5. Terminal nodes : The node with no successor is called
terminal node.
D,E,H,I are terminal nodes.
Q ) DRAW THE BINARY TREE STRUCTURE
FOR THE FOLLOWING EXPRESSIONS.
1. E=(a+b)/[(c*d)-e]
=

E /

+ -

a b * e

c d
CONTINUE….

[(a+b)*c]/[a*((b–c)+a]
/

* *

+ c a +

a b - a

b c
CONTINUE…

Q) (2x+y)(a-7b)^3 *

Q) (2*x+y)*(a-7*b)^3 + ^

* y - 3

2 x a *

7 b
CONTINUE…

Q) Z=(A+B/E)*(C+D/F)
=

Z *

+ +

A / C /

B E D F
Q) HOW BINARY TREES ARE REPRESENTED IN MEMORY ?…
INFO LEFT RIGHT
1 B 7 4
2 G 12 13
3
4 E 11 0
5 A 1 9
6
7 D 0 0
8
9 C 14 2
10
11 H 0 0
12 I 0 0
13 J 0 0
14 F 0 0
5
1 A 9

7 B 4 14 C 2

X D X 11 E 0 X F X 12 G 13

X H X X I X X J X
Q) EXPLAIN STACK AND QUEUE WITH
SUITABLE EXAMPLE.
Q) EXPLAIN LIFO AND FIFO.
 LIFO (LAST IN FIRST OUT)
1. LIFO system is last in first out system . In this tyoe of system the element which is
inserted at the last, will be deleted first.
2. Stack is an example of LIFO system
3. The insertion operation is referred to as PUSH and deletion operation as POP.
Eg. Consider a stack of dishes.
FIFO (FIRST IN FIRST OUT)
1. In this type of system , the element which is inserted first in the list will also be
deleted first.
2. Queue is an example of FIFO system. A queue is a linear list, in which insertion takes
place only at one end of the list known as ‘rear’ of the list and deletion takes place at
the other end , called as ‘front’ of the list.
Q) WRITE AN ALGORITHM FOR LINEAR
SEARCH TECHNIQUE WITH SUITABLE
EXAMPLE.
Step 1 : [insert X at the end of data]
Set DATA[N+1] = x
Step 2 : [initialize counter]
set LOC = 1
Step 3 : [Search for item]
Repeat while DATA [LOC] != x
set LOC = LOC + 1
[END of loop]
Step 4 : if LOC = N + 1,then :
print elements not found else print location
Step 5 : EXIT
EXAMPLE…..
Given DATA array with following 5 elements
1 2 3 4 5
11 22 33 44 55

Suppose ITEM = 33
Step 1 : set DATA [6] = 33 therefore list becomes
11 22 33 44 55 33
Step 2 : LOC = 1
Step 3 : Since DATA [1] = 11!=33 LOC = 2
Since DATA[2] = 22!=33 LOC=3
Here DATA[3] = 33 = 33 ITEM
Step 4 : HENCE item = 33 found at position, LOC= 3
Q) WRITE AN ALGORITHM FOR BINARY
SEARCH TECHNIQUE WITH EXAMPLE.
Binary(DATA,LB,UB,X,LOC)
Step 1 : [initialize variables]
Set BEG = LB, END = UB and MID = INT ((BEG + END)/2)
Step 2 : Repeat steps 3 and 4
while BEG<=END & DATA[MID] !=X
Step 3 : if X < DATA[MID] then: step 5 : if DATA[MID] = X then
set END=MID-1 set LOC=MID
Else set BEG=MID +1 else
[End of if structure] LOC =null
Step 4 : Set MID = INT(BEG+END)/2 step 6 : EXIT
[End of step 2 loop]
EXAMPLE OF BINARY SEARCH

11 22 30 33 40 44 55
Suppose X= 40
Step 1 : Initially BEG = 1 and END = 7
MID=(BEG+END) / 2 = (1+7)/2=4
DATA[MID]=DATA[4]=33
Step 2 : Since 33 < 40 , BEG =MID + 1 =4 + 1=5
MID =(5+7)/2=6
DATA[MID] = DATA[6]=44
Step 2 : Since 44> 40 , END =MID - 1 =6- 1=5
MID =(5+5)/2=5
Q) EXPLAIN BUBBLE SORT ALGORITHM WITH
SUITABLE EXAMPLE.
Bubble sort (DATA , N , I , j)
Step 1 : Repeat steps 2 and 3 for I = 1 to N-1
Step 2 : Set j = 1
Step 3 : Repeat while j<=N-I
i) If ( DATA[j] > DATA[j+1] ) , then interchange
DATA[j] AND DATA[j+1]
[END of if structure]
ii) j=j+1
[END of inner loop]
[END of outer loop]
Step 4: EXIT
EXAMPLE….
Array = 1 2 3 4 5
55 43 5 6 9

Pass 1 : 1 2 3 4 5
55 43 5 6 9
43 55 5 6 9
i=1
43 5 55 6 9
43 5 6 55 9
43 5 6 9 55
CONTINUE..

Pass 2 : 1 2 3 4 5
43 5 6 9 55
5 43 6 9 55
i=2
5 6 43 9 55
5 6 9 43 55
WHAT IS INSERTING ? WRITE AN ALGORITHM
INSERT ( LA , N , K , X )
Step 1 : [initialize counter]
set J = N
Step 2: Repeat steps 3 and 4 while J>=K
Step 3 : [move jth element forward]
setLA[J+1]=LA[J]
Step 4 : decrement counter set J=J-1
Step 5 : set LA[K] = X
Step 6 : Reset N
Set N=N+1
Step 7 : Exit
EXAMPLE

1 2 3 4 5
10 20 40 50 60

LA[5] ,X=30,K=3
N=5
J=N=5
1. LA[J+1]=LA[J] 6. LA[4]=LA[3]=40
2. LA[5+1]=LA[5]=60 7. LA[K] = X
3. J=J-1=5-1=4 LA[3]=30
4. LA[5]=LA[4]=50 8. N=N+1=5+1=6
5. J=J-1=4-1=3
WHAT IS DELETING ? EXPLAIN ALGORITHM

DELETE(LA,N,K,X)

Step 1 : set X = LA[K]


Step 2 : set J = K
Step 3 : repeat 4 and 5while J<N
Step 4 : Move J+1ST element backward
LA[J] =LA[J+1]
Step 5 : J=J+1
Step 6 : reset N
N=N-1
Step 7 : Exit
WHAT IS DELETING ? EXPLAIN ALGORITHM

1 2 3 4 5 6
10 20 40 50 60
N=6,K=3,X=?
J=K, J<N
1. X=LA[K]=30
2. LA[J]=LA[J+1]
LA[3]=LA[4]=40
3. J=J+1=3+1=4
4. LA[4]=LA[5]=50
5. J=J+1=4+1=5 7. N=N-1
6. LA[5]=LA[6]=60 8. EXIT
WHAT IS TRAVERSING ? EXPLAIN
ALGORITHM
Traversing(LA,K,LB,UB)
Step 1 : Initialize counter
set K = LB
Step 2 : Repeat 3 and 4 while K<=UB
Step 3 : [Visit element]
Apply process to LA[K]
Step 4 : Increment counter
K=K+1
[End of step 2 loop]
Step 5 : EXIT

You might also like