COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Welcome to CMPE003 Personal Computers: Hardware and Software Dr. Chane Fullmer Fall 2002 UC Santa Cruz.
Chapter 1 An Overview of Computers and Programming Languages.
 The amount of time it takes a computer to solve a particular problem depends on:  The hardware capabilities of the computer  The efficiency of the.
8 Algorithms Foundations of Computer Science ã Cengage Learning.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
COSC 120 Computer Programming
IT Systems Operating System EN230-1 Justin Champion C208 –
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Operating Systems  By the end of this session, you will know: What an Operating System is. The functions it performs.
Algorithms and Programming
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems CSCI-6140 – Computer Operating Systems David Goldschmidt, Ph.D.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
CSC 211 Data Structures Lecture 13
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Operating Systems Lesson Objective: Understanding the functions of an operating system. Learning Outcome: Answer some basic questions on operating systems.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris
Computer Software Operating Systems – Programs. Computer Language - Review We learnt that computers are made up of millions of tiny switches that can.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Course Title: Introduction to Computer Course Instructor: ILTAF MEHDI Chapter No: 04 1BY ILTAF MEHDI (MCS, MCSE, CCNA)
Chapter 10 Algorithmic Thinking. Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
COSC 3330/6308 Second Review Session Fall Instruction Timings For each of the following MIPS instructions, check the cycles that each instruction.
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.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Chapter 1 Introduction 2nd Semester H
Component 1.6.
Algorithms and Problem Solving
Introduction to Operating Systems
Memory Management.
Operating System Review
Chapter 2 Memory and process management
Algorithmic Efficency
Lesson Objectives Aims Key Words
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Introduction CSE 1310 – Introduction to Computers and Programming
Operating System Review
Introduction to Operating Systems
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Chapter 9: Virtual-Memory Management
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Operating System Review
Memory Management Tasks
CS 201 Fundamental Structures of Computer Science
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Translation Buffers (TLB’s)
Modern PC operating systems
Algorithms and Problem Solving
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
CSE 471 Autumn 1998 Virtual memory
Basic Concepts of Algorithm
B-Trees.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
WJEC GCSE Computer Science
Presentation transcript:

COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris

CHAPTER II COMPUTING

Chapter overview How computers work  Hardware  Software Algorithms and Heuristics  Algorithmic thinking

HOW COMPUTERS WORK

Overall organization CPU MAIN MEMORY programs with their data Hard disk User inputs and outputs

Inside the main memory Running programs: we call them "processes" KERNEL allocates memory to processes grants CPU to processes control disk accesses Operate in user mode Operates in kernel mode

The running programs Reside in main memory  while they are running Include many background processes  We do not see them  Take space and often CPU time Having a large main memory allows us to run more programs at the same time

TIP If your computer becomes slow whenever you switch among programs  You need more memory If your computer takes a lot of time to boot  You could have a slow disk  Your OS has a lot of things to load into main memory Useful and not so useful

The kernel Responsible for  Managing the resources Which process should get the CPU How our files are stored …  Enforcing security and preventing crashes

Security issues Must protect running programs from attempts to modify them by other programs  Mostly programming issues  Also viruses Must protect our data on disk  Especially if computer is shared

Running a program OS creates a process  Allocates memory space to the process  Disk copy of program is brought from disk into main memory Process competes with other processes for CPU time Process is deleted when program terminates

Saving the results Normally done by saving the results in a file stored on disk Can print them later

What is inside a program? Instructions:  Telling the CPU what to do Constants:  Stable values Variables: Memory locations where results can be stored

CHAPTER III ALGORITHMS Work in progress: Will add new material s

What is an algorithm? “Effective method expressed as a finite list of well-defined instructions for calculating a function”  Wikipedia

Three important points It must be an effective method  Guaranteed to produce the result The instructions should be well-defined  Anybody using the algorithm should obtain the same answer It should have a finite number of steps  An algorithm must terminate after a finite number of finite steps

These are not algorithms On a shampoo bottle:  Lather  Rinse  Repeat

These are not algorithms On a shampoo bottle:  Lather  Rinse  Repeat How many times?

These are not algorithms On fuel tank cap:  Turn until three o'clock

These are not algorithms On fuel tank cap:  Turn until three o'clock That could be a long time!

Example: Converting C into F If you travel outside of the US, temperatures are likely to be given in Celsius not Fahrenheit. How the scales differ:  In Fahrenheit: Water freezes at 32 F and boils at 212 F  In Celsius: Water freezes at 0 C and boils at 100 C

Example: Converting C into F 1. Read Celsius temperature x 2. Multiply by Add 32 to obtain Fahrenheit temperature y

Example: Converting C into F Another way to do it: 1. Read Celsius temperature x 2. Fahrenheit temperature y = 1.8×x +32

Counter-example (I) British weatherman's rule of thumb:  Multiply C temperature by 2  Add 30 Very good for temperatures in F range During a Texas summer, better use:  Multiply C temperature by 2  Add 25

Counter-example (II) These two rules are heuristics, not algorithms  Do not always give the right conversion  Still useful Double and add 25 rule converts 30 C into 85 F Right answer is 86 F

A program is not algorithm It is the expression of an algorithm in a programming language Picking the right algorithm is the most important task  After that, we just have to code!

Example Finding a name in a table Naïve solution is sequential search Binary search is much faster

Sequential search (I) We look for search_name in list list 1. Start at beginning of list 2. If list is empty stop and return NOT FOUND 3. If search_name matches name of first list entry stop and return list entry 4. If we have reached the end of the list stop and return NOT FOUND

Sequential search (II) 5. Look for next list entry 6. If search_name matches name of next list entry stop and return list entry 7. Go to step 4

Binary search (I) We look for search_name in list list 1. If list is empty stop and return NOT FOUND 2. Find entry exactly in middle of list 3. If search_name matches the name of that entry stop and return list entry

Binary search (II) 4. If search_name goes before the name of entry restart search for first half of list 5. If search_name goes after the name of entry restart search for second half of list

Example of binary search List contains Alan Alice Barbara Emily Francis Gina Peter

Example of binary search We look for Charles in a sorted list of names Alan Alice Barbara Emily Francis Gina Peter

Example of binary search We compare search name with entry exactly in the middle of the list (Emily) Alan Alice Barbara Emily Francis Gina Peter

Example of binary search Since Charles comes before Emily we can eliminate second half of list Alan Alice Barbara

Example of binary search We compare search name with entry exactly in the middle of the list (Alice) Alan Alice Barbara

Example of binary search Since Charles comes after Alice we can eliminate the first half of list Barbara

Example of binary search We compare search name with entry exactly in the middle of the list (Barbara) Barbara

Example of binary search Since Charles comes after Alice we can eliminate the first half of the list Barbara

Example of binary search Since Charles comes before Barbara we can eliminate one half of the list

Example of binary search Since list to be searched is now empty we conclude that the list does not contain Charles

Comparing performances List with 1024 entries Sequential search:  Maximum number of steps: 1024  Average number of steps: 512 (one half) Binary search:  Number of steps: 10 (= log )

Heuristics (I) Many problems have no practical algorithmic solution  Algorithm will take too long Example:  Finding the absolute best price for an item  Should check everywhere  Not cost-effective

Heuristics (I) Heuristics provide solutions  That are not guaranteed to work in all cases  That provide a good approximation of the correct solution Example:  When we want to buy an item, we focus on the stores that are likely to sell the item at a good price

An example Finding the maximum of a curve  Start at any given point  Move on the curve following the upward direction  Stop when the curve reaches a start going downward

It works

It does not always work

Which one is the most useful? ALGORITHM Always provides the right answer Can be very slow HEURISTICS Normally provide a good approximation of the right answer Relatively fast

Algorithmic thinking Way to analyze problems and come with one or more algorithmic solutions that  fully describe the solution  handle all special cases  can implemented on a computer system  will run at a reasonable cost Most important skill for a programmer  Can be learned