CS1010 Programming Methodology A beginning in problem solving in Computer Science. Aaron Tan http://www.comp.nus.edu.sg/~cs1010/ 20 July 2015



Similar documents
Report on Game Design and Development Courses Meeting Knowledge Areas

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Course Syllabus. COSC 1437 Programming Fundamentals II. Revision Date: August 21, 2013

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Informatica e Sistemi in Tempo Reale

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

Sources: On the Web: Slides will be available on:

The C Programming Language course syllabus associate level

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

El Dorado Union High School District Educational Services

AP Computer Science Java Subset

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

COURSE SYLLABUS EDG 6931: Designing Integrated Media Environments 2 Educational Technology Program University of Florida

UNIVERSITY OF MACAU DEPARTMENT OF COMPUTER AND INFORMATION SCIENCE SFTW 463 Data Visualization Syllabus 1 st Semester 2011/2012 Part A Course Outline

Basic info Course: CS 165 Accelerated Introduction to Computer Science Credits: 8 Instructor: Tim Alcon timothy.alcon@oregonstate.

CP Lab 2: Writing programs for simple arithmetic problems

CS 40 Computing for the Web

Cabrillo College Catalog

#820 Computer Programming 1A

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

University of Dayton Department of Computer Science Undergraduate Programs Assessment Plan DRAFT September 14, 2011

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Unit title: Computer Games: Programming (SCQF level 6)

CS 261 C and Assembly Language Programming. Course Syllabus

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Education: P.h.D. Candidate (Santa Clara University, California) M.S. in Computer Engineering (Santa Clara University, California)

Major prerequisites by topic: Basic concepts in operating systems, computer networks, and database systems. Intermediate programming.

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

J a v a Quiz (Unit 3, Test 0 Practice)

Basic Programming and PC Skills: Basic Programming and PC Skills:

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs

Course MS10975A Introduction to Programming. Length: 5 Days

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

Exploring Computer Science A Freshman Orientation and Exploratory Course

CS 241 Data Organization Coding Standards

Syllabus for CS 134 Java Programming

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

C++ Programming Language

PHP Tutorial From beginner to master

Computer Science Course Descriptions Page 1

Programming and Software Development CTAG Alignments

Programming with the Dev C++ IDE

The programming language C. sws1 1

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

Help on the Embedded Software Block

if and if-else: Part 1

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

02-201: Programming for Scientists

NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department. COURSE: CST2403 C++ Programming Part 1 ( 4 hours, 3 credits )

An Incomplete C++ Primer. University of Wyoming MA 5310

Introduction to Java

MICHIGAN TEST FOR TEACHER CERTIFICATION (MTTC) TEST OBJECTIVES FIELD 050: COMPUTER SCIENCE

Introduction to Programming System Design. CSCI 455x (4 Units)

Java Application Developer Certificate Program Competencies

COS 217: Introduction to Programming Systems

Some programming experience in a high-level structured programming language is recommended.

UNDERGRADUATE DEGREE PROGRAMME IN COMPUTER SCIENCE ENGINEERING SCHOOL OF COMPUTER SCIENCE ENGINEERING, ALBACETE

CISC 181 Project 3 Designing Classes for Bank Accounts

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Conditionals (with solutions)

Course Descriptions. preparation.

Algorithm and Flowchart Structured Programming 1

VB.NET Programming Fundamentals

Pseudo code Tutorial and Exercises Teacher s Version

El Dorado Union High School District Educational Services

COMP[29]041 - Software Construction 15s2. Course Goals. Course Goals. 41 Introduction 15s2]COMP[29]041 Introduction 15s2

Computer Programming I

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

AP Computer Science AB Syllabus 1

Teaching large lecture classes online: Reflections on engaging 200 students on Blackboard and Facebook

CS 6371: Advanced Programming Languages

School of Computing and Information Sciences. Course Title: Computer Programming III Date: April 9, 2014

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Florida National University Online Courses Platform

Debugging with TotalView

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

2. Basis for computing design and implementation at all levels through OS, distributed systems, human interface and computer graphics.

1.3 Conditionals and Loops

CS135 Computer Science I Spring 2015

Teaching Scheme. Theory Practical Course Code L T P Credits Max. Min. Max. Min. ISE MA201 Linear Algebra 3 1-4

Master of Science (M.S.), Major in Software Engineering

COMM 430 / DIGITAL DESIGN / SPRING 2015

1 Introduction. 2 Overview of the Tool. Program Visualization Tool for Educational Code Analysis

Computer and Information Sciences

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

CMSC Fundamentals of Computer Programming II (C++)

COMPUTER SCIENCE (5651) Test at a Glance

50 Computer Science MI-SG-FLD050-02

Computer Programming I & II*

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Software development and programming. Software

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Transcription:

CS1010 Programming Methodology A beginning in problem solving in Computer Science Aaron Tan http://www.comp.nus.edu.sg/~cs1010/ 20 July 2015

Announcements This document is available on the CS1010 website http://www.comp.nus.edu.sg/~cs1010 /4_misc/freshmen.html 2

Announcements Choosing CS1101S over CS1010 URL: https://register.comp.nus.edu.sg/ugoffice4 Deadline: 23 July 2015, Thursday, 6pm Default: CS1010 (No action needed if you decide to take CS1010) No bidding queue in CORS for both CS1010 and CS1101S Students from IS Dept are precluded from taking CS1101S DDP students in CS and Maths/Applied Maths will be pre-allocated CS1101S Diploma holders who are exempted CS1010 will be pre-allocated CS1020 For more details, please contact SoC Undergraduate Office @ COM1, Level 2, Room 19 3

Computer Science Curricula 2013 Ironman draft identifies 18 knowledge areas (http://ai.stanford.edu/users/sahami/cs2013/ironman-draft/cs2013-ironman-v1.0.pdf) AL - Algorithms and Complexity AR - Architecture and Organization CN - Computational Science DS - Discrete Structures GV - Graphics and Visual Computing HCI - Human-Computer Interaction IAS Security and Info Assurance IM - Information Management IS - Intelligent Systems P = NP? NC Networking and Communication OS - Operating Systems PBD Platform-based Development PD Parallel and Distributed Computing PL - Programming Languages SDF S/W Dev. Fundamentals SE - Software Engineering SF Systems Fundamentals SP - Social and Professional Issues O(n 2 ) 4

CS1010 Introduces the fundamental concepts of problem solving by computing and programming using an imperative programming language. Outcomes C as a tool Solve simple algorithmic problems Write good small programs Not just about C 5

Programming Language constructs Problem solving Coding 6

A C Program (welcome.c) // Author: Aaron Tan // Purpose: Ask for user s name and display a welcome message. #include <stdio.h> int main(void) { char name[20]; printf("what is your name? "); scanf("%s", name); printf("hi %s.\n", name); printf("welcome to CS1010!\n"); return 0; } library What is your name? Aaron Hi Aaron. Welcome to CS1010! Input Outputs 7

Problem Solving Process Determine problem features Write algorithm Produce code Check for correctness and efficiency Analysis Design Implementation Testing Rethink as appropriate 8

Your Friendly CS1010 Lecturers Prof. Wynne Hsu Dr Zhao Jin Office: COM2 #03-05 whsu@comp.nus.edu.sg Office: COM2 #02-50 zhaojin@comp.nus.edu.sg 9

CS1010: Sectional and Discussion Groups Sectional groups (SGs) Small lecture group (< 40 students) Conducted in programming labs; 3 hours per week Discussion groups (DGs) Even smaller groups (about 13 students) CS1010 way of calling tutorial groups Conducted in labs; 2 hours per week Your SG and DG will be pre-allocated to you. All groups cover the SAME syllabus, and have common tests, and all students are graded together as a whole. Grading NOT by bell curve. 10

Workload (4 MCs) Lectures: 3 hours/week in a lab setting. Discussion sessions: 2 hours/week in a lab setting. Continual assessment: Take-home lab assignments 2 Practical Exams (Saturdays) Term Test (Saturday) Final Exam 11

A Peek at a Lecture Session (1/2) Lecturer s screen is broadcast to every student s monitor. Interacting with students always makes me happy. 12

A Peek at a Lecture Session (2/2) Explaining how to edit and compile a program. Discussing MasterMind. 13

Module Website http://www.comp.nus.edu.sg/~cs1010 14

IVLE https://ivle.nus.edu.sg Watch out for announcements Participate in the forums Multimedia videos 15

Mid-Semester Review Topics in C covered so far Basic C program structure main() function Variable declarations Data types (int, float, double, char) Arithmetic operations (+,-,*,/,%) Input/output functions (scanf(), printf()) Preprocessor directives #include #define Control structures Sequential statements Selection statements Relational operators (<, <=, >, >=, ==,!=) Logical operators (&&,,!) Conditional operator (? :) Integer as boolean if, if-else, switch Repetition statements while, do-while, for Functions Return type Parameters Function prototypes Scope of variables/parameters Pointers Arrays 16

Mid-Semester Review Topics in C Program development Programming environment/tools Operating system: UNIX Editor: vim Debugger: gdb Writing pseudocodes Edit compile execute cycle Step-wise refinement Hand-tracing codes Incremental coding Testing Debugging Problem solving Class exercises Practice exercises Lab assignments 17

Algorithmic Problem Solving #1: Coin Change Given these coin denominations: 1, 5, 10, 20, 50, and $1, find the smallest number of coins needed for a given amount. You do not need to list out what coins are used. Example 1: For 375 cents, 6 coins are needed. Example 2: For 543 cents, 10 coins are needed. 18

Algorithmic Problem Solving #1: Coin Change Algorithm: input: amt (in cents) output: coins coins 0 coins += amt/100; amt = remainder of amt/100; coins += amt/50; amt = remainder of amt/50; coins += amt/20; amt = remainder of amt/20; coins += amt/10; amt = remainder of amt/10; coins += amt/5; amt = remainder of amt/5; coins += amt/1; amt = remainder of amt/1; print coins 19

Algorithmic Problem Solving #2: Maximum Sum of Path in a Pyramid 5 5 5 3 1 3 1 3 1 2 3 8 2 3 8 2 3 8 5 2 4 3 5 2 4 3 5 2 4 3 Figure 1. (a) A pyramid of integers. (b) A path with sum of 13. (c) A path with sum of 18. 20

Maximum Sum of Path in a Pyramid 5 38 16 10 2 11 3 14 8 15 5 13 2 18 4 17 3 21

Maximum Sum of Path in a Pyramid 5 38 16 10 2 11 3 14 8 15 5 13 2 18 4 17 3 Search for largest value in last row. r = 1 r = 3 r = 2 int maxpathvalue(int arr[][max_rows], int size) { int r, c, max; } for (r = 1; r < size; r++) { arr[r][0] += arr[r-1][0]; // left-most item for (c = 1; c < r; c++) { if (arr[r-1][c-1] > arr[r-1][c]) arr[r][c] += arr[r-1][c-1]; else arr[r][c] += arr[r-1][c]; } arr[r][r] += arr[r-1][r-1]; // right-most item } // find maximum in last row max = arr[size-1][0]; for (c = 1; c < size; c++) if (arr[size-1][c] > max) max = arr[size-1][c]; return max; 22

Maximum Sum of Path in a Pyramid 18 5 r = 0 10 3 13 1 72 73 12 8 r = 1 5 2 4 3 r = 2 Why not from bottom to top? int maxpathvalue(int arr[][max_rows], int size) { int r, c; for (r = size-2; r >= 0; r--) { for (c = 0; c <= r; c++) { if (arr[r+1][c] > arr[r+1][c+1]) arr[r][c] arr[r][c] += (arr[r+1][c] += arr[r+1][c]; > arr[r+1][c+1])? else arr[r+1][c] : arr[r+1][c+1]; arr[r][c] += arr[r+1][c+1]; } } } return arr[0][0]; 23

Algorithmic Problem Solving #3: Mad Scientist A mad scientist wishes to make a chain out of plutonium and lead pieces. There is a problem, however. If he places two pieces of plutonium next to each other In how many ways can he safely construct a chain of length 6? General case: What about length n? 24

Algorithmic Problem Solving #3: Mad Scientist Length #ways 1 2 3 4 5 6? n 25

Algorithmic Problem Solving #4: Sudoku 26

Algorithmic Problem Solving #5: MasterMind (1/2) Sink: Correct colour, correct position Hit: Correct colour, wrong position Secret code Sinks Hits Secret code Sinks Hits Guess #1 1 1 Guess #1 1 0 Guess #2 1 2 Guess #2 0 1 Guess #3 2 2 Guess #3 1 0 Guess #4 4 0 Guess #4 1 1 27

Algorithmic Problem Solving #5: MasterMind (2/2) 6 colours: R: Red B: Blue G: Green Y: Yellow C: Cyan M: Magenta Given a secret code (secret) and a player s guess (guess), how do we compute the number of sinks and hits? 28

CS1010 versus CS1101S The differences CS1010 CS1101S MC 4 5 Language Imperative PL (C) Functional PL (Javascript) Enrolment 160 110 Lecture mode In lab In LT/seminar room The similarities Small-group teaching Assume no programming background Expect students to put in much effort; independent learning 29

What to Prepare Before Class Starts? Check out CS1010 website http://www.comp.nus.edu.sg/~cs1010 Read document Intro Workshop: Getting Started with UNIX and CodeCrunch) (http://www.comp.nus.edu.sg/cs1010/3_a/labs.html) Learn UNIX Learn vim 30

Attitude is Everything Your attitude, not your aptitude, will determine your altitude. If you think you can, you can. If you think you cannot, you are right. Don t complain about heavy workload. Work hard, REALLY hard! 31

We are doing everything we can to help you Exercises during sectional teaching Exercises during discussion sessions Practice exercises on CodeCrunch On-line quizzes IVLE forums Help sessions 32

Announcements Choosing CS1101S over CS1010 URL: https://register.comp.nus.edu.sg/ugoffice4 Deadline: 23 July 2015, Thursday, 6pm Default: CS1010 (No action needed if you decide to take CS1010) No bidding queue in CORS for both CS1010 and CS1101S Students from IS Dept are precluded from taking CS1101S DDP students in CS and Maths/Applied Maths will be pre-allocated CS1101S Diploma holders who are exempted CS1010 will be pre-allocated CS1020 For more details, please contact SoC Undergraduate Office @ COM1, Level 2, Room 19 33

Announcements This document is available on the CS1010 website http://www.comp.nus.edu.sg/~cs1010 /4_misc/freshmen.html 34

Have a GREAT TIME in School of Computing! 35