Principles in Programming: Orientation & Lecture 1 1
Course Objectives Introduce various subjects in computer science through puzzles and problems Most problems came from ICPC 2
Introduction Instructor: Euiseong Seo Associate professor, Software Dept. Web page: http://csl.skku.edu/euiseong E-mail: euiseong@skku.edu Office: #85564 (5F of Industrial Collaboration Bldg.) Course Homepage http://csl.skku.edu/swe2004s15 Lab Thursday class #400222 Conducted by Two TAs 3
Course Elements 14 Lectures (once every week) (10%) 10 Programming Labs (20%) 2 Individual Programming Homework Assignments (15%) 1 Team Project (15%) Final Exam (40%) Most questions will be based on labs and assignments Programming 4
Textbook Programming Challenges by Steven S. Skiena and Miguel A. Revilla Springer You can download from the SKKU library 5
Course Rules (1/2) Cheating in exams machine check will receive an F for the course Late homework 10% penalty per day Cheating on homework will receive a 0 point 1% penalty for missing a lecture class 2% penalty for missing a Lab. 6
Course Rules (2/2) not attending a class includes not attending a class being late to a class leaving a class in the middle chatting in class having the mobile phone on in class if you sleep, you will die!! 7
Course Outline 8
Problem Solving Using C Basic Software Engineering Programming Patterns Problem Solving Techniques Practice 9
What You Need to Solve a Problem by Programming Programming Language Skills Correct rules Identifying rule violations Programming Skills Training on programming patterns Training on software engineering methods Problem Solving Skills Logical thinking 10
Programming Programming Is To Use the Dumb Computer To Solve a Problem That A Human Cannot Solve Fast Enough. The Computer Needs Very Very Very Precise and Detailed Instructions. The Instructions Must Be in a Programming Language, Not a Natural Language. 11
Natural Language What is 27.2 times 13.8? 12
Programming Languages Machine Languages Assembly Languages High-Level Languages 13
Machine Language 000000 00001 00010 00110 00000 100000 Add the registers 1 and 2 and place the result in register 6 100011 00011 01000 00000 00001 000100 Load a value into register 8, taken from the memory cell 68 after the location listed in register 3: 000010 00000 00000 00000 00100 000000 Jump to the memory address 1024: 14
Assembly Language MOV r0, #0C load base address of string into r0 LOAD: MOV r1,(r0) load contents into r1 CALL PRINT call a print routine to print the character in r1 INC r0 point to the next character JMP LOAD load next character 15
High-Level Language float length, width, area; length = 27.2; width = 13.8; area = length * width; 16
High-Level Languages Over 500 Languages ( http://en.wikipedia.org/wiki/list_of_programming_lang uages_by_category) Basic, FORTRAN, COBOL, RPG (Algol, Pascal, PL/1), C C++, C#, Java (ADA, Smalltalk, Eiffel) Perl, TCL, Java Script, PHP, Python, Ruby SNOBOL, LISP, (Scheme) MATLAB, (APL) Shell, Awk, REXX SQL, (Prolog), XML, Xquery, XSLT, Postscript, OWL 4GL UML Verilog, VHDL 17
Executing Programs 1. Compile Converting programs written in a high-level language into an assembly language or a pseudo code 2. Assemble Converting programs written in an assembly language into a machine language Interpret Running programs written in a high-level language with out compiling (one instruction at a time) 18
Programming Languages You Can Solve Any Problem Using Any Programming Language But Different Languages Are Designed To Serve Different Purposes Better. FORTRAN for scientific computations COBOL for business data processing LISP for list processing VisualBasic for user-interface programming SQL, PHP for database applications C++, Java for object-oriented software development C for most modern enterprise/scientific applications 19
Sample Problem: Game Strategy Alice and Bob are playing a board game. The board is divided into positions labeled a, b, c, d,... and the players use a gamepiece to mark the current position. Each round of the game consists of two steps: 1. Alice makes a choice. Depending on the current position, she has different options, where each option is a set of positions. Alice chooses one set S among the available sets of positions. 2. Bob makes a choice. His choice is one position p from the set S that Alice chose in step 1. Bob moves the gamepiece to position p, which is the position for the start of the next round. Prior to the first round, each player independently selects one of the positions and reveals it at the start of the game. Bob s position is where the game starts. Alice wins the game if she can force Bob to move the gamepiece to the position she has chosen. To make things interesting, they have decided that Bob will pay Alice a certain amount if he loses, but Alice must pay Bob a certain amount after every round. The game now ends if Alice s position is reached or when Alice runs out of cash. Both Alice and Bob play optimally: Alice will always choose an option that will lead to her winning the game, if this is possible, and Bob will always try to prevent Alice from winning. For all possible start and end positions, Alice would like you to determine whether she can win the game and if so, how many rounds it will take. 20
Sample Problem: Game Strategy Input The input consists of a single test case. The first line contains the number of positions n (1 apple n apple 25). The n positions are labeled using the first n letters of the English alphabet in lowercase. The rest of the test case consists of n lines, one for each position p, in alphabetical order. The line for position p contains the options available to Alice in position p. It starts with the number of options m (1 apple m<2 n ), which is followed by m distinct strings, one for each option. Each string contains the positions available to Bob if Alice chooses that option. The string has at least 1 character, the characters (which correspond to valid board positions) are in alphabetical order, and no characters are duplicated. The total number of options for the test case is at most 10 6. Output For each position p in alphabetical order, display one line. In that line, for each position q in alphabetical order display the minimal number of rounds in which Alice can be guaranteed to arrive at position q when starting the game in position p, or 1 if Alice cannot be guaranteed to reach q from p. 21
Sample Problem: Game Strategy Sample Input 1 Sample Output 1 2 2 ab b 1 b 0 1-1 0 Sample Input 2 Sample Output 2 3 1 b 2 b a 2 ab ac 0 1-1 1 0-1 2 2 0 22