268 Data Structure Lecture 3 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

268 Data Structure Lecture 3

Description:

addElement: adds elements to the set if it is not already present ... radix sort-- Comparable. int compare(Object RHS) compare this object with RHS for order ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 20
Provided by: ESO17
Category:

less

Transcript and Presenter's Notes

Title: 268 Data Structure Lecture 3


1
268 Data Structure Lecture 3
  • Soundararajan Ezekiel
  • Department of Computer Science
  • Ohio Northern University
  • ADA, OHIO 45810

2
Announcement
  • Written Assignment 1
  • Out today
  • Quiz 1 today( Last 10- 15 Min)
  • This Friday Lab Problems
  • Out today

3
Review Fundamental ADT(Abstract Data Type)
  • Collection
  • boolean isEmpty
  • int size
  • Enumeration elements
  • Bag Simplest type of collection
  • addElement
  • containsElement
  • findElement
  • removeElement

4
Set
  • Same as Mathematical Set--
  • Every element is unique--
  • It allow no duplication
  • addElement adds elements to the set if it is not
    already present
  • unionWith Forms union of current set with
    argument set--Argument set is not modified

5
Continue
  • intersectWith Forms intersection of the current
    set with argument set-Argument set is not
    modified
  • differenceWith form difference between current
    set and argument set-- argument set is not
    modified
  • subsetOfreturns True if the members of current
    set is also members of argument set
  • False Otherwise

6
Sorted
  • One of the most frequently performed computing
    task--studied intensively-- many algorithms have
    been devised--
  • given the set of elements, the sorting problem is
    to arrange the elements from smallest to largest

7
Types of Sort
  • Insertion sort-
  • Bubble sort-
  • selection sort--
  • the cost of exchange of sort-
  • shell sort--
  • quick sort--
  • mergesort--
  • heapsort--
  • binsort--
  • radix sort--

8
Comparable
  • int compare(Object RHS)
  • compare this object with RHS for order
  • return negative(-1) if this object is less than
    RHS
  • return Zero if equal
  • return Positive(1) if this object is greater
    than RHS
  • throw ClassCastException if it not comparable

9
Comparator
  • int compare(Object RHS, Object RHS)
  • compares its two arguments for order, using the
    same rules as compareTo
  • Most useful when the natural ordering is not
    exactly what is needed
  • example sort the string by their string

10
Stack
  • A stack is a container of objects that are
    inserted and removed according to the last-in
    first-out(LIFO)principle
  • Objects can be inserted into a stack at any time
    BUT the most recently inserted (that is
    last)object can be removed at any time.
  • The name stack is derived from the metaphor of
    a stack of plates in a spring-loaded , cafeteria
    plate dispensor

11
Example1 Stack
  • Internet Web Browsers store the addresses of
    recently visited sites on a stack. ---Each time a
    user visits a new site, that sites address is
    pushed on to the stack of addressed. The browser
    then allow the user to pop back to previously
    visited sites using the back button

12
Example 2
  • Text Editors usually provide an undo mechanism
    that cancels recent operations and reverts to
    former states of a document. This undo operation
    can be accomplished by keeping text changes in a
    stack

13
Stack supports
  • push
  • pop
  • size
  • isEmpty
  • top

14
Queue
  • Another fundamental ADT is queue
  • It is a close cousin of Stack
  • is a container of object that are inserted and
    removed according to the first-in first-out
    (FIFO) principle
  • that is elements can be inserted at any time, but
    only the element that has been in the queue the
    longest can be removed at any time
  • enter queue at rear and are removed from the
    front
  • addLast---- getFirst -- nosuchElementException

15
Deque
  • Cobines the feature of Stack and Queue
  • Adding and Removing Elements from both sides

16
FindMin FindNth
  • Add new elements to collection
  • find and remove the smallest( min) value of the
    collection
  • FindNth-- provide ability to find Nth smallest
    value in a collection

17
Indexed Collection and Sorting Algorithm
  • able to access in a sequence, from beginning to
    end
  • Objects are indexed using integer value index
  • Like arrays

18
Map
  • Map a map is used to store a collection of
    entries that consists of keys and their values
  • the Map maps keys to values
  • keys must be unique, but several keys can map to
    the same values
  • these values need not to be unique
  • the map is implemented by Hashmap and Treemap

19
Matrix
  • 2-dim structure
  • setSize
  • numberRows
  • numberColumns
  • elementAt
  • setElementAt
Write a Comment
User Comments (0)
About PowerShow.com