chapter 3 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter 3 PowerPoint Presentation
Download Presentation
Chapter 3

Loading in 2 Seconds...

play fullscreen
1 / 78

Chapter 3 - PowerPoint PPT Presentation

  • Uploaded on

Chapter 3. ADTs unsorted List and Sorted List. List Definitions. Linear relationship Each element except the first has a unique predecessor, and each element except the last has a unique successor. Length The number of items in a list; the length can vary over time. List Definitions.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Chapter 3' - jenaya

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 3

Chapter 3

ADTs unsorted List and Sorted List

list definitions
List Definitions

Linear relationship Each element except the first has a unique predecessor, and each element except the last has a unique successor.

Length The number of items in a list; the length can vary over time.

list definitions1
List Definitions

Unsorted list A list in which data items are placed in no particular order; the only relationship between data elements is the list predecessor and successor relationships.

Sorted list A list that is sorted by the value in the key; there is a semantic relationship among the keys of the items in the list.

Key The attributes that are used to determine the logical order of the list.

assumptions for all our lists
Assumptions for All our Lists
  • Our lists are composed of unique elements.
  • When sorted, our lists are sorted from the smallest to largest key value.
  • We use the “by copy” approach.
  • Signature The distinguishing features of a method heading. The combination of a method name with the number and type(s) of its parameters in their given order.
  • Overloading The repeated use of a method name with a different signature.
simple observers
Simple Observers

public boolean isFull ( )

// Returns whether this lis is full


return (list.length == numItems);


deleting bobby move up
Deleting Bobby (move up)
  • Requires moving all of the names after Bobby.
  • In the worst case, the whole list could be moved
  • The last name becomes part of the garbage.
deleting bobby swap more efficient
Deleting Bobby (swap)—more efficient
  • The idea is to swap the last element with the one you want to delete.
  • Then decrease the size of the list.
  • This only works for unsorted lists.
  • A sorted list has many advantages over an unsorted list, but deleting in unsorted lists is more efficient. Its one advantage.
reuse operations
Reuse Operations

Ways we could reuse the code of the Unsorted List ADT to create the code for the Sorted List ADT:

  • Cut and Paste—”cut and paste” the code that we are able to reuse into the new file.
  • Direct Inheritance—have the Sorted List ADT inherit methods from the Unsorted List ADT.
  • Abstract Classes—resolve the deficiencies of both of the previousapproaches.
steps for using abstract class approach
Steps for Using Abstract Class Approach
  • We first create an abstract list class.
    • Its concrete methods provide the operations that our two list ADTs share in common.
    • Its abstract methods provide the operations that are not shared.
  • Then create two concrete classes that extend the abstract list class.
    • One that implements an unsorted list
    • The other that implements a sorted list
insert operation1
insert Operation
  • Find the place where the new element begins.
  • Create space for the new element.
  • Put the new element on the list.
binary search algorithm
Binary Search Algorithm

Searching for Aurora

comparison of algorithms
Comparison of Algorithms

Big-O Notation A notation that expresses computing time (complexity) as the term in a function that increases most rapidly relative to the size of a problem


f(N) = N4 + 100N2 + 10N + 50

then f(N) is 0(N4).

N represents the size of the problem.

generic adts
Generic ADTs

So far…

  • An unsorted list of strings
  • An unsorted list of strings that extended String List
  • A sorted list of strings that extended String List


  • Lists of generic data

Generic Data Type A type for which the operations are defined but the types of the items being manipulated are not

a generic sorted list adt
A Generic Sorted List ADT
  • Please click on the following link Programs/C03P200.jpg to view the appropriate program.
using the generic list
Using the Generic List

To Create a sorted list of strings use either of its constructors:

SortedList list1 = new SortedList();

SortedList list2 = new SortedList (size);

Declare at least one object of class ListString

ListString aString;

Instantiate ListString objects and place them on the list.

aString = new ListString(“Amy”);