1.31k likes | 1.41k Views
60-140-01 Introduction to Algorithms & Programming I. Dr. Robert D. Kent Winter 2009. Course Description. This course is the first of a two-course sequence designed to introduce students to algorithm design and programming in a high-level language such as C.
E N D
60-140-01Introduction toAlgorithms & Programming I Dr. Robert D. Kent Winter 2009
Course Description • This course is the first of a two-course sequence designed to introduce students to algorithm design and programming in a high-level language such as C. • The main objectives of the course are to develop the ability to identify, understand and design solutions to a wide variety of problems. • Topics include: computer system overview, hardware and software, problem solving steps, concepts of variables, constants, data types, algorithmic structure, sequential logic, decisions, loops, modular programming, one-dimensional arrays, text files. • If possible, problems like searching/sorting will be addressed.
60-140-01Course Outline – It Matters Dr. Robert D. Kent Winter 2009
Course Outline – It matters! • Instructor: Dr. Robert D. Kent • Email: rkent@uwindsor.ca (Preferred) • Office: 5100 Lambton Tower • Phone: 519-253-3000 ext. 2993 (Email preferred) • Office Hours: Tuesday & Thursday 11:00am – 2:00pm (subject to cancellation without notice; or by appointment) • Lab Instructor: Ritu Chaturvedi (rituch@uwindsor.ca) • Note: Only email originating from a valid University of Windsor student account will be accepted from students wishing to contact the instructor. Please include your full name and student ID in your correspondence.
Course Outline (continued) • Graduate Teaching Assistants: • GA’s help in the labs and students should ask questions • GA’s will evaluate lab work, mark assignments and examinations (under the supervision of the instructor) • GA’s will hold consulting office hours at times and places to be announced • The GA staff (email addresses on outline): • Luo, Fangyun • Mabroukeh, Nizar • Soleimani, Ahmad • Wang, Zhuo
Course Outline (continued) Pre-Requisities: • This is an introductory level course with no pre-requisites and is required for all programs leading to a degree in Computer Science (including combined degrees). This course may be required by certain other programs. • Students who have taken courses in Computer Science in secondary school may find some material to be review; however, students are strongly advised that the required depth and breadth of coverage of topics in this course, as well as the expectations of required performance in labs, assignments and examinations may be very challenging in comparison with secondary school courses. • Students may require special permission to take this course as it is intended, in the first instance, for students in the MCA program of study.
Course Outline (continued) • LABS: You must register in one of the following sections: • Section 51-53 (Note: 54 is on HOLD) • All labs are held in the West Leddy Libary Room 305 • NOTE: Laboratory attendance is mandatory. Labs start on Monday January 12. You must have a working student computer account before coming to the lab. You can obtain a UWINID account from the Computer Centre or call ITS ext. 4440.
Course Outline (continued) • Required Textbook: • Deitel, H.M. and Deitel P.J. C How To Program, 5th Edition. Prentice-Hall: New Jersey. • NOTE: Earlier editions of the textbook may be used, but all references to the textbook will apply to the 5th edition. • Some students may wish to use another textbook. There are many good texts covering C programming and algorithms, but they are not supported in this course.
Course Outline (continued) • Evaluation Scheme: • 17% Midterm #1 (in class – 75 minutes) • 17% Midterm #2 (in class – 75 minutes) • 45% Final Exam (Location TBA by Instructor) • 10% Laboratory (Mandatory Attendance, Lab Exercises, Quizzes and Lab Exams) • 10% Assignments • 1% Lecture attendance and participation (in class, up to 3 randomly selected classes by the instructor without prior notice, and/or up to 3 unannounced Quizzes) • NOTE: Consistent with University Senate Bylaws, no required (ie. marked) work will be assigned to students during the last 3 days of Intersession lectures, nor will any assigned work come due for submission during this same period.
Course Outline (continued) • Assignments and projects (eg. Lab exercises) are expected to be completed on the assigned due date and time. • LATE ASSIGNMENTS ARE NOTACCEPTED. You must allocate enough time to complete the assignments; start early and report difficulties to the instructor. • UNDOCUMENTED CODE WILL NOT BE GRADED and will receive a mark of zero. • Failure to submit the work in the correct format will be penalized. (i.e. incorrect email subject or unreadable/missing file attachments as instructed, etc…). • All submitted work MUST be prepared and must be compilable and executable on the Computer Science servers.
Course Outline (continued) • THERE IS NO MAKE-UP EXAM FOR MIDTERMS. • Missing a test or an exam will greatly affect your grade since they carry a lot of weight. In the case of illness or serious and unavoidable reason (as per the Senate Bylaws), please consult with the instructor in advance, if possible, to make alternate arrangements. You must formally inform the instructor in writing and present proper supporting documents (stating that the student was unable to attend the exam at the specified time and date) within a week from the midterm or earlier to be verified. • If the reason is deemed valid, the weight of the midterm will be added to that of the final exam. (i.e. the final exam’s weight will increase to include the missed midterm weight). All students are required to write and PASS the final exam in order to pass the course.
Course Outline (continued) • NO MAKE-UP FINAL EXAMINATION. • Students who miss the Final Examination due to valid reasons will normally be required to write the Final Examination in the next semester the course is offered (eg. Fall 2008). • Keep in mind that non-completion of a pre-requisite course will prevent students from progressing in their program of study.
Course Outline (continued) • PLAGIARISM: Should the instructor or grader find a reason for suspicion – or just cause – in plagiarized student work (assignment, lab or test), the work in question will not be graded and the student(s) will have to answer to the department’s Director and the Dean of Science. Refer to the University’s policy on Plagiarism in the Senate Bylaws. This issue is taken extremely seriously and students who are found guilty of plagiarism may suffer considerable short and long term negative effects. • Students who submit semantically equivalent assignments [or labs] (in other words, the same thing to within trivial modifications) will receive a grade of zero on ALL assignments [or labs].
Course Outline (continued) • All students should keep the instructor informed about their difficulties with the course. To the extent possible, students should contact the instructor outlining their problems with the course. Most consultations will be by e-mail or in person. • What you learn today, you must practice at for tomorrow! This course is a vital pre-requisite for other courses – some in the next semester (eg. 60-141) and others in Years 2, 3 or 4. • Pre-requisite does not just refer to Calendar course regulations; it really means retaining a core basis of understanding and competency over time (ie. don`t forget what you`ve learned, just because you haven`t had a course recently).
Course Outline (conclusion) • A University of Windsor graduate will have the ability to demonstrate: • the acquisition, application and integration of knowledge • research skills, including the ability to define problems and access, retrieve and evaluate information (information literacy) • critical thinking and problem-solving skills • literacy and numeracy skills • responsible behaviour to self, others and society • interpersonal and communications skills • teamwork, and personal and group leadership skills • creativity and aesthetic appreciation • the ability and desire for continuous learning
Computers, Systems and Networks Lecture 1A
Overview and Motivation To begin, let’s reflect on what we might know. Then we’ll consider what we might be able to do if we learn more.
Computers, Systems and Networks • Computer system overview • Hardware and software • Operating systems • Application programs • Editors and compilers • Programs • Programming paradigms and languages • The Internet and World Wide Web
Computer system overview • Modern computing systems consist of hardware devices and software logic • Hardware • Dedicated microprocessors and sensors • Storage • Fully integrated personal and server computers • Networks interconnecting devices • Wireless, mobile • Software • Operating systems, File systems • Application programs • Communications protocols
Computer System Output Device Bus Bus Input Device Computer Data Bus Main Memory CPU Secondary Storage Device Control Hardware • Charles Babbage (~1850) and John von Neuman (~1950) provided the basic model of a stored program digital computer. Five Main Components: 1. CPU 2. Main Memory (RAM) 3. I/O Devices 4. Mass Storage 5. Interconnection network (Bus)
Computer Data Main Memory CPU Secondary Storage Device Control Hardware NOTE: CPU’s do not make any sense of human readable text. Rather, they respond to and act on groups (strings) of bits, according to the engineered capabilities of individual components. IMPLICATION: Programs written as characters (text) must be converted (transformed) into appropriate binary encodings that the CPU can “comprehend”. • Charles Babbage (~1850) and John von Neuman (~1950) provided the basic model of a stored program digital computer. Computer Logic Sub-system Character Input (program) Processing of binary encoded strings of bits (instructions and data) Character and Binary files
Hardware • Some computer scientists focus on design of hardware, but in recent years this study has become the focus of computer engineers. • Computer science is primarily concerned with how to express the logic of a problem solution using the fundamental capabilities of the machines available. • It is useful, if not necessary, to understand how hardware works (instruction sets) and what are its limitations (speed, precision, error) • A useful concept is that of a primitive, or atomic, operation. Most CPU instructions (built as electronic circuits) are always guaranteed to complete their operation, once it has been commenced.
Hardware • Students may take courses in digital design and logic and assembly/machine language programming. • We will discuss only some relevant aspects of hardware appropriate to the conceptual discussion of programming logic. • Data representations • Instruction types and timing • Volatile Memory (RAM)
Software • As much as hardware defines the limiting capability of a (set of) machines to carry out a specific set of logical operations, software is the actual set of operations expressed as executable units. • A program is a static entity stored on a disk. It does not actually do anything, though it may have the potential to solve a problem. • A process is a dynamic entity that has been loaded into volatile memory (RAM) while notifying the Operating System to provide resources (such as memory space, file access and time on the CPU) • For simplicity, we will often use the generic name “program”.
Software • The act of designing and perfecting a program is referred to as programming. More recently, the techniques of design have become formalized in the study of software engineering. • Software takes many forms and uses: • Operating systems • Application programs • Editors, word processors • Email, ftp, communications • Engineering, Science, Social Science, Finance ….. • Data structures (protocols) • File systems
Operating systems • Operating systems (O/S’s) are programs that are used to manage the underlying hardware systems of computers • Resource allocation • Device control • Programs • Process concurrency • Inter-process communication • Communication sockets, port allocation • Files • Fault detection and recovery • Security • Often designed using the C language
Application programs • Application programs are special purpose programs designed to solve specific problems in a restricted domain of interest. • Word processing and editing • Compilers and Translators • Image processing, multi-media, graphics • Mathematical, scientific, engineering • Expert rule-based systems • Communications • Designing an application involves selecting an appropriate choice of programming languages. • The choice may affect the ease of design, performance or ongoing maintenance of program codes.
Editors and compilers • General word processing programs are used to markup text (and possibly graphics and multimedia content). • Files created using WP’s are not suitable for transformation into executable programs. • Editors are simple tools used for text entry and editing, but they create files that contain no markup content. • Unix: nedit, xedit, vi • Windows: textedit (NOT Notepad)
Editors and compilers • Compilers are special application programs that • accept inputs of program text (source) codes • translate the codes into machine-dependent strings of bit encodings (0’s and 1’s) • analyze code syntax and semantics, detect and report errors • organize the bit encodings to support process execution in RAM and CPU • produce object (or executable) files that can be stored and used repeatedly (without re-compiling). • REMEMBER: Files created using WP’s are not suitable for transformation into executable programs.
Editors and compilers • Compilers are intended to perform translation of source codes to executable codes once • Although compilation is done anew each time errors are fixed (debugged) or programs are moved (ported) to a new computer. • Translators (sometime called emulators) are similar to compilers, but they feature the ability to consider a single instruction (and data) and perform execution. • Usually very slow compared to compiled programs • Programs must always be re-translated each time they are executed.
Programs • A program is a set of ordered, logical statements that, once initiated, process data to produce a final result, then terminate. • Programming languages impose rigorous constraints on syntax and punctuation. • Programmers must follow the rules defined by the language designers! • Programs are the technical embodiment of logic. • Logic is ultimately mathematics, but most of us can do it (and we do it all the time as part of our own survival!). • Some problems seem to deny the use of logic and are considered to be non-computable. • How much do you love your mother?
Programs • Programs are categorized into • High-level :: Abstract, suitable for human logic • Low-level :: Concrete, suitable for direct control over devices • Programs typically contain definitions of variables using symbolic namesand attribute types. • Containers for data (where bits must be stored) • Programs typically are written hierarchically • Using computational units such as functions (or objects or documents). • Often these units are provided in programming libraries
Programming paradigms and languages • Many different programming languages have been developed (including only a few): • C Pascal Modula • PL/I COBOL Ada SQL • LISP Miranda Simula Prolog • Java C++ SmallTalk • These languages are often grouped into conceptual paradigms (ways of thinking and planning): • Procedural Functional Declarative • Logic Object Oriented ... and others • Learning new languages and paradigms greatly improves one’s ability to solve problems. C is an example of a strongly typed, proceduralprogramming language. It is sometimes also called a systems programming language.
The Internet and World Wide Web • The Internet has grown from early research work on networks and communications (ARPAnet) to a sophisticated network of high-throughput devices that supports massive amounts of data to be transferred on a global scale. • Often called a “network of networks” • Many kinds - LAN, WAN, VPN • Technologies - Ethernet, optical, wireless, satellite • Core hardware - SONET, bus, routers, switches, NICs • Communication protocols - IP, TCP, UDP, ICMP, BGP • This subject is discussed in considerable detail in a future course in Computer Networks (60-367).
The Internet and World Wide Web • The World Wide Web is a software infrastructure that permits increasingly effective modes of accessing and sharing data (and information) on a massive scale. • Standard web browsers (eg. IE, Mozilla) are enabling technologies that support WWW interactions for users • Current research efforts are directed at semantic websthat support rich, user-perspective oriented data mining. • An emergent software technology called SOA (Service Oriented Architecture) is forming the basis for a potential new industry in (stateful) Web Services.
Structured Problem Solving Lecture 1B
Structured Problem Solving • The challenge of complex systems • Pseudo-code • Flowcharts • Modularization • Top-Down versus Bottom-Up design principles • Concepts of function, control structures and computability. • Testing and Validation • Software engineering
Units of Scale for Computing Time: 1 Second 10-3milli second 10-6 micro second 10-9nano second 10-12picosecond Storage capacity *: 1 Byte (=8 bits) 210 Kilo byte (1024) 220 Mega byte (about 106) 230 Giga byte (about 109) 240Tera byte (about 1012) 250Peta byte (about 1015) * Also used with frequency (clock speed) measured in units of Hertz (oscillations, or “ticks”, per second) Hence, Gigahertz CPU’s are based on clocks that tick about a billion times a second. The challenge of complex systems • EMERGING TRENDS: • Micro-miniaturization of circuit elements continues. Research in biological, photonic, quantum and molecular computing paradigms have produced promising results and future possibilities. We talk about pervasive and ubiquitous computing and we view sets of computers and networks as computational grids, much like the power grid we rely on for electricity, with massively distributed workload and access to huge informational resources. • Incredibly small – nanoscale architectures • Incredibly fast – switching times and smaller distances • Incredibly parallel – multiple processing elements working simultaneously • Incredibly distributed – networks carrying vast amounts of information • Many problems are suitable for computation, but determining detailed, logical solutions to all aspects of the problems demands careful planning in design. • Some issues that arise in complex systems • Memory requirements • Number of instructions executed in CPU(s) • Distribution of codes and data on multiple platforms • Storage requirements • Data communication within and between computers (latency) • Fault detection, tolerance and recovery
The challenge of complex systems ALGORITHM: A finite, ordered set of statements with a beginning and an ending, intended to carry out a set of logical operations to solve a problem. • The strategy of a solution is a matter of logic – not programming language! • Programming languages do affect matters such as efficiency of execution, maintenance of codes, portability of codes and even ease of implementation • Designers of algorithms need additional tools and formalisms besides programming languages alone • Language independent approaches to logic • Mathematical formalism • Pseudo-language for logic representation • Graphical tools for logic representation and workflow
Structured problem solving - beginnings • Now, as nice and easy as it is to sit back and read about the fantastic things that others have done, it is time for a reality check • Would you like to participate directly in the Information Age and the Knowledge Revolution? • Are you motivated to learn the basics before you try to conquer the universe with re-invented tools? • Are you ready to accept discipline and excellent work and study habits as strong requirements for success? • It’s time to take a step back and begin anew!
Mathematical logic and formalism • The mathematics of computational logic is rooted in Boolean Set Theory (George Boole). • The concepts of bits (binary digits) and binary logic (calculus) based on set theoretic operations (complement/not, and, or, nand, nor, xor, xnor) • This is the fundamental connection point between computer science and computer engineering since BST applies directly to design of digital circuits • Further work added an interpretive aspect to Boole’s work and led to various kinds of calculus systems (predicate, lambda and pi) • Suitable for specifying formal logic operations on data objects with logical attributes
Mathematical logic and formalism • Pure Mathematics offers methods for formally proving theorems, based on axioms (starting assumptions) and consistent argumentation • Deductive and Inductive logic • Applied Mathematics offers methods for analysis of static and dynamic systems for which a mathematical basis exists (eg. Physics, Chemistry, Biology, Finance, Games, etc.) • Algebra, Trigonometry, Calculus • Vectors, Matrices, Linear algebra • Statistics offers methods for analysis of discrete systems with large numbers of interacting elements, whose behaviours can only be estimated • Regression analysis • Queueing theory
Mathematical logic and formalism • From time to time we will refer to mathematics in a formal way • In general, we will take a less formal approach based on technical approaches that have proven effectiveness, but are based on trained reasoning principles • This may sound a bit “fuzzy”, but it is based on the observations … • In mathematics, the student learns to prove theorems by proving theorems (often incorrectly, at first) • In programming and algorithm design, the student learns to achieve results/programs by achieving results/programs (often incorrectly, at first).
Two simple problems – with variations • Find the sum of the ages (in years) of 3 friends, as well as their average age. Each friend tells his/her age when you ask them. • Find the sum and average of the ages (in years) of N friends. Each friend will tell their age when asked, but the very first friend will know the actual value of N. (version 1) • Find the sum and average of the ages (in years) of N friends. Each friend will tell their age when asked, but the actual value of N can only be determined by counting the friends. (version 2)
Pseudo-code • First we will develop and express a solution to each problem based on our own experience and in a somewhat structured language. This language is called pseudo-code (‘syu-do’ from Greek).
Pseudo-code • Find the sum of the ages (in years) of 3 friends, as well as their average age. Each friend tells his/her age when you ask them. • Solution – in human terms: • Select clear paper and pencil to record ages and do arithmetic • Ask first friend’s age and write it on paper • Ask second friend’s age and add it to total age on paper • Ask third friend’s age and add it to total age on paper • Divide total age on paper by 3 to find average age • Tell everyone the total age and the average age
Pseudo-code • Find the sum of the ages (in years) of 3 friends, as well as their average age. Each friend tells his/her age when you ask them. • Solution – in human terms: • Select clear paper and pencil to record ages and do arithmetic • Ask first friend’s age and write it on paper • Ask second friend’s age and add it to total age on paper • Ask third friend’s age and add it to total age on paper • Divide total age on paper by 3 to find average age • Tell everyone the total age and the average age
Pseudo-code • Find the sum of the ages (in years) of 3 friends, as well as their average age. Each friend tells his/her age when you ask them. • Solution – in more structured terms: • Identify variables: Age, TotalAge and AverageAgeInitialize: TotalAge to 0. • Ask first friend’s age and write it on paper • Ask second friend’s age and add it to total age on paper • Ask third friend’s age and add it to total age on paper • Divide total age on paper by 3 to find average age • Tell everyone the total age and the average age
Pseudo-code • Find the sum of the ages (in years) of 3 friends, as well as their average age. Each friend tells his/her age when you ask them. • Solution – in more structured terms: • Identify variables: Age, TotalAge and AverageAgeInitialize: TotalAge to 0. • Ask friend’s Age and add it to TotalAge • Ask friend’s Age and add it to TotalAge • Ask friend’s Age and add it to TotalAge • Divide total age on paper by 3 to find average age • Tell everyone the total age and the average age