Lists

1,919 views
1,736 views

Published on

Published in: Technology, Travel
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,919
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Lists

  1. 1. Data Structures and Algorithm Analysis By Abdul Ghaffar (MCS, KU)
  2. 2. Reference Books <ul><li>Data Structures and Algorithm Analysis in C </li></ul><ul><ul><li>By Mark Allen Weiss </li></ul></ul><ul><ul><ul><li>Published by Addison Wesley </li></ul></ul></ul><ul><li>Data Structures (Schaum’s Outline Series) </li></ul><ul><ul><li>By Seymour Lipschutz </li></ul></ul><ul><ul><ul><li>Published by Mc Graw Hill </li></ul></ul></ul>
  3. 3. Abstract Data Types (ADT) <ul><li>Definition: </li></ul><ul><ul><li>An Abstract Data Type is a mathematical abstraction of an organization of data and a set of operations to implement on the ADT. </li></ul></ul><ul><ul><li>Basic Idea: </li></ul></ul><ul><ul><ul><li>Implement the operation once and use them anywhere in the program to perform the operation any number of times. There is no rule telling which operation must be supported for each ADT. This is a design Decision. </li></ul></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>Data Types </li></ul></ul></ul><ul><ul><ul><ul><li>Integer, Real, Bool, Character </li></ul></ul></ul></ul><ul><ul><ul><li>ADTs </li></ul></ul></ul><ul><ul><ul><ul><li>Lists, Trees, Stacks, Sets, Graphs </li></ul></ul></ul></ul>
  4. 4. From Data to ADTs machine level data storage primitive data types basic data structures Data Structures And ADTs 0100110001101001010001 28 3.1415 'A' stack queue list array structure
  5. 5. L I S T S Based on Chapter 3 Of Reference Book #1
  6. 6. List <ul><li>The List Model </li></ul><ul><ul><li>The form of the List is as Al, A2, A3, AN </li></ul></ul><ul><ul><li>The size of this list is N. </li></ul></ul><ul><ul><li>An empty list is a special list of size 0 . </li></ul></ul><ul><ul><li>For any list except the empty list, w say the t Ai+1 follows (or succeeds) Ai (i < N) and that Ai-1 precedes Ai (i > 1). </li></ul></ul><ul><ul><li>The first element of the list is Al, and the last element is AN. </li></ul></ul><ul><ul><li>The predecessor of Al or the successor of AN will not be defined. </li></ul></ul><ul><ul><li>The position of element Ai in a list is i. </li></ul></ul><ul><li>Set of operations </li></ul><ul><ul><ul><li>printList </li></ul></ul></ul><ul><ul><ul><li>MakeEmpty </li></ul></ul></ul><ul><ul><ul><li>Find ‘ returns the position of e firs-t occurrence of a key </li></ul></ul></ul><ul><ul><ul><li>Insert and Delete ‘ insert and delete some key from some position </li></ul></ul></ul><ul><ul><ul><li>FindKth ‘ which returns the element in some position </li></ul></ul></ul>
  7. 7. List <ul><li>Example: </li></ul><ul><li>If the list is 34, 12, 52, 16, 12 then </li></ul><ul><ul><ul><li>Find(52) might return 3 </li></ul></ul></ul><ul><ul><ul><li>Insert(X, 3) might make the list into 34, 12, 52, X, 16, 12 (if we insert after the position given) </li></ul></ul></ul><ul><ul><ul><li>Delete(52) might turn that list into 34, 12, X, 16, 12. </li></ul></ul></ul><ul><ul><li>Notes: </li></ul></ul><ul><ul><ul><ul><li>What is appropriate for a function is entirely up to the programmer </li></ul></ul></ul></ul><ul><ul><ul><ul><li>We could also add operations such as Next and Pmvious , which would take a position as argument and return the position of the successor and predecessor, respectively. </li></ul></ul></ul></ul>
  8. 8. List <ul><li>Implementations </li></ul><ul><ul><li>As an Array </li></ul></ul><ul><ul><ul><li>Limitations </li></ul></ul></ul><ul><ul><ul><ul><li>Size of the list must be known in advance </li></ul></ul></ul></ul><ul><ul><ul><ul><li>May cause wastage of the memory space </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Deletion and insertion are difficult </li></ul></ul></ul></ul><ul><ul><ul><li>Advantages </li></ul></ul></ul><ul><ul><ul><ul><li>Implementation is easy </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Searching and Traversing is easy </li></ul></ul></ul></ul>
  9. 9. List <ul><ul><li>As Linked list </li></ul></ul><ul><ul><ul><li>Definition: </li></ul></ul></ul><ul><ul><ul><li>The linked list consists of a series of structures, which are not necessarily adjacent in memory. Each structure contains the element and a pointer to a structure containing its successor. </li></ul></ul></ul>NULL
  10. 10. List <ul><ul><ul><li>Advantages </li></ul></ul></ul><ul><ul><ul><ul><li>Less memory is required </li></ul></ul></ul></ul><ul><ul><ul><ul><li>List can be dynamic, so there no need to know the size in advance </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Insertion and deletion are easy </li></ul></ul></ul></ul><ul><ul><ul><li>Disadvantages </li></ul></ul></ul><ul><ul><ul><ul><li>Implementation is comparably difficult </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Requires more processing </li></ul></ul></ul></ul>
  11. 11. List <ul><ul><li>Insertion and deletion </li></ul></ul>
  12. 12. List <ul><ul><ul><li>Programming Details </li></ul></ul></ul><ul><ul><ul><ul><li>Some Problems </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>No way to insert at, and delete the elements from the front </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>For deletion keep record for the previous element of the deleted item </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><li>Solutions </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Use Header or dummy node </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Build a routine FindPrevious </li></ul></ul></ul></ul></ul>
  13. 13. Example:- <ul><ul><li>Declarations: </li></ul></ul>List ADT
  14. 14. Example:- <ul><ul><li>Declarations: </li></ul></ul>List ADT
  15. 15. Example:- <ul><ul><li>Function to test if The List is empty </li></ul></ul><ul><ul><li>Function to test last position </li></ul></ul>List ADT
  16. 16. Example:- <ul><ul><li>Find routine </li></ul></ul>List ADT
  17. 17. Example:- <ul><ul><li>Deletion Routine for a item X </li></ul></ul>List ADT
  18. 18. Example:- <ul><ul><li>Find Previous Routine </li></ul></ul>List ADT
  19. 19. Example:- <ul><ul><li>Insertion Routine </li></ul></ul>List ADT
  20. 20. Example:- <ul><ul><li>Delete List routine </li></ul></ul>List ADT
  21. 21. List <ul><ul><li>Doubly Linked Lists </li></ul></ul><ul><ul><ul><li>Includes an extra pointer to the previous cell </li></ul></ul></ul><ul><ul><ul><li>Increase the processing for insertion and deletion </li></ul></ul></ul><ul><ul><ul><li>Simplifies the deletion process </li></ul></ul></ul><ul><ul><ul><ul><li>Circular Linked List </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Pointer of the last cell points to the first cell </li></ul></ul></ul></ul></ul>
  22. 22. List <ul><ul><li>Applications of Lists </li></ul></ul><ul><ul><ul><li>Processing the Polynomials </li></ul></ul></ul>Polynomial
  23. 23. List <ul><ul><li>Applications of Lists </li></ul></ul><ul><ul><ul><li>Radix Sort (Example) : </li></ul></ul></ul><ul><ul><ul><li>Initial data -> 64, 8, 216, 512, 27, 729, 0, 1, 343, 125 </li></ul></ul></ul>Radix Sort
  24. 24. List Radix Sort
  25. 25. List <ul><ul><ul><li>Multilists </li></ul></ul></ul>Multilists

×