data str synopsis

Upload: lucky-sinha

Post on 05-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Data Str Synopsis

    1/15

    Lovely Professional University

    Term paper

    Sub:-Data Structure

    Sub Code:-CSE-205

    Topic:- Application of Linked Lists in Operating System.

    Submitted By- Submitted To:-

    Bipin Kumar Mrs. Parul PraKram

    Section:-K3R01 Department Of

    Roll No:-A07

    Date of Allotment

    28/01/2012

    Date of Submission

    27/3/2012

  • 8/2/2019 Data Str Synopsis

    2/15

    Acknowledgement:-

    First, i am thankful to my dear teacher, Parul Mam who hadhelped 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

  • 8/2/2019 Data Str Synopsis

    3/15

    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 list-

    4.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. Agrounded 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/2019 Data Str Synopsis

    4/15

    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 datastructures. 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 (orprevious) 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 oron disk, allowing the list of items to be traversed in a different order. A linked list is a self-referential data type because it contains a pointer or link to another datum of the same type.

    We can use Link lists when we don t 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 datastructure. 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-linkedlists, 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 withoperations to access the linked list. Procedural or object-oriented languages such as C, C++, andJava typically rely on mutable references to create linked lists.

  • 8/2/2019 Data Str Synopsis

    5/15

    2. History:-

    Linked lists were developed in 1955-56 by Allen Newell, Cliff Shaw and Herbert Simon at RANDCorporation as the primary data structure for their Information Processing Language. IPL was used by theauthors to develop several early artificial intelligence programs, including the Logic Theory Machine, theGeneral 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 Terminologyis 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 Array Linked Lists1.Indexing O(1) O(n)

    2.Inserting / Deleting at end O(1) O(1) or O(n)

    3.Inserting / Deleting in middle O(n) O(1)

    4.Persistent No Singly yes

    5.Locality Great Bad

    4. Disadvantages of Array:-1. The size of the array is fixed. Most often this size is specified at compile time with a simpledeclaration such as in the example above. With a little extra effort, the size of the array can bedeferred 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 dynamicallyresizing 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 whichseem "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 thearray really is wasted.

  • 8/2/2019 Data Str Synopsis

    6/15

    (b)Inserting new elements at the front is potentially expensive because existing elements need tobe 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 strategyof 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 andonly when Necessary.Linked lists have several advantages over arrays. Elements can be insertedinto 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 arrayfrom which many elements are removed may become wastefully empty or need to be madesmaller.

    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 traversethe list

    5. Properties of Linked List:- Linked list is a data structure with the following specifics-1. 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.

  • 8/2/2019 Data Str Synopsis

    7/15

    6. Types of Link List:-There are three types of Linked List-

    1. Singly Linked List2. Doubly Linked List3. 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 eachnode in the list stores the contents of the node and a pointer or reference to the next node in thelist. 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 onlyneed to store a reference or pointer to the first node in that list. The last node has a pointer tonothingness to indicate that it is the last node.

    The singly-linked list is the most basic of all thelinked 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 listvariants.

    A singly-linked list containing three integer values

    Figure- Singly-linked list variations

  • 8/2/2019 Data Str Synopsis

    8/15

    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 arereferences 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 asentinel 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 listsformed 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 nodehas 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 theend 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 thatevery list (even one that contains no data elements) always has a "first" and "last" node. Lisp hassuch 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 notwould 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 Header List

    (b) Circular Header List

  • 8/2/2019 Data Str Synopsis

    9/15

    6.3.1. (a) Grounded Header List

    Agrounded 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 forboth singly and doubly linked lists. To traverse a circular linked list, you begin at any node andfollow 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 usefulfor 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 accesspointer.

    A circularly-linked list containing three integer values

    In other words acircular 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.

  • 8/2/2019 Data Str Synopsis

    10/15

    Thus, it is necessary in case of circular linked to establish the first node and last node. It is usefulif 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- linkedlist, 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. Forthis reason, it's usual to retain a reference to only the last element in a singly-c ircularly-linkedlist, 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 circularlinked 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 lastnode 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 listhas 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 withsentinel nodes.

  • 8/2/2019 Data Str Synopsis

    11/15

    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 canconstruct many linked data structures with lists; this practice originated in the Lisp programminglanguage, 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 toimplement 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 datastructures such as self-balancing binary search trees even on small data sets (see the discussion inassociative 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 structureinvolveda 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 WestLafayette 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 Motorola6800 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 doublylinked lists in the same manner.

  • 8/2/2019 Data Str Synopsis

    12/15

    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 utilityflea 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 theinfected 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

    System-

    8.1.1. Heap memory allocation-

    Quite a practical and common mechanism for heap management is to store a linkedlist 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 andwhatever is left over.

  • 8/2/2019 Data Str Synopsis

    13/15

    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 allthree holes, into one big hole.

  • 8/2/2019 Data Str Synopsis

    14/15

    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 justdescribed).

    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 uplarge 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 approachmight be to find the biggesthole each time---the 'worst' fit for the requested memory

    allocation---and allocate from that. All the holes this produces should be large anduseful.

    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/2/2019 Data Str Synopsis

    15/15

    8.3.2. Several hole lists

    If we know that some sizes of block are very commonly allocated, we might keepseveral lists, one for each common block size, and perhaps another list of

    miscellaneous sizes. This makes allocation at these common sizes a lot faster. Thedisadvantage 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 everyoperating 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 thecontents 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