Thursday, September 15, 2016
Data structure 1st annual 2015 past paper solution
Q.No1: what is data structure explain the operation performed
on data structures.
Ans: DATA STRUCTURE In computer
science, a data structure is a way of storing data in a computer so that it can
be used efficiently. Often a carefully chosen data structure will allow a more
efficient algorithm to be used. The choice of the data structure often begins
from the choice of an abstract data structure. A well-designed data structure
allows a variety of critical operations to be performed on using as little
resources, both execution time and memory space, as possible
OPERATIONS ON DATA STRUCTURE
A data structure is created to define and process complex data. The data
in a data structure is processed using certain operations
·
Insertion: Adding new
data items into a data structure is called insertion.
·
Deletion: Removing data items from a data
structure is called deletion.
·
Searching: Finding specific data item in data
structure is called searching.
·
Traversing: Accessing
each record or item in a data structure exactly one for processing is called
traversing. It is also called visiting.
·
Sorting:Arranging data items in a data
structure into a specific order is called sorting.
·
Merging: Combining two lists of data items
into a single list is called merging
Q.No2(a): write an algorithm to insert a value M at location I in
array list1 having N elements.
1. [Initialize counter] set j:=N
2. Repeat step 3 and 4while(j>=i)
3. [Move Jthelement
downward]
Set list1[j+1]:=list1[j]
4.[Decrease counter] set j=j-1
End of step 2
loop]
5. [Insert element] set list1[i]=m
6. [Reset N] set N=N+1
7. Exit
Q.No2(b): write a program in C language to convert a string from
lower case to uppercase
Solution:
#include<stdio.h>
#inlcude<conio.h>
#include<string.h>
Void main()
{
char s[20];
int i;
puts("enter string");
gets(s);
for(i=0;i<=strlen(s);i++)
{
if(s[i]>=97&&s[i]<=122)
s[i]=s[i]-32;
}
printf("the string in upper case is
%s",s);
getch();
}
QNo.3(a):what is stack? Explain with examples.
A stack is a data structure in which addition of new element or deletion
of an existing element always takes place at the same end. This end is known as
top of the stack. When an item is added t the stack the operation is called
“push” and when an item is removed from the stack the operation is called
“pop”. Stack is also called LIFO (Last in First out) list. If the elements are
added continuously to the stack it grows at one end. On deletion of elements
the stack shrinks at the same end, as the elements at the top get removed.
Example:1
stack of plates in cafeteria where every new plate added to the stack is
added at the top. Similarly, every new plate taken off the stack is also from
the top of the stack.
QNo.3(b):Convert the following infix expressions into postfix notation
Infix expression: x+6*(y+z)^3
|
||
Char scanned
|
Stack
|
Postfix Expression
|
X
|
X
|
|
+
|
+
|
X
|
6
|
+
|
X,6
|
*
|
+*
|
X,6
|
(
|
+*(
|
X,6
|
Y
|
+*(
|
X,6,y
|
+
|
+*(+
|
X,6,y
|
Z
|
+*(+
|
X,6,y,z
|
)
|
+*
|
X,6,y,z+
|
^
|
+*^
|
X,6,y,z+
|
3
|
+*^
|
X,6,y,z+3
|
+*
|
X,6,y,z+3^
|
|
+
|
X,6,y,z+3^*
|
|
empty
|
X,6,y,z+3^*+
|
Q.No.4: Differentiate between Queue and Deque.write the algorithm to delete the element from input restricted deque from rear end.
Queue
|
Deque
|
It is
pronounced as Queue
|
It is
pronounced as “dequeue” or “deck”
|
It permits
insertion of a new element at one end and deletion of an element at the other
end
|
It permits
insertion or deletion of element at both end
|
It is known
as single ended Queue
|
It is known
as double ended Queue
|
Algorithm:
Step1. Start
Step2. If(front=rear) then [ check the queue is empty or not as ]
Print “Queue is empty”
Else
element=Queue[rear] [ Delete element at rear position as ]
Step.3 rear=rear-1 [ Update pointer rear ]
Step.4 if(front==rear) [ reset pointer front and rear ]
Step.5 front=rear= -1
Step.6 Exit
QNo.5:Write an algorithm to delete a specific node in linked list.
Solution:
Step1. Input data and loc to be
inserted
Step2. Initialize temp=p; and i=0
Step3. Repeat the step3 while(i<loc)
(a)
Temp=tempèlink
(b)
If(temp==NULL)
(i)
Print “node in list lessthen
theposition”
(ii)
Return;
(c)
i=i+1
Step4.Create a New node
Step5.NewNodeèData=Data
Step.6 NewNodeèlink=tempèlink
Step.7 tempèlink=NewNode
Step.8 exit
QNo.6:
Solution: Updated soon
Q.No.7: Explain selection sort with examples.
Ans: Selection
sort:
In selection sort the array is
divided into two parts. The sorted part to the left of present iterator(or
index), and unsorted part to the right of present iterator.
This can be explain in another words as repeatedly finding the minimum or
maximum element from unsorted part and putting it at the beginning.
Selection sort example in (Accending order):
Array[]=(22,24,28,21,27)
Pass 1: 21 22 28
21 27
Pass 2: 21 22 28 24
27
Pass 3: 21 22 24 28 27
Pass 4: 21 22 24 27 28
Q.No.8: Write an
algorithm to reverse the elements of Queue without using another Queue.
Solution: Updated soon
Subscribe to:
Post Comments
(
Atom
)
apple watch 6 titanium
ReplyDeleteapple watch 6 titanium is premium grade titanium rings steel. This titanium nose hoop durable black titanium wedding bands steel is perfect for use on your Mac, iPad titanium tv and iPod titanium water bottle touch, as well as tablets.