Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Computer Science An Overview EE461 Introduction to Computer Science 1 Preface 4 Beginning computer science students need exposure to the breadth of the subject in which they are planning to major. 4 A foundation from which they can understand the relevance and interrelationships of future courses. 2 Introduction 4 Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. 4 Computer science provides the underpinnings for today’s computer applications as well as the foundations for tomorrow’s applications. 3 The Study of Algorithms 4 An algorithm is a set of steps that defines how a task is performed. 4 In the domain of computing machinery, algorithms are represented as programs within computers. 4 Algorithms + Data Structure -> Programs, Programs -> Software <=> Hardware. 4 The Study of Algorithms 4 The study of algorithms began as a subject in mathematics. 4 The major goal is to find a single set of directions that described how any problem of a particular type could be solved. 4 E.g., the long division algorithm and the Euclidean algorithm. 5 The Euclidean algorithm for finding the greatest common divisor of two positive integers 6 The Study of Algorithms 4 Machine Architecture - . Data storage (Ch. 1) . Data manipulation (Ch. 2) 4 Software . Operating systems and networks (Ch. 3) . Algorithms (Ch. 4) . Programming languages (Ch. 5) . Software engineering (Ch. 6) 4 Data Organization . Data structures (Ch. 7) . File structures (Ch. 8) . Database structures (Ch. 9) 4 AI and Theory of Computation 7 The Development of Algorithmic Machines 4 Abacus.[ Ancient Greek+ Roman Civiliz.] 4 Babbage’s difference engine.[1850] 4 Jacquard’s loom.[1801] 4 Herman Hollerith (holes in paper cards).[1890] 4 Mark I at Harvard University.[1944] 4 ENIAC at U. of Pennsylvania.[After 1944] 8 Jacquard’s loom 9 The Mark I computer 10 The Evolution of Computers 4 First Generation [1946-54] 4 Technologies [ Vacuum tubes; acoustic memories; CRT memories]. 4 Hardware features [ Fixed-point arithmetic] 4 Software features [assembly language] 11 The Evolution of Computers 4 Second Generation [1955-64] 4 Technologies [ Discrete transistors; ferrite cores; magnetic disks]. 4 Hardware features [ Floating-point arithmetic; index registers; IO processors]. 4 Software features [ High-level languages; subroutine libraries; batch monitors]. 12 The Evolution of Computers 4 Third Generation [1965-74] 4 Technologies [ Integrated circuits ( SSI and MSI)] 4 Hardware features [ Microprogramming; pipelining; cache memory] 4 Software features [ Multiprogramming; multiprocessing; operating systems; virtual memory]. 13 The Evolution of Computers 4 Fourth Generation [ 1975-1990] 4 Technologies [ LSI circuits; semiconductor memories] 4 Fifth Generation [ 1990- ] 4 Technologies [ VLSI circuits ] 14 The central role of algorithms in computer science 15 The Evolution of Computer Science Languages Software Algorithms Hardware Applications 16 Abstraction and Other Issues 4 Abstraction - the distinction between the external properties of a component and the internal details of the component’s construction. 4 Ethical issues. 4 Social issues. 4 Legal issues. 17 The hierarchy of abstraction in the hardware of a typical personal 18 Part I: Machine Architecture 4 A major process in the development of a science is the construction of theories that are confirmed or rejected by experimentation. 4 In some cases these theories lie dormant for extended periods, waiting for technology to develop to the point that they can be tested. 19 Ch. 1 Data Storage 4 4 4 4 4 4 4 4 Storage of bits. Main memory. Mass storage. Coding information for storage. The binary system. Storing integers. Storing Fractions. Communication errors. 20 Storage of bits 4 Boolean operations, e.g., AND, NOT, and OR. 4 Gates are devices that produce the output of a Boolean operation when given the operation’s input values. 4 A flip-flop is a circuit that has one of two output values (i.e., 0 or 1), the output will flip or flop between two values under control of external stimuli. 21 The Boolean operations AND, OR, and XOR (exclusive or) 22 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values (continued) 23 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values 24 A simple flip-flop circuit 25 Setting the output of a flip-flop to 1 (continued) 26 Setting the output of a flip-flop to 1 (continued) 27 Setting the output of a flip-flop to 1 28 Another way of constructing a flipflop 29 Hexadecimal Notation 4 In the internal activities of a computer, we must deal with strings of bits , some of which can be quite long, it is called a stream. 4 Streams are difficult for human mind to manipulate. [ 1011010100111011 ] 4 To simplify the representation of such bit patterns. 4 We use hexadecimal notation. 30 The hexadecimal coding system 31 Storage of Bits 4 A flip-flop is ideal for the storage of a bit within a computer (on a single wafer or chip). A flip-flop loses data when its power is turned off. 4 Cores, a donut-shaped rings of magnetic material, are obsolete today due to their size and power requirements. 4 A magnetic or laser storage device is commonly used when longevity is important. 32 4 Hexadecimal notation. Main Memory 4 Cells - a typical cell size is 8 or called byte. 4 Address is used to identify individual cells in a main memory. 4 Random access memory (RAM). 4 Read only memory (ROM). 4 Most significant bit (MSB) and least significant bit (LSB). 33 Memory cells arranged by address 34 The organization of a byte-size memory cell 35 Mass Storage 4 Secondary memory. 4 Storing large units of data (called files). 4 Mass storage systems are slow due to mechanical motion requirement. 4 On-line Vs. off-line operations. 36 Mass Storage 4 4 4 4 Disk storage. Compact disks and CD-ROM. Tape storage. Physical Vs. logical records. 37 HARD DISK 38 HARD DISK 4 Track: Circle on the disk 4 Sector: Each track is divided into arcs called Sector. 4 Seek Time: The time required to move the read/write heads from one track to another.[ m sec ]. 39 HARD DISK 4 Latency Time: Half the time required for the disk to make a complete rotation.[m sec] 4 Access Time: The sum of the seek time and the latency time(rotational delay)[ m sec ]. 4 Transfer Rate: The rate at which data can be transferred to or from the disk 40 HARD DISK 4 Hard disk Rotational Speed: 4 [ 7000- 10000- 15000 ] RPM 4 Floppy disk Rotational Speed; 4 [ 300 ] RPM 4 Transfer Rate: HD 4 Floppy MB/sec KB/sec 41 CD storage format 42 A magnetic tape storage mechanism 43 Data in Mass Storage 4 File: Information is stored on mass storage systems in large units called File. 4 Buffer: is a storage area used to hold data on a temporary basis usually during the process of being transferred from one device to anther. 4 Physical record: a block of data conforming to the physical characteristics of a storage device. 4 Logical record: natural division determined by the information represented such naturally occurring blocks of data are called logical records. 44 Logical records versus physical records on a disk 45 Coding Information for Storage 4 American Standard Code for Information Interchange (ASCII) - 8-bit codes. 4 International Standards Organization (ISO) - 16-bit codes. 4 Binary-decimal number conversion. 46 The message “Hello.” in ASCII 47 The base ten and binary systems 48 Decoding the binary representation 100101 49 An algorithm for finding the binary representation of a positive integer 50 Applying the algorithm to obtain the binary representation of thirteen 51 Representing Images. 4 Images representation can be classified into two 4 4 4 4 categories: Bit map techniques: An image is considered to be a collection of dots, each of which is called a pixel . Vector Techniques: An image is presented as a collection of lines and curves. [Provides a means of scaling ] 52 Representing Images 4 Bit map representation 4 A pixel can be black or white , represented by a bit 4 A pixel can be a color , represented by three byte [ RBG ]. 4 A typical photograph consists of 1280 rows of 1024 pixels 4 Requires several megabytes of storage 4 Image compression is required 53 Images Standards 4 Graphical Interchange Format [ GIF ]: 4 Each pixel is represented by a single byte. 4 Joint Photographic Experts Group[ JPEG] 4 Motion Picture Experts Group [MPEG] 54 Representing Sound 4 The most generic method of encoding audio information for computer storage is to sample the amplitude of the sound wave at regular intervals and record the series of values obtained. 4 Rate of Sampling 4 8000 samples per sec. 4 Musical CDs use 44100 samples per sec. 55 The sound wave represented by the sequence 0, 1.5, 2.0, 1.5, 2.0, 3.0, 4.0, 3.0, 0 56 The Binary System 4 Binary addition. 4 Fractions in binary. 4 Radix point (same as decimal point in decimal notation). 57 The binary addition facts 58 Decoding the binary representation 101.101 59 Two’s complement notation systems 60 Coding the value -6 in two’s complement notation using four bits 61 Addition problems converted to two’s complement notation 62 An excess eight conversion table 63 An excess notation system using bit patterns of length three 64 Floating-point notation components 65 Floating-Point Notation 4 EX. 0 110 1011 This means that: 4 The sign bit is 0 , the exponent is 110 ,and the mantissa is 1011. To decode the byte Extract the mantissa and place a radix point on its left side. [ .1011 ] 4 Extract the exponent field [110] and decoded from the three-bit excess method i.e. +2 66 Floating-Point Notation 4 This means that the radix in our solution to the right by two bits.( a negative exponent would mean to move the radix to the left) 4 Which gives [10.11] 4 The sign bit is 0 so the value represent a positive value. [ + 10.11 ] 4 Truncation Errors: Round-off errors meaning that part of the value being stored is lost because the mantissa field is not large enough. 67 Coding the value 2 5/8 68 Storing Fractions 4 Floating-point notation. 4 Sign bit => Exponent => Mantissa. 4 Round-off errors. 69 DATA COMPRESSION 4 Run-length encoding: 4 Best result when data being compressed consist of long sequences of the same value. It is the process of replacing such sequences of the same value 4 11111111110000000000111111111111111 by 10 ones 10 zeros 15 ones 70 DATA COPRESSION 4 Relative Encoding 4 The approach is to record the differences between consecutive data blocks rather than entire blocks. i.e. Each block is encoded in terms of its relationship to the previous block. 71 DATA COMPRESSION 4 Frequency-dependant Encoding 4 The length of the bit pattern used to represent a data item is inversely related to the frequency of the item’s use. 4 Ex. Variable length codes 4 Huffman codes 72 DATA COMPRESSION 4 Adaptive dictionary encoding 4 Lempel-Ziv encoding 4 ABAABQB (5,4,A) (0,0,D) (8,6,B) 73 Decompressing xyxxyzy (5, 4, x) 74 Communication Errors 4 How can you make sure the information you receive is correct??? 4 Coding techniques for error detection and correction. 4 Parity bits. 4 Error-correcting codes. 75 The ASCII codes for the letters A and F adjusted for odd parity 76 An error-correcting code 77 Decoding the pattern 010100 78 Ch. 2 Data Manipulation 4 The central processing unit. 4 The stored-program concept. 4 Program execution. 4 Other architectures. 4 Arithmetic/logic instructions. 4 Computer-peripheral communication. 79 The Central Processing Unit CPU ALU Regs. Control unit Bus Main memory 80 Adding values stored in memory 81 The Central Processing Unit 4 General-purpose registers - temporary holding places for data being manipulated by the CPU. 4 Cache memory (memory hierarchy!). 4 Bus - CPU/memory interface. 4 Machine instructions - data transfer, arithmetic/logic, and control. 82 The Stored-Program Concept 4 In early computing, the program is built into the control unit as a part of the machine. The user rewires the control unit to adapt different programs. 4 Instructions as bit patterns - a program and data can be coded and stored in main memory. A computer’s program can be changed merely by changing the contents of the computer’s memory instead of rewiring the control unit. 83 The Stored-Program Concept 4 The main concept of the stored-program is that both program and data are stored in main memory instead of data were stored in memory and programs were part of the control unit. 4 Machine instructions consists two fields: op-code and operand. 84 Dividing values stored in memory 85 The Stored-Program Concept ALU CPU Control unit Regs. Instr. Reg. Program counter Bus Op-code Address 00 Main FF memory operand 86 Program Execution 4 The machine cycle: 4 1. Fetch: retrieve the next instruction from memory and then increment the program counter. 4 2. Decode: decode the bit pattern in the instruction register. 4 3. Execute: perform action requested by the instruction in the instruction register. 87 The machine cycle 88 Decoding the instruction B258 89 Figure 2.10: The program stored in main memory ready for execution 90 Figure 2.11:Performing the fetch step of the machine cycle (continued 91 Other Architectures 4 The design of a machine’s language - complex instruction set Vs. simple instruction set. 4 CISC Vs. RISC. 4 CISC – micro program. 4 RISC - simple CPU design. 92 Performing the fetch step of the machine cycle 93 Other Architectures 4 Pipelining - the throughput concept. 4 Multiprocessor machines - parallel processing. 4 SISD, SIMD, MIMD. 4 Load balancing problem in multiprocessor machines. 4 Distributed systems. 94 Rotating the bit pattern A3 one bit to the right 95 Arithmetic/Logic Instructions 4 Logic operations - AND, OR, XOR, …. 4 Masking (AND operation) and bit map. 4 Rotation and shift operations - logic shift and arithmetic shift (leave the sign bit unchanged). 4 Arithmetic operations - add, subtract,….. 96 Computer-Peripheral Communication 4 Controllers handle communication between machine’s CPU and peripheral devices. 4 The controllers are often a stand-alone small computer, each with its own memory and CPU that performs a program to convert messages and data back and forth between machine and a peripheral device. 97 Computer-Peripheral Communication Peripheral device Controller CPU Bus Main memory Controller Peripheral device 98 A conceptual representation of memory-mapped I/O 99 Computer-Peripheral Communication 4 Direct memory access (DMA) - the ability of controller which can access memory directly. 4 Buffering - a buffer is any location where one system leaves data to be picked up later by another. 4 von Neumann bottleneck - central communication bus problem. 100 Computer-Peripheral Communication Peripheral device Memory-mapped I/O Controller Main memory CPU Bus 101 Computer-Peripheral Communication 4 Port - the block of addresses associated 4 4 4 4 4 4 with a controller. Handshaking - the two-way communication that takes place between devices. Parallel and serial communications. Bits per second (bps) and baud rate. Data compression. Huffman code. Lempel-Ziv encoding. 102 Part II: Software 4 In part II, we focus on topics associated 4 4 4 4 with software. In particular, we will investigate the discovery, representation, and communication of algorithms. Operating systems and networks. Algorithms. Programming languages. Software engineering. 103 Ch. 3 Operating Systems and Networks 4 The evolution of operating systems. 4 Operating system architecture. 4 Coordinating the machine’s activities. 4 Handling Competition among processes. 4 Networks. 4 Network protocols. 104 Operating Systems 4 Why needs an operating system? 4 Computer applications often require a single machine to perform activities that may compete with one another for the machine’s resources. It requires a high degree of coordination to ensure that unrelated activities do not interfere with one another and that communication between related activities is efficient and reliable. 4 What is an operating system? A software system which handles such a coordination 105 task. The evolution of Operating Systems 4 Single-processor systems. 4 Batch processing - the execution of jobs (programs) by collecting them in a single batch, then executing them without further interaction with the user. 4 A job queue (FIFO) and a job control language (JCL). 4 The main drawback to batch processing is no interaction between user and job. 106 Batch processing 107 Software classification 108 The Evolution of Operating Systems Interactive processing, Real-time processing. Time-sharing. Multitasking - time-sharing for a single user systems. 4 Multiprocessor systems - networks such as internet. 4 Load balancing and scaling problems. 4 4 4 4 109 Interactive processing 110 Operating System Architecture Software Application Utility System Operating system Shell Kernel 111 Operating System Architecture 4 A machine’s software can be divided into two categories: application software and system software. 4 Application software - the programs for performing tasks particular to the machine’s utilization. 4 System software - performs tasks which are common to computer systems in general. 112 Operating System Architecture Software Application Utility System Operating system Shell Kernel 113 The shell as an interface between users and the operating system 114 Operating System Architecture 4 System software can be divided into two categories: operating-system software and utility software. 4 Utility software consists of software units that extend the capabilities of the operating system. For example, the ability to format a disk or software for communicating through a modem over telephone lines. 115 Operating System Architecture 4 Shell - the portion of an operating system that defines the interface between the operating system and its users. 4 Graphical user interface (GUI). 4 Importance of uniformity in the humanmachine interface across a variety of machines. 4 UNIX Vs. MS-DOS and Windows. 116 Operating System Architecture 4 Kernel - the internal part of an operating system, which contains those software components that perform the very basic functions required by the computer installation. 4 File manager - directory (folder) and path. 4 Device drivers. 4 Memory manager. 117 OPERATING SYSTEM TASKS 4 1- Processor Management 4 2- Memory and Storage Management 4 3- Device Management 4 4- Application Interface 4 5- User Interface 118 OPERATING SYSTEM TASKS 4 A- Processor Management 4 1- Ensuring that each process and application receives enough of the processor’s time to function properly. 4 2- Using as many processor cycles for real work as is possible. 119 OPERATING SYSTEM TASKS 4 B- Memory and Storage Management 4 1- Each process must have enough memory in which to execute and it can neither run into the memory space of another process nor be run into by another process. 4 2- The different types of memory in the system must be used properly so that each process can run most effective. 120 OPERATIND SYSTEM TASKS 4 C- Device Management 4 The path between the OS and virtually all hardware not on the mother board goes through a special program called a driver. It’s function to communicate with the controllers to carry out operations on the peripheral devices. 121 OPERATION SYSTEM TASKS 4 D- Application Interface 4 Just as drivers provide a way for applications to make use of hardware sub systems without having to know every detail of the hardware operation. [Application Program Interfaces ] use functions of the computer and operating system without having to directly keep track of all the details. 122 OPERATING SYSTEM TASKS 4 E- User Interface ( UI ) 4 User Interface brings structure to the interaction between a user and the computer. 4 EX: 4 Graphical User Interface [GUI] 4 Window Manager 123 Operating System Architecture 4 4 4 4 4 Main memory Vs. virtual memory. Pages. Scheduler and dispatcher. Booting (booting strapping). Bootstrap - a short program placed in ROM and this program is executed automatically when the machine is turned on. 124 VIRTUAL MEMORY 4 The memory mangers will divide the required space into units called Pages and store the contents of these Pages in mass storage [ typical page size a few K Bytes ]. When different pages are required in the main memory. The memory manager would exchange them for pages that are not required. This is called VIRTUAL MEMORY 125 OPERATING SYSTEM 4 In time sharing system 4 Scheduler: determines which activities are to be considered for execution 4 Dispatcher: controls the allocation of time slices to these activities. 126 BOOTSTRAP 127 Coordinating the Machine Activities 4 Process - is a dynamic activity whose properties change as time progresses. 4 Process state - is a snapshot of the machine at that time. For example, the current position in the program being executed and the values in the CPU registers. 4 A program Vs. a process. 4 Interprocess communication. 128 Coordinating the Machine’s Activities 4 Process administration - the tasks associated with process coordination are handled by the scheduler and dispatcher within the operating system’s kernel. 4 Process table - keeps information of a process when it is created (assigned memory area, the priority, the status - ready or waiting). 129 between clients and servers operating on the same machine and distributed among different machines 130 Coordinating the Machine’s Activities 4 The dispatcher is the component of the kernel that ensures that the scheduled processes are actually executed. 4 In a time-sharing system, the dispatcher divides time into time slices or quantum. 4 The dispatcher interrupts the process running out of a time slice and assign a time slice to another process (process switch). 131 Time-sharing between process A and process B 132 Coordinating the Machine’s Activities 4 The client/server model. 4 A client - makes requests of other units. 4 A server - satisfies the requests made by clients. 4 The client/server model in the design software leads to uniformity among the types of communication taking place in the system. 133 The client/server model 134 Handling Competition Among Processes 4 4 4 4 Competing resources among processes. Semaphores. Test-and-set. Critical region - is a sequence of instructions which can be executed by only one process. 135 DEADLOCK 136 Handling Competition Among Processes 4 Deadlock - when two or more processes are blocked from processing because each is waiting for access to resources allocated to another. 4 Three necessary conditions to avoid deadlock: 4 1. There is competition for non-shareable resources. 137 Handling Competition Among Processes 4 2. The resources are requested on a partial basis; that is, having received some resources, a process will return later to request more. 4 3. Once a resource has been allocated, it cannot be forcibly retrieved. 4 Spooling - holding data for output at a later but more convenient time. 138 Networks 4 Local area networks (LAN). 4 Wide area networks (WAN). 4 Proprietary networks. 4 Open networks. 4 Network topology - ring, bus, star, and irregular. 139 140 141 NETWORK TOPOLOGIES 142 NETWORK TOPOLOGIES 143 The distinction between a bridge and a router 144 Networks 4 Internet - initiated in 1973 by the Defense Advanced Research Projects Agency (DARPA). Goal: develop the ability to connect a variety of computer networks o that they can function as a single network. 4 Internet addressing - domains (a collection of network clusters), network identifier, host address; ex., [email protected]. 145 Networks 4 Email and name server. 4 The world wide web - hypertext and hypermedia documents. 4 A browser - a client. 4 Uniform resource locator (URL) - a browser can contact the proper server and request the desired document. 4 Hypertext Markup Language (HTML). 146 A typical approach to connecting to the Internet 147 INTERNET ADDRESSING Each machine in the internet is assigned a unique address called IP IP is a pattern of 32 bits consisting of two parts: 1- Pattern identifying the Domain ( Network Identifier ) 2- Pattern identifying the machine within the domain ( Host Address ). 192.207.177.133 Network Host Identifier Machine Domain Name: ksu.edu.sa 148 INTERNET Electronic Mail [ Mail Server ] The world wide web [ www ] The internet became a means of propagating multimedia documents known as hypertext [ text, images, sound, and video ] Browser software is needed to browse the net. In order to locate and retrieve documents on the ( www ) each document is given a unique address called Uniform Resource Locator ( URL ). Hypertext Markup Language [ HTML ] 149 A typical URL 150 A simple Web page expressed in HTML 151 Network Protocols Protocols - the rules that govern the communication between different components within a computer system. Token ring protocol for networks with the ring topology. CSMA/CD (carrier sense, multiple access with collision detection) in an Ethernet. 152 Communication over a ring network 153 Communication over a bus network 154 The Layered Approach to Internet Software This can be explained by the analogy if you were to send a gift in a package from the west coast of Saudi Arabia to a friend on the East coast. You would warp the gift in a package and write the address outside the package. You would take the package to a shipping company. The following fig. shows the process for the package-shipping example. 155 Package-shipping example 156 The internet software layers. The internet software has four layers each consisting of a collection of software routines. The four layers are known as the application, transport, network, and link layers. Layers are present on each machine in the internet. 157 The Internet software layers 158 NETWORK PROTOCOLS 1- The application layer A- File Transfer Protocol [ FTP ] B- Telnet: allowing a person to access a machine across the internet. C- Simple Mail Transfer Protocol ( SMTP ): Software used by the mail servers when transferring E- mail. 159 NETWORK PROTOCOL 2- The transport layer Its function is to accept messages from the application layer and to ensure that the messages are properly formatted for transmission over the internet. 160 NETWORK PROTOCOLS 3- The network layer It is responsible for seeing that the packets it receives are forwarded from one network within the internet to another until they reach their final destinations 161 NETWORK PROTOCOLS 4- The link layer Its function is to deal with the communication details particularly to the individual network in which the machine resides 162 Network Protocols: The Internet Software Layer Message source Message destination Application layer Application layer Transport layer Transport layer Network layer Network layer Link layer Link layer 163 Network Protocols Open system interconnection (OSI). International standards organization (ISO). TCP/IP (transmission control protocol/internet protocol). UDP (user datagram protocol). 164 Differences between TCP &UDP 1- TCP transport layer is said to establish a connection before sending a message. UDP dose not establish such a connection prior to sending a message. UDP is called connectionless protocol. 2- TCP transport layers at the origin and destination work together by means of acknowledgments and packet retransmissions to confirm that all segments of a message are successfully transferred to the destination. UDP dose not offer such retransmission services but UDP is more streamlined than TCP. 165 TCP AND UDP E-mail is normally sent by TCP but the communication carried out by the name servers when translating addresses from mnemonic form into IP form uses UDP. IP is the internet standard for network layer. 166 Networks Unauthorized access to information and vandalism Passwords and data encryption Virus Worm 167 SECURITY 1-Password 2- Public-key encryption 3- Secure Socket Layer [ SSL ] 168 VIRUS It is a program segment that attaches itself to other programs in the computer system. When programs are executed, the virus may perform malicious acts that are readly noticeable. 169 WORM Normally refers to an autonomous program that transfer it self through a network, taking up residence in machines and forwarding copies of it self through the network. These programs can be designed merely to replicate themselves or to perform additional vandalism 170 FIREWALL It forms a protective barrier that shields the region on one side from the dangers on the other side. 171 Ch. 4 Algorithms The concept of an algorithm. Algorithm representation. Algorithm discovery. Iterative structures. Recursive structures. Efficiency and correctness. 172 The Concept of an Algorithm An algorithm is an ordered set of unambiguous, executable steps, defining a terminating process. Parallel algorithms. Program Vs. algorithm Vs. process. A program is a representation of an algorithm A process is the activity of executing an algorihm. 173 ABSTRACT NATURE OF ALGORITHM An algorithm is abstract and distinct from its representation. A single algorithm can be represented in many ways. EX: The algorithm for converting temperature readings from Celsius to Fahrenheit. F= (9/5 ) C + 32 Or it could be represented by Multiply the Temp. Reading in C by 9/5 and then add 32 to the product. Or it can be represented by an electronic circuit [ Analogue Computer]. 174 ALGORITHM REPRESENTATION The representation of an algorithm requires some form of language. [ English, Arabic, Russian,....... ] or the language of pictures. Algorithm representation can be constructed, such a building block is called a PRIMITIVE. A collection of primitives along with a collection of rules stating how primitives can be combined to represent more complex ideas constitutes a Programming Language. 175 ALGORITHM REPRESENTATION PRIMITIVE = SYNTAX + SEMANTICS Syntax refers to the Primitive’s symbolic representation Semantics refers to the meaning of the primitive. AIR The syntax of AIR consists of the three symbols A,I,R The Semantics : AIR is gaseous substance that surrounds the world. 176 Algorithm Representation Primitive is a set of well-defined building blocks which algorithm representations can be constructed. Primitive - graphical and texture. Primitive => programming language. Primitive - syntax and semantics. 177 Folding a bird from a square piece of paper (continued) 178 Folding a bird from a square piece of paper 179 Origami primitives (continued) 180 Origami primitives 181 Algorithm Representation Pseudo code - is a notational system in which ideas can be expressed informally during the algorithm development process. Ex. If you have more than $10 buy a cake; otherwise buy nothing => if (cond) then (act1) else (act2) Ex. As long as you have money, you an spend => while(having money) do (spend) 182 Algorithm Representation Ex. Assign name the value price+tax. Begin a pseudocode with procedure name. Ex. The pseudocode for Greetings: procedure Greetings assign Count the value 3; while Count > 0 do (print the message “Hello” and assign Count the value Count - 1) 183 Algorithm Discovery The development of a program consists of two activities - discovering the underlying algorithm and representing that algorithm as a program. The basic principles for problem-solving: 1. Understand the problem. 2. Get an idea as to how an algorithmic procedure might solve the problem. 184 Algorithm Discovery 3. Formulate the algorithm and represent it as a program. 4. Evaluate the program for accuracy and for its potential as a tool for solving other problems. Conscious work Vs. inspiration. Stepwise refinement - a top-down methodology. 185 EXAMPLE Person A is charged with the task of determining the age of Person B’s 3 children: CLUES: 1-The product of the children’s ages is 36 2- The sum of the children’s ages is given Find the ages of the three children. 186 EXAMPLE 187 EXAMPLE The clues is not enough because if the sum is 13 we have two possibility 1+6+6 and 2+2+9. We need a third clue. The third clue is the oldest child plays the piano The solution is 2,2,9 188 EXAMPLE 2 Before A , B, C, and D ran a race they made the following predictions: A predicted that B would win B predicted that D would be last C predicted that A would be third D predicted that A’s prediction would be correct Only one of these predictions was true and this was the prediction made by the winner. In which order did A , B , C , and D finish the race? 189 EXAMPLE 2 Prediction A & D are equivalent Since only one Pred. Was true .Then A & D must be false. Thus neither A nor D were winners. If A Pred. Was false , the B did not win either. The only remaining choice for winner is C. Thus C won the race & C prediction was true. If A came in third We have two order for finishing the race CBAD OR CDAB 190 EXAMPLE 2 C B A D OR CDAB CBAD order is ruled out because B’s prediction must be false. There fore finishing order was : C D A B 191 THE SEQUENTIAL SEARCH ALGORRITHM The problem of searching sorted list for Target value sequentially can be done by comparing the target value to each entry in the list. The sequential search algorithm can be presented in pseudo code as follows. 192 The sequential search algorithm in pseudocode 193 Iterative Structures Iterative structures - a collection of instructions is repeated in a looping manner. The while loop structure. The repeat loop structure. The insertion sort algorithm. 194 LOOP CONTROL WHILE ( condition ) DO ( body ) {WHILE [ The pH level is greater than 4] DO [ add a drop of sulphuric acid ]} add 3 times No Termination Condition Number 1 ; WHILE ( Number NEQ 6 ) DO ( Number = Number + 2 ) 195 Components of repetitive control 196 The while loop structure 197 REPEAT LOOP REPEAT ( ACTIVITY ) UNTIL ( Condition) EX: Repeat ( take a coin from your pocket ) Until ( there are no coins in your pocket ). In the above ex. We assume there is a coin in your pocket at the beginning, but While ( there is a coin in your pocket ) Do ( take a coin from your pocket ) We does not assume that. 198 The repeat loop structure 199 THE INSERTION SORT ALGORITHM The insertion sort algorithm is useful for sorting a list of names alphabetically. The method selects a pivot entry and move it to a temporary location and makes a comparison with the list entries. 200 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued) 201 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued) 202 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically 203 The insertion sort algorithm expressed in pseudocode 204 Recursive Structures Recursive structures provide an alternative to the loop paradigm for repetitive structures (by invoking itself). The binary search algorithm. It is more faster than the sequential search algorithm 205 Applying our strategy to search a list for the entry John 206 A first draft of the binary search technique 207 The binary search algorithm in pseudocode 208 Binary Search Algorithm Consider the list [ Alice , Bill , Carol , David , Evelyn , Fred , and George ], for the target value Bill. Our search begins by selecting David ( the middle entry ) as the test entry under consideration . Since the target value ( Bill ) is less than this test entry, we are instructed to apply the procedure Search to the list of entries preceding David 209 Binary Search Algorithm 210 Binary Search Algorithm Let us consider the list: [ Alice , Carol , Evelyn , Fred , and George ] Searching for the entry ( David ) 211 Binary Search Algorithm 212 Binary Search Algorithm 213 Binary Search Algorithm 214 Efficiency and Correctness You can develop a variety of algorithms to solve the same problem. However, the choice between efficient and inefficient algorithms can make the difference between a practical solution to a problem and an impractical one. Time and storage complexity of the algorithm. 215 Efficiency and Correctness In the insertion sort algorithm the worst scenario is that each pivot must be compared to all the preceding entries before its proper location can be found. This occurs if the original list is in reverse order. The first pivot is compared to two names. The total number of comparisons when sorting a list of n entries is { 1+2+3+ -----+( n-1 ) } = ½[n(n-1] If n=10 would require 45 comparison 216 Efficiency and Correctness In the average case of insertion sort the result is half worst case i.e. ¼[ n(n-1)] Comparison 217 Applying the insertion sort in a worst-case situation 218 Graph of the worst-case analysis of the insertion sort algorithm 219 Graph of the worst-case analysis of the binary search algorithm 220 Efficiency and Correctness How to make sure the algorithm and program developed is correct? Difference between testing and verification. Precondition, assertions, loop invariant. 221 SOFTWARE VERIFICATION A traveller with a gold chain of seven links must stay in an isolated hotel for seven nights. The rent each night consists of one link from the chain. What is the FEWEST number of links that must be cut so that the traveller can pay the hotel one link of the chain each morning without paying for lodging in advance. 222 Separating the chain using only three cuts 223 Solving the problem with only one cut 224 ALGORITHM 1- First morning give the hotel the single link. 2- Second morning retrieve the single link and give the hotel the two link piece. 3- Third morning Give the hotel the single link. 4- Fourth morning retrieve the three links held by the hotel and give the hotel the four 225 link piece. ALGORITHM 5- Fifth morning give the hotel the single link. 6- Sixth morning retrieve the single link and give the hotel the double link piece. 7- Seventh morning give the hotel the single link. 226 VERIFICATION Proof of correctness begins with the assumption that certain conditions, called preconditions, are satisfied at the beginning of the program’s execution. How the consequences of these preconditions propagate through the program. 227 VERIFICATION EX: IF ( condition) THEN ( instruction 1) ELSE ( instruction 2) If some statement is known to hold before execution instruction 1, we know that both that statement and the condition tested are true. Where as if instruction 2 is to be executed, we know the statement and the negative of the condition must hold. 228 The assertions associated with a typical while structure 229 Linear Programming Linear programming is useful tool for solving problems of allocation particularly in maximising or minimising a linear function of variables, 230 LP Example A man owns large premises and wishes to act as a retailer for one of the motor car companies. His capital is 360000 SR and his premises are large enough to accommodate up to 36 cars. He chooses to concentrate his sales on the rapidly selling Maxi model and Mini model and decides to order these two types only. 231 LP Example The manufacturer supplies the Maxi and Mini at 12000SR and 8000 SR respectively and the man wishes to fix his profit on each model at only 300SR and 240SR respectively. By keeping his profits down, he may hope to establish a reputation for not over charging his customers, this is a long-term objective. 232 LP Example Arrangements have been made to prepare the premises to receive the new cars directly from the manufacturer. The man now has to make a very important decision. How many of each model should be order? 233 LP Graphical Solution Let x be the number of Maxi cars to be order. Let y be the number of Mini cars to be order Let P be the total profit he will make by selling all his cars. P is called Object function 234 LP Graphical Solution The aim is to Maximize the objective function P = 300 x + 240 y The restrictions of space and capital must also be taken into account. Such restrictions are called constraints. 235 LP Graphical Solution x + y <= 36 Space Constraint 12000x+8000y<=360000 Capital Constraint . Dividing Capital Const. By 4000 3 x + 2 y <= 90 The LP problem can be stated as: 236 LP Solution Max P = 300 x + 240 y Subject to x + y <= 36 3 x + 2 y <= 90 x >= 0 y >= 0 237 Graphical Solution 238 Simplex Method 1- Construct the first table 2- Locate a pivot 3- Calculate a new table 4- Repeat step 2 and 3 until the terminal table is obtained 239 Linear Programming Problem The general form of the LP problem is as follows: Max. the objective function P = C1X1+ C2X2+ ----------- +CnXn Subject To: a11X1+a12X2+---------- +a1nXn <=b1 a21X1+a22X2+-----------+a2nXn <=b2 ak1X1+ak2X2+------------ +aknXn<=bk X1,X2,------------- Xn >= 0 240 Simplex Method 1- After construction of the first table select any column which contains the most negative coefficient for the non basic variables. 2- Divide each positive entry in this column into the corresponding element in the last column i.e. Form the quotient ( b/a ) for all k pairs of elements unless a is negative. The entry which yields the smallest quotient is called the pivot. It’s column is called Pivotal Column and its row is called Pivotal Row. 3- If the table has no negative indicator then it is called Terminal table and has no pivot 241 Simplex Method Consider the LP problem Max. P= 4*x1 + 3* x2 Subject to : 2x1 + 3x2 <= 6 - 3x1 + 2x2 <= 3 2x2 <= 5 2x1 + x2 <= 4 x1>=0 , x2 >= 0 The equations can be written as follows by introducing Slack variable. 242 Simplex Method P = 4x1+ 3x2+ 0S1+ 0S2+ 0S3 + 0S4 Subject to: 2x1+ 3x2+ S1 =6 -3x1+2x2 +S2 =3 0x1 + 2x2 +S3 =5 2x1 + x2 +S4 = 4 x1, x2, S1, S2, S3, S4 >= 0 The basic feasible solution x1= x2= 0 Then S1= 6 , S2= 3, S3= 5 , and S4 =4. 243 Simplex Method ( First Table ) Basic P x1 x2 S1 S2 S3 S4 Solution ---------------------------------------------------------------------P0 0 -4 -3 0 0 0 0 0 P equation ----------------------------------------------------------------------S1 0 2 3 1 0 0 0 6 S2 0 -3 2 0 1 0 0 3 S3 0 0 2 0 0 1 0 5 S4 0 2 1 0 0 0 1 4 244 Simplex Method The non basic variables are x1&x2= 0 yield P =0 The entering variable be selected as the non basic variable having a negative coefficient in the P equation of the table. In our example both x1 &x2 have negative coefficient . The variable with the most negative coefficient is selected. This column is called the pivotal column 245 Simplex Method Basic Solution x1 Ratio(b/a) S1 6 2 6/2=3 S2 3 -3 ----S3 5 0 -----S4 4 2 4/2= 2 min. 2 is called the Pivot element. Do row operation to get new table We divide the row by the pivot and replace S4 by x1. 246 Simplex Method The pivotal Row is divided by the pivot [ 2 ] P0 x1 x2 S1 S2 S3 S4 Solution X1 0 1 1/2 0 0 0 1/2 2 Do row operation for the other rows P0 -4 -3 0 0 0 0 0 + 4 2 0 0 0 2 8 ------------------------------------------------------------0 -1 0 0 0 2 8 247 Simplex Method S1 2 3 1 0 0 0 6 + -2 -1 0 0 0 -1 -4 ------------------------------------------------------------0 2 1 0 0 -1 2 S2 -3 2 0 1 0 0 3 + 3 3/2 0 0 0 3/2 6 ------------------------------------------------------------0 7/2 0 1 0 3/2 9 S3 0 2 0 0 1 0 5 248 Simplex Method ( New Table) Basic P P0 1 S1 0 S2 0 S3 0 X1 0 x1 0 0 0 0 1 x2 -1 2 7/2 2 1/2 S1 S2 S3 S4 Solution 0 0 0 2 8 1 0 0 -1 2 0 1 0 3/2 9 0 0 1 0 5 0 0 0 1/2 2 The new basic solution: x1= 2, x2= 0, S1= 2, S2= 9, S3=5, S4= 0, and P=8 249 Simplex Method The new entry variable is x2, it has the only negative coefficient in P equation. To find the pivot do Basic Solution x2 Ratio S1 2 2 2/2=1 min. Pivot S2 9 7/2 9(2/7)= 18/7 S3 5 2 5/2= 2.5 X1 2 1/ 2 2(2/1)=4 X2 is the entry variable and S1 is the leaving variable. Do Row operation to get new table 250 Simplex Method ( New Table) Basic P0 x1 x2 S1 S2 S3 S4 Solution -----------------------------------------------------------------P0 1 0 0 1/ 2 0 0 3/2 9 -----------------------------------------------------------------X2 0 0 1 1/ 2 0 0 - 1/ 2 1 S2 0 0 0 -7/ 4 1 0 13/4 3/2 S3 0 0 0 -1 0 1 1 3 X1 0 1 0 - 1/ 4 0 0 3/ 4 3/ 2 Since all the coefficient of P equation is positive So we have terminal table. The solution is : X1= 1.5 X2= 1 P ( max )=9 251 LP Example A paper company received three orders for paper rolls with the widths and lengths indicated in the following table Order Number Width[m] Length[m] 1 5 10000 2 7 30000 3 9 20000 Rolls are produced in the company in two standard widths, 10 and 20 meters. There is no limit on the lengths of the standard rolls. The objective is to determine the production schedule ( cutting patterns) that minimizes the trim losses while satisfying the given demand. 252 LP Example <- ---- 10m-----> < ------- 20 m------------- > ______________ _____________________ < 5m > < 5m > < 7m > < 9m > < 4m > Trim loss=0m Trim loss = 4 m For the above cut the trim loss for 10m is 0 m square but the trim loss area for the 20 m roll is : 4*30000 + 9*10000 = 210000 m square This is only one of the possible cutting patterns. The optimum solution must specify the length of the standard roll that must be cut according to each pattern. 253 LP Example Now let Xij be the length of the i roll [ i=1 for 10m roll and i=2 for 20m roll ] which is cut according to the jth pattern. Width X11 X12 X13 X21 X22 X23 X24 X25 X26 Requirements 5m 2 0 0 4 2 2 1 0 0 10000 7m 0 1 0 0 1 0 2 1 0 30000 9m 0 0 1 0 0 1 0 1 2 20000 ___________________________________________________________________ Trim loss 0 3 1 0 3 1 1 4 2 254 LP Example Now let S1, S2, and S3 be the surplus lengths produced of the rolls with widths 5m, 7m, and 9m. So the LP problem can be formulated as: Minimize The objective function: P= 3X12+X13+3X22+X24+4X25+2X25+5S1+7S2+9S3 Subject to: 2X11+4X21+2X22+2X23+X24- S1 = 10000 X12 +X22+ 2X24+ X25 -S2 = 30000 X13+X23+ X25+ 2X26 - S3 = 20000 Xij>=0 , Si >= 0 for all i and all j 255 Iterative Techniques A) Repeated Substitution Consider the two linear equations: Y=7–X [1] X= ½ ( Y + 2 ) [2] Solving it by the method of Repeated Substitution. Initially let X= 0 Then substitute in Equation [1] to give Y=7 Then substitute in equation [2] to give X= 9/2 Then this value substitute in Eq. [1] gives new value of Y, and this cycle process can be repeated indefinitely while the value of X and Y approach the exact solution. 256 Graphical Solution ( X=3, Y=4) 257 Algorithm 1- Read Eqns.[1] and [2] 2- Set X = 0 3- Substitute X into Eqn. [1] to give Y 4-Substitute value of Y from step 3 into Eqn.[2] to give X 5- Go to Step ( 3 ). To stop the iteration calculate [ Xi+1 – Xi ] for each iteration and stop at appropriate value. [ very small value ]. This method is used for nonlinear equations. 258 The Bisection Method Consider the equation: Y= 20Xpower3- 59Xpower2- 33X+90 The smallest positive solution to this equation is required. The dominant Xpower3 term, as X becomes large and +ve Y becomes large and +ve and as X becomes large and –ve Y becomes large and –ve. The behaviour of small values of X can be determined by simple calculation. 259 Bisection Method When X = 0 , Y = 90 When X = 1 , Y = 20 – 59 – 33 + 90 = + 18 When X = 2 , Y = 160 – 236 – 66 + 90 = - 52 This indicate there is a root between X> 1 & X< 2. We can draw the function to a much greater accuracy the section of the curve between X=1 & X=2. 260 261 Bisection Method We can use the fact : the value X=1[ for Y>0] is too small, and the value X=2 [ for Y<0] is too large. By bisecting the interval between the upper and lower bounds on the root and testing the value of Y, the gap ( G ) between the upper bound (U) and the lower bound (L) can be systematically reduced. This is called the Bisection Method. The algorithm for the method is given which constructed to deal with the case where the curve has –ve gradient at the point where it crosses the X-axis i.e. F(L) >0 and F(U) < 0 262 Bisection Method If the curve has +ve gradient at the root then the bounds will be given by: F(L) < 0 and F(U) > 0 In which case the first decision must be change to Y<= 0 263 Bisection Algorithm 1- Let L=1 and U= 2 2- G = U – L 3- X = L + G/2 4- Calculate Y = F ( X ) 5- If Y >= 0 let L= X , go to 7 6- U = X 7- If G NOT sufficiently small Go to step 2 8- Print X 9- Stop 264 Numerical Integration A) Trapezium Rule 265 Trapezium Rule If the area under a curve f(x) is divided into n strips each of width w, then the area is given by: Area = w [ ½(Y0+Yn) + sum of remaining Y- sticks ] Where Yi is the height above the axis of the point on the curve whose x coordinate is xi. PROOF: Divide the area into n parallel strips of width w. Area under the curve = the sum of areas of all trapezium. = w(1/2(Y0+Y1))+w( ½(Y1+Y2))+.........+w(1/2( Yn-1+ Yn))= w [ 1/2Y0+Y1+Y2+............+Yn-1+1/2Yn] = w[ ½(Y0+Yn)+ sum of remaining Y sticks ] 266 Simpson's Rule This rule states that if the area under a curve f(x) is divided into 2n strips ( i.e. n pairs of sticks) each of width w, then the area is given by: Area= (w/3)[(Y0+Y2n) +( 4* sum of odd Y-sticks) + ( 2* sum of even Y-sticks)] PROOF: For any three points on the curve ,it can be joined by a parabola: Y(x) = a *Xpower2 + b* X + c 267 Simpson’s Rule 268 Simpson’s Rule The point P (-w. Y0) , Q ( 0, Y1) , R ( w, Y2) The area under the curve is given by : Area = integral f(x) dx from –w to w = [ (aXpower3/3)+ (bX power2/2) +cX] from –w to w ={[(a*wpower3/3)+(b*wpower2/2)+c*w]- [(a*wpower3/3)+( b*wpower2/2) –c*w]} = [ (2*a *wpower3/3) + 2* c* w ] = (w/3 )* (2*a* wpower2 + 6* c ) 269 Simpson’s Rule Substituting the known values of x to find expressions for the values of Y at the points P, Q, and R. At P Y0= a* w power 2 – b* w + c At Q Y1= +c At R Y2= a* w power 2 + b* w + c By inspection 2*a * w power2 +6*c = Y0+4*Y1+Y2 Replacing the term in Area equation Area = (w/3)*( Y0 + 4* Y1 + Y2) 270 Simpson’s Rule 271 Simpson’s Rule Area= sum of the area beneath the curve f(x). = Sum of areas of the n pairs of strips = area of 1st pair+ area of 2sd pair +......+ area of nth pair = (w/3){ (Y0+4Y1+y2)+( Y2+4Y3+Y4)+..............+ (Y2n-2+4Y2n-1+Y2n)}. Area= (w/3)*{( Y0+Y2n)+ ( 4* sum of odd Y sticks)+ ( 2* sum of even Y- sticks )} 272 Ch. 5 Programming Languages Historical perspective. Traditional programming concepts. Program units. Language implementation. Parallel computing. Declarative programming. 273 Historical Perspective Machine language - binary form direct controls the hardware. Assembly language - mnemonic form of the machine language. High-level programming language English like language. Evolution? 274 Programming Lag. The programming process required the programmer to express all algorithms in the machine language. First Generation Second Generation Machine Lang. Assembly Lang. 15 5C LD R5, Price 16 6D LD R6, Shipping charge 50 56 ADDI R0,R5,R6 30 6E ST R0, Total Coast C0 00 HLT 275 Programming Lang. Disadvantages: 1- Program written in assembly lang. Is Machine Dependant 2- Programmer required to code instructions in bit pattern form. 276 Historical Perspective HLL Machine independent Compiler Assembler 1 Assembler n Machine dependent Arch 1 Arch n 277 Programming Lang. [ HLL ] The third generation Their primitives were higher level and machine independent. FORTRAN [ FORmula TRANslation ] COBOL [ Common Business Oriented Language ] A program called Translator, was written to translate programs into machine language programs. This translator often had to compile several machine instructions into short sequences to simulate the activity required by a single high level primitive. Thus these translators were often called COMPILERS. 278 Historical Perspective 1st-generation - machine language. 2nd-generation - assembly language. 3rd-generation - machine independent. 4th-generation - software packages that allow users to customize computer software to their applications without needing technical expertise. 5th-generation - declarative (logic) programming. 279 Historical Perspective Problems solved in an environment in which the human must conform to the machine’s characteristics 1st Problems solved in an environment in which the machine conforms to the human’s characteristics 4th 280 Programming Lang. Programming Languages are divided into four groups: 1- Imperative Paradigm 2- Functional Paradigm 3- Object-Oriented Paradigm 4- Declarative Paradigm 281 IMPERATIVE PARADIGM Imperative paradigm , also known as the procedure paradigm [ Machine Languages, FORTRAN, COBOL, ALGOL, BASIC, APL, C , PASCAL , and ADA ]. It defines the programming process to be the development of a sequence of commands that, when followed, manipulate data to produce the desired result. 282 Functional Paradigm It views the process of program development as the construction of ( black boxes) each accepts inputs and produces outputs [ LISP, ML , Scheme ]. The primitives of a functional programming lang. Consist of elementary functions from which the programmer must construct the more elaborate functions required to solve the problem at hand. 283 Generations of programming languages 284 Ex. Functional Paradigm A function that computes the average of a list of numbers constructed from the simpler functions Sum, Count, and Divide 285 Object- Oriented Paradigm In this type units of data are viewed as active “Objects’’ rather than the passive units envisioned by the imperative paradigm, [ SIMULA, Smalltalk, C++, Ada95, Java ]. 286 Example Consider a list of names, in imperative paradigm the list is considered merely a collection of data . Any program accessing this list must contain the algorithms for performing the required manipulations. Thus the list is passive in the sense that it is maintained by a controlling program rather than having the responsibility of maintaining it self. In the object-oriented approach, the list is constructed as an object consisting of the list together with a collection of procedures for manipulating the list. 287 Example This may include procedures for: Inserting a new entry in the list Deleting an entry from the list Detecting if the list is empty Sorting the list A program accessing the list does not need to contain algorithms for performing these task. 288 Declarative Paradigm It discover and implement a general problem-solving algorithm, [ GPSS, Prolog] The trick here is to discover and implement a general problem-solving algorithm. Once this is done , problems can be solved merely by stating them in a form that is compatible with this algorithm. 289 Traditional Programming Concept Statements in programming languages tend to fall into three categories: declarative statements, imperative statements, and comments. Declarative statements - define customized terminology used in the program. Imperative statements - describe steps in the underlying algorithm. Comments. 290 The composition of a typical imperative program or program unit 291 Traditional Programming Concept Variables, constants, and literals. Data type - integer, real, Boolean, char….. Data structure - array, queue, list,…….. Assignment statements Control statements. Comments - internal documentation. 292 Variables and Data Types High level language allows locations in main memory to referenced by descriptive names rather than by numeric addresses. Such names is known as variables. The type of data that will be stored at the memory location associated with the variable is known as data type. Integer Real Float Boolean 293 The same variable declarations in different languages 294 Data Structure Data structure is the conceptual shape or arrangement of data. Ex. Text is viewed as long string of characters Sales Records : is viewed as a rectangular table of numeric values. 295 Homogenous Array A block of values of the same types. Ex. One dimension array Two dimension array The individual component can be identified by means of row and column and called INDICES. 296 A two-dimensional array with two rows and nine columns 297 Heterogeneous Array It is block of data in which different elements can have different types. Ex. Block of data referring to an employee may consist of: 1- An entry called Name ( Character ) 2- An entry called Age ( Integer ) 3- An entry called Skill Rating ( Real ) 298 Declaration of heterogeneous arrays in Pascal and C (continued) 299 Declaration of heterogeneous arrays in Pascal and C 300 Constant and Literals When a fixed predetermined value is used in a program. Such value is called LITERAL. A = B+250 Where A and B are variables and 250 is literal. Using literal in program is not good programming it is better to use CONSTANT. Constant is descriptive name to be assigned 301 to specific, non changeable value. Assignment Statements Z=X+Y; Z := X + Y ; ZX+Y; 302 Control Statement Control Statement is an imperative statement that alter the execution sequence of the program. The simplest control statement is GO TO EX. IF statement Two options WHILE statement Two options CASE statement Many options The loop structure 303 Control structures and their representations in C, C++, C#, and Java (continued) 304 Control structures and their representations in C, C++, C#, and Java 305 The for loop structure and its representation in Pascal, C++, C#, and Java (continued) 306 The loop 307 Comment Programming languages provide ways of inserting explanatory statements called COMMENTS Ex. /* This is a comment*/ C++,C, Java // This is a comment . C This is a comment. FORTRAN 308 Program Units Breaking large programs into manageable units, units = modules, functions, objects. Procedures and functions. Parameter passing - formal parameters and actual parameter, call by address and call by value. I/O statements. 309 Procedural Units A procedure is a set of instructions for performing a task that can be used as an abstract tool by other program units. Ex. Procedure Sort ( List ) The generic term (list) is called PARAMETER The terms used in writing the procedure is called formal parameter. 310 Procedure The precise meanings assigned to these formal parameters when the procedure is applied are called actual parameters. When parameter is passed by value the data in the calling program unit are never changed. But if the parameters are passed reference allows the procedure to modify the data residing in the calling program. 311 The flow of control involving a procedure 312 The procedure Project Population written in the programming 313 Example Procedure Demo ( Formal ) Formal = Formal + 1 314 Executing the procedure Demo and passing parameters by value (continued) 315 Executing the procedure Demo and passing parameters by value (continued) 316 Executing the procedure Demo and passing parameters by value 317 Executing the procedure Demo and passing parameters by reference (continued) 318 Executing the procedure Demo and passing parameters by reference (continued) 319 Executing the procedure Demo and passing parameters by reference 320 Function Function is a program unit similar to a procedure except that a value is transferred back to the calling program unit as the value of the function. 321 The function CylinderVolume written in the programming language C 322 INPUT&OUTPUT Statement EX. Read in ( value ) write in ( value ) 323 An example of formatted output 324 Language Implementation Translation - converting a program from one language to another. Translation involves three activities: 1. Lexical analysis, 2. Parsing, and 3. Code generation. Lexical analysis - recognizing which strings of symbols from the source program represent a single entity. 325 The translation process 326 Lexical Analyzer Ex. 153 should not interpreted as a 1 , a 5, and a3. but should be recognized as single numeric value [ 153 ] base 10. Lexical analyzer generates a bit pattern known as token to represent the unit and hands the token to the parser. During this process lexical analyzer skips overall comment statements. 327 Language Implementation Parsing - identifying the grammatical structure of the program and recognizing the role of each component. Fixed-format languages{ FORTRAN} Vs. free-format languages { C }. Key words, reserved words, syntax diagram, parse tree. Coercion and strongly typed. 328 The Parser The parser views the program in terms of lexical units [ tokens ] rather than individual symbols. The parser job to group these units into statement. Key words [ IF , THEN , ELSE ] are called reserved words. The parsing process is based on a set of syntax rules. 329 The Parser The syntax rules defined by syntax diagrams. Fixed Format Languages [ FORTRAN ] Free Format Languages [ C ] 330 A syntax diagram of our if-then-else pseudo code statement 331 Syntax diagrams describing the structure of a simple algebraic expression 332 Parse tree for X+Y*Z The parse tree for the string x + y z based on the syntax diagrams 333 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued) 334 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued) 335 Coercion The statement X + Y If X is integer and Y is real The parser choose to have the code generator build the instructions to convert one value to the other type and then perform the addition such implicit conversion between types is called Coercion. Strongly typed: means that all activities requested by a program must involve data of agreeable types without coercion. Parsers for these lang. Report all type conflicts as Errors 336 Language Implementation Code generation - constructing the machine language instructions to simulate the statements recognized by the parser. Code optimization. Linker - links all necessary object programs to produce a complete, executable program. Loader - place the program in memory for execution (what about multitasking?) 337 If the object program is requests services from other programs. The task of making these connections is preformed by a program called LINKER . Its job to link several object programs. The result is executable program called LOAD module. The module is placed in Memory by a program called a LOADER which is a part of Operating System. 338 An object-oriented approach to the translation process 339 The complete program preparation process 340 Parallel Computing Developing languages for describing processes that execute simultaneously. Ada. Linda - tuple space (a shared storage area), in which each process in the system can deposit and retrieve data bundles. 341 Object-Oriented Programming The object oriented programming entails the development of active program units called objects , each of which contains procedures describing how that object should respond to various stimuli. 342 Object-Oriented The object oriented approach to a problem is to identify the objects involved and describe them as self-contained units. 343 Classes and Objects Consider the task of developing a computer game in which the player must protect the Earth from falling meteors by shooting them with high power lasers. Each laser contains a finite internal power source that is partially consumed each time the laser is fired. Once this source is depleted the laser becomes useless. Each laser should be able to respond to the commands to aim further to the right, aim further to the left, and to fire it’s laser beam. 344 Classes and Objects In object oriented, each laser in the game would be implemented as an object that contains a record of its remaining power as well as procedures for modifying its aim and firing its laser beam. Since all the laser objects have the same properties, they can be build from the same template. This template is called class. A variable that resides within an object, such as Remaining Power, is called an INSTANCE variable and the procedures within an object are called Methods 345 The structure of a class describing a laser weapon in a computer game 346 CONSTRUCTORS In the game we might want the different laser to have different initial power setting. This is done by special methods called CONSTRUCTORS. Initialization needs are handled by defining special methods called constructors 347 A class with a constructor 348 ENCAPSULATION It refers to restricting access to an objects internal properties. To say that certain features of an object are encapsulated means that only the object itself is able to access them. 349 Our Laser-Class definition using encapsulation as it would appear in a Java or C# program 350 DECLARATIVE PROGRAMMING Logical Deduction Suppose we know that either Ali is on stage Or Ali is sick And we are told that: Ali is not on stage, We could the conclude that Ali must be sick This is an example of a deductive-reasoning principle called RESOLUTION 351 Declarative Programming Example: Let A: Ali is a prince. B: Miss Salma is an actress. Then A OR B Means Ali is a prince or Miss Salma is an actress. And B AND ( NOT A ) Miss Salma is an actress and Ali is not a prince 352 Example And A B ( A implies B ) Ali is a prince implies Miss Salma is an actress In general if : P OR Q and R OR ( NOT Q ) We can conclude the statement P OR R 353 Example The two original statements resolve to form the third statement which it is called RESOLVENT. Prolog Programming language is example of declarative programming Prolog is Programming in logic 354 Declarative Programming Resolution can be applied only to pairs of statements that appear in clause form-that is statements whose elementary components are connected by the Boolean operation OR. Thus P OR Q is In clause form whereas P -> Q is not. 355 Resolving the statements (P OR Q) and (R OR Q) to produce (P OR R) 356 Declarative Programming Inconsistent- in a collection of statements, it is impossible for all the statements to be true at the same time. A simple example a statement of the form P combined with the statement NOT P. The rule is that if repeated application of the resolution produces the empty clause [ the result of resolving a clause of the form with 357 a clause of the form NOT P ] Declarative Programming Then the original collection of statements must be inconsistent. 358 Resolving the statements (P OR Q), (R OR Q), R, and P 359 Ch. 6 Software Engineering The software engineering discipline. The software life cycle. Modularity. Development tools and techniques. Documentation. Software ownership and liability. 360 The Software Engineering Discipline How to develop and manage a large program (>100K lines of code) or a huge program (>1M lines of code)??? What is software engineering discipline? What is the quantitative system (metrics) to measure the quality and successfulness of the underlying software development??? Developing techniques for immediate applications and for future applications. 361 The Software Life Cycle Development Use Modification 362 The Software Life Cycle Analysis Design Development phase Implementation Testing 363 The Software Life Cycle Waterfall model. Computer-aided software engineering (CASE). Prototyping. 364 A structure chart for a simple Internet “mail order” business 365 A class diagram for a simple Internet “mail order” business 366 A structure chart showing data coupling 367 A collaboration diagram of a simple Internet “mail order” business 368 Logical and functional cohesion within an object representing an order form in a simple Internet “mail order” business 369 Modularity Modular implementation - structure chart. Coupling - control and data coupling. Implicit coupling, global data - why is not good? Side effects! Cohesion - the coupling between modules. Logical cohesion and functional cohesion. 370 The publisher-subscriber pattern 371 The component-container pattern 372 Development Tools and Techniques Top-down design. Bottom-up design. Dataflow diagrams - a pictorial representation of data paths. Entity-relationship diagrams - a pictorial representation of the items of information (entities) within the system and the relationships between these pieces of information. 373 A dataflow diagram of a simple Internet “mail order” business 374 An entity-relationship diagram 375 One-to-one, one-to-many, and many-to-many relationships between entities of types X and Y 376 Development Tools and Techniques Data dictionaries - a central depository of information about the data items appearing throughout the system. Enhancing communication between the potential user of the system. Establishing uniformity throughout the system. 377 Documentation, software Ownership and Liability User documentation and system documentation. Copyright and patent laws. 378 Part III: Data Organization Data structures. File structures. Database structures. 379 DATA STRUCTURES Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence the selection of a computational strategy for a given data processing job. 380 DEFINITIONS 1- A List is a collection of sets of data elements. LIST and FILE have the same meaning. 2- Nodes : The sets of data contained in a list are referred to as Node. Each node will contain several related data items. A node is equivalent to a record. 381 DEFINITION The items within a node are required to be stored in storage locations, though the nodes themselves need not be adjacent to one another. 3- Field: Each of the items within a given node is said to occupy a field. A field can contain either a data item or a link [or pointer]. 382 DEFINITION 4- The Link [ Pointer]: Contain the starting addresses of other nodes, thus creating a structural interrelationship among the nodes. 383 Novels arranged by title but linked according to authorship 384 DEFINITION The link tell us that the next node in the list has starting address of xxxx. A node need not be restricted to one link, multilinked nodes are common. Each of the nodes in a given list should contain the same number of links. 385 DEFINITION Linear Lists: A linear list is a list which the nodes are ordered in one dimensional arrangement. [ N1, N2, ---, Nr] Sequential linear list When Nodes are stored consecutive adjacent to one another. We refer to the list as sequential linear list .[M/C language, Computer programs, Magnetic tape data files are usually stored in the form of sequential linear list]. 386 LINKED LINEAR LIST Most searching, sorting, and merging operations can be carried out quite easily with sequential linear lists. The simple type of the linked list is the single linked linear list. Each node will contain one pointer, which indicates the starting address of the next node in the list. 387 The array of Readings stored in memory starting at address 388 A two-dimensional array with four rows and five columns stored in row major order 389 Names stored in memory as a contiguous list 390 The structure of a linked list 391 Deleting an entry from a linked list 392 Inserting an entry into a linked list 393 A procedure for printing a linked list 394 MULTIPLE LINKS If each node in the list contains several items, each of which should be ordered in some particular manner, then a different set of links is established for each item. Each set of links establishes a separate single linked linear list. 395 STACKS A stack is a list in which all insertions and deletions are performed at the same end of the structure. Stack known as last-in, first-out [LIFO] structures. 396 BACKTRACKING A classic application of a stack occurs when a program unit requests the execution of a procedure. If the procedure itself request the execution of another procedure, and so on . Stack is an ideal structure for such a system. This process is called Backtracking 397 Nested procedures terminating in the opposite order to that in which they were requested 398 BACKTRACKING Suppose we want to print the names in a linked list in a reverse order that is last name first. We can access the names only by following the link structure. Thus we need to use the stack. 399 Using a stack to print a linked list in reverse order (continue d) 400 Using a stack to print a linked list in reverse order 401 A procedure (using an auxiliary stack) for printing a linked list in reverse order 402 A stack in memory 403 Stacks Last-in first-out. Push and pop. Using stacks for maintaining procedure calls. Other applications??? 404 QUEUES Queue is a list in which all insertions are performed at one end while all deletions are made at the other end. The end at which entries are removed is called the Head [ or sometimes the Front] of the queue. The end of the queue at which new entries are added is called the Tail[ or Rear]. 405 QUEUES QUEUE uses two memory cells to use as pointers instead of just one . Head Pointer Tail Pointer 406 A queue implemented with head and tail pointers 407 A queue “crawling” through memory 408 A circular queue (a) containing the letters F through O as actually stored in memory 409 A circular queue (b) in its conceptual form in which the last cell in the block is “adjacent” to the first cell 410 Queues First-in first-out. Head and tail. Circular queue. 411 TREES The last Data structure that we will consider is the tree, which is the structure reflected by an organization chart of a typical company. 412 An example of an organization chart 413 TREES Tree consists of a collection of nodes which are interconnected by branches to form a tree like configuration, as shown below: 414 Tree terminology 415 TREES The branches emanate downward from the nodes, The node is presented by a square. The top node is called the root of the tree. All of the remaining nodes are called either branch or terminal nodes. The branch nodes have branches emanating from them, the terminal nodes do not. 416 TREES The degree of a node is equal to the number of sub-trees that emanate from that node. Terminal nodes are therefore nodes of degree zero. All trees have two or more levels. The root is the 1st level. The subsequent nodes increase in level as they branch out from the root. 417 BINARY TREE It is tree in which each node has at most two children. This trees are stored in memory using a linked structure with two pointer called: Left Child Pointer Right Child Pointer 418 The structure of a node in a binary tree 419 The conceptual and actual organization of a binary tree using a linked storage system 420 A tree stored without pointers 421 BINARY TREE Another alternative storage system The location of a node’s parent can be found by dividing the node’s position in the block by 2 while discarding any remainder [the parent of the node in position 7 would be the node in position 3] 422 BINARY TREES The location of a nodes sibling can be found by adding 1 to the location of a node in even position or subtract 1 from location of a node in an odd position. Node 4 ( 4+1)= 5 Node 3 ( 3- 1 )= 2 423 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers 424 Searching the list If the list were stored according to the linked list model , we would be forced to search the list in sequential fashion, a process could be very inefficient if the list should become long. We will seek an implementation that allows us to use the binary search algorithm. 425 Searching The List To apply this algorithm , our storage system must allows us to find the middle entry of successively smaller portion of the list. This can be done using linked binary tree. Ex. The list of letters [ A, B, C, D, E, F, G, H, I, J, K, L, and M ] 426 The letters A through M arranged in an ordered tree 427 The binary search as it would appear if the list were implemented as a linked binary tree 428 The successively smaller trees considered by the procedure in when searching for the letter J 429 Printing a search tree in alphabetical order 430 A procedure for printing the data in a binary tree 431 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree (continued) 432 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree 433 A procedure for inserting a new entry in a list stored as a binary tree 434 Trees Trees - an organization chart; e.g., family tree and company’s organization . Root node, leaf nodes, arc, sub trees. Parent, children, siblings. Depth of a tree. Tree implementation. Binary tree. 435 A stack of integers implemented in C++ 436 A stack of integers implemented in Java and C# 437 Our first attempt at expanding the machine language to take advantage of pointers 438 Loading a register from a memory cell that is located by means of a pointer stored in a register 439 Customized Data Types User-defined types - allow programmers to define additional data types using the primitive types and structures as building blocks. Abstract data types - encompasses both the storage system and the associated operations. Encapsulation. 440 The role of an operating system when accessing a file 441 Object-Oriented Programming Objects. Methods (or member functions). Class. Inheritance. 442 Ch. 8 File Structures Sequential files. Text files. Indexed files. Hashed files. The role of the operating system. 443 Maintaining a file’s order by means of a file allocation table 444 Sequential Files When to use it? When all the records need to be proceeded, it makes no difference which records are proceeded first. If the storage device is a tape system, we normally follow the sequential order because of the sequential nature of the tape itself. What’s about a disk system??? EOF and sentinel. How to update a sequential file? 445 Sequential Files In PASCAL, statements read() and write() are used to retrieve and deposit information. Transaction file Old master file Merge Alg. See Figure8.3 New master file 446 Text Files Text file - the size of the logical records in a sequential file to a single byte (Char). How to manipulate a text file? A word processor? How to use text files to define an input and an output files to a program? 447 Indexed Files If you need to retrieve records in the file in an arbitrary order throughout the day, what is the main problem when you use a sequential file to store the records? What’s the fast way to find the subject you are interesting in from a book??? Ans. Using the index. 448 Indexed Files An index for a file consists of a listing of the key field values occurring in the file along with the location in mass storage of the corresponding record. Key field. An inverted file - primary key and secondary key. When records are inserted and deleted, all indexes must be updated. 449 The structure of a simple employee file implemented as a text file 450 The first two bars of Beethoven’s Fifth Symphony 451 Converting data from two’s complement notation into ASCII for storage in a text file (continued) 452 Converting data from two’s complement notation into ASCII for storage in a text file 453 Indexed Files Index size - since the index must be moved to main memory to be searched, it must remain small enough to fit within a reasonable memory area. What if the index size is too large??? The partial-index structure. An index to the index. 454 Hashed Files Sequential files - process in a serial order. Indexed files - direct access (random access) . Overhead: maintaining an index table. Hashed files - reduce the overhead by computing the location of a record in mass storage by applying an algorithm to the value of the key field in question. 455 Opening an indexed file 456 An inverted file 457 Hashed Files A particular hashing technique: 1. Divide the mass storage area allotted to the file into several sections called buckets. 2. Convert any key field value into a numeric value. 3. Divide any key field value stored in memory by the number of buckets. 4. Convert any key field value into an integer that identifies the bucket in memory. 458 A file with a partial index 459 Hashed Files What is the main concern when using hashed files? Distribution problems - once we have chosen the hash algorithm, we have no control over the distribution of records in mass storage. Clustering problem - majority of records are placed in the same bucket and the rest of buckets contain almost no records. 460 The rudiments of a hashing system, in which each bucket holds those records that hash to that bucket number (continued) 461 The rudiments of a hashing system, in which each bucket holds those records that hash to that bucket number 462 Hashed Files Overflow problem - unless the buckets are extremely large, overflow may occur. Goal - how to select a hash algorithm that evenly distributes the records among the buckets. Division method. The midsquare method. The extraction method. 463 Hashing the key field value 25X3Z to one of 40 buckets 464 Handling bucket overflow 465 Hashed Files Collision - more than one record will hash to the same bucket. Assume insert records into 41 buckets: the probability of placing the 1st record to an empty bucket is 41/41, the 2nd is 40/41, the 3rd is 39/41 and so on. The probability of placing 8 records into 8 empty buckets is (41/41)(40/41)(39/41)….(34/41) = .482 Less than 50%!!! 466 A large file partitioned into buckets to be accessed by hashing 467 Hashed Files The high probability of collisions indicates that a hashed file should never be implemented under the assumption that clustering will never occur. How to handle the overflow problem? Reserve an additional area of mass storage to hold overflow records. Double hashing method. 468 The Role of the Operating System Operating systems need to manipulate files to perform designated tasks. Operating systems maintains a table called a file descriptor or file control block for each file being processed. In PASCAL, file descriptors can be created by assign() and reset(). 469 Ch. 9 Database Structures General issues. The layered approach to database implementation. The relational model. Object-oriented databases. Maintaining database integrity. 470 General Issues A file Vs. a database organization. Why needs a database system? The consolidation approach - advantage: central control, disadvantage: security. Database administrator (DBA). Access privileges - schema and subschema. Other issues - size and scope, privacy. 471 The Layered Approach to Database Implementation End user Application software Data seen in terms of the applications Data seen in terms of a database model Database management system Actual database Data seen in its actual organization 472 The Layered Approach to Database Implementation Database management system (DBMS). The advantages of the separation of application software and the database management system: 1. Simplify the design process - for example the distributed database. 2. Providing a central controlling access to the database. 473 A file versus a database organization (continued) 474 A file versus a database organization 475 The Layered Approach to Database Implementation 3. Data independence - the ability to change the organization of the database itself without changing the application software. 4. Allows the application software to be written based on a simplified, conceptual view of the database (database model) instead of the actual complex database structure. Host languages. 476 The Relational Model Relation - tuple (row) and attribute (column). How to make up the database using the relations of data? Extending the relation - pro and con? Dividing information into various relations (nonloss decomposition) - pro and con? 477 The Relational Model Relational operations: The SELECT operation. The PROJECT operation. The JOIN operation. The SQL (Structured Query Language). 478 Object-Oriented Databases Why object-oriented databases: 1. Data independence can be achieved by encapsulation. 2. The concepts of classes and inheritance fit schemas and subschemas of databases. 3. Intelligent data objects that can answer questions themselves. 4. It may overcome some of the restrictions inherent in other database models. 479 Maintaining Database Integrity Why database integrity is important? The commit/rollback protocol. Cascading roll back. Locking protocol - shared locks and exclusive locks. Wound-wait protocol. 480 A relation containing employee information 481 A relation containing redundancy 482 An employee database consisting of three relations (continued) 483 An employee database consisting of three relations (continued) 484 An employee database consisting of three relations 485 Finding the departments in which employee 23Y34 has worked (continued) 486 Finding the departments in which employee 23Y34 has worked 487 A relation and a proposed decomposition 488 The SELECT operation 489 The PROJECT operation 490 The JOIN operation 491 Another example of the JOIN operation 492 An application of the JOIN operation (continued) 493 An application of the JOIN operation 494 PART IV: The Potential of Algorithmic Machines Artificial Intelligence. Theory of Computation. 495 The associations between objects in an object-oriented database 496 Ch. 10 Artificial Intelligence Some philosophical issues. Image analysis. Reasoning. Control system activities. Using Heuristics. Artificial neural networks. Applications of AI. 497 Some Philosophical Issues Machines Vs. humans. Performance Vs. simulation. Intelligence as an interior characteristic Turing test and program DOCTOR (ELIZA). How to create an intelligent machine? 498 An Intelligent puzzle-solving machine This machine takes the form of a metal box equipped with a gripper, a video camera, and a finger with a rubber end so that it does not slip when pushing something. Actions: 1. Turn on the machine. 2. Place the puzzle. 3. The finger pushes the tiles back to the original order. 4. Turn off the machine. 499 Image Analysis The first intelligent behavior required by the puzzle-solving machine is the extraction of information through a visual medium. Perceive ability - determine the current status of the puzzle. Optical character readers. Character recognition based on matching the geometric characteristics. 500 Reasoning Is possible to develop proper programs targeted to all possible initial configurations (in total 181,440 of them)? Develop a program which can solve the problem itself - the ability to make decisions, draw conclusions, and in short, perform elementary reasoning activities. 501 Our puzzle-solving machine 502 The eight-puzzle in its solved configuration 503 Reasoning A production system consists of three main components: 1. A collection of states - start/goal states. 2. A collection of productions (rules). 3. A control system - which consists of the logic that solves the problem of moving from the start state to the goal state. State graph - conceptualizing all states, rules, and preconditions in a production 504 system. Reasoning Socrates is a man. All men are humans. All humans are mortal. Start state Goal state Socrates is a man. All men are humans. All humans are mortal. Socrates is a human. Socrates is a man. All men are humans. All humans are mortal. Socrates is a human. Socrates is mortal. 505 Control System Activities A state-graph traversal problem. Search tree. How to build a search tree? It is impractical to develop a full search tree for a complex problem. Using depth-first construction instead of breadth-first manner. Avoiding redundancy. 506 Using Heuristics Heuristics - the use of intuition, a rule of thumb which may lead to a correct direction but offer no assurance on it. How to develop a heuristic - first develop a quantitative measure by which a program can determine which of several states is considered closest to the goal (cost function). 507 Artificial Neural Networks Neural networks - model networks of neurons in living biological systems. Compute effective inputs Threshold value Output 0 or 1 I1W1+…+InWn 508 Applications of Artificial Intelligence Language processing. Robotics. Database systems. Expert systems. 509 A small portion of the eight-puzzle’s state graph 510 Deductive reasoning in the context of a production system 511 An unsolved eight-puzzle 512 A sample search tree (continued) 513 A sample search tree (continued) 514 A sample search tree (continue d) 515 A sample search tree 516 Productions stacked for later execution 517 An unsolved eight-puzzle 518 An algorithm for a control system using heuristics 519 The beginning of our heuristic search 520 The search tree after two passes 521 The search tree after three passes 522 The complete search tree formed by our heuristic system 523 A neuron in a living biological system 524 Ch. 11 Theory of Computation A bare bones programming. Turing machines. Computable functions. A noncomputable function. Complexity and its measure. Problem classification. 525 The activities within a processing unit 526 Representation of a processing unit 527 A neural network with two different programs (continued) 528 A Bare Bones Programming Language A universal programming language - a language encompasses the power of algorithmic processes themselves; i.e., if a problem can be solved algorithmically, the an algorithm for solving the problem can be expressed in the language. On the other hand, if the problem can not be expressed in the language, there is no such an algorithm to solve the problem. 529 Uppercase C and uppercase T 530 Various orientations of the letters C and T (continued) 531 The structure of the character recognition system 532 The letter C in the field of view 533 The letter T in the field of view 534 An artificial neural network implementing an associative memory 535 The steps leading to a stable configuration (continued) 536 The steps leading to a stable configuration 537 Crossing two poker-playing strategies 538 Coding the topology of an artificial neural network (continued) 539 Coding the topology of an artificial neural network 540 A semantic net 541 A Bare Bones Programming Language Data description statements - all variables are considered to be of type “bit pattern of any length.” => no need a declarative part. Process description statements - three assignment statements: clear, incr, decr and one control structure: while-end. 542 An attempt to display the function that converts measurements in yards into meters 543 The components of a Turing machine 544 A Bare Bones Programming Language “move tax to extra” Clear aux; clear extra; while tax not 0 do; incr aux; decr tax; end; while aux not 0 do; incr tax; incr extra; decr aux; end; 545 Turing Machines Turing machines - are conceptual devices for studying the power of algorithmic processes. A Turing machine consists of a control unit that can read and write symbols on a tape The machine must be in one of a finite number of states, start/halt states. 546 A Turing machine for incrementing a value 547 A Bare Bones program for computing XY 548 A Bare Bones implementation of the instruction “copy Today to Tomorrow” 549 Turing Machines Today’s computers <=> Turing machines finite memories <=> infinite supply of tape CPU <=> the control unit bit patterns <=> states The significance of Turing machines in theoretical computer science - the computation power of Turing machines is as great as any algorithmic system. 550 Computable Functions How to measure computing power? Goal: using Turing machines to investigate the power of the bare bones language. Computing the functions is the process of determining an output of a function from its inputs. If one machine is capable of computing more functions than another, the former is considered the more powerful. 551 Computable Functions Ex. A system in which function outputs are predetermined and recorded in a table. Ex. Finding function outputs would be to describe how to compute the output. Computable - the functions whose output values can be determined algorithmically from their input values. Noncomputable functions! 552 Computable Functions Turing computable. The Church-Turing thesis. If a computational system is capable of computing all the Turing-computable functions, it is considered to be a universal system. Apply the Church-Turing these to confirm that the bare bones language is a universal programming language. 553 A Noncomputable Function Computing the Godel number. The halting problem. 554 Complexity and Its Measure Time and storage complexities (Big O). Order of complexity. Polynomial and nonpolynomial problems. NP problems - nondeterministic polynomial problems. NP-complete problems. 555 Testing a program for self-termination 556 Proving the unsolvability of the halting program (continued) 557 Proving the unsolvability of the halting program (continued) 558 Proving the unsolvability of the halting program 559 Roadmap to Computer Science Study Fundamental courses: Physics, Mathematics, and Introduction to Computer Science. Software: 1. Fundamental: Problem Solving and Programming, Data Structure, Algorithm, and Software Engineering. 2. Language: Assembly Language, Programming Language, C, and JAVA. 560 A procedure MergeLists for merging two lists 561 The merge sort algorithm implemented as a procedure MergeSort 562 The hierarchy of problems generated by the merge sort algorithm 563 Graphs of the mathematical expressions n, lg n, n lg n, and n2 564 A graphic summation of problem classification 565 Encrypting a bit pattern as a knapsack problem 566 Public key encryption using knapsack problems 567 Constructing a public key encryption system 568 Roadmap to Computer Science Study 3. Theory: Formal Language and Theory of Computation. 4. System: Operating System, Compiler, Networking, Database, and Multimedia. Hardware: 1. Fundamental: Electronics, Logic Design, Digital System Design, and Computer Architecture. 569 Roadmap to Computer Science Study 2. System: Microprocessors and VLSI design. Applications: 1. Consumer products. 2. Artificial Intelligence. 3. Networking. 4. Image Processing. 5. Computer Architecture and Compiler. 570 Roadmap to Computer Science Study 6. VLSI and Computer-Aided Design. 7. Biological (Medical) Computing. 8. Multimedia. 9. Databases. 10. Education. 11. Business and management. 12. And more!!! 571