You are on page 1of 8

Enroll. No.

_________
MARWADI UNIVERSITY
FDS
COMPUTER ENGINEERING - DIPLOMA
Semester 3 - Winter

Subject : DATA STRUCTURE ( 09CE2303 )


Date : 20-Sep-2023 Time : 1 Hours 15 Minutes Total Marks : 30
Instructions :

1. Attempt all questions.


2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.
4. English version is authentic.

Que.1 Answer the following questions. [6]


(A)
(1) What is circular Queue? (વર્તુળાકાર ક્યુ શું છે?)
Ans. Circular queue is one in which the insertion of new element is done at very first location of queue if last location of queue
is full.
વર્તુળાકાર ક્યુ એ છે કે જેમાં ક્યુ નું છેલ્લું સ્થાન ભરેલું હોય તો નવો તત્વનો પ્રવેશ ક્યુના ખૂબ પહેલા સ્થાને કરવામાં આવે છે.

(2) What is Algorithm?


એલ્ગોરિધમ એટલે શું?
Ans. Algorithm is a precise plan for performing sequence of actions that occurring in some specific sequence and produce
effective output based on given input in finite amount of time.
એલ્ગોરિધમ ક્રિયાઓનો ક્રમ કરવા માટે ચોક્કસ યોજના છે જે અમુક ચોક્કસ ક્રમમાં થાય છે અને સમય મર્યાદામાં આપેલ ઇનપુટના
આધારે અસરકારક આઉટપુટ ઉત્પન્ન કરે છે.

(3) Is there is a wastage of memory in a circular queue? Yes or no. (શું વર્તુળાકાર ક્યુ માં મેમરીનો બગાડ થાય છે? હા કે ના.)
Ans.
No (ના)

(4) What is Primitive Data Structure?


પ્રિમિટિવ ડેટા સ્ટ્ર ક્ચર શું છે?
Ans. The Data structure that directly operated upon by machine level instruction are called primitive data structure.
મશીન સ્તરની સૂચના દ્વારા સીધા સંચાલિત ડેટા સ્ટ્ર ક્ચરને પ્રિમિટિવ ડેટા સ્ટ્ર ક્ચર કહેવામાં આવે છે.

(5) What is Non-Primitive Data Structure?


નોન-પ્રિમિટિવ ડેટા સ્ટ્ર ક્ચર શું છે?
Ans. The Data structure that does not directly operated upon by machine level instruction are called non primitive data structure
મશીન સ્તરની સૂચના દ્વારા સીધા સંચાલિત ન થતા ડેટા સ્ટ્ર ક્ચરને નોન પ્રિમિટિવ ડેટા સ્ટ્ર ક્ચર કહેવામાં આવે છે

(6) What is Data Structure?


ડેટા સ્ટ્ર ક્ચર એટલે શું?
Ans. Data may be organized in many different ways, the logical or mathematical model of particular organization of data is
called data structure.
ડેટાને ઘણી જુદી જુદી રીતે ગોઠવી શકાય છે, ડેટાના ચોક્કસ સંગઠનના લોજિકલ અથવા ગાણિતિક મોડેલને ડેટા સ્ટ્ર ક્ચર કહેવામાં
આવે છે.
Que.2
(A) Write advantages and disadvantages of array. [4]

Ans. Advantages:
It is used to represent multiple data items of same type by using only single name.
simple and easy to create.
It can be used to implement other data structures like linked lists, stacks, queues, trees, graphs.
2D arrays are used to represent matrices.
It allows random accessing of elements i.e. any element of the array can be randomly accessed using indexes.
Disadvantages:
We must know in advance that how many elements are to be stored in array.
Array is static structure. It means that array is of fixed size. The memory which is allocated to an array not be increased or
reduced.
Since array is of fixed size, if we allocate more memory than requirement then the memory space will be wasted. And if
we allocate less memory than requirement, then it will create problem.
The elements of array are stored in consecutive memory locations. So insertions and deletions are very difficult and time
consuming.

(B) Convert a following expression into postfix form using stack ( આપેલ અભિવ્યક્તિ ને સ્ટેક ની મદદ થી પોસ્ટફિક્ષ માં [8]
ફેરવો)
(A+B)*D+E/(F+G*D)+C
Ans.

OR
(B) Write an algorithm for simple queue to perform Enque and Deque operation. (સિમ્પલે ક્યુ માટે એન્ક્યુ અને ડેક્યુ [8]
ઓપરેશન ના અલ્ગોરીધમ લખો.)
Ans. Initially front=-1,rear= -1
Insert(Q,front,rear,X)
Step 1: [Check for overflow]
If rear>=N-1 then
Write “queue overflow”
Exit
Step 2: [increment rear pointer ]
Rear=rear+1
Step 3: [perform insertion]
Q[r]=X

Step 4: [Is frot pointer properly set?]


If (front=-1) then
front=0
exit
Step 5: [finished]
Exit

Initially front=-1,rear= -1
Delete (Q,front,rear,X)
Step 1: [Check for underflow]
If (front=-1) then
Write “queue underflow”
Exit
Step 2: [delete element]
Y=q[front]
Step 3: [increment front]
If (front==rear) then
Front = rear = -1
Else
Front = front+1
Step 4: [finished]
Exit

Que.3
(A) Explain Analysis of Algorithm. [8]
એલ્ગોરિધમનું વિશ્લેષણ સમજાવો.
Ans. Algorithm is a precise plan for performing sequence of actions to achieve purpose.
It is step by step finite sequence of instruction to solve any problem.
It is sequence of computational steps that transform input to output.
Analysis it means to discover its characteristics in order to evaluate its efficiency for various application.
We have many algorithm for same situation. Some algorithms are more efficient than others. We would like to choose
efficient algorithm.
So through analysis we can choose best algorithm from many.
Complexity of algorithm is function describing the efficiency of the algorithm.
There are two main complexity measures of the efficiency of algorithm.
1. Time complexity
2. Space complexity
Time complexity: Time Complexity of an algorithm is the representation of the amount of time required by the algorithm to
execute to completion.
It means: Number of memory accesses performed,
Number of comparisons between integers.
Number of times some inner loop is executed.
Time requirements can be denoted or defined as a numerical function t(N), where t(N) can be measured as the number of
steps, provided each step takes constant time.
For example, in case of addition of two n-bit integers, N steps are taken. Consequently, the total computational time is t(N)
= c*n, where c is the time consumed for addition of two bits. Here, we observe that t(N) grows linearly as input size
increases.

Best case complexity: Best case complexity of algo. is function defined by minimum number of steps taken on any instance
of size. Or when sorting tech. have minimum number of comparisons occurs.
Ex: if searching no is 1 and i/p : 1 2 3 4 5

Worst case complexity: Worst case complexity of algo. is function defined by maximum number of steps taken on any
instance of size. Or when sorting tech. have maximum number of comparisons occurs.
Ex: if searching no is 1 and i/p : 2 3 1 4 5

Average case complexity: Average case complexity of algo. is function defined by Average number of steps taken on any
instance of size. Or when sorting tech. have Average number of comparisons occurs.
Ex: if searching no is 1 and i/p : 5 2 3 4 1

Space complexity: Space complexity of an algorithm represents the amount of memory space needed the algorithm in its
life cycle.
It means: It is measure of how much storage is required by algorithm.
It is amount of computer memory required during program.
A fixed part that is a space required to store certain data and variables (i.e. simple variables and constants, program size
etc.), that are not dependent of the size of the problem.

A variable part is a space required by variables, whose size is totally dependent on the size of the problem. For example,
recursion stack space, dynamic memory allocation etc.

Space complexity S(p) of any algorithm p is S(p) = A + Sp(I) Where A is treated as the fixed part and S(I) is treated as the
variable part of the algorithm which depends on instance characteristic I.
Following is a simple example that tries to explain the concept

SUM(P, Q)
Step 1 - START
Step 2 - R ← P + Q + 10
Step 3 – Stop

Here we have three variables P, Q and R and one constant. Hence S(p) = 1+3. Now space is dependent on data types of
given constant types and variables and it will be multiplied accordingly.

(B) Difference between Linear and nonlinear data structure. [4]


રેખીય હોય અને રેખીય ન હોય તેવા ડેટા સ્ટ્ર ક્ચર વચ્ચેનો તફાવત આપો.
Ans. Linear NonLinear
A data structure is said to be linear if its elements form A data structure is said to be non linear if its elements do not
sequence or linear list. form sequence or linear fashion.
Every item(value) is related to its previous and next Every item is attaached with many other items.
item.
Data items can be traversed in a single run. Data items can not be traversed in a single run.
Implement is easy Implement is difficult
Ex: Array,stack,linked list ,queue Ex:tree,graph

OR
(A) Explain Operations on Stack. Write an algorithm of Push, Pop, Peep, Change Operation. [8]
સ્ટેક ના ઓપરેશન સમજાવો.પુશ, પોપ, પીપ અને ચેન્જ ઓપેરેશન ના અલ્ગોરીધમ લખો.
Ans. (1) Push: The operations that add an element to the top of the stack is called PUSH operation. It is used to insert an
element into the stack.
(2) Pop: The operation that delete top element from the top of stack is called POP. it is used to delete an element from
stack
(3) Peep: it is used to retrieve ith element from the top of the stack.
(4) Change: it is used to change value of the ith element from the top of the stack.

Algorithms for Stack Operation


(1) Algorithm for PUSH Operation.
In push operation, we can add elements to the top of the stack, so before push operation, user must check the stack, it
should not be a full.
If stack is already full and when we try to add the elements then error occurs. It is called “Stack Over Flow” error.

PUSH(S, TOP, VAL)


This algorithm insert an element X to the top of the stack.
The Stack is represented by vector S which contains N elements.
TOP is a pointer which points to the top element of the Stack.

Step 1: [Check for stack overflow]


If TOP >= N then
Write (‘Stack Overflow’)
Return
Step 2: [Increment TOP]
TOP = TOP + 1
Step 3: [Insert Element]
S [TOP] = VAL
Step 4:[Finished]
Return
Algorithm for POP Operation.
In POP operation, we can delete or remove an elements from top of the stack, so before pop operation, user must check the
stack, stack should not be a empty.
If the stack is empty, and we try to pop an element, then error occur. It is called “Stack under Flow” error.
POP(S, TOP)
This algorithm removes an element from the Top of the Stack.
The Stack is represented by vector S which contains N elements.
TOP is a pointer which points to the top element of the Stack.

Step 1: [Check for the Underflow on the Stack]


If TOP = 0 then
Write (‘STACK UNDERFLOW’)
Exit
Step 2: [Decrement Pointer]
TOP = TOP - 1
Step 3: [Return former top element of the stack]
Return(S [TOP + 1])
Algorithm for PEEP Operation.
PEEP(S, TOP, I)
This algorithm returns the value of the ith element from the Top of the Stack.
The Stack is represented by vector S which contains N elements.
TOP is a pointer which points to the top element of the Stack.
Step 1: [Check for the Underflow on the Stack]
If TOP – i + 1 ≤ 0 then
Write (‘STACK UNDERFLOW’)
Exit
Step2: [Assign the ith element from the TOP of the Stack]
Xß S [TOP – i+ 1]
Step 3: [Return value]
Return (X)
Algorithm for CHANGE Operation.
CHANGE(S, TOP, VAL, i)
This algorithm changes the value of the ith element from the Top of the Stack by X.
The Stack is represented by vector S which contains N elements.
TOP is a pointer which points to the top element of the Stack.
Step1: [Check for the Underflow on the Stack]
If TOP – i+ 1 ≤ 0 then
Write (‘STACK UNDERFLOW’)
Exit
Step 2: [Change ith element from the TOP of the Stack]
S [TOP – i+ 1] ß VAL
Step 3: [finished]
Return

(B) Difference between link list and Array. [4]


લિસ્ટ અને એરરે વચ્ચેનો તફાવત આપો.
Ans. List Array
List is ordered set of element Array is unordered set of element
It consist of variable number of element It consist fixed no of element
Insertion and deletion can be performed easily. Insertion and deletion cannot be performed easily
It does not need movements of nodes for insertion and deletion It needs movements of nodes for insertion and
deletion
There are two types of list There are three types of arrays
1.linear list 1.one dimensional
2.non linear list 2.two dimensional
3.multi-dimensional
Location cannot be easily accessible Location can easily accessible
Address calculation is complicated Address calculation is very easy because memory
allocated sequentially
Different amount of time is required to access each element according Same amount of time is required to access each
to requirements element.
Space is not wasted Space is wasted
If we want to go particular node then we Have to go through all those If we want to go particular node then we can reach
nodes that come before that node there directly.
---Best of Luck---

You might also like