answersLogoWhite

0


Best Answer

Header linked list contains a special node at the top,this header node need not represent the same type of data that succeding nodes do,it can have data like,no. of nodes,any data...

header node can access the data of all your nodes

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Header node in linked list is used to keep the address of the first node of the linked so that when some operations are performed on list like insert or delete, it can be done with the reference of header node.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Linked lists maintain a pointer to the first node in the list. A doubly-linked list may also maintain a pointer to the last node in the list. Initially both will be NULL, because the list is initially empty. As a result, the list must handle much of the implementation, because it must ensure nodes actually exist before any operations can be carried out, including the major methods to insert, extract and traverse nodes.

By including a sentinel or dummy node to mark the head of the list, the implementation can be simplified by delegating all the work to the nodes themselves. That is, the nodes can sort themselves out far more easily than the list can, because all nodes are intrinsically the same, and the head node is guaranteed to exist at all times.

For example, suppose we have a singly-linked list and we want the nodes to be automatically sorted as they are inserted (insertion sort). When the list receives data to be inserted, it simply calls the head node's Insert(data) method. It doesn't have to check if the head node exists because the head node always exists, and never changes. The head node knows it is the head node and nothing comes before it, so it calls Next = Next.Insert(data). If the next node is the tail node (as it will be initially), the tail node knows it is the tail node and nothing comes after it, so it create a new node for the data, points it to itself, and returns a pointer to the new node. The head node receives the pointer to the new node and sets its next node to the new node.

It gets more interesting when the second node is inserted. Again, the call is passed to the head node which passes it on to the next node (the node we just inserted). That node knows it is a data node so it performs a comparison with its own data. If the given data is greater or equal, it calls Next = Next.Insert(data), and the tail creates the new node and returns it, just as it did before. However, if it is less, the node instantiates a new node, points it to itself and returns the new node to the head node, which becomes its next node.

Granted, it's a bit of a mouthful to explain, but hopefully you can appreciate just how simple and elegant the algorithm is. No node does more work than it has to and the list itself does absolutely nothing, other than to delegate to the head node. The head node automatically updates its next node, the last node always inserts before it, and the individual data nodes can work out between them where new data will be inserted, updating their links automatically according to the return value.

Note also that, although it is a singly linked list, the calls from one node's Insert(data) method to its next node's method automatically reverses the traversal when a new node is inserted, thus updating the previous node's next pointer, but leaving all others exactly as they were.

Although you could implement this algorithm in a normal linked list (without sentinels) the list must check if the list has any nodes before it can proceed, and if there are no nodes, the list itself must perform the insertion. That being the case, it might as well perform the comparisons as well. But that's a lot of work for an object who's sole concern should be to maintain a pointer to the first node (or a head node!). The problem is the first node may be NULL, which means work that should really be delegated to the nodes (because they have intimate knowledge of each other) must instead be handled by the list, and that's a very definite sign of poor design and inherent inefficiency.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantage of header linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Which one is the two way linked list a Circular link list b Node having header and trailer in the list C Array?

b Node having header and trailer in the list


What contains A dummy header in the linked list?

a. First record of the actual data


How do you find an element in the linked list?

You might look at the header record if the linked list has one. Better yet graduate to a btree and all these problems go away


What are the types of singly linked list?

Classification #1 - With a sentinel (header) element. - Without a sentinel (header) element. Classification #2 - Normal - Circular


What is the different between header file and header pointer?

Header file is a file which is meant to be included into another file during compilation. Examples: string.h, stdio.h, inttypes.h. Header pointer is a pointer to an object called header (for example header of a linked list).


How linked list can be used for the polynomial manipulation?

Header linked list are frequently used for maintaining polynomials in memory. The header node plays an important part in this representation, since it is needed to represent the zero polynomial. This representation of polynomial will be presented in the context of a specific


Need for header node in linked list?

The utility of a header node in a linked list is to simplify the functions of adding and deleting elements in the list. If you have a pointer in memory that points to the first element, then you need to pass the address of that pointer, rather than the value of that pointer, to the routines for list manipulation, because that pointer would need to change if an element were added or deleted at the head of the list. If that pointer, however, points to a special element in the list which is actually the pointer to the head of the list, then you do not need to pass the address of the pointer - you can pass its value, and it will never change. This technique "wastes" the data portion of that first element.


What is a linked list used for?

A linked list is used in computer science to store data as a series of related nodes. Linked lists are used as the basis for abstract data types when programming. The chief advantage of a linked list is that data can be added or removed from the list without having to reorganize the whole list. A drawback to linked lists can be that it is difficult to sort, organize, or recall specific information from the list.


What is singly linked list and doubly linked list?

Singly Linked list Each item in the list is called a node and contains two fields  Information field - The information field holds the actual elements in the list  Next address field- The next address field contains the address of the next node in the list. The entire linked list is accessed from an external pointer called the List. Doubly linked list is a collection of node. Each node contains three fields an info field that contains the information stored in the node. The left and right field that contains the address of the node on its left and right. The doubly linked list could be linear, circular and may have a header node.


What is the advantage of doubly linked list over Doubly linked list?

A doubly linked list can be traversed in both directions (forward and backward). A singly linked list can only be traversed in one direction. A node on a doubly linked list may be deleted with little trouble, since we have pointers to the previous and next nodes. A node on a singly linked list cannot be removed unless we have the pointer to its predecessor. On the flip side however, a doubly linked list needs more operations while inserting or deleting and it needs more space (to store the extra pointer).


Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.