CS 7: Introduction to Computer Programming Algorithms.

Slides:



Advertisements
Similar presentations
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
1 CS101 Introduction to Computing Lecture 17 Algorithms II.
Chapter 2: Problem Solving
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
CS105 INTRODUCTION TO COMPUTER CONCEPTS INTRO TO PROGRAMMING Instructor: Cuong (Charlie) Pham.
Introduction to Programming. COMP104 Lecture 1 / Slide 2 Objectives * To learn fundamental problem solving techniques: n define a problem n design an.
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Program Design and Development
Computers: Tools for an Information Age
Algorithm Design CS105. Problem Solving Algorithm: set of unambiguous instructions to solve a problem – Breaking down a problem into a set of sub- problems.
An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming.
Structured Program Development in C
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Your Interactive Guide to the Digital World Discovering Computers 2012.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Evolution of Programming Languages Generations of PLs.
COMPUTER PROGRAMS AND LANGUAGES Chapter 4. Developing a computer program Programs are a set (series) of instructions Programmers determine The instructions.
UniMAP Sem1-08/09EKT120: Computer Programming1 Week 1 – Lecture 1.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Computer Organization Six logical units in every.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
PSEUDOCODE C Programming Technique – Firdaus-Harun.com.
C Lecture Notes 1 Structured Program Development.
Visual Basic Programming
Chapter 2: General Problem Solving Concepts
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
Introduction to Programming in VB Chapter 1. 2 Software Development Life Cycle Gather Requirements Design Program Code & Test Program Implement u Software.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 1.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
CSCI-235 Micro-Computer Applications
Computer Programming.
Chapter 2.1 Control Structures (Selection)
CSC113: Computer Programming (Theory = 03, Lab = 01)
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
Programming Fundamentals
Unit# 9: Computer Program Development
Program Control using Java - Theory
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
CS105 Introduction to Computer Concepts Intro to programming
Chapter 3 - Structured Program Development
Algorithm and Ambiguity
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
An Introduction to Programming with C++ Fifth Edition
WJEC GCSE Computer Science
CS105 Introduction to Computer Concepts Intro to programming
Structural Program Development: If, If-Else
Presentation transcript:

CS 7: Introduction to Computer Programming Algorithms

Review What are the 5 generation languages (“GL”)? 1 GL – machine language 2 GL – assembly language 3 GL – high level language 4 GL – “non-procedural, specification language” 5 GL – “constraint-based, Artificial Intelligence language”

Trade-offs among the 5 G’s Productivity Time to write, debug, maintain code Portability Ease of taking program written on 1 computer and moving it to another Efficiency Time it takes code to run Amount of space it takes to run Task Dependent Is the language developed for a specific task?

1 GL Example Add registers 1 and 2, place result in register 6 Low productivity Lots of instructions needed for simple tasks Low portability Different machine languages for different architectures High efficiency can take advantage of architecture dependent features can write more quick and compact code Not task dependent Everything ultimately must be in machine code!

2 GL - MIPS Example add $1, $2, $6 Add registers 1 and 2, place result in register 6 Low productivity Lots of instructions needed for simple tasks Usually 1-to-1 correspondence with machine language Easier to read Low portability Different machine languages for different architectures High efficiency can take advantage of architecture dependent features can write more quick and compact code Not task dependent

3 GL – Java, C++, BASIC, FORTRAN Example d = e + f; Add the values in e and f, place result in d High productivity 1 instruction can be 100, 1000 lines of machine code Much more like human language Highly portable Run on any machine with necessary compiler, interpreter Efficiency Not as good as machine code Not task dependent

4 GL – SQL, Visual Basic’s GUI Creator Example FIND ALL RECORDS WHERE NAME IS “HOFFMANN” High productivity Easy than 3 GL Highly portable Run on any machine with necessary compiler, interpreter Efficiency Not as good as machine code or high level language Task dependent SQL used for database queries Visual Basic’s GUI Creator is for designing Graphical User Interfaces (GUIs)

5 GL – Prolog, Neural Networks Example Specify neural network architecture for learning to map written character to ASCII equivalent High productivity Highly portable Efficiency Not as good as machine code or high level language Task dependent Used to solve problems with specific constraints

Some Notes Syllabus Typo (5 not 6 projects) Make sure to read all of the relevant sections of book for the week before the first lecture of that week Labs start today

Algorithms

Algorithms - Definition Set of instructions used to complete a task Can be represented as Pseudocode – list of steps, is precise but not implemented in programming language Flowchart – graphical representation

Algorithms - Representation How do you… Make a peanut butter sandwich? Calculative a derivative? Find a job? Do the hokey pokey?

Hokey Pokey – List of Steps Representation Volunteers? Anything unclear in the steps the song gives?

Flowchart symbols Action Symbol Instructions changing a state Decision Symbol Instructions testing a state Flowline Instructions transferring to next step Start/End Symbol

Control Structures Bohm & Jacopini showed all programs could be written in terms of 3 structures: Sequence – which instruction should be done next? Selection – select between options Repetition – repeat an action while a given condition stays true

Sequence 1) Open the jar 2) Scoop out the peanut butter 3) Spread the peanut butter on the bread

Selection Single Selection (if) If you’ve won the lottery: raise your hand Double Selection (if-else) If you’re happy: smile else: frown Won lottery? Raise Hand True False Happy? Smile TrueFalse Frown

Selection (continued) Multiple Selection (switch) If the light is... red -> stop green -> go yellow -> slow down Light Red? Stop True False Light Green? Go False Light Yellow? Slow Down False True

Repetition While Do-while Mixture Clumpy? Stir True False Parent say “Yes”? True False Must I eat Veggies? ask parents if must eat vegetables while parents say “Yes” while it’s still clumpy Stir the mixture

Repetition (continued) For Counter ≤ 10? Print counter True False Counter = 1 Add 1 to counter Teaching a baby to count from 1 to 10: counter = 1 if counter <= 10: increment counter print counter number

Hokey Pokey - Flowchart

Pseudocode Pseudocode - Algorithm written in way that resembles code: Example (from BlackJack) method computeScore(cards): for each card in hand: if card is ace: add 1 to score add 1 to numAces else if card is face card: add 10 to score otherwise: add face value to score while numAces > 0 and count < 21: add 10 to counter return counter value

Algorithms - characteristics What kinds of things are we seeing in these tasks? They have an input, an output, and do some processing That processing needs to terminate, be unambiguous, and simple to perform (we want to be able to easily implement it from the algorithm)

References Deitel, H.M., and Deitel, P.J. Java: How to Program, 3 rd edition. Chapter 4,5 Wikipedia. 4ges.html 4ges.html