15-121 Introduction to Data Structures 1 September 2020 Margaret - - PowerPoint PPT Presentation
15-121 Introduction to Data Structures 1 September 2020 Margaret - - PowerPoint PPT Presentation
15-121 Introduction to Data Structures 1 September 2020 Margaret Reid-Miller Today Course Logistics Course Topics A (very basic) Java introduction Course website: https://www.cs.cmu.edu/~mrmiller/15-121 Fall 2020 15-121
Fall 2020 15-121 (Reid-Miller) 2
Today
- Course Logistics
- Course Topics
- A (very basic) Java introduction
- Course website:
https://www.cs.cmu.edu/~mrmiller/15-121
Fall 2020 15-121 (Reid-Miller) 3
Me
Margaret Reid-Miller mrmiller@cs.cmu.edu Gates 6003, x 8-2640 I am an
- Assistant Teaching Professor
- CS Upperclass Academic Advisor
What to call me? Margaret, please (or formally, Professor Reid-Miller)
You
- Take 15-121 if you are an IS major, or if you don’t
plan to take CS core courses.
- Take 15-122 if you are a CS or ECE major or minor,
- r plan to take more CS classes.
- Why learn Java?
- One of the most common languages used in
industry.
- Used for large applications
- It's objected-oriented.
Fall 2020 15-121 (Reid-Miller) 4
Fall 2020 15-121 (Reid-Miller) 6
Office Hours
For extra help on the class material or assignments you may reach
- ut to our two Teaching Assistants or me.
Office Hours: (tentatively) Sean Tavares (TA): Saturday 2:00 pm – 4:00 pm Leah Watko (TA): Sunday 2:00 pm – 4:00 pm Margaret: Monday 10:00 am – 12:00pm (noon) Other times by appointment Assignments are due Monday nights. What office-hour times are best for you?
OHQueue
- During office hours, when you have a question open
your personal Zoom meeting.
- Go to the OHQueue (see webpage sidebar) and
select 15-121 P (not 15-121 Q). It may be the last in the list.
- (You can pin 15-121 P to the top of the list by clicking
the red asterisk.)
- Include a link to your Zoom meeting in the Question
part.
- When it is your turn a TA or I will join your Zoom
meeting to help you.
Fall 2020 15-121 (Reid-Miller) 7
Prerequisites
- Formally: 15-112
- You will need:
- Laptop or desktop computer
- The Java JDK and an editor or IDE
– Eclipse (what I will use in class) – DrJava (only runs Java 6 on Mac) Under Resource, see Extra Help for instructions on how to install Java JDK and Eclipse
Fall 2020 15-121 (Reid-Miller) 8
Why Data Structures?
Data structures are ways to organize and store data and perform operations on the data efficiently.
- Understand and create new algorithms
- Analyze algorithms (time/space efficiency)
- Which data structures we use will depend on
- What operations we expect to perform often on our
data.
- What are performance tradeoffs for access/update.
- Efficient algorithms are essential with big data.
(Think Google, databases, Amazon, Facebook,…)
Fall 2020 15-121 (Reid-Miller) 9
Introduction to Data Structures
- This course provides a foundation for organizing
large data sets for efficiency. Two parts:
- Conceptual information about various data structures
- How to use and implement those data structures in
your programs.
- We assume you know how to write programs using
fundamental programming concepts (variables, booleans, conditional, loops, functions, lists, …)
Fall 2020 15-121 (Reid-Miller) 10
Course elements
- Lectures: Notes and code will be posted to
website
- Participation – 5%
- Recitation labs – 5%
- Quizzes – 10%
- Homework – 40%
- 2 Midterms – 20%: 10% each
- Final – 20%
Fall 2020 15-121 (Reid-Miller) 11
Lectures over Zoom
- Recordings will be put on Canvas
- Be prepared to take notes, and have paper and
pen/pencil. I often ask you to write code or draw figures, and may ask you to turn in what you write.
- Answer and ask lots of questions (It helps your
classmates who are equally curious and it gives me feedback.)
Fall 2020 15-121 (Reid-Miller) 12
Participation 5%
- You must attend lectures, ask questions, and
submit in-class exercises.
- If you miss a couple of days of class, you may
still earn 100% for participation.
- If you miss class half the time, you will earn
0% for participation.
- If attending lectures synchronously is difficult,
please email me to make alternative arrangements.
Fall 2020 15-121 (Reid-Miller) 13
Wednesday Recitations 5%
- In person and remote
- There will be (~12) weekly labs of short coding
- exercises. Only 10 count towards your grade.
- You must attend and participate to get credit.
- You are encouraged to work collaboratively.
- Submitting after class will not be accepted.
- I will post solutions after class.
Tomorrow’s recitation, though, will be a lecture!
Fall 2020 15-121 (Reid-Miller) 14
Homework 40%
- There will be weekly assignments that include a
written portion and programming.
- Due Monday nights at 11:59 pm.
- You are allowed up to 4 late days total without
penalty, with a maximum of 2 late days per assignment.
- No credit will be given for late work after you have
used up all your late days.
- I recommend you submit often (even if incomplete)
- ne day before and again one hour before its due.
Fall 2020 15-121 (Reid-Miller) 15
Quizzes 10%
- Most weeks on Thursday there will be short
quiz (15-20 minutes).
- It will test the previous week’s work.
- We will drop your lowest TWO quizzes.
- There will be no make-up quizzes for any
reason.
Fall 2020 15-121 (Reid-Miller) 16
2 Written Midterms 10% each
- Midterm Exams will be in class on
- Thursday, Oct 8
- Tuesday, Nov 9
(Dates may change, see schedule)
- No makeup exams except by prior approval
by me for
- medical or family emergencies
- pre-arranged university-approved
absences
Fall 2020 15-121 (Reid-Miller) 17
Final Exam 25%
- During final exams.
- We will not proctor the final exam prior to the
registrar scheduled exam (makeup day is Dec 21).
Fall 2020 15-121 (Reid-Miller) 18
Disabilities
- If you suspect or have a documented
disability, you may be eligible to receive accommodations from the Office of Disability Resources (access@andrew.cmu.edu)
- Please use their online system to notify me
and to discuss your needs early in the semester.
Fall 2020 15-121 (Reid-Miller) 19
Fall 2020 15-121 (Reid-Miller) 20
Today
ü Course Logistics ➤Overview of Course
- A (very basic) Java introduction
Course Topics
- Java Objects, Arrays, ArrayLists, Efficiency
- Big-O, Linked Lists, Recursion,
- Interfaces, Iterators, Stacks & Queues
- Searching & Sorting, Trees, BSTs, Recursion
- Sets & Maps, Hashing, Priority Queues,
- Heaps, (Graphs), Review & Final Exam
Fall 2020 15-121 (Reid-Miller) 21
Fall 2020 15-121 (Reid-Miller) 22
Today
ü Course Administration ü Overview of Course ➤A (very basic) Java introduction
The image part with relationship ID rId3 was not found in the file.Executing Code
- Java and Python are high-level programming languages
(human readable) created in a text editor.
- Programs in high-level languages (source code)
cannot be run by the computer directly.
- Program translation converts source code to a low-level
target language.
- This target or machine code uses only a small set of
instructions specific to the machine.
- Run-time is the period when the computer is executing
commands.
- The operating system copies the machine code from
disk to memory and starts running it directly.
Fall 2020 15-121 (Reid-Miller) 23
Program Translation
- Compiler is a program that translates code in a high-
level source language, all at once, into low-level target language.
- E.g., Java is compiled to bytecode.
- The source code is translated only once.
- The target code can be executed many times.
- Interpreter - program that translates each statement
and then executes it, one at a time, much like a human interpreter
- E.g., Python is interpreted, also to bytecode
Fall 2020 15-121 (Reid-Miller) 24
Traditional Compilation
Fall 2020 15-121 (Reid-Miller) 25
Windows Intel Linux HP Linux IBM Mac OS X iMac Source code Machine code Machine code Machine code Machine code compile Source code Source code Source code Different hardware/operating systems need slight variants of each program and separate compilers.
Java Translation
Fall 2020 15-121 (Reid-Miller) 26
JVM - Java Virtual Machine
JVM Linux HP Windows Intel Linux IBM Mac OS X iMac
Game.java Game.class (bytecode)
Compile (or compile) Interpret JVM JVM JVM Java compiles to a single “virtual” machine.
Types of Programming Errors
- Compile-time errors - Syntax errors found by the
compiler or syntax-aware editors (e.g., Eclipse).
- e.g., x - * y =
- Run-time errors - Error causes program to stop
abnormally; often called an exception.
- e.g., x = y / z (What if z is zero?)
- Logical errors - Program produces incorrect results
without complaint.
- e.g., Sort program that runs to completion but
does not always sort the data
Fall 2020 15-121 (Reid-Miller) 27
Java vs Python Syntax
- In Python, indentation is semantic (has meaning)
- E.g., indentation delimits statement blocks
- In Java, indentation is recommended
- We require it in this class, however, for style
and readability.
- Instead, in Java statement blocks are surrounded
by curly braces {} and most statements end in semi-colons.
Fall 2020 15-121 (Reid-Miller) 28
Java program structure
- Every Java program consists of one or more
classes:
- Each class contains methods:
– Each method contains the statements to execute
- Everything is Java must have a type.
- Every Java program starts its execution at a
method called main.
Fall 2020 15-121 (Reid-Miller) 29
public class <name> { <method> <method> … <method> }
All Java code are inside classes
- The basic form of a Java class is at follows:
Fall 2020 15-121 (Reid-Miller) 30
Keywords are in purple Same name as the file name
Every Java program must have a method named main
- The program execution starts at the main method.
Fall 2020 15-121 (Reid-Miller) 31
public static void main (String[] args) { <statement> <statement> … <statement> } method header grouping characters return type argument type
A simple program
/* * Prints three lines to the console. */ public class DreamDisplayer { public static void main(String[] args) { System.out.println("When I grow up ... "); System.out.println(); // blank line System.out.print("I want to be "); System.out.println(”an astronaut."); } }
Fall 2020 15-121 (Reid-Miller) 32
Comments println: adds newline at end. print: stays on same line System.out: where to find the method. Statements end with semicolons
OUTPUT: When I grow up ... I want to be an astronaut.
Our first program
- Your first homework is to do 20 problems on
- CodingBat. It is due next Tuesday at
11:55pm (a day later than usual)
- Let’s use CodingBat to write our first Java
program.
Fall 2020 15-121 (Reid-Miller) 33