answersLogoWhite

0

There is no single container that is ideally suited to every task, therefore the container you choose is often a compromise, depending upon which operations you need to perform the most.

Linked lists are ideally suited to applications where a lot of insertions need to occur within the middle of the list. The downside is that you must first traverse the list from the first or last element in order to reach the insertion point; there is no constant time random access. Thus the average search time is O(n/4) for a list of n elements. For a forward list, search times increase to O(n/2).

Traversing an array has a similar complexity, but because array elements occupy contiguous memory, they are actually quicker to traverse. And if the array is also sorted, traversal becomes O(n log n) by taking advantage of binary search traversal (recursively starting at the middle element and discounting one half of the array on each recursion). However, arrays are suited to insertions at the end of the array only. This is achieved by reserving more memory than is actually needed, but when that reserve runs out, the entire array has to be reallocated, which can result in every element being copied to new memory.

Lists are not ideally suited to sorting algorithms other than those solely reliant upon sequential access (such as merge sort). However, it can still be quicker to copy the list to an array, sort the array, and then reconstruct the list from the sorted array.

Ultimately no-one can tell you which is the best container to use in any given situation. Never assume that just because a container is ideally suited to a specific task that it is ideal for all the tasks you actually need to perform. Always measure the performance and try other containers to see which works best overall.

As a rule of thumb, consider the vector as your default option. Measure the performance using high-resolution timers, then try an alternative container.

User Avatar

Wiki User

10y ago

What else can I help you with?

Continue Learning about Engineering

Write an algorithm for the implementation of a circular doubly linked list?

Create a new node, making sure it is not allocated locally in the function and thus will not be destroyed when the function execution finishesFill in dataUse the "last node" pointer in the list and copy the "next" pointer location (pointing to the first node) into the new nodes "next" pointerSet the "last node" "next" pointer to point to the new nodeChange the list's "last node" pointer to point to the new nodeFor an example of implementation see: How_you_insert_a_newnode_in_singly_circular_link_list


Write algorithm to delete last node in circular linked list?

This depends on whether the list is singly or doubly(or multiply) linked, and on the actual implementation of the list. For example, you can write a CDLL(circular doubly linked list) without maintaining your beginning or ending nodes, using only a current pointer, thus this question doesn't really apply as there would be no "last" node and thus it would be like deleting any node.A typical implementation of a circular singly-linked list (CSLL) list actually maintains the pointer to the last element (hence it's FIFO nature) and thus there are both last and first nodes.This deletion is a little tricky. Consider that you have situations where the next pointer will point to the current element. On the other hand, you also have a situation where there are n-values that you have to iterate over to find the next-to-last value. Typically you would delete the first node in these lists, again dictated by the FIFO nature of these lists, but deletion of the last node is also not impossible.set struct node *last to list->endif (list->end->next == list->end){set list->end to null (leaving an empty list)} else {while(true){if(last->next == list->end){break}set last to last->next}set link->last to list->end->next (this temporarily sets list's end node to current first node)free last->next (frees the last node)set last->next to list->end (set the new last node next pointer to the first node)set list->end to last (set the list's end node to the new last node)}


Write Algorithm to perform the insertion and deletion operation of a linear array?

//Algorithm to perform the insertion and deletion operation of a linear arrayINSERT (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i <=n. The element 'item' will be inserted into the ith position in ArrA.1. j = n2. repeat steps 3 and 4 while j >= i3. ArrA[j+1] = ArrA[j]4. j = j - 15. ArrA[i] = item6. n = n+1DELETE (ArrA, n, i, item) where ArrA is a linear array with n elements and i is a positive integer where i <=n. The element 'item' will be deleted from the ith position in ArrA.1. item = ArrA[i]2. repeat for j = i to n -1 ArrA[j] = ArrA[j+1]4. n = n - 1NO HARD RETURNS ALLOWED


Explain Pseudo code for circular linked list?

write pseudocode for link list


Write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student?

write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student.

Related Questions

Write a Linked list program for insertion and deletion of a node using structureswitch case and in c language?

for all datastructure ,c,c++ programs just visit codingdatastructure.blogspot.com and found on blog archive..


Write an algorithm for the implementation of a circular doubly linked list?

Create a new node, making sure it is not allocated locally in the function and thus will not be destroyed when the function execution finishesFill in dataUse the "last node" pointer in the list and copy the "next" pointer location (pointing to the first node) into the new nodes "next" pointerSet the "last node" "next" pointer to point to the new nodeChange the list's "last node" pointer to point to the new nodeFor an example of implementation see: How_you_insert_a_newnode_in_singly_circular_link_list


Why did Wikianswers say your question was harmful please write in the discussion if you have any questions?

It means that the question was marked for deletion. If it was marked for deletion accidently, it will be fixed.


How to write an implementation details in the project documentation?

In order to write an implementation details in the project documentation, you need to be very specific. You should indicate the specific steps that are involved in the implementation and the results expected.


Write A program to implement insertion using AVL trees?

yes


How do you insert data in middle of file in java?

One way to do it would be as follows: * Read the entire file to a String variable * Write the data before the insertion point * Write the data to be inserted * Write the data after the insertion point Probably the following would be more efficient: * Read the part of the file after the insertion point, to a String variable * Write the data to be inserted * Write the data after the insertion point Perhaps some classes have methods that can automate this, from the point of view of the programmer. But if you want to INSERT something, it's unavoidable to have the overhead of reading the data after the insertion point, and writing it back again. This assumes you use a text file; when working with a database, there are other, usually more efficient, options.


Write a algorithm for doubly linked list in c?

sorry


Write a c program to implement a sorted doubly linked list?

The implementation of a sorted doubly linked list is similar to an unsorted doubly linked list. The only change will be in the insertion function where you will need to search for the position where the new element should be inserted.Consider a doubly linked list with node structure as:typedef struct node{int data;node *next. *prev;}node;node *head = NULL;int isempty(){//This function returns whether the list is empty or notreturn !head;}The code for insertion:void insert( int num, int ** head){node *temp, *temp1= *head;temp = (node *)malloc(sizeof(node));if( temp == NULL){printf("Not enough space\n");return;}temp->data = num;temp->next = temp->prev = NULL;if(isempty()){//insertion when the list is empty*head= temp;return;}if( temp1->data > num){//Insertion at the headtemp->next = head;temp1->prev = num;return;}while( temp1->next != NULL && temp->next->data < num)//Determiningthe postion of the element for insertiontemp1 = temp1->next;temp->next = temp1->next;if( !temp->next)temp->next->prev = temp;temp->prev = temp1;temp1->next = temp;}If you want to know how to implement a normal doubly linked list, check the related liks below.


How to write aC program to merge two singly linked list?

write a c program to circular queue


How do you make technical background in thesis?

Write the description of the Poject, Hardware and Software Needed, Implementation Plan.


Write a program in C to create a Circular Linked list?

#include&lt;iostream.h&gt;


Write algorithm to delete last node in circular linked list?

This depends on whether the list is singly or doubly(or multiply) linked, and on the actual implementation of the list. For example, you can write a CDLL(circular doubly linked list) without maintaining your beginning or ending nodes, using only a current pointer, thus this question doesn't really apply as there would be no "last" node and thus it would be like deleting any node.A typical implementation of a circular singly-linked list (CSLL) list actually maintains the pointer to the last element (hence it's FIFO nature) and thus there are both last and first nodes.This deletion is a little tricky. Consider that you have situations where the next pointer will point to the current element. On the other hand, you also have a situation where there are n-values that you have to iterate over to find the next-to-last value. Typically you would delete the first node in these lists, again dictated by the FIFO nature of these lists, but deletion of the last node is also not impossible.set struct node *last to list->endif (list->end->next == list->end){set list->end to null (leaving an empty list)} else {while(true){if(last->next == list->end){break}set last to last->next}set link->last to list->end->next (this temporarily sets list's end node to current first node)free last->next (frees the last node)set last->next to list->end (set the new last node next pointer to the first node)set list->end to last (set the list's end node to the new last node)}