Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIS 215 Module 1 – Unordered Lists

Similar presentations


Presentation on theme: "MIS 215 Module 1 – Unordered Lists"— Presentation transcript:

1 MIS 215 Module 1 – Unordered Lists

2 Where are we? MIS215 Basic Algorithms Introduction List Structures
Advanced structures Search Techniques Intro to Java, Course Sorting Techniques Java lang. basics Linked Lists Hashtables Binary Search Graphs, Trees Stacks, Queues Arrays Bubblesort Fast Sorting algos (quicksort, mergesort) Newbie Programmers Designers Developers Professionals

3 Today’s buzzwords Unordered Lists Linked Lists Java References
Lists that are not REQUIRED to be ordered to be functional That does not mean that they cannot be ordered if necessary Linked Lists A data structure where the lists are implemented using a dynamically allocated structure, with nodes and links to the next nodes. Java References A “reference” in Java is simply a variable of an object type All objects are dynamically allocated at runtime (with “new”) Its like a pointer, but still not like a pointer 

4 Overview List introduction List specifications List implementations
Contiguous Simply Linked Simply Linked with Position Pointer Doubly Linked Strings Application: Text Editor Linked Lists in Arrays Application: Generating Permutations

5 Unordered Lists Lists that do not have to be ordered to be functional
Can be ordered if necessary Examples?

6 The Specifications of General Lists
Basic operations: clear, isListEmpty, isListFull, size, traverse List operations: insert, remove, find. The Insert operation: insert(Itemtype x) OR insert(int p, Itemtype x) Pre: The list has been created, and is not full, x is a valid list entry, and 0<=p<=n, where n is the number of entries in list. Post: x has been inserted into position p in list; the entry formerly in position p (provided p<n) and all later entries have their position numbers increased by 1.

7 Our List Skeleton (for now)
/** * Our first List class. Notice the Javadoc style comments */ public class MyList { * The MyList Constructor - we may need variants later public MyList() {} * The clear operation - removes all entries from the list public void clear() {} * Check if the list is empty public boolean isListEmpty() {} * Check if the list is full public boolean isListFull() {} * What is the current size of the list? Note that this is * different from the maximum possible size. public int size() {} * Traverse the list - maybe just print all items in the screen public void traverse() {} }

8 The Implementations of General lists
Contiguous implementation using arrays insertions and deletions are done with movement of data entries Linked implementations singly linked lists allocating memory dynamically insertions and deletions are done by changing references doubly linked lists using two references for each entry

9 Lets try arrays first! What variables should MyList need?
What possible variations of the constructor? What would be useful to know when the list is being created? What would you allow your users to set once for the life of the instance?

10 Implementing List as Array
CFC on the MyList class How do we implement clear? How do we implement isListEmpty? How do we implement isListFull?

11 Now for the List operations
insert remove find

12 A singly linked list Each node in the list contains...
data (we’ll use only integers, as usual) a link to the next node in Java, we’ll call this a reference (if you know C, it’s a pointer) Here’s a picture....

13 Links (contd.) data next node

14 Class Design Our first UML in MIS215 Node LinkedList 0..M int Item
Node Next LinkedList Node First 0..M

15 Insertion on a Linked List
Stacks lists are Stacks lists are simple

16 Deletions on a Linked List
Stacks are structures simple but important data Stacks structures are simple but data important ?

17 Doubly Linked List

18 Comparison of the Implementations
In processing a continuous list with n entries: insert and remove require O(n) time clear, isListEmpty, isListFull, size operate in constant time. We call this O(1) complexity In processing a linked list with n entries: Complexity of insert? Complexity of remove? Complexity of size? Complexity of isListEmpty? Complexity of isListFull?

19 Complexity Analysis Complexity of _____________
O(1) … i.e., Constant time O(n) … i.e., proportional to #items More than O(n)?

20 Build this table for unordered lists
Operation Array implementation Linked List Implementation create/constructor O(1) size clear traverse isListFull isListEmpty insert remove find findAt*

21 Quick Quiz: Accessing items in the chain
In an array, how do we access an item in the array (say, the 4th item)? If we have a chain (i.e., linked list), how do we get to the 4th item in the chain?

22 Analysis of the Implementations
Contiguous storage is generally preferable: when the structures are individually small when the size of the list is known when the program is written when fewer insertions or deletions need to be made except at the end of the list when random access is important. Linked storage proves superior: when the structures are large when the size of the list is not known in advance when flexibility is needed in inserting, deleting and re-arranging the entries.


Download ppt "MIS 215 Module 1 – Unordered Lists"

Similar presentations


Ads by Google