Data Structures Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Software Engineering Session 14 INFM 603. Software Software represents an aspect of reality –Input and output represent the state of the world –Software.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Binary Trees. DCS – SWC 2 Binary Trees Sets and Maps in Java are also available in tree-based implementations A Tree is – in this context – a data structure.
 What are the basic GUI components we’ve learned so far? › JFrame › JPanel › JButton › JLabel › JTextArea › JTextField › JCheckBox › JRadioButton › Paint.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Structured Programming and UML Overview Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Modular Programming and Use Case Models Session 3 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Software Development Process and Introduction to Java Session 1 LBSC 790 / INFM 718B Building the Human-Computer Interface.
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Chapter 19 Java Data Structures
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Data Structures Session 8 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
Graphical User Interfaces and Java Display Components Session 6 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Algorithms Session 7 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Collections. The Plan ● Why use collections? ● What collections are available? ● How are the collections different? ● Examples ● Practice.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
Chapter 18 Java Collections Framework
Computer Science 209 Software Development Java Collections.
Data structures Abstract data types Java classes for Data structures and ADTs.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Building Java Programs Bonus Slides Hashing. 2 Recall: ADTs (11.1) abstract data type (ADT): A specification of a collection of data and the operations.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
Algorithms and Graphical User Interfaces (part 2) Session 8 LBSC 790 / INFM 718B Building the Human-Computer Interface.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Basics of GUI Programming Chapter 11 and Chapter 22.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Maps Nick Mouriski.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
CSE 143 Lecture 11: Sets and Maps reading:
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
Java Collections Framework The client view. The Big Picture.
Structured Programming and UML Introduction Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Software Engineering Session 12 INFM 603. Software Software represents an aspect of reality –Input and output represent the state of the world –Software.
Using the Java Collection Libraries COMP 103 # T2
Chapter 19 Java Data Structures
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Software Development Java Collections
JAVA COLLECTIONS LIBRARY
Week 2: 10/1-10/5 Monday Tuesday Wednesday Thursday Friday
Road Map CS Concepts Data Structures Java Language Java Collections
FINAL EXAM Final Exam Wednesday, Dec 14: 8: :00 AM (Frny G140)
FINAL EXAM Final Exam Tuesday, May 3: 1:00 - 3:00 PM (Phys 112)
Presentation transcript:

Data Structures Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface

Agenda Questions Some useful data structures Project discussion Wrap-up

What’s Wrong With Arrays? Must specify maximum size when declared –And the maximum possible size is always used Can only index with integers –For efficiency they must be densely packed Adding new elements is costly –If the elements are stored in order Every element must be the same type

What’s Good About Arrays? Can get any element quickly –If you know what position it is in Natural data structure to use with a loop –Do the same thing to different data Efficiently uses memory –If the array is densely packed Naturally encodes an order among elements

Linked Lists A way of making variable length arrays –In which insertions and deletions are easy Very easy to do in Java But nothing comes for free –Finding an element can be slow –Extra space is needed for the links –There is more complexity to keep track of

Making a Linked List In Java, all objects are accessed by reference –Object variables store the location of the object New instances must be explicitly constructed Add reference to next element in each object –Handy to also have a reference to the prior one Keep a reference to the first object –And then walk down the list using a loop

Linked List Example Jill Joe Tom first Public static main (String[] argv) { Student first; … } Public class Student { int String name; public Student next; }

Linked List Operations Add an element –Easy to put it in sorted order Examine every element –Just as fast as using an array Find just one element –May be as slow as examining every element Delete an element after you find it –Fast if you keep both next and prior links

Linked List Insertion Jill Joe Tom first public void insert(String newName) { Student temp = first; boolean done = false; while (!done) { if ((temp.next==null) || (temp.next.name.follows(newName))){ Student new = new Student(name, temp.next); temp.next=new; done = true; } temp = temp.next; }}

Trees Linked list with multiple next elements –Just as easy to create as linked lists –Binary trees are useful for relationships like “<“ Insertions and deletions are easy Useful for fast searching of large collections –But only if the tree is balanced Efficiently balancing trees is complex, but possible

Binary Tree Example Jill Joe Tom root Public class Student { int String name; public Student left; public Student right; }

Data Structures in Java Resizable array [O(n) insertion, O(1) access]: –ArrayList Linked list [O(1) insertion, O(n) access, sorted]: –LinkedList Hash table [object index, unsorted, O(1)]: –HashSet (key only) –HashMap (key+value) Balanced Tree [object index, sorted, O(log n)]: –TreeSet (key only) –TreeMap (key+value)

Hashtables Find an element nearly as fast as in an array –With easy insertion and deletion –But without the ability to keep things in order Fairly complex to implement –But Java defines a class to make it simple Helpful to understand how it works –“One size fits all” approaches are inefficient

How Hashtables Work Create an array with enough room –It helps a lot to guess the right size first Choose a variable in each object as the key –But it doesn’t need to be an integer Choose a spot in the array for each key value –Using a fast mathematical function –Best if things are scattered around well Choose how to handle multiple keys at one spot

Java HashMap Class Hashtables are objects like any other –import java.util.* –Must be declared and instantiated The constructor optionally takes a size parameter put(key, value) adds an element containsKey(key) checks for an element get(key) returns the “value” object for that key

Stacks Maintain an implicit order –Last In-First Out (LIFO) Easy additions and deletions –push and pop operations Maps naturally to certain problems –Interrupt a task to compute an intermediate value Implemented as a Java class –import java.util.*

Choosing a Data Structure What operations do you need to perform? –Reading every element is typically easy –Other things depend on the representation Hashing finds single elements quickly –But cannot preserve order Stacks and linked lists preserve order easily –But they can only read one element at any time Balanced trees are best when you need both Which operations dominate the processing?

Rapid prototyping process Evaluate Refine Design Specification Identify needs/ establish requirements Build Prototype Final specification Exemplifies a user-centered design approach Start

Rapid Prototyping + Waterfall Update Requirements Choose Functionality Build Prototype Initial Requirements Write Specification Create Software Write Test Plan Project

A Disciplined Process Agree on a project plan –To establish shared expectations Start with a requirements document –That specifies only bedrock requirements Build a prototype and try it out –Informal, focused on users -- not developers Document the new requirements Repeat, expanding functionality in small steps

Characteristics of Good Prototypes Easily built (“about a week’s work”) –Intentionally incomplete Insightful –Basis for gaining experience –Well-chosen focus (DON’T built it all at once!) Easily modified –Facilitates incremental exploration

Prototype Demonstration Choose a scenario based on the task Develop a one-hour script –Focus on newly implemented requirements See if it behaves as desired –The user’s view of correctness Solicit suggestions for additional capabilities –And capabilities that should be removed

Requirements Approval Plan on between 12 and 50 iterations –For the class project, you’ll do only the first 3 –Adding about 10 new objects per iteration Use the project plan to enforce a deadline –New requirements shrink, but never disappear Schedule a formal approval demonstration –Allow one more iteration to fix any problems

Project Check-in What use cases have you identified? Can you prototype all of them in a week? –Leave a week for bug fixes, client review Any new requirements? What challenges, risks do you face?

Discussion: Pair Programming

Coming up Homework - No more! Project spec 1 –due tomorrow at 6:00 pm Proto 1 / Spec 2 –due Nov 9 Next week: –Testing & debugging –Swing Data Models

Muddiest Point On a blank sheet of paper, write a single sentence that will convey to me what you found to be the most confusing thing that was discussed during today’s class.

Java Containers Displayable windows –JFrame Subordinate windows (“dialogs”) –JOptionPane, JColorChooser, JFileChooser Grouping for layout management –JPanel Specialized containers –JScrollPane –JTabbedPane –JSplitPane Examples

Some Layout Managers BorderLayout: top, bottom, sides, center (default for JFrame) FlowLayout: rows, with “component wrap” (default for JPanel) GridLayout: graph paper, identical shapes BoxLayout: one column (or row) GridBagLayout: graph paper w/different shapes Examples

Exercise File Menu Help Book ListBook Details RequestRecallCheck out

Swing Controls JButton JToggleButton JRadioButton JCheckBox JList JMenuBar, JMenu, JMenuItem JComboBox (pop up menu) JTree JSlider JTextField, JTextArea

Display Elements JLabel Icon JProgressBar setToolTipText()