Lect 10 Zaheer Abbas


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lect 10 Zaheer Abbas

  1. 1. Created by Zaheer Abbas Aghani
  3. 3. What is a List? <ul><li>In computer science, a list is a collection of entities/items . OR </li></ul><ul><li>List is a collection of short pieces of information such as names of peoples or list of groceries etc. </li></ul><ul><li>List is among the most generic of data structure. </li></ul><ul><li>It is usually used in the daily life routine </li></ul><ul><li>E.g. </li></ul><ul><li>birthday list of friends. </li></ul><ul><li>shopping list </li></ul><ul><li>etc. </li></ul>
  4. 4. Nature of List Structure <ul><li>List is a collection of items that are all of same type. </li></ul><ul><li>The items or elements of list are stored in some particular order. </li></ul><ul><li>It is possible to insert new elements into various position in list and remove any element of list. </li></ul><ul><li>The order is important here. It is not just a random collection it is an ordered collection. </li></ul>
  5. 5. List Implementation <ul><li>Lists are usually implemented using different data structure. </li></ul><ul><li>There are two main ways to implement lists into memory. </li></ul><ul><li>One way to store such data is by means of arrays, but array have certain disadvantages </li></ul><ul><li>e.g. </li></ul><ul><ul><li>It is relatively expensive to insert and delete elements. </li></ul></ul><ul><ul><li>it occupies a block of memory space, one can not increase the size of array when space is required. </li></ul></ul>
  6. 6. <ul><li>Another way of storing list in memory to have each element in the list contain field called link or pointer. </li></ul><ul><li>Pointer contains the address of next element in the list. Thus successive element in the list need not occupy adjacent space in memory. </li></ul><ul><li>If some one is interested in searching through data for inserting and deleting as in word processing one would not store data in an array but rather in list using pointers. </li></ul><ul><li>This type of data structure is called a linked list </li></ul>
  7. 7. Linked List <ul><li>A linked list, or one way list is a linear collection of data elements called nodes, where each element contains a pointer to the next element. </li></ul><ul><li>OR </li></ul><ul><li>A linked list is a data structure where every element contains both a 'value' and a link/reference/pointer to a 'next' element. </li></ul><ul><li>The whole list is represented by a pointer/reference/link to the first element of the list. </li></ul>
  8. 8. Linked list continue….. <ul><li>In computer science, a linked list is one of the fundamental data structure, and can be used to implement other data structure. </li></ul><ul><li>Its consists of sequences of nodes, each contain arbitrary data fields and one or two references (links) pointing to the next and /or pervious nodes. </li></ul><ul><li>linked lists allocate memory for each element separately and only when necessary. </li></ul><ul><li>A linked list is also called self-referential data type because it contains a pointer or link to other datum of same type. </li></ul>
  9. 9. What Linked Lists Look Like <ul><li>An array allocates memory for all its elements lumped together as one block of memory. </li></ul><ul><li>In contrast, a linked list allocates space for each element separately in its own block of memory called a &quot; linked list element&quot; or &quot;node&quot;. The list gets is overall structure by using pointers to connect all its nodes together like the links in a chain </li></ul><ul><li>Each node contains two fields: a &quot;data&quot; field to store whatever element type the list holds and a &quot;next&quot; field which is a pointer used to link one node to the next node. </li></ul><ul><li>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 &quot;first&quot; and &quot;last&quot; node. </li></ul>
  10. 10. . <ul><li>Above is a schematic diagram of a linked list with 5 nodes. Each node contain two parts i.e. </li></ul><ul><li> the left part represents the information part of the node. </li></ul><ul><li> the right part represents the next pointer field of the node. </li></ul><ul><li>Start points to the first element of list and the pointer of last node contain a special value, called the null pointer, which is any invalid address. </li></ul>x start