0% found this document useful (0 votes)
4 views

ds5 (1)

The document outlines various data structures and their operations, including primitive data structures, linear data structures, stacks, queues, and linked lists. It details operations such as creation, insertion, deletion, searching, and sorting, along with algorithms for specific tasks like searching and sorting. Additionally, it describes the applications of stacks and queues in programming and computing contexts.

Uploaded by

Keerthana Balaji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ds5 (1)

The document outlines various data structures and their operations, including primitive data structures, linear data structures, stacks, queues, and linked lists. It details operations such as creation, insertion, deletion, searching, and sorting, along with algorithms for specific tasks like searching and sorting. Additionally, it describes the applications of stacks and queues in programming and computing contexts.

Uploaded by

Keerthana Balaji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Data structures

5-Marks Questions
1.What is primitive data structure? Explain the different operations performed on
primitive data structure.
Data structures that are directly operated upon by machine-level instructions are known
as primitive data structures. Ex: int ,float, pointer etc.,
The various operations that can be performed on primitive data structures are:
Create: Create operation is used to create a new data structure. This operation reserves
memory space for the program elements.
Destroy: Destroy operation is used to destroy or remove the data structures from the
memory space.
Select: Select operation is used by programmers to access the data within data
structure.
Update: Update operation is used to change data of data structures.

2.Explain the different operations performed on linear data structure.


Traversal: The process of accessing each data item exactly once to perform some
operation is called traversing.
Insertion: The process of adding a new data item into the given collection of data items
is called insertion.
Deletion: The process of removing an existing data item from the given collection of
data items is called deletion.
Searching: The process of finding the location of a data item in the given collection of
data items is called as searching.
Sorting: The process of arrangement of data items in ascending or descending order is
called sorting.
Merging: The process of combining the data items of two structures to form a single
structure is called merging.

3. Explain the different operations performed on one-dimensional array.


Traversing: Accessing each element of the array exactly once to do some operation.
Searching: Finding the location of an element in the array.
Sorting: Arranging the elements of the array in some order.
Insertion: Inserting an element into the array.
Deletion: Removing an element from the array.
Merging: Combining one or more arrays to form a single array.
4.Explain the different operations performed on stacks.
stack() creates a new stack that is empty. It needs no parameters and returns an empty
stack.
push(item) adds a new item to the top of the stack. It needs the item and returns nothing.
pop() removes the top item from the stack. It needs no parameters and returns the item.
The stack is modified.
peek () returns the top item from the stack but does not remove it. It needs no parameters.
The stack is not modified.
isEmpty() tests whether the stack is empty. It needs no parameters and returns a Boolean
value.
size() returns the number of items on the stack. It needs no param eters and returns an
integer.

5.What are the applications of stacks.


1) The simplest application of a stack is to reverse a word.
2) Another application is an “undo” mechanism in text editors.
3) Conversion of decimal number into binary
4) To solve tower of Hanoi
5) Expression evaluation and syntax parsing
6) Conversion of infix expression into prefix and postfix.
7) Rearranging railroad cars

Continued …. next page


6.What is a queue? Explain different types of queue.
A queue is an ordered collection of items where an item is inserted at one end called the
“rear,” and an existing item is removed at the other end, called the “front.”
Types of queue
Simple Queue: In Simple queue insertion occurs at the rear end of the list, and deletion
occurs at the front end of the list.

Front Rear

FRONT=1
10 20 30 REAR=3
0 1 2 3 4

Circular Queue: A circular queue is a queue in which all nodes are treated as circular
such that the last node follows the first node.
Priority Queue: A priority queue is a queue that contains items that have some preset
priority. An element can be inserted or removed from any position depending on some
priority.
Dequeue (Double Ended queue): It is a queue in which insertion and deletion takes place
at both the ends.

7.Explain the different operations performed on queue.


Queue() creates a new queue that is empty. It needs no parameters and returns an empty
queue.
enqueue(item) adds a new item to the rear of the queue. It needs the item and returns
nothing. This operation is generally called as push.
dequeue() removes the front item from the queue. It needs no parameters
and returns the item. The queue is modified. This operation is generally called as pop.
isEmpty() tests to see whether the queue is empty. It needs no parameters and returns a
Boolean value.
size() returns the number of items in the queue. It needs no parameters and returns an
integer.
8.What are the applications of queue?
• Simulation
• Various features of operating system.
• Multi-programming platform systems
• Different type of scheduling algorithm
• Round robin technique or Algorithm
• Printer server routines
• Various applications software is also based on queue data structure
9.What are the operations performed on the linked list?
1. Creating a linked list
2. Traversing a linked list
3. Inserting an item into a linked list
4. Deleting an item from the linked list
5. Searching an item in the linked list
6. Merging two or more linked lists
10. Define the following: a. Root Node b. Leaf Node c. Height
a. Depth e. Internal node.
a. Root Node: The topmost node in a tree is called the root node.
b. Leaf Node: Node that do not have any children are called leaf node.
c. Height: The length of the longest downward path to a leaf from that node is called
height.
d. Depth: The length of the path to its root is called depth.
e. Internal node: Any node of a tree that has child nodes and is thus not a leaf no de is
called internal node.
11. Write an algorithm to insert an element in an array.
A is array with N elements & item is element to be inserted in the position P.
Step 1: for i=N-1 down to P
A[i+1] =A[i]
End For
Step 2:A[P]=item
Step 3:N=N+1
Step 4: Exit
12. Write an algorithm to delete an element from an array.
A is array with N elements & item is element to be deleted from the position P.
Step 1: item= A[P]
Step 2: for i=P to N-1
A[i]= A[i+1]
End for
Step 3: N=N-1
Step 4: Exit
13. Write an algorithm for searching an element using linear search method.
Step 1: LOC = -1
Step 2: for P = 0 to N-1
if(A[P] = ELE)
LOC = P
GOTO 3
End of if
End of for
Step 3: if(LOC >= 0)
PRINT LOC
else
PRINT “Search is unsuccessful”
Step 4: Exit
14. Write an algorithm to search an element in an array using binary search.
Step 1: set B = 0, E = n-1, LOC=-1
Step 2: while (B <= E)
M= int(B+E)/2
if(ELE = A[M]
loc = M
GOTO 4
else
if(ELE <A[M])
E = M-1
else
B = M+1
End of while
Step 3: if(LOC >= 0)
PRINT LOC
else
PRINT “Search is unsuccessful”
Step 4: Exit
15. Write an algorithm to sort an array using insertion sort.
Step 1: for I = 1 to N-1
Step 2: J = I
while ( J >= 1 )
if( A[J] < A[J-1])
temp = A[J]
A[J] = A[J-1]
A[J-1] = temp
if end
J = J-1
while end
for end
Step 3: Exit
16. Write an algorithm for push and pop operation in stack using array.
An algorithm for PUSH Operation:
STACK is the array that contain N elements and TOP is the pointer to
top element of the array. Item the element to be inserted.

Step 1: If TOP = N -1 then [overflow]


PRINT “Stack is full”
Exit
End of If
Step 2: TOP = TOP + 1 [Increment the TOP]
Step 3: STACK[TOP] = ITEM [Insert the ITEM]
Step 4: Return
An algorithm for pop operation:

STACK is the array that contain N elements and TOP is the pointer to top element of the array. This
procedure deletes TOP element from STACK.

Step 1: If TOP = NULL then [underflow]


PRINT “Stack is empty”
Exit
End of If
Step 2: ITEM = STACK[TOP] [Copy the top element]
Step 3: TOP = TOP – 1
[Decrement the top]
Step 4: Return

17. Write an algorithm to insert a data element at the rear end of the queue.
Let Queue is the linear array with N elements
Front is the pointer contains the location of the element to be deleted
Rear contains the location of the inserted element.

Step 1: if REAR=N-1 then


PRINT “Overflow”
Exit
Step 2: if(FRONT=NULL) then
FRONT=0
REAR=0
Else
REAR=REAR+1
Step 3: Queue[REAR]=item
Step 4: Return

18. Write an algorithm to delete a data element from the front end of the queue.
Let Queue is the linear array with N elements
Front is the pointer contains the location of the element to be deleted
Rear contains the location of the inserted element.
Step 1: if FRONT=NULL then
PRINT “Underflow” Exit
Step 2: item=Queue[FRONT]
Step 3: if(FRONT=REAR) then
FRONT=0 REAR=0
Else
FRONT = FRONT +1
Step 4: Return

19. Write an algorithm to delete a data element from the front end of the queue.
Let Queue is the linear array with N elements
Front is the pointer contains the location of the element to be deleted
Rear contains the location of the inserted element.
Step 1: if FRONT=NULL then
PRINT “Underflow” Exit
Step 2: item=Queue[FRONT]
Step 3: if(FRONT=REAR) then
FRONT=0 REAR=0
Else
FRONT = FRONT +1
Step 4: Return

You might also like