Introduction to Algorithms and Data Structures

Similar documents
Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Lecture 3: Variables and assignment

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

2: Basics of Java Programming

ECE 122 Engineering Problem Solving with Java

2 rd class Department of Programming. OOP with Java Programming

Chapter. Let's explore some other fundamental programming concepts

Chapter 1. Introduction

Computer Components. Software{ User Programs. Operating System. Hardware

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

COMP 202 Java in one week

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Welcome to COS151! 1.1

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Computers in Engineering COMP 208. A Brief History. Mechanical Calculators. A Historic Perspective Michael A. Hawker

Computers in Engineering COMP 208

CompSci 125 Lecture 02

Computer Components. Software{ User Programs. Operating System. Hardware

An overview of Java, Data types and variables

Data Representation and Applets

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Building Java Programs. Chapter 1: Introduction to Java Programming

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

3. Java - Language Constructs I

Pace University. Fundamental Concepts of CS121 1

Lab # 2. For today s lab:

Program Fundamentals

What did we talk about last time? Examples switch statements

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

The Java Language Rules And Tools 3

CS140 Lecture 09a: Brief History of Computing

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

Computer Basics. Computer Technology

Computer Hardware and Software Introduction. Mr. Smith AP Computer Science A

3. Java - Language Constructs I

Part (01) Introduction to Computer

Chapter 2. Elementary Programming

Course Outline. Introduction to java

Chapter 1. The Big Picture

Getting started with Java

You Will Need Floppy Disks for your labs!

COMP 202 Java in one week

Fundamentals of Python: First Programs. Chapter 1: Introduction Modifications by Mr. Dave Clausen

Programming in C++ 4. The lexical basis of C++

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Basic Programming Language Syntax

Building Java Programs. Introduction to Programming and Simple Java Programs

UEE1302 (1102) F10: Introduction to Computers and Programming

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

Chronological History of the Pre-Computer Developments

CSC 1214: Object-Oriented Programming

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Name: Date: Hour: The abacus (still in use today) is about 5,000 years old. Not a computer.

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

The trusted, student-friendly online reference tool. Name: Date:

Welcome to COSC Introduction to Computer Science

Computer Systems. Hardware, Software and Layers of Abstraction

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

AP Computer Science A: Java Programming

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Full file at

Selection Statements and operators

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Chapter 2: Data and Expressions

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

HISTORY OF CALCULATION. Evolution of Computation

CPS109 Computer Science 1

Monday, January 27, 2014

A Brief History of Computer Science

Selection Statements and operators

Section 2: Introduction to Java. Historical note

CS101 Lecture 29: Brief History of Computing

Data Representation and Applets

Week 2: Data and Output

Chapter 2: Programming Concepts

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

2011 Francisco Delgadillo

Data Representation and Applets

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Introduction Basic elements of Java

C H A P T E R 1. Introduction to Computers and Programming

Transcription:

Introduction to Algorithms and Data Structures CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this presentation are adapted from the slides accompanying Java Software Solutions by Lewis & Loftus

What is this course about? Computer Science Problem solving Algorithmic thinking Data representation Object oriented programming

Course website www.csc.villanova.edu/~map/1051/ Links to: Schedule topics, slides, projects, labs, code, etc. Syllabus course information Piazza class discussions, announcements Blackboard submit projects, check grades Peer Tutors extra help available for this course Exam archive past exams and quizzes & solutions

Our textbook Java Software Solutions John Lewis & William Loftus 9th Edition On reserve at the library Older Editions: (generally ok, except for graphics sections and some exercise numbers that may be different)

An old quote A priest asked: What is Fate, Master? And he answered: It is that which gives a beast of burden its reason for existence. It is that which men in former times had to bear upon their backs. It is that which has caused nations to build byways from City to City upon which carts and coaches pass, and alongside which inns have come to be built to stave off Hunger, Thirst and Weariness. And that is Fate? said the priest. Fate... I thought you said Freight, responded the Master. That's all right, said the priest. I wanted to know what Freight was too. - Kehlog Albran Source unknown. This quote appeared as one of the fortunes displayed by the fortune cookie program on old unix systems. ( fortune was a program that ran automatically every time you logged out of a unix session and displayed a random, pithy saying.)

Context: Reverse History of computing Examine what we already know, travel backwards 1. What we see now all around us a connected world of computing 2. Focus on a single traditional computer 3. Dig deeper data and processing

Computer Networks A network is two or more computers that are connected so that data and resources can be shared Local Area Network (LAN) / Wide Area Network (WAN) The Internet is a WAN which spans the planet The Internet Protocol (IP) determines how data are routed devices have unique IP addresses, e.g., 204.192.116.2 The World Wide Web provides a common interface to internet data: text, graphics, video, sound, audio, executable programs Web documents often use HyperText Markup Language (HTML) Uses Uniform Resource Locator (URL), eg: http://www.whitehouse.gov/issues/education A browser accesses network resources Popular browsers: Chrome, Internet Explorer, Safari, Firefox My first browser: Mosaic <3

Historical Note: Connecting the world The Internet History: Started as a United States government project, sponsored by the Advanced Research Projects Agency (ARPA) in late 1960 s See also: http://www.internethalloffame.org/internet-history/timeline 1970 s and 1980 s: ARPANET wide area network protocols for communication 1990 s: World Wide Web html and web browsers 1969: first four nodes of the internet Image source: http://www.computerhistory.org/internet_history/full_size_images/1969_4-node_map.gif

Historical Note: Connecting the world The Arpanet in 1971 Interface Message Processor (IMP) evolved into today s routers. Image source: http://www.computerhistory.org/internet_history/index.html

Reverse History of computing Examine what we already know, travel backwards 1. What we see now all around us a connected world of computing 2. Focus on a single traditional computer 3. Dig deeper data and processing

A Computer Specification Consider the following specification for a personal computer: 3.07 GHz Intel Core i7 processor 4 GB RAM 750 GB Hard Disk 16x Blu-ray / HD DVD-ROM & 16x DVD+R DVD Burner 17 Flat Screen Video Display with 1280 x 1024 resolution Network Card

Computer Architecture

Memory memory locations (or cells) identified by a unique numeric address jargon alert! Memory = Main Memory = Random Access Memory = RAM ( Random because you don t have to scan the memory sequentially go to data directly using the address) 9278 9279 9280 9281 9282 9283 9284 9285 9286 10011010

CPU and Main Memory Historical note: Von Neuman architecture John Von Neuman, USA 1945 Chip that executes program commands Central Processing Unit http://en.wikipedia.org/wiki/von_neumann Main Memory Primary storage area for programs and data that are in active use Synonymous with RAM

The Central Processing Unit A CPU is on a chip called a microprocessor It continuously follows the fetch-decode-execute cycle: Retrieve an instruction from main memory fetch execute decode system clock controls speed, measured in gigahertz (GHz) Carry out the instruction Determine what the instruction is

The Central Processing Unit Arithmetic / Logic Unit Performs calculations and makes decisions Control Unit Registers Coordinates processing (system clock, decoding, etc) Small, very fast memory

Historical Note: Automatic control of computation A machine that can follow a series of steps - a program Early efforts: Jacquard loom (France 1801) Babbage's Difference engine and Analytical engine (England 1822) Holerith's census machine (USA 1890) Image: http://www.biography.com/people/alan-turing-9512017

Historical Note: Automatic control of computation Jacquard Loom This portrait of Jacquard was woven in silk on a Jacquard loom using 24,000 punched cards (1839). Charles Babbage owned one of these portraits; it inspired him in using punched cards in his analytical engine. Collection of the Science Museum in London, England. (Source: Wikipedia) punched cards determine the pattern

Historical Note: Automatic control of computation Charles Babbage & Ada Lovelace Designed the Analytical Engine First Programmer for (not yet built) Analytical Engine

Historical Note: Automatic control of computation A machine that can follow a series of steps - a program 20 th Century it all comes together: Colossus Mark I first electronic computer to be programmable (Alan Turing, England 1944) Stored program and the fetch/decode/execute cycle (John von Neumann, USA 1945) ENIAC - first fully electronic digital computer (Eckert and Mauchley, University of Pennsylvania, 1946) Alan Turing Image: http://www.biography.com/people/alan-turing-9512017

Historical Note: Automatic control of computation 1945: The word computer changes its meaning Captain Grace Hopper and other computers The Electronic Numeric Integrator and Calculator (ENIAC) Programmers Betty Jean Jennings (left) and Fran Bilas (right) operate ENIAC's main control panel at the Moore School of Electrical Engineering. (U.S. Army photo from the archives of the ARL Technical Library)

Historical Note: Automatic control of computation 2014: Benedict Cumberbatch shows the world how cool Alan Turing was http://www.imdb.com/title/tt2084970/

Reverse History of computing Examine what we already know, travel backwards 1. What we see now all around us a connected world of computing 2. Focus on a single traditional computer 3. Dig deeper data and processing

Data Representation Computers store all information digitally, using binary codes: numbers text images audio video program instructions 9278 9279 9280 9281 9282 9283 9284 9285 9286 01110100

A byte is a group of eight bits 01110100 a number? a letter? the red component of a pixel? a program instruction? Computing devices store use binary codes to reprepresent data of all kinds

Example: Representing Text Characters, including spaces, digits, and punctuation are represented by numeric codes H i, H e a t h e r. 72 105 44 32 72 101 97 116 104 101 114 46 The ASCII (American Standard Code for Information Interchange) character set uses eight bits per character, allowing for 256 unique characters 01110100 ASCII 00000000 01110100 UNICODE The Unicode character set extends ASCII to sixteen bits per character, allowing for 65,536 unique characters.

Example: Representing Pixels red=116 green=86 blue=142 Color(01110100, 01010110, 10001110) CSC 1051 M.A. Papalaskari, Villanova University

Example: Representing Program Instructions Intel opcode for the instruction JZ (jump if zero): 01110100

Historical Note: Symbolic Representation & Mechanization of Arithmetic Development of number systems & geometry The notion of an algorithm Creation of special purpose calculators

Historical Note: Symbolic Representation & Mechanization of Arithmetic Basic human needs: counting & measuring http://www.dreamstime.com/royalty-free-stock-photography-counting-sheep-image129737 http://ghoststudy.com/new11_galleries/halloweve1067.jpg

Historical Note: Symbolic Representation & Mechanization of Arithmetic Basic human needs: Symbolism :-) π apple <3

Historical Note: Symbolic Representation & Mechanization of Arithmetic Development of number systems & geometry Abacus (China ~2400 BC) Number systems (Babylonian, Greek, Roman, Arabic 1000 BC - 800 AD) Geometry (Egypt/Greece 300 BC) images:"euclid Elements Book 3 Proposition 35 c" by Aldoaldoz - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons - https://commons.wikimedia.org/wiki/file:euclid_elements_book_3_proposition_35_c.png#/media/file:euclid_elements_book_3_proposition_35_c.png http://kids.britannica.com/elementary/art-86844/the-abacus-is-an-ancient-device-to-help-solve-math http://www.pelfusion.com/25-remarkable-roman-numeral-tattoos/

Historical Note: Symbolic Representation & Mechanization of Arithmetic The notion of an algorithm Euclid (300 BC) Muhammad ibn Musa al-khwarizmi (800 AD) images:http://www.thefamouspeople.com/profiles/euclid-436.php https://en.wikipedia.org/wiki/muhammad_ibn_musa_al-khwarizmi

Historical Note: Symbolic Representation & Mechanization of Arithmetic Creation of special purpose calculators Stonehenge (1900-1600 BC) Pascal's adder (1642) Leibniz's calculator (1670s) 1975 Texas Instruments calculator images: https://upload.wikimedia.org/wikipedia/commons/8/80/arts_et_metiers_pascaline_dsc03869.jpg http://www.livescience.com/22427-stonehenge-facts.html http://history-computer.com/mechanicalcalculators/pioneers/lebniz.html

Historical notes: Trends that gave rise to the modern computer Symbolic representation and the mechanization of arithmetic the concepts of numbers, symbols, algorithms, and computation + Automatic control of computation a program to control operations (fetch/decode/execute cycle and the stored program concept) + Connecting the world networks and telecommunications = modern computer

Welcome to Computer Science! A new paradigm that focuses humanity s search for understanding in the areas of: Symbolic representation Problem solving Algorithms Mechanization History Epilogue: This quest began in prehistoric times! But with the development of electronic computers in the 20th century, it all came together as a new field, much like the other sciences branched off from Philosophy during the renaissance. Today, computing is inseparable from the networked world that we see all around us, a world that it helped create, while it also continues to be about algorithms, about mechanization, about new ways solving problems and about symbolic representation (of numbers, and everything else).

What is this course about? Computer Science Problem solving Algorithmic thinking Data representation Object oriented programming

Java and other high-level programming languages Programmer writes Source code Translation produces Machine code (binary code suitable to run on the computer) Translation is performed by an assembler, compiler, or interpreter (stay tuned)

Java Program Structure In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements These terms will be explored in detail throughout the course A Java application always contains a method called main See Lincoln.java

Java Program Example //******************************************************************** // Lincoln.java Author: Lewis/Loftus // // Demonstrates the basic structure of a Java application. //******************************************************************** public class Lincoln { //----------------------------------------------------------------- // Prints a presidential quote. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ("A quote by Abraham Lincoln:"); } } System.out.println ("Whatever you are, be a good one.");

Java Program Structure // comments about the class public class MyProgram { class header class body } Comments can be placed almost anywhere

Java Program Structure // comments about the class public class MyProgram { // comments about the method public static void main (String[] args) { } method body method header }

Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Alternative ways of making Java comments: // This comment runs to the end of the line /* This comment runs to the terminating symbol, even across line breaks */

White Space (Spaces, blank lines, and tabs ) Extra white space is ignored Programs should be formatted to enhance readability, using consistent indentation See Lincoln2.java, Lincoln3.java

Development Environments There are many programs that support the development of Java software, including: Sun Java Development Kit (JDK) Sun NetBeans IBM Eclipse IntelliJ IDEA Oracle JDeveloper BlueJ jgrasp Though the details of these environments differ, the basic compilation and execution process is essentially the same

Java Translation Java source code Java bytecode Java compiler Bytecode interpreter Bytecode compiler Machine code

Basic Program Development Edit and save program errors? Compile program errors? errors? Execute program Evaluate results

Errors

Errors A program can have three types of errors The compiler will find syntax errors and other basic problems (compile-time errors) If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)

The original bug found in the relays of Harvard s Mark II computer by Admiral Grace Murray Hopper s team. Source: en.wikipedia.org/wiki/file:h96566k.jpg

Lab 1: Learn about jgrasp - the programming environment (IDE) that we will be using Compile. and run a java program Understand the relationship between a Java class name and file names Practice using basic Java output statements and adding comments Learn the basics of sequential execution, variables, and the assignment statement System.out.println ("Howdy " + name); System.out.println ("The answer is " + x); System.out.print ("Counting... up: " + (count + 1)); System.out.println ("... and\n... down: " + (count - 1)); Experience some errors!

Identifiers Identifiers are used for naming variables, classes, and other components of a program. An identifier can be made up of: letters (upper or lower case case sensitive!) digits (but cannot begin with a digit) underscore character ( _ ) the dollar sign ($) NOTHING ELSE! Example: Total, total, and TOTAL are different identifiers Conventions: use case to indicate whether it is a class or a variable etc.

Reserved Words These identifiers have a special meaning in Java and cannot be used in any other way: abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while

Character Strings A string literal is represented by putting double quotes around the text Examples: "This is a string literal." "123 Main Street" "X" spaces matter in here!

The println Method In the Lincoln program we invoked the println method to print a character string The System.out object represents a destination (the monitor screen) to which we can send output System.out.println ("Whatever you are, be a good one."); object method name information provided to the method (parameters)

The print Method In the Lincoln program we invoked the println method to print a character string The System.out object represents a destination (the monitor screen) to which we can send output print is similar to println except that it does not advance to the next line System.out.print ("Whatever you are, be a good one."); object method name information provided to the method (parameters)

String Concatenation The string concatenation operator (+) is used to append one string to the end of another "And one more " + "thing"

Hands on: Use MyQuote.java as a starting point (Lab 1), focus on this part of the code: System.out.println ("Howdy " + name); System.out.println ("The answer is " + x); System.out.print ("Counting... up: " + (count + 1)); System.out.println ("... and\n... down: " + (count - 1)); System.out.println("The perimeter of a circle with radius " + x + " is " + (2* pi * x)); Try the following: 1) Change pi to Math.PI (more accurate value for π) 2) What if you remove the parentheses around (count + 1)? 3) What does the \n do? What happens if we try this way of breaking a line: System.out.print ("Counting... up: " + (count + 1)); 4) How can we get all this output to print all in one line? Additional examples from textbook: Countdown.java Facts.java

Escape Sequences What if we wanted to print the quote character? e.g., System.out.println ("I said "Hello" to you."); // WRONG!!! An escape sequence is a series of characters that represents a special character. Example: System.out.println ("I said \"Hello\" to you."); Some Java escape sequences: Escape Sequence Meaning \t \n \" \' \\ tab newline double quote single quote backslash

Example from textbook: Roses.java //******************************************************************** // Roses.java Author: Lewis/Loftus // // Demonstrates the use of escape sequences. //******************************************************************** public class Roses { //----------------------------------------------------------------- // Prints a poem (of sorts) on multiple lines. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ("Roses are red,\n\tviolets are blue,\n" + "Sugar is sweet,\n\tbut I have \"commitment issues\",\n\t" + "So I'd rather just be friends\n\tat this point in our " + "relationship."); } Output } Roses are red, Violets are blue, Sugar is sweet, But I have "commitment issues", So I'd rather just be friends At this point in our relationship.

Quick Check Write a single println statement that produces the following output: "Thank you all for coming to my home tonight," he said mysteriously.

Summary History of computing Computer hardware and software overview An introduction to Java: Identifiers Comments Errors Strings and printing