MIS 215 Module 1 - PowerPoint PPT Presentation

About This Presentation
Title:

MIS 215 Module 1

Description:

... Professionals Designers MIS215 Binary Search Search Techniques Sorting Techniques Bubblesort Basic Algorithms Fast Sorting ... Lists A data structure where ... – PowerPoint PPT presentation

Number of Views:115
Avg rating:3.0/5.0
Slides: 23
Provided by: Wright51
Category:

less

Transcript and Presenter's Notes

Title: MIS 215 Module 1


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
Hashtables
Linked Lists
Binary Search
Graphs, Trees
Stacks, Queues
Arrays
Bubblesort
Fast Sorting algos (quicksort, mergesort)
Newbie
Programmers
Developers
Professionals
Designers
3
Todays buzzwords
  • Unordered Lists
  • 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 0ltpltn,
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 pltn)
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
  • /

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 (well use only integers, as usual)
  • a link to the next node
  • in Java, well call this a reference
  • (if you know C, its a pointer)
  • Heres a picture....

13
Links (contd.)
data
next
node
?
14
Class Design
  • Our first UML in MIS215

Node int Item Node Next
LinkedList Node First
0..M
15
Insertion on a Linked List
16
Deletions on a Linked List
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) 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.
Write a Comment
User Comments (0)
About PowerShow.com