Data STR Synopsis

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Lovely Professional University

Term paper Sub:-Data Structure Sub Code:-CSE-205 Topic:- Application of Linked Lists in Operating System.

Submitted ByBipin Kumar Section:-K3R01 Roll No:-A07

Submitted To:Mrs. Parul PraKram Department Of CSe/it

Date of Allotment 28/01/2012 Date of Submission 27/3/2012

Acknowledgement:First, i am thankful to my dear teacher, Parul Mam who had helped me to create this term
paper on the topic, Application of Linked Lists in Operating System at least 4 cases. This creation is totally devoted to my respective teacher, and the books, websites and persons who had helped me to create it.

Thanks.... Bipin Kumar

Contents:1. Link List:2. History:3. Why Link List:3.1. Linked Lists Vs Arrays

4. Disadvantages of Array:4.1. Advantages of a linked list4.2. Disadvantages of a linked list-

5. Properties of Linked List:6. Types of Link List:6.1. Singly Linked List:6.2. Doubly Linked List:6.2.1. Sentinel Nodes

6.3. Header Linked List:6.3.1. A grounded header list 6.3.2. Circularly-linked list

7. Applications of linked lists 8. Use of Linked List In Operating System:8.1. Memory Management
8.1.1. Heap memory allocation 8.1.2. Allocating memory 8.1.3. De-allocating memory

8.2. Searching the list 8.2.1. First fit 8.2.2. Best fit 8.2.3. Worst fit 8.3. Sorting the list 8.3.1. Separate holes & blocks list 8.3.2. Several hole lists 8.4. Directory Management

9. References:-

1. Link List: A link list is one of the fundamental data structures and can be used to implement other data
structures. It consists of a sequence of nodes, each containing (one or more as per requirement) data fields and one (or two) references (two for doubly link list) pointing to the next (or previous) nodes. The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk, allowing the list of items to be traversed in a different order. A linked list is a selfreferential data type because it contains a pointer or link to another datum of the same type. We can use Link lists when we dont know actual number of data. Link lists permit insertion and removal of nodes at any point in the list. It is the among the simplest and most common data structure. Linked lists permit insertion and removal of nodes at any point in the list in constant time, but do not allow random access. Several different types of linked list exist: singly- linked lists, doubly- linked lists, and circularly- linked lists. Linked lists can be implemented in most languages. Languages such as Lisp and Scheme have the data structure built in, along with operations to access the linked list. Procedural or object-oriented languages such as C, C++, and Java typically rely on mutable references to create linked lists.

2. History:-

Linked lists were developed in 1955-56 by Allen Newell, Cliff Shaw and Herbert Simon at RAND
Corporation as the primary data structure for their Information Processing Language. IPL was used by the authors to develop several early artificial intelligence programs, including the Logic Theory Machine, the General Problem Solver, and a computer chess program.

3. Why Link List:Linked lists and arrays are similar since they both store collections of data. The Terminology is that arrays and linked lists store "elements" on behalf of "client" code. The Specific type of element is not important since essentially the same structure works to Store elements of any type. One way to think about linked lists is to look at how arrays Work and think about alternate approaches. 3.1. Linked Lists Vs Arrays Concept 1.Indexing
2.Inserting / Deleting at end 3.Inserting / Deleting in middle 4.Persistent 5.Locality

Array
O(1) O(1) O(n) No Great

Linked Lists
O(n) O(1) or O(n) O(1) Singly yes Bad

4. Disadvantages of Array:1. The size of the array is fixed. Most often this size is specified at compile time with a simple declaration such as in the example above. With a little extra effort, the size of the array can be deferred until the array is created at runtime, but after that it remains fixed. (extra for experts) You can go to the trouble of dynamically allocating an array in the heap and then dynamically resizing it with realloc(), but that requires some real programmer effort. 2. Because of (1), the most convenient thing for programmers to do is to allocate arrays which seem "large enough. Although convenient, this strategy has two disadvantages(a) Most of the time there are just 20 or 30 elements in the array and 70% of the space in the array really is wasted.

(b)Inserting new elements at the front is potentially expensive because existing elements need to be shifted over to make room. But, Linked lists have their own strengths and weaknesses, but they happen to be strong where arrays are weak. The array's features all follow from its strategy of allocating the memory for all its elements in one block of memory. Linked lists use an entirely different strategy. As we will see, linked lists allocate memory for each element separately and only when Necessary.Linked lists have several advantages over arrays. Elements can be inserted into linked lists indefinitely, while an array will eventually either fill up or need to be resized, an expensive operation that may not even be possible if memory is fragmented. Similarly, an array from which many elements are removed may become wastefully empty or need to be made smaller.

4.1. Advantages of a linked list(i)Use as much memory as we need (ii)Computational efficient to add/delete data

4.2. Disadvantages of a linked list (i) Memory overhead. Store of extra information
(ii)Slow access of the data. You have to traverse the list

5. Properties of Linked List: Linked list is a data structure with the following specifics1. Data is dynamically added or removed. 2. Every data object has two parts-a data part and a link part. Together they constitute a node. 3. The list can be traversed only through pointers. 4. Every node is an important constituent of the data. 5. The end of the data is always a leaf end. 6. Tree structures (branched link lists) are used to store data into disks.

6. Types of Link List:There are three types of Linked List1. Singly Linked List 2. Doubly Linked List 3. Header Linked List

6.1. Singly Linked List: Singly Linked Lists are a type of data structure. It is a type of list. In a singly linked list each node in the list stores the contents of the node and a pointer or reference to the next node in the list. It does not store any pointer or reference to the previous node. It is called a singly linked list because each node only has a single link to another node. To store a single linked list, you only need to store a reference or pointer to the first node in that list. The last node has a pointer to nothingness to indicate that it is the last node. The singly- linked list is the most basic of all the linked data structures. A singly- linked list is simply a sequence of dynamically allocated objects, each of which refers to its successor in the list. Despite this obvious simplicity, there are myriad implementation variations. Figure shows several of the most common singly- linked list variants.

A singly-linked list containing three integer values

Figure- Singly- linked list variations

6.2. Doubly Linked List: In computer science, a doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes' previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. If there is only one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items, but in opposite sequential orders. That is a more sophisticated kind of linked list is a doubly-linked list or two-way linked list. Each node
has two links: one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the next, or points to a null value or empty list if it is the final node.

A doubly-linked list containing three integer values In some very low level languages, Xor-linking offers a way to implement doubly- linked lists using a single word for both links, although the use of this technique is usually discouraged.

6.2.1. Sentinel Nodes


Linked lists sometimes have a special dummy or sentinel node at the beginning and/or at the end of the list, which is not used to store data. Its purpose is to simplify or speed up some operations, by ensuring that every data node always has a previous and/or next node, and that every list (even one that contains no data elements) always has a "first" and "last" node. Lisp has such a design - the special value nil is used to mark the end of a 'proper' singly- linked list, or chain of cons cells as they are called. A list does not have to end in nil, but a list that did not would be termed 'improper'.

6.3. Header Linked List: A header linked list which always contains a special node, called the header node, at the beginning of the list. The following are two kinds of widely used header list. (a) Grounded Heade r List (b) Circular Header List

6.3.1. (a) Grounded Heade r List A grounded header list is a header l its where the last node contains the null pointer.

Header Linked List

6.3.2. Circularly-linked list In a circularly-linked list, the first and final nodes are linked together. This can be done for both singly and doubly linked lists. To traverse a circular linked list, you begin at any node and follow the list in either direction until you return to the original node. Viewed another way, circularly- linked lists can be seen as having no beginning or end. This type of list is most useful for managing buffers for data ingest, and in cases where you have one object in a list and wish to see all other objects in the list. The pointer pointing to the whole list may be called the access pointer.

A circularly-linked list containing three integer values

In other words a circular header list is a header list where the last node points back to the header

node. Unless otherwise stated or implied, our header list will always be circular list. Accordingly, in such a case, the header node also acts as a sentinel indicating the end of the list. In Circular Linked List, the list element are arranged in the same way as in the singly linked list having only one difference that the last element of the circular linked list always point to the first node of the list i.e. it means that last node does not point to NULL. In other words, we can say that the circular list is a list which does not have an end.

Thus, it is necessary in case of circular linked to establish the first node and last node. It is useful if we set external pointer i.e. head to point to the last node in the list.

6.3.2.1. Singly-circularly-linked list In a singly-circularly- linked list, each node has one link, similar to an ordinary singly- linked
list, except that the next link of the last node points back to the first node. As in a singly- linked list, new nodes can only be efficiently inserted after a node we already have a reference to. For this reason, it's usual to retain a reference to only the last element in a singly-circularly- linked list, as this allows quick insertion at the beginning, and also allows access to the first node through the last node's next pointer. Advantages:(i)Given any node, we can traverser the entire list. (ii)Certain operations, such as concatenation and splitting of string,is more efficient with circular linked list. Disadvantage:Danger of an infinite loop ! (The header node is used to prevent infinite loop)

6.3.2.2. Doubly-circularly-linked list


In a doubly-circularly-linked list, each node has two links, similar to a doubly-linked list, except that the previous link of the first node points to the last node and the next link of the last node points to the first node. As in doubly- linked lists, insertions and removals can be done at any point with access to any nearby node. Although structurally a doubly-circularly- linked list has no beginning or end, an external access pointer may formally establish the pointed node to be the head node or the tail node, and maintain order just as well as a doubly- linked list with sentinel nodes.

7. Applications

of linked lists

Linked lists are used as a building block for many other data structures, such as stacks, queues and their variations. The "data" field of a node can be another linked list. By this device, one can construct many linked data structures with lists; this practice originated in the Lisp programming language, where linked lists are a primary (though by no means the only) data structure, and is now a common feature of the functional programming style. Sometimes, linked lists are used to implement associative arrays, and are in this context called association lists. There is very little good to be said about this use of linked lists; they are easily outperformed by other data structures such as self-balancing binary search trees even on small data sets (see the discussion in associative array). However, sometimes a linked list is dynamically created out of a subset of nodes in such a tree, and used to more efficiently traverse that set.

8. Use of Linked List In Operating System:Linked lists are absolutely everywhere in almost all large application programs. If things are

created and destroyed during a programs execution, there is usually a dynamic data structure involved a linked list or something very similar. Some obvious examples include, (i) The set of open windows on your computers desktop. (ii) The set of files inside a folder. (iii) The text being typed into a window, which would typically be stored as a list of blocks of characters. Several operating systems developed by Technical Systems Consultants (originally of West Lafayette Indiana, and later of Raleigh, North Carolina) used singly linked lists as file structures. A directory entry pointed to the first sector of a file, and succeeding portions of the file were located by traversing pointers. Systems using this technique included Flex (for the Motorola 6800 CPU), mini-Flex (same CPU), and Flex9 (for the Motorola 6809 CPU). A variant developed by TSC for and marketed by Smoke Signal Broadcasting in California, used doubly linked lists in the same manner.

The TSS operating system, developed by IBM for the System 360/370 machines, used a double linked list for their file system catalog. The directory structure was similar to UNIX, where a directory could contain files and/or other directories and extend to any depth. A utility flea was created to fix file system problems after a crash, since modified portions of the file catalog were sometimes in memory when a crash occurred. Problems were detected by comparing the forward and backward links for consistency. If a forward link was corrupt, then if a backward link to the infected node was found, the forward link was set to the node with the backward link.

8.1. Following Are Some Examples Of Linked List In Operating System8.1.1. Heap memory allocation

Quite a practical and common mechanism for heap management is to store a linked list of all the allocated areas and all the holes.

8.1.2. Allocating memory


To allocate some space, we search along the list til we find an unallocated area of

memory which is big enough (typically much faster than searching a bitmap). When we find a suitable hole, split it into two parts, enough to satisfy the request and whatever is left over.

Replace the single 'hole' node in the list, with a 'allocated block' node, followed by a 'hole' node.

Return to the address of block.

8.1.3. De-allocating memory To de-allocate memory, we can just change its list node from 'allocated' to 'hole'. Obviously (hopefully), if we've just created a 'hole' next to another 'hole', we can merge the two hole nodes. In fact, if we've just de-allocated some memory, the memory above and below it (the nodes after and before it), might be allocated, or might be free. If we de-allocate some memory between two holes, we can merge all three holes, into one big hole.

8.2. Searching the list This is the basic algorithm, but there are several variations on the theme. Firstly, there is the choice as to how we search the list: 8.2.1. First fit The simplest way is just to wonder along till we find a hole which is big enough. It's quite fast (as fast as possible with the simple linked-list algorithm we've just described). 8.2.2. Best fit Another possibility is to find the smallest hole which will possibly satisfy the request; the snuggest fit of all the holes in the linked list. Best fit tries to avoid breaking up large holes which may be required later. Unfortunately, best fit tends to produce lots of small, useless holes, and surprisingly, wastes more memory this way than does first fit. 8.2.3. Worst fit In response to best fit creating lots of small, useless holes, an alternative approach might be to find the biggest hole each time---the 'worst' fit for the requested memory allocation---and allocate from that. All the holes this produces should be large and useful.

8.3. Sorting the list Then we have the choice of how to arrange the list. The list structure we mentioned, which has all the nodes---blocks and holes---linked in order of memory address is simple and efficient. Merging holes is easy. 8.3.1. Separate holes & blocks list If we keep the holes and allocated blocks on different lists, we can speed up time to allocate memory, since we're only searching the holes list. It does make deallocation a bit slower, though, because we must update two lists instead of one.

8.3.2. Several hole lists If we know that some sizes of block are very commonly allocated, we might keep several lists, one for each common block size, and perhaps another list of miscellaneous sizes. This makes allocation at these common sizes a lot faster. The disadvantage is that we no longer have the hole lists in order of memory address, so it is difficult to detect if two holes are adjacent in memory and may be merged into one hole. A similar approach might be to sort the hole list in increasing order of size. This means that the first fit search automatically becomes a best fit search. It has two disadvantages: best fit isn't ideal, and again it is difficult to merge adjacent holes. 8.4. Directory Management In our operating system, management of operating system is a very important. In almost every
operating system management of directory is achieved through Linked List. As we know that a directory contains subdirectory and files. So the starting of linked list is a directory name and the contents of directory are the info part of the linked list. And the pointer part of linked list the name of another directory name. Our linked list ends any files in directory or subdirectory. So, file acts as null for linked list.

9. References: 1. Schaum Outline series by: Seymour Lipschutz

2. Answer.com 3. About.com

You might also like