data structure assignment
data structure assignment
data structure assignment
Ans:
16. Condition after inserting a single element in the stack (stack is empty) ?
Ans: Condition After Inserting a Single Element: The stack will have one element, and the `top` pointer will be set to `0`
(indicating the index of the only element).
.
31. Function for deleting a node at end of the single linked list ?
Ans: Node* ptr = *start;
Node* prev = NULL;
// Traverse to the last node
while (ptr->link != NULL) {
prev = ptr;
ptr = ptr->link;
} // If there is only one node
if (prev == NULL) {
*start = NULL; } else {
prev->link = NULL; // Remove the last node
}
free(ptr); // Free the memory of the node
}
29. Function for deleting a node at the beginning of the single linked list ?
Ans: void delete_at_beginning(Node** start) {
if (*start == NULL) {
printf("Underflow\n");
return; }
// Set PTR to the current start
Node* ptr = *start;
// Update START to the next node
*start = (*start)->link;
// Free the memory of the old start node
free(ptr); }
30. Function for deleting a node at particular position of the single linked list ?
Ans: void delete_at_position(Node** start, int loc) {
if (*start == NULL) {
// Check if the list is empty
printf("Underflow\n"); return;
}
Node* ptr = *start; Node* prev = NULL; int i = 1;
while (i < loc && ptr != NULL) {
prev = ptr;
ptr = ptr->link;
i++; }
if (ptr == NULL) {
printf("Location Not Found\n"); } else {
if (ptr == *start) {
node *start = ptr->link; } else {
// If deleting a node in the middle or end
prev->link = ptr->link; }
free(ptr);
.
39. Overflow condition for Circular queue ?
Ans: if ((rear + 1) % MAX_SIZE == front) {
printf("Queue Overflow\n");
}
40. Underflow condition for Circular queue ?
Ans: if (front > rear) {
printf("Queue Underflow\n");
}
41. Definition of dequeue and priority queue ?
Ans: Definition of Deque: A deque (double-ended queue) is a linear data structure that allows insertion and deletion of
elements from both the front and the rear ends. It combines features of both stacks and queues.
Definition of Priority Queue: A priority queue is a data structure where each element has a priority assigned to it.
Elements are dequeued based on their priority, with higher-priority elements being removed before lower-priority ones.
44. difference b/w linear and nonlinear data structure with proper example ?
Ans:
Linear Data-Structure Non -Linear Data-Structure
45. Find the address of 10th location of the array element whose base address is 1000 and each element is having size 6
bits.
Ans: To find the address of the 10th element in an array, you can use the formula:
Address=Base Address+(Index * Size of each element)
Given:
Base Address (B) = 1000
Index (I) = 9
Size of each element (W) = 6 bits (which is 0.75 bytes, since 1 byte = 8 bits)
Address=1000+(9×0.75)=1000+6.75=1006.75
.
19. Smallest element of linked list ?
Ans: Smallest Element of Linked List: The smallest element is the one with the minimum value among all the nodes in the
linked list after traversing the entire list.
Example :
25. Condition after inserting an element into a single lined list (single linked list is empty) ?
Ans: After inserting the first element into an empty singly linked list, the head pointer is no longer NULL; it points to the
newly created node. The next pointer of this new node is set to NULL.
26. Function for inserting a node at the beginning of the single linked list ?
Ans: void insertAtBeginning(int item) {
FRESH = nextFreeIndex;
nodes[FRESH].data = item;
if (START == -1) {
nodes[FRESH].next = -1;
} else {
nodes[FRESH].next = START;
}
START = FRESH;
nextFreeIndex++;
}
.
1. Definition of abstract Datatype ?
Ans : The process of providing only the essential and hiding the details is known as data abstraction.
2. Difference
Big-ohbetween Big-Oh
represents the(O) and bound
upper big omega notation ?
of the Big-omega represents the lower bound of the
Ans: running time of an algorithm. running time of an algorithm.
it gives the worst case complexity of an it gives the best case complexity of an
algorithm. algorithm.