DOC PREVIEW
Penn CIT 594 - Types of Collection

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CIT 594Basic contentTypes of CollectionThe Collections hierarchyUniformity through interfacesCreating lists in JavaA short list of categoriesExample recursive algorithmsExample backtracking algorithmExample greedy algorithmTime and spacey = x2 + 3x + 5, for x=1..20The EndCIT 594Basic contentCIT 594 is a continuation of CIT 591Java will be used throughoutHowever, CIT 594 is not primarily a course about JavaTopics:Data StructuresSupplied by JavaHow to create your ownAlgorithmsA sampling of some better-known algorithmsAnalysis of algorithmsSimple algebra is requiredTypes of CollectionA collection is a structured group of objectsJava supplies several types of Collection:Set: cannot contain duplicate elements, order is not importantSortedSet: like a Set, but order is importantList: may contain duplicate elements, order is importantJava also supplies some “collection-like” things:Map: a “dictionary” that associates keys with values, order is not importantSortedMap: like a Map, but order is importantThe Collections hierarchyUniformity through interfacesMuch of the elegance of the Collections Framework arises from the intelligent use of interfacesFor example, the Collection interface specifies (among many other operations):boolean add(Object o)boolean isEmpty()boolean remove()int size()Object[] toArray()Iterator iterator()Creating lists in Java class Cell { int value; Cell next; Cell (int v, Cell n) { // constructor value = v; next = n;} } Cell temp = new Cell(17, null); temp = new Cell(23, temp); temp = new Cell(97, temp); Cell myList = new Cell(44, temp);44 97 23 17myList:A short list of categoriesAlgorithm types we will consider include:Simple recursive algorithmsBacktracking algorithmsDivide and conquer algorithmsDynamic programming algorithmsGreedy algorithmsBranch and bound algorithmsBrute force algorithmsRandomized algorithmsExample recursive algorithmsTo count the number of elements in a list:If the list is empty, return zero; otherwise,Step past the first element, and count the remaining elements in the listAdd one to the resultTo test if a value occurs in a list:If the list is empty, return false; otherwise,If the first thing in the list is the given value, return true; otherwiseStep past the first element, and test whether the value occurs in the remainder of the listExample backtracking algorithmTo color a map with no more than four colors:color(Country n):If all countries have been colored (n > number of countries) return success; otherwise,For each color c of four colors,If country n is not adjacent to a country that has been colored cColor country n with color crecursively color country n+1If successful, return successIf loop exits, return failureExample greedy algorithmSuppose you want to count out a certain amount of money, using the fewest possible bills and coinsA greedy algorithm would do this would be:At each step, take the largest possible bill or coin that does not overshootExample: To make $6.39, you can choose:a $5 billa $1 bill, to make $6a 25¢ coin, to make $6.25A 10¢ coin, to make $6.35four 1¢ coins, to make $6.39For US money, the greedy algorithm always gives the optimum solutionTime and spaceTo analyze an algorithm means:developing a formula for predicting how fast an algorithm is, based on the size of the input (time complexity), and/ordeveloping a formula for predicting how much memory an algorithm requires, based on the size of the input (space complexity)Usually ti me is our biggest concernMost algorithms require a fixed amount of spacey = x2 + 3x + 5, for x=1..20The


View Full Document

Penn CIT 594 - Types of Collection

Documents in this Course
Trees

Trees

17 pages

Searching

Searching

24 pages

Pruning

Pruning

11 pages

Arrays

Arrays

17 pages

Stacks

Stacks

30 pages

Recursion

Recursion

25 pages

Hashing

Hashing

24 pages

Recursion

Recursion

24 pages

Graphs

Graphs

25 pages

Storage

Storage

37 pages

Trees

Trees

21 pages

Arrays

Arrays

24 pages

Hashing

Hashing

24 pages

Recursion

Recursion

25 pages

Graphs

Graphs

23 pages

Graphs

Graphs

25 pages

Stacks

Stacks

25 pages

Recursion

Recursion

25 pages

Quicksort

Quicksort

21 pages

Quicksort

Quicksort

21 pages

Graphs

Graphs

25 pages

Recursion

Recursion

25 pages

Searching

Searching

24 pages

Counting

Counting

20 pages

HTML

HTML

18 pages

Recursion

Recursion

24 pages

Pruning

Pruning

11 pages

Graphs

Graphs

25 pages

Load more
Download Types of Collection
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Types of Collection and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Types of Collection 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?