CS Lecture 2 Abstract Data Types

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Abstract Data Types

data type (object data + applications)

  • Users of the ADT don’t need to know what the implementation is (“how”)

  • They only need to know the functionality (“what”)

  • Someone has to care about the “how” – it needs to get built by someone!

    • We call this person the “implementer”

  • In this course we will deal with ADTs from both the user’s and the implementer’s perspective.

2
New cards

How do we represent ADTs in java

generic types “T” types

3
New cards
<p>what does this do </p>

what does this do

swap any two items in an array (of any T type) with the same method

4
New cards
<p>what does this do </p>

what does this do

creates a genetic method that can sort any array of comparables

“<T extends Comparable<? super T>>” means that this method (bubbleSort) can work on any type (T) that extends Comparable<T> or extends Comparable<superclass of T>.

5
New cards

Can you have more than one generic type

yuh

6
New cards

The wild card operator (?)

represents an unknown class type

7
New cards

Bag ADT “rules”

no rule about how many items to put, order of items, duplicate items, what type of items can go in

impossible to fumble

8
New cards

What is missing from BagInterface

Doesn’t mention what types of data can be stored in Bags

  • strings? integers? arraylists of strings?

doesn’t mention any implementation of guidance on how things should be implemented

  • what should each of those methods do?

  • how should we handle special cases

9
New cards

What is a benefit of Bag

we don’t care about order so it’s good for adding and removing very fast

10
New cards

Preconditions

specifically the assumed state of the ADT before a method is executed

11
New cards

Postconditions

specify the intended state of the ADT after method execution

12
New cards

possible abnormal bag situtations where add might return false

Bag is in an invalid state

bag is full

newentry is an invalid object

13
New cards

supresswarning

Code is going to do smth will cause an error with the compiler but it supress allows it to compile anyway

14
New cards

Look over recap for all slides

15
New cards

What does ‘? extends T’ describe?

  1. Refers to the T interface

  2. A boolean expression to see if something extends T

  3. Refers to any class that extends the generic type T

  4. Refers to any class that implements the generic type T

3 and 4

16
New cards

ArrayBag<?> vs. ArrayBag<T>

ArrayBag<?> = an arraybag that can operate on any type

ArrayBag<T> = an arraybag that operates on the generic type T

17
New cards

Pros of using array for bag

adding an entry to the bag is fast

removing an entry is fast

18
New cards

Cons of using an array for bag

may be wasteful of memory

doubling capacity requires copying each item to a new array

19
New cards
<p>Bag Array Implementation: how could this be an issue</p>

Bag Array Implementation: how could this be an issue

the white squares are extra space, if we add 4 more items to the bag they would no longer be wasted (in use). However, if we don’t add any more items, those 4 spaces can’t be used by any other program and are wasted space