CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.

Slides:



Advertisements
Similar presentations
CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative.
Advertisements

Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Written by: Dr. JJ Shepherd
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
CHAPTER 3 COLLECTIONS Abstract Data Types. 2 A data type consists of a set of values or elements, called its domain, and a set of operators acting on.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
CS503: Tenth Lecture, Fall 2008 Review Michael Barnathan.
Searching. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an element in it static.
CS 307 Fundamentals of Computer Science ADTS and Generic Data Structures 1 Topic 12 ADTS, Data Structures, Java Collections and Generic Data Structures.
Programming with Collections Grouping & Looping - Collections and Iteration Week 7.
Abstract Data Types and Encapsulation Concepts
CS 171: Introduction to Computer Science II Stacks Ymir Vigfusson.
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CIS Computer Programming Logic
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Invitation to Computer Science, Java Version, Second Edition.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Course: Object Oriented Programming - Abstract Data Types Unit1: IntroductionSlide Number 1 Introduction Course: Object Oriented Programming Abstract Data.
Introduction. 2COMPSCI Computer Science Fundamentals.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
CS 106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Introduction to Data Structures
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
CSC 212 – Data Structures Lecture 37: Course Review.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Types in programming languages1 What are types, and why do we need them?
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
CS 11 java track: lecture 2 This week: more on object-oriented programming (OOP) objects vs. primitive types creating new objects with new calling methods.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Written by: Dr. JJ Shepherd
CSC 205 Java Programming II Introduction. Topics Syllabus Course goals and approach Review I Java language fundamentals.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
Collections Using Generics in Collections. 2 Chapter Objectives Define the concept and terminology related to collections Explore the basic structure.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
Chapter 0: Introduction
Objects as a programming concept
Abstraction A tool (concept) to manage complexity
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
structures and their relationships." - Linus Torvalds
Introduction to Computer Science for Majors II
Review CSE116 2/21/2019 B.Ramamurthy.
Introduction to Data Structure
CSE 12 – Basic Data Structures
CS2013 Lecture 7 John Hurley Cal State LA.
structures and their relationships." - Linus Torvalds
Presentation transcript:

CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia Lee is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Based on a work at Permissions beyond the scope of this license may be available at LeeCreative Commons Attribution-NonCommercial 4.0 International Licensehttp://peerinstruction4cs.org

What do I do in class?  Think of me as your tutor  Be your guide in inducing you to explore concepts  Create situations and pose problems that set the scene for your exploration  Answer your questions  Not spend lecture reading the textbook to you with slightly different words 2

What do you do in class? (before class, you prepared yourself by reading; a reading quiz at the beginning of class will check your preparation) 1. I ask a question 2. You first answer it by yourself 3. Then discuss in assigned groups of 3-4 students  Like a jury, you must come to a unanimous decision  Answer the question a second time 4. I will ask groups to share their insights, and I will provide additional clarification as needed 3

Tips for a good group discussion  Take turns being the first one to talk  Once you all agree on the answer, don’t stop!  Always go over each wrong answer and explain why it is wrong  Also interesting and useful to think about why somebody might be tempted to choose it—how was Prof. Lovett hoping to “trick” somebody by including that wrong answer?  Even if your group-mate has said something very clearly and correctly, it’s a good idea to repeat it yourself  “So, what I think you said was, …”  Might seem pointless, but your brain will remember better if YOU say it too 4

Data Structures Map of the course

Course topics  Abstraction and Abstract Data Types (ADTs)  Application Programmer Interfaces (APIs)  Algorithm Time, Space, and Energy Cost Analysis  Object-oriented Software Design Patterns, including Inheritance, Composition, Adapter, and Iterator  Software Testing and the JUnit framework  Java Classes and Interfaces  Collections, and the Java Collections Framework  Java Generics  Arrays, Stacks, Queues, Circular Arrays  Searching and Sorting Algorithms  Trees, Heaps, Binary Search Trees, Abstract Syntax Trees  Hashing and Hash Tables

Abstraction o Abstraction means: o Hiding irrelevant details to focus on the essential features needed to understand and use a thing o Abstraction is an essential tool for managing complexity o Designing, implementing, and using complex systems would be impossible without abstraction 7

Group discussion  What is another good “daily life” example of abstraction?  Maybe I can use yours next quarter instead!

One kind of abstraction in Computer Science: Data Types o Specifying an Abstract Data Type ADT) requires specifying two things: o Possible values for instances of the type o Operations that can be performed on those instances o Does NOT require specifying: o How are those values and operations implemented? 9

ADT Implementers and Users  This kind of abstraction is very powerful.  The ADT can be implemented without having to know details of how it will be used (except that it will be used in accordance with its interface specification)  The ADT can be used without having to know the details of how it is implemented (except that it was implemented to satisfy its interface specification)  With any specification of an ADT interface: The ADT can be used infinitely many ways, and… The ADT can be implemented infinitely many ways!  This makes designing, implementing, using and maintaining software easier and more flexible 10

Example: a String ADT  You might define a String abstract data type along these lines:  Values: a String is a sequence of zero or more Unicode 1.0 characters  Operations: Create a String Add a character to the end of a String Say what character is at a particular position in a String …  What other operations might be good to specify for a String ADT? 11

ADTs are language-neutral  In CSE 12 we will concentrate on implementing ADT’s in Java  And we will consider many features of Java that are useful for implementing ADT’s  But always keep in mind that the basic principles of ADT design and analysis are language-neutral! 12 APIs are like ADTs, but specify the interface in a particular language  Users and impelmenters still do things as they please, but both within a common language

Application Programmer Interface (API)  The implementer of an ADT in a particular language is a programmer  And, usually, the client or user of an ADT is also a programmer in that language, who wants to use the ADT as a component in a larger software application  Therefore the interface to an ADT in a particular language is said to be the Application Programmer Interface, or API, for the ADT in that language 13

Checkpoint: ADTs and APIs  Which of the following would be elements of an ADT specification, and which would be elements of an API specification? I. int getValueAtIndex(int index) throws IndexOutOfBoundsException II. Get operation: given an index, returns the value at that index A. I is part of an API and II is part of an ADT B. II is part of an API and I is part of an ADT C. Both I and II could be part of an API or ADT D. Other 14

Discussion  ADTs and APIs exist to prevent users from knowing the implementation details (and vice versa). But…  Are there times when it would be useful to know the implementation details of an ADTs operations or values? Why?

Next time Abstraction, continued The Inheritance and Composition Patterns Intro to UML Intro to the Java Collections Framework (JCF) Intro to Unit Testing with JUnit Reading: Gray, Ch 1 and Ch 2 16

Thought of the Week “To be a good geek you have to have both humility and arrogance in equal measures. The humility is so you’ll admit you don’t know something and get help/read the docs/etc. The arrogance is the bit that says “I don’t know that now… but I can and I will soon.”” --Thomas Beagle, IT/programmer 17

Abstraction by interface The Application Programmer Interface (API) of List specifies everything an application programmer (client, user) needs to know in order to use a List. List insert(element) remove(element) find(element) isEmpty() public interface

Same interface, different uses Any client (user) can make use of a List through its public Application Programmer Interface (API) without knowledge of how the List is implemented.

Same interface, different implementations There are many possible implementations of any ADT. The implementation details are hidden from the user of the ADT, who can rely just on the ADT’s API.

User-defined data types in Java  Java has 8 primitive types : byte, short, int, long, char, float, double, boolean  And those are all there are: Java does not allow additional user-defined primitive types  If you want to define a type in Java, you must define either an interface, or a class  Often we will use both interfaces and classes when implementing an ADT in Java 21

ADT’s and Java classes  An ADT specifies the possible values that instances of the ADT can have, and the operations that can be performed on them  A Java class defines instance variables, and instance methods  So, there is a very close relationship between an ADT and a class!  Variables defined in the class correspond to ADT values  Methods defined in the class correspond to ADT operations 22

ADT’s and Java interfaces  Usually, instance variables should be private in a class They are considered part of the implementation, not to be accessed directly from outside the class  Then, we write public instance methods to manipulate the instance variables Mutator methods change the values of instance variables; Accessor methods just ‘read out’ the values This permits precise control over how the instance variables can be accessed and changed  So, the principle of abstraction suggests we can concentrate on the public instance methods  Java interfaces do that: they define a Java type, but specify only public instance method signatures (no method bodies, no instance variables) 23