Algorithms and Programming

Slides:



Advertisements
Similar presentations
GCSE Computing Lesson 5.
Advertisements

compilers and interpreters
Chapter 1 An Overview of Computers and Programming Languages.
Computers and Scientific Thinking David Reed, Creighton University Algorithms and Programming Languages 1.
Programming Types of Testing.
Chapter 1 - An Introduction to Computers and Problem Solving
Computer Concepts 5th Edition Parsons/Oja Page 546 CHAPTER 11 Software Engineering Section A PARSONS/OJA Computer Programming.
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
Chapter 16 Programming and Languages: Telling the Computer What to Do.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Introduction to a Programming Environment
Chapter 1 Program Design
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
PRE-PROGRAMMING PHASE
Intro to Programming CST JavaScript. Objectives Define software Identify the different types of software Differentiate the different types of programming.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
1 Chapter-01 Introduction to Computers and C++ Programming.
CSCI-100 Introduction to Computing Algorithms Part I.
Lecture # 8 ALGORITHMS AND FLOWCHARTS. Algorithms The central concept underlying all computation is that of the algorithm ◦ An algorithm is a step-by-step.
COMPUTER SCIENCE I C++ INTRODUCTION
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Standard Grade Computing SYSTEM SOFTWARE CHAPTER 19.
Slide 1 Standard Grade Computing Studies Systems Software.
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
Tranlators. Machine Language The lowest-level programming languageprogramming language Machine languages are the only languages understood by computers.languagescomputers.
Introduction to Programming ICS2O Findlay. Learning Goals  We will learn  The definitions of a computer, program and programming language.  The different.
An Introduction to Programming with C++ Sixth Edition
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
FOUNDATION IN INFORMATION TECHNOLOGY (CS-T-101) TOPIC : INFORMATION SYSTEM – SOFTWARE.
Compilers and Interpreters. HARDWARE Machine LanguageAssembly Language High Level Language C++ Visual Basic JAVA Humans.
 Computer Languages Computer Languages  Machine Language Machine Language  Assembly Language Assembly Language  High Level Language High Level Language.
Programming and Languages Dept. of Computer and Information Science IUPUI.
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
Compilers and Interpreters
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
CSCI-235 Micro-Computers in Science Algorithms Part II.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
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.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Programming Languages
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 0: Historical Overview.
Introduction to computer software. Programming the computer Program, is a sequence of instructions, written to perform a specified task on a computer.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Evolution and History of Programming Languages
Component 1.6.
Topic: Programming Languages and their Evolution + Intro to Scratch
Introduction to programming
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
A451 Theory – 7 Programming 7A, B - Algorithms.
Teaching Computing to GCSE
Teaching Computing to GCSE
Translators & Facilities of Languages
Chapter 1 Introduction(1.1)
Algorithms and Programming Languages
ICT Programming Lesson 1:
ICT Gaming Lesson 2.
Computers and Scientific Thinking David Reed, Creighton University
1.3.7 High- and low-level languages and their translators
Presentation transcript:

Algorithms and Programming Lect 3

Algorithm An algorithm is a finite step-by-step sequence of instructions for carrying out some task Algorithms predate computers, e.g. Euclid's algorithm for finding the greatest common factor Find average of some values

Finding the Oldest (1) ask the first person to state his or her name and birthday, then write this information down on a piece of paper for each successive person in line: ask the person for his or her name and birthday if the stated birthday is earlier than the birthday on the paper, cross out old information and write down the new at the end of the line, the name and birthday of the oldest person will be on the paper

Oldest (1)

Find the Oldest (2) line up all the people along one wall as long as there is more than one person in the line, repeatedly have the people pair up– if there is an odd number of people, the last person will be without a partner ask each pair of people to compare their birthdays and request that the younger of the two leave the line when there is only one person left in line, that person is the oldest

Oldest(2)

Algorithm Analysis algorithm 1 involves asking each person’s birthday and then comparing it to the birthday written on the page the amount of time to find the oldest person is proportional to the number of people if you double the amount of people, the time needed to find the oldest person will also double

Algorithm Analysis algorithm 2 allows you to perform multiple comparisons simultaneously the time needed to find the oldest person is proportional to the number of rounds it takes to shrink the line down to one person -- the logarithm (base 2) of the number of people if you double the number of people, the time increases by the cost of one more comparison requires carrying out comparisons in parallel (special hardware is the price you have to pay)

algorithm vs. logarithm the words algorithm and logarithm are similar – do not be confused algorithm: a finite step-by-step sequence of instructions for carrying out a task logarithm: the exponent to which a base is raised to produce a number e.g., 210 = 1024, so log2(1024) = 10

Searching A common problem in computer science involves storing and maintaining large amounts of data, and then searching the data for particular value.

Searching sequential search general purpose relatively slow There are two commonly used algorithms for searching a list of items sequential search general purpose relatively slow binary search data must be sorted faster guess my number

Searching Algorithm 1 takes time proportional to the number of values Algorithm 2 is again proportional to the log2.

Algorithms There may be many algorithms to solve a given problem. Some algorithms may be faster than others some algorithms may require different resources (memory, special hardware).

Programming In order to use a computer to solve a problem, we go through a series of steps. Determine how to solve the problem and come up with an algorithm (a finite sequence of steps to solve the problem). Formulate the algorithm in a way that a computer can use to carry out the steps. A program is a set of instructions to solve a problem written in a manner that a computer can use (not in English).

Programming A computer understands only its own machine language. We write the program in a high-level language. It uses English-like words. A program called a compiler or interpreter "translates" the program written in the high-level programming language to machine language.

Machine Language machine language consists of instructions that correspond directly to the hardware operations of a particular machine i.e., instructions deal directly with the computer’s physical components machine language instructions are written in binary programming in machine language is tedious and error prone code is nearly impossible to understand and debug Each machine has its own machine language.

Languages in the early 1950’s, assembly languages evolved from machine languages substitute words for binary codes much easier to remember and use, but still a low level of abstraction in the late 1950's, high-level languages were introduced allow the programmer to write code closer to the way humans think a much more natural way to solve problems programs are machine independent

Translation Using a high-level language, the programmer is able to reason at a high-level of abstraction But programs must still be translated into machine language that the computer hardware can understand/execute. Inside a computer, everything is binary. Two standard approaches to program translation Interpreter – translate and execute each instruction Compiler -- translate entire program

Translating a speech an interpreter can be used to provide real-time translation the interpreter hears a phrase, translates, and immediately speaks the translation ADVANTAGE: the translation is immediate DISADVANTAGE: if you want to hear the speech again, must interpret all over again

Translating a speech a translator (or compiler) translates the entire speech offline the translator takes a copy of the speech and translates the entire speech ADVANTAGE: once translated, it can be read over and over very quickly DISADVANTAGE: must wait for the entire speech to be translated

Compiler vs. Interpreter Compilation is done once and then the compiled version can be reused many times. Often, that’s what’s sold. Interpretation can be done before the whole program is available, but has to be repeated each time the program is used. Interpreter is suitable for Javascript, because the program can be interpreted as the page is being loaded, doesn't have to wait for the whole page to download.

Debugging A bug is an error in a program Debugging is removing the errors without introducing new ones. The compiler may find errors - mistakes in the way the program was formulated - and will not be able to complete the translation process. Fix the errors and repeat the process until the program compiles successfully.

Debugging Run (or execute) the program. At this point, we may find other errors and we may have to correct the program again. Test the program. Test it and see if there are any mistakes. Fix errors and test again.

Software Life-Cycle Determine an algorithm to solve the problem Write a program to implement the algorithm: use very specific, detailed instructions use a “language” the computer understands. Compile the program: A compiler translates the program into machine language. Fix any syntax errors that the compiler finds. Run (or execute) the program: At this time we may find other errors that must be corrected. Test the program: Test the program and fix any errors. Maintain the program: Keep monitoring the program for unexpected errors. Make changes

Examples of Bugs The Mars Climate Orbiter was lost in space in 1999. In the calculation of its route, some programmers used the metric system while others used English units! A Patriot missile failed to intercept a scud fired at US troops in 1991. The time in tenths of a second, as measured by the system’s internal clock, was multiplied by 10 to produce the time in seconds.

For the future A recipe is a good analogy for a program: ingredients Constants, variables data types, integer and real numbers, characters detailed step-by-step-instructions statements repeated actions (e.g., separate 5 eggs) loops decisions (e.g., bake until brown, beat until firm, etc.) pre defined actions (e.g., saute, puree, etc.) functions, parameters