answersLogoWhite

0


Best Answer

O(n)

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Time taken to insert an element after an element pointed by some pointer in data structure?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the time taken to insert an element after an element pointed by some pointer?

Constant time.


What is an algorithm of inserting elements of link list?

To insert an element in a linked list, you need a pointer to the new element, and a pointer to the target element. Set new.next = target.next, and then set target.next = new. This will insert new after target. To insert before target, you need the pointer to the element brfore target, and you can find that by searching from top until you find an element where element.next == target. To insert at top, a special case, you set new.next = top, and then set top = new.


Role of data structure to insert an element in the data structure?

using data structure an element can insert at any position easily. with out traversing through the entire list.


Adavantage of pointer based of a list over an array?

One advantage of a linked list (with pointers) is that it is fairly cheap to insert or delete an element - once you know where it is. A disadvantage is that getting a specific element - for example, the 1000th. element - is expensive.


What are the applications of double pointer in c?

insert or delete values both side.so use double pointer


Why insert element in queue?

It depends on how you implement your stack. The most simple method is (for a stack of 42 int, no checks) : int *stack. int *stack_pointer; /* create stack */ stack_pointer = stack = malloc(42 * sizeof (int)); /* insert (push) element */ *stack_pointer++ = element; /* extract (pop) element */ element = *--stack_pointer;


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Write a c program to insert an element in the beginning at the end at the specified position in a linear linked list?

#include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; }node; void insert(node *pointer, int data) { /* Iterate through the list till we encounter the last node.*/ while(pointer->next!=NULL) { pointer = pointer -> next; } /* Allocate memory for the new node and put data in it.*/ pointer->next = (node *)malloc(sizeof(node)); pointer = pointer->next; pointer->data = data; pointer->next = NULL; } int find(node *pointer, int key) { pointer = pointer -> next; //First node is dummy node. /* Iterate through the entire linked list and search for the key. */ while(pointer!=NULL) { if(pointer->data == key) //key is found. { return 1; } pointer = pointer -> next;//Search in the next node. } /*Key is not found */ return 0; } void delete(node *pointer, int data) { /* Go to the node for which the node next to it has to be deleted */ while(pointer->next!=NULL && (pointer->next)->data != data) { pointer = pointer -> next; } if(pointer->next==NULL) { printf("Element %d is not present in the list\n",data); return; } /* Now pointer points to a node and the node next to it has to be removed */ node *temp; temp = pointer -> next; /*temp points to the node which has to be removed*/ pointer->next = temp->next; /*We removed the node which is next to the pointer (which is also temp) */ free(temp); /* Beacuse we deleted the node, we no longer require the memory used for it . free() will deallocate the memory. */ return; } void print(node *pointer) { if(pointer==NULL) { return; } printf("%d ",pointer->data); print(pointer->next); } int main() { /* start always points to the first node of the linked list. temp is used to point to the last node of the linked list.*/ node *start,*temp; start = (node *)malloc(sizeof(node)); temp = start; temp -> next = NULL; /* Here in this code, we take the first node as a dummy node. The first node does not contain data, but it used because to avoid handling special cases in insert and delete functions. */ printf("1. Insert\n"); printf("2. Delete\n"); printf("3. Print\n"); printf("4. Find\n"); while(1) { int query; scanf("%d",&query); if(query==1) { int data; scanf("%d",&data); insert(start,data); } else if(query==2) { int data; scanf("%d",&data); delete(start,data); } else if(query==3) { printf("The list is "); print(start->next); printf("\n"); } else if(query==4) { int data; scanf("%d",&data); int status = find(start,data); if(status) { printf("Element Found\n"); } else { printf("Element Not Found\n"); } } } }


Implement a queue using a singly linked list l the operations insert and delete should still take o1time?

Suppose we have a Queue as follows: E -> D -> C -> B We maintain a head pointer to E and a tail pointer to B. To add an element, we make a new queue item (say A), we set B->next = A, and set tail = A. To delete an element, we let a temp pointer to the head (say tempHead = head), set head = E->next and deallocate tempHead.


What is seekp in oop?

seekp sets the put pointer in an output stream -- the point where the next insert will occur.


Insert an element after an element in an array?

To begin, obtain the element to be added, such as x Then, say pos, get the position where this element will be put. Then shift the array items one position ahead, then do the same for all the other elements next to pos. Because the location pos is now empty, insert the element x there. To learn more about data science please visit- Learnbay.co


How do you write a algorithm of inserting an element at end of a linked list?

Algorithm to insert an element at the end of a linked listSpecial case: the list is empty.Create a new node for the element, assigning nullptr (0) to its next node.Assign the new node to the head of the list.Return a pointer to the new node and exit.All other cases: the list is not empty.Start at the head node (make it current).Repeat: while the current node has a next node, traverse to that node (make it current).Create a new node for the element, assigning nullptr (0) to its next node.Assign the new node as the current node's next node.Return a pointer to the new node and exit.