Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Computer Science An Overview EE461 Introduction to Computer Science.

Similar presentations


Presentation on theme: "1 Computer Science An Overview EE461 Introduction to Computer Science."— Presentation transcript:

1 1 Computer Science An Overview EE461 Introduction to Computer Science

2 2 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.

3 3 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.

4 4 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.

5 5 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.

6 6 The Euclidean algorithm for finding the greatest common divisor of two positive integers

7 7 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

8 8 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]

9 9 Jacquard’s loom

10 10 The Mark I computer

11 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

12 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

13 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

14 The Evolution of Computers 4 Fourth Generation [ 1975-1990] 4 Technologies [ LSI circuits; semiconductor memories] 4 Fifth Generation [ 1990- ] 4 Technologies [ VLSI circuits ] 14

15 15 The central role of algorithms in computer science

16 16 The Evolution of Computer Science Algorithms Hardware Software Languages Applications

17 17 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.

18 18 The hierarchy of abstraction in the hardware of a typical personal

19 19 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.

20 20 Ch. 1 Data Storage 4 Storage of bits. 4 Main memory. 4 Mass storage. 4 Coding information for storage. 4 The binary system. 4 Storing integers. 4 Storing Fractions. 4 Communication errors.

21 21 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.

22 22 The Boolean operations AND, OR, and XOR (exclusive or)

23 23 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values (continued)

24 24 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values

25 25 A simple flip-flop circuit

26 26 Setting the output of a flip-flop to 1 (continued)

27 27 Setting the output of a flip-flop to 1 (continued)

28 28 Setting the output of a flip-flop to 1

29 29 Another way of constructing a flip- flop

30 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

31 31 The hexadecimal coding system

32 32 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. 4 Hexadecimal notation.

33 33 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).

34 34 Memory cells arranged by address

35 35 The organization of a byte-size memory cell

36 36 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.

37 37 Mass Storage 4 Disk storage. 4 Compact disks and CD-ROM. 4 Tape storage. 4 Physical Vs. logical records.

38 38 HARD DISK

39 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

40 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

41 HARD DISK 4 Hard disk Rotational Speed: 4 [ 7000- 10000- 15000 ] RPM 4 Floppy disk Rotational Speed; 4 [ 300 ] RPM 4 Transfer Rate: HD MB/sec 4 Floppy KB/sec 41

42 42 CD storage format

43 43 A magnetic tape storage mechanism

44 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

45 45 Logical records versus physical records on a disk

46 46 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.

47 47 The message “Hello.” in ASCII

48 48 The base ten and binary systems

49 49 Decoding the binary representation 100101

50 50 An algorithm for finding the binary representation of a positive integer

51 51 Applying the algorithm to obtain the binary representation of thirteen

52 Representing Images. 4 Images representation can be classified into two categories: 4 Bit map techniques: 4 An image is considered to be a collection of dots, each of which is called a pixel. 4 Vector Techniques: 4 An image is presented as a collection of lines and curves. [Provides a means of scaling ] 52

53 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

54 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

55 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

56 56 The sound wave represented by the sequence 0, 1.5, 2.0, 1.5, 2.0, 3.0, 4.0, 3.0, 0

57 57 The Binary System 4 Binary addition. 4 Fractions in binary. 4 Radix point (same as decimal point in decimal notation).

58 58 The binary addition facts

59 59 Decoding the binary representation 101.101

60 60 Two’s complement notation systems

61 61 Coding the value -6 in two’s complement notation using four bits

62 62 Addition problems converted to two’s complement notation

63 63 An excess eight conversion table

64 64 An excess notation system using bit patterns of length three

65 65 Floating-point notation components

66 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

67 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

68 68 Coding the value 2 5/8

69 69 Storing Fractions 4 Floating-point notation. 4 Sign bit => Exponent => Mantissa. 4 Round-off errors.

70 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

71 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

72 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

73 DATA COMPRESSION 4 Adaptive dictionary encoding 4 Lempel-Ziv encoding 4 ABAABQB (5,4,A) (0,0,D) (8,6,B) 73

74 74 Decompressing xyxxyzy (5, 4, x)

75 Communication Errors 75 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.

76 76 The ASCII codes for the letters A and F adjusted for odd parity

77 77 An error-correcting code

78 78 Decoding the pattern 010100

79 79 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.

80 80 The Central Processing Unit CPU ALU Regs. Control unit Main memory Bus

81 81 Adding values stored in memory

82 82 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.

83 83 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.

84 84 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.

85 85 Dividing values stored in memory

86 86 The Stored-Program Concept CPU ALU Regs. Control unit Main memory Bus Program counter Instr. Reg. Address 00 FF Op-code operand

87 87 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.

88 88 The machine cycle

89 89 Decoding the instruction B258

90 90 Figure 2.10: The program stored in main memory ready for execution

91 91 Figure 2.11:Performing the fetch step of the machine cycle (continued

92 92 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.

93 93 Performing the fetch step of the machine cycle

94 94 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.

95 95 Rotating the bit pattern A3 one bit to the right

96 96 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,…..

97 97 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.

98 98 Computer-Peripheral Communication CPU Peripheral device Controller Main memory Controller Peripheral device Bus

99 99 A conceptual representation of memory-mapped I/O

100 100 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.

101 101 Computer-Peripheral Communication CPU Peripheral device Controller Main memory Bus Memory-mapped I/O

102 102 Computer-Peripheral Communication 4 Port - the block of addresses associated with a controller. 4 Handshaking - the two-way communication that takes place between devices. 4 Parallel and serial communications. 4 Bits per second (bps) and baud rate. 4 Data compression. 4 Huffman code. 4 Lempel-Ziv encoding.

103 103 Part II: Software 4 In part II, we focus on topics associated with software. In particular, we will investigate the discovery, representation, and communication of algorithms. 4 Operating systems and networks. 4 Algorithms. 4 Programming languages. 4 Software engineering.

104 104 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.

105 105 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 task.

106 106 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.

107 107 Batch processing

108 108 Software classification

109 109 The Evolution of Operating Systems 4 Interactive processing, 4 Real-time processing. 4 Time-sharing. 4 Multitasking - time-sharing for a single user systems. 4 Multiprocessor systems - networks such as internet. 4 Load balancing and scaling problems.

110 110 Interactive processing

111 111 Operating System Architecture Software ApplicationSystem Utility Operating system ShellKernel

112 112 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.

113 113 Operating System Architecture Software ApplicationSystem Utility Operating system ShellKernel

114 114 The shell as an interface between users and the operating system

115 115 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.

116 116 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 human- machine interface across a variety of machines. 4 UNIX Vs. MS-DOS and Windows.

117 117 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.

118 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

119 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

120 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

121 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

122 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

123 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

124 124 Operating System Architecture 4 Main memory Vs. virtual memory. 4 Pages. 4 Scheduler and dispatcher. 4 Booting (booting strapping). 4 Bootstrap - a short program placed in ROM and this program is executed automatically when the machine is turned on.

125 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

126 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

127 BOOTSTRAP 127

128 128 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.

129 129 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).

130 130 Identical communication structure between clients and servers operating on the same machine and distributed among different machines

131 131 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).

132 132 Time-sharing between process A and process B

133 133 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.

134 134 The client/server model

135 135 Handling Competition Among Processes 4 Competing resources among processes. 4 Semaphores. 4 Test-and-set. 4 Critical region - is a sequence of instructions which can be executed by only one process.

136 DEADLOCK 136

137 137 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.

138 138 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.

139 139 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.

140 140

141 141

142 NETWORK TOPOLOGIES 142

143 NETWORK TOPOLOGIES 143

144 The distinction between a bridge and a router 144

145 145 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., chunghaw@cs.nthu.edu.tw.

146 146 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).

147 A typical approach to connecting to the Internet 147

148 INTERNET ADDRESSING 4 Each machine in the internet is assigned a unique address called IP 4 IP is a pattern of 32 bits consisting of two parts: 4 1- Pattern identifying the Domain ( Network Identifier ) 4 2- Pattern identifying the machine within the domain ( Host Address ). 4 192.207.177.133 4 Network Host 4 Identifier Machine 4 Domain Name: ksu.edu.sa 148

149 INTERNET 4 Electronic Mail [ Mail Server ] 4 The world wide web [ www ] 4 The internet became a means of propagating multimedia documents known as hypertext [ text, images, sound, and video ] 4 Browser software is needed to browse the net. 4 In order to locate and retrieve documents on the ( www ) each document is given a unique address called Uniform Resource Locator ( URL ). 4 Hypertext Markup Language [ HTML ] 149

150 150 A typical URL

151 151 A simple Web page expressed in HTML

152 152 Network Protocols 4 Protocols - the rules that govern the communication between different components within a computer system. 4 Token ring protocol for networks with the ring topology. 4 CSMA/CD (carrier sense, multiple access with collision detection) in an Ethernet.

153 153 Communication over a ring network

154 154 Communication over a bus network

155 The Layered Approach to Internet Software 4 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. 4 You would warp the gift in a package and write the address outside the package. 4 You would take the package to a shipping company. 4 The following fig. shows the process for the package-shipping example. 155

156 156 Package-shipping example

157 The internet software layers. 4 The internet software has four layers each consisting of a collection of software routines. 4 The four layers are known as the application, transport, network, and link layers. 4 Layers are present on each machine in the internet. 157

158 158 The Internet software layers

159 NETWORK PROTOCOLS 4 1- The application layer 4 A- File Transfer Protocol [ FTP ] 4 B- Telnet: allowing a person to access a machine across the internet. 4 C- Simple Mail Transfer Protocol ( SMTP ): Software used by the mail servers when transferring E- mail. 159

160 NETWORK PROTOCOL 4 2- The transport layer 4 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

161 NETWORK PROTOCOLS 4 3- The network layer 4 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

162 NETWORK PROTOCOLS 4 4- The link layer 4 Its function is to deal with the communication details particularly to the individual network in which the machine resides 162

163 163 Application layer Network Protocols: The Internet Software Layer Transport layer Network layerLink layer Application layerTransport layer Network layerLink layer Message sourceMessage destination

164 164 Network Protocols 4 Open system interconnection (OSI). 4 International standards organization (ISO). 4 TCP/IP (transmission control protocol/internet protocol). 4 UDP (user datagram protocol).

165 Differences between TCP &UDP 4 1- TCP transport layer is said to establish a connection before sending a message. 4 UDP dose not establish such a connection prior to sending a message. UDP is called connectionless protocol. 4 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. 4 UDP dose not offer such retransmission services but UDP is more streamlined than TCP. 165

166 TCP AND UDP 4 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. 4 IP is the internet standard for network layer. 166

167 4 Unauthorized access to information and vandalism 4 Passwords and data encryption 4 Virus 4 Worm 167 Networks

168 SECURITY 4 1-Password 4 2- Public-key encryption 4 3- Secure Socket Layer [ SSL ] 168

169 VIRUS 4 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

170 WORM 4 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

171 FIREWALL 4 It forms a protective barrier that shields the region on one side from the dangers on the other side. 171

172 172 Ch. 4 Algorithms 4 The concept of an algorithm. 4 Algorithm representation. 4 Algorithm discovery. 4 Iterative structures. 4 Recursive structures. 4 Efficiency and correctness.

173 173 The Concept of an Algorithm 4 An algorithm is an ordered set of unambiguous, executable steps, defining a terminating process. 4 Parallel algorithms. 4 Program Vs. algorithm Vs. process. 4 A program is a representation of an algorithm 4 A process is the activity of executing an algorihm.

174 ABSTRACT NATURE OF ALGORITHM 4 An algorithm is abstract and distinct from its representation. A single algorithm can be represented in many ways. 4 EX: The algorithm for converting temperature readings from Celsius to Fahrenheit. 4 F= (9/5 ) C + 32 Or it could be represented by 4 Multiply the Temp. Reading in C by 9/5 and then add 32 to the product. 4 Or it can be represented by an electronic circuit [ Analogue Computer]. 174

175 ALGORITHM REPRESENTATION 4 The representation of an algorithm requires some form of language. [ English, Arabic, Russian,....... ] or the language of pictures. 4 Algorithm representation can be constructed, such a building block is called a PRIMITIVE. 4 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

176 ALGORITHM REPRESENTATION 4 PRIMITIVE = SYNTAX + SEMANTICS 4 Syntax refers to the Primitive’s symbolic representation 4 Semantics refers to the meaning of the primitive. 4 AIR The syntax of AIR consists of the three symbols A,I,R 4 The Semantics : AIR is gaseous substance that surrounds the world. 176

177 177 Algorithm Representation 4 Primitive is a set of well-defined building blocks which algorithm representations can be constructed. 4 Primitive - graphical and texture. 4 Primitive => programming language. 4 Primitive - syntax and semantics.

178 178 Folding a bird from a square piece of paper (continued)

179 179 Folding a bird from a square piece of paper

180 180 Origami primitives (continued)

181 181 Origami primitives

182 182 Algorithm Representation 4 Pseudo code - is a notational system in which ideas can be expressed informally during the algorithm development process. 4 Ex. If you have more than $10 buy a cake; otherwise buy nothing => if (cond) then (act1) else (act2) 4 Ex. As long as you have money, you an spend => while(having money) do (spend)

183 183 Algorithm Representation 4 Ex. Assign name the value price+tax. 4 Begin a pseudocode with procedure name. 4 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)

184 184 Algorithm Discovery 4 The development of a program consists of two activities - discovering the underlying algorithm and representing that algorithm as a program. 4 The basic principles for problem-solving: 4 1. Understand the problem. 4 2. Get an idea as to how an algorithmic procedure might solve the problem.

185 185 Algorithm Discovery 4 3. Formulate the algorithm and represent it as a program. 4 4. Evaluate the program for accuracy and for its potential as a tool for solving other problems. 4 Conscious work Vs. inspiration. 4 Stepwise refinement - a top-down methodology.

186 EXAMPLE 4 Person A is charged with the task of determining the age of Person B’s 3 children: 4 CLUES: 4 1-The product of the children’s ages is 36 4 2- The sum of the children’s ages is given 4 Find the ages of the three children. 186

187 187 EXAMPLE

188 4 The clues is not enough because if the sum is 13 we have two possibility 1+6+6 and 2+2+9. 4 We need a third clue. 4 The third clue is the oldest child plays the piano 4 The solution is 2,2,9 188

189 EXAMPLE 2 4 Before A, B, C, and D ran a race they made the following predictions: 4 A predicted that B would win 4 B predicted that D would be last 4 C predicted that A would be third 4 D predicted that A’s prediction would be correct 4 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

190 EXAMPLE 2 4 Prediction A & D are equivalent 4 Since only one Pred. Was true.Then A & D must be false. 4 Thus neither A nor D were winners. 4 If A Pred. Was false, the B did not win either. 4 The only remaining choice for winner is C. Thus C won the race & C prediction was true. 4 If A came in third 4 We have two order for finishing the race 4 C B A D OR C D A B 190

191 EXAMPLE 2 4 C B A D OR C D A B 4 CBAD order is ruled out because B’s prediction must be false. 4 There fore finishing order was : 4 C D A B 191

192 THE SEQUENTIAL SEARCH ALGORRITHM 4 The problem of searching sorted list for Target value sequentially can be done by comparing the target value to each entry in the list. 4 The sequential search algorithm can be presented in pseudo code as follows. 192

193 193 The sequential search algorithm in pseudocode

194 194 Iterative Structures 4 Iterative structures - a collection of instructions is repeated in a looping manner. 4 The while loop structure. 4 The repeat loop structure. 4 The insertion sort algorithm.

195 LOOP CONTROL 4 WHILE ( condition ) DO ( body ) 4 {WHILE [ The pH level is greater than 4] DO [ add a drop of sulphuric acid ]} add 3 times 4 No Termination Condition 4 Number  1 ; 4 WHILE ( Number NEQ 6 ) DO 4 ( Number = Number + 2 ) 195

196 196 Components of repetitive control

197 197 The while loop structure

198 REPEAT LOOP 4 REPEAT ( ACTIVITY ) UNTIL ( Condition) 4 EX: 4 Repeat ( take a coin from your pocket ) Until ( there are no coins in your pocket ). 4 In the above ex. We assume there is a coin in your pocket at the beginning, but 4 While ( there is a coin in your pocket ) Do ( take a coin from your pocket ) 4 We does not assume that. 198

199 199 The repeat loop structure

200 THE INSERTION SORT ALGORITHM 4 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

201 201 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued)

202 202 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued)

203 203 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically

204 204 The insertion sort algorithm expressed in pseudocode

205 205 Recursive Structures 4 Recursive structures provide an alternative to the loop paradigm for repetitive structures (by invoking itself). 4 The binary search algorithm. 4 It is more faster than the sequential search algorithm

206 206 Applying our strategy to search a list for the entry John

207 207 A first draft of the binary search technique

208 208 The binary search algorithm in pseudocode

209 Binary Search Algorithm 4 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

210 210 Binary Search Algorithm

211 4 Let us consider the list: 4 [ Alice, Carol, Evelyn, Fred, and George ] 4 Searching for the entry ( David ) 211

212 212 Binary Search Algorithm

213 213 Binary Search Algorithm

214 214 Binary Search Algorithm

215 215 Efficiency and Correctness 4 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. 4 Time and storage complexity of the algorithm.

216 Efficiency and Correctness 4 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. 4 This occurs if the original list is in reverse order. The first pivot is compared to two names. 4 The total number of comparisons when sorting a list of n entries is { 1+2+3+ ------ +( n-1 ) } = ½[n(n-1] 4 If n=10 would require 45 comparison 216

217 Efficiency and Correctness 4 In the average case of insertion sort the result is half worst case i.e. 4 ¼[ n(n-1)] Comparison 217

218 218 Applying the insertion sort in a worst-case situation

219 219 Graph of the worst-case analysis of the insertion sort algorithm

220 220 Graph of the worst-case analysis of the binary search algorithm

221 221 Efficiency and Correctness 4 How to make sure the algorithm and program developed is correct? 4 Difference between testing and verification. 4 Precondition, assertions, loop invariant.

222 SOFTWARE VERIFICATION 4 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

223 223 Separating the chain using only three cuts

224 224 Solving the problem with only one cut

225 ALGORITHM 4 1- First morning give the hotel the single link. 4 2- Second morning retrieve the single link and give the hotel the two link piece. 4 3- Third morning Give the hotel the single link. 4 4- Fourth morning retrieve the three links held by the hotel and give the hotel the four link piece. 225

226 ALGORITHM 4 5- Fifth morning give the hotel the single link. 4 6- Sixth morning retrieve the single link and give the hotel the double link piece. 4 7- Seventh morning give the hotel the single link. 226

227 VERIFICATION 4 Proof of correctness begins with the assumption that certain conditions, called preconditions, are satisfied at the beginning of the program’s execution. 4 How the consequences of these preconditions propagate through the program. 227

228 VERIFICATION 4 EX: IF ( condition) THEN ( instruction 1) 4 ELSE ( instruction 2) 4 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

229 229 The assertions associated with a typical while structure

230 Linear Programming 4 Linear programming is useful tool for solving problems of allocation particularly in maximising or minimising a linear function of variables, 230

231 LP Example 4 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

232 LP Example 4 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

233 LP Example 4 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

234 LP Graphical Solution 4 Let x be the number of Maxi cars to be order. 4 Let y be the number of Mini cars to be order 4 Let P be the total profit he will make by selling all his cars. 4 P is called Object function 234

235 LP Graphical Solution 4 The aim is to Maximize the objective function 4 P = 300 x + 240 y 4 The restrictions of space and capital must also be taken into account. 4 Such restrictions are called constraints. 235

236 LP Graphical Solution 4 x + y <= 36 Space Constraint 4 12000x+8000y<=360000 Capital Constraint. 4 Dividing Capital Const. By 4000 4 3 x + 2 y <= 90 4 The LP problem can be stated as: 236

237 LP Solution 4 Max P = 300 x + 240 y 4 Subject to 4 x + y <= 36 4 3 x + 2 y <= 90 4 x >= 0 4 y >= 0 237

238 Graphical Solution 238

239 Simplex Method 4 1- Construct the first table 4 2- Locate a pivot 4 3- Calculate a new table 4 4- Repeat step 2 and 3 until the terminal table is obtained 239

240 Linear Programming Problem 4 The general form of the LP problem is as follows: 4 Max. the objective function 4 P = C1X1+ C2X2+ ----------- +CnXn 4 Subject To: 4 a11X1+a12X2+---------- +a1nXn <=b1 4 a21X1+a22X2+-----------+a2nXn <=b2 4 - 4 ak1X1+ak2X2+------------ +aknXn<=bk 4 X1,X2,------------- Xn >= 0 240

241 Simplex Method 4 1- After construction of the first table select any column which contains the most negative coefficient for the non basic variables. 4 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. 4 3- If the table has no negative indicator then it is called Terminal table and has no pivot 241

242 Simplex Method 4 Consider the LP problem 4 Max. P= 4*x1 + 3* x2 4 Subject to : 2x1 + 3x2 <= 6 4 - 3x1 + 2x2 <= 3 4 2x2 <= 5 4 2x1 + x2 <= 4 4 x1>=0, x2 >= 0 4 The equations can be written as follows by introducing Slack variable. 242

243 Simplex Method 4 P = 4x1+ 3x2+ 0S1+ 0S2+ 0S3 + 0S4 4 Subject to: 4 2x1+ 3x2+ S1 = 6 4 -3x1+2x2 +S2 = 3 4 0x1 + 2x2 +S3 = 5 4 2x1 + x2 +S4 = 4 4 x1, x2, S1, S2, S3, S4 >= 0 4 The basic feasible solution x1= x2= 0 Then S1= 6, S2= 3, S3= 5, and S4 =4. 243

244 Simplex Method ( First Table ) 4 Basic P x1 x2 S1 S2 S3 S4 Solution 4 ---------------------------------------------------------------------- 4 P0 0 -4 -3 0 0 0 0 0 P equation 4 ----------------------------------------------------------------------- 4 S1 0 2 3 1 0 0 0 6 4 S2 0 -3 2 0 1 0 0 3 4 S3 0 0 2 0 0 1 0 5 4 S4 0 2 1 0 0 0 1 4 244

245 Simplex Method 4 The non basic variables are x1&x2= 0 yield P =0 4 The entering variable be selected as the non basic variable having a negative coefficient in the P equation of the table. 4 In our example both x1 &x2 have negative coefficient. The variable with the most negative coefficient is selected. 4 This column is called the pivotal column 245

246 Simplex Method 4 Basic Solution x1 Ratio(b/a) 4 S1 6 2 6/2=3 4 S2 3 -3 ----- 4 S3 5 0 ------ 4 S4 4 2 4/2= 2 min. 4 2 is called the Pivot element. 4 Do row operation to get new table 4 We divide the row by the pivot and replace S4 by x1. 246

247 Simplex Method 4 The pivotal Row is divided by the pivot [ 2 ] 4 P0 x1 x2 S1 S2 S3 S4 Solution 4 X1 0 1 1/2 0 0 0 1/2 2 4 Do row operation for the other rows 4 P0 -4 -3 0 0 0 0 0 4 + 4 2 0 0 0 2 8 4 ------------------------------------------------------------- 4 0 -1 0 0 0 2 8 247

248 Simplex Method 4 S1 2 3 1 0 0 0 6 4 + -2 -1 0 0 0 -1 -4 4 ------------------------------------------------------------- 4 0 2 1 0 0 -1 2 4 S2 -3 2 0 1 0 0 3 4 + 3 3/2 0 0 0 3/2 6 4 ------------------------------------------------------------- 4 0 7/2 0 1 0 3/2 9 4 S3 0 2 0 0 1 0 5 248

249 Simplex Method ( New Table) 4 Basic P x1 x2 S1 S2 S3 S4 Solution 4 P0 1 0 -1 0 0 0 2 8 4 S1 0 0 2 1 0 0 -1 2 4 S2 0 0 7/2 0 1 0 3/2 9 4 S3 0 0 2 0 0 1 0 5 4 X1 0 1 1/2 0 0 0 1/2 2 4 The new basic solution: x1= 2, x2= 0, S1= 2, S2= 9, S3=5, S4= 0, and P=8 249

250 Simplex Method 4 The new entry variable is x2, it has the only negative coefficient in P equation. To find the pivot do 4 Basic Solution x2 Ratio 4 S1 2 2 2/2=1 min. Pivot 4 S2 9 7/2 9(2/7)= 18/7 4 S3 5 2 5/2= 2.5 4 X1 2 1/ 2 2(2/1)=4 4 X2 is the entry variable and S1 is the leaving variable. 4 Do Row operation to get new table 250

251 Simplex Method ( New Table) 4 Basic P0 x1 x2 S1 S2 S3 S4 Solution 4 ------------------------------------------------------------------ 4 P0 1 0 0 1/ 2 0 0 3/2 9 4 ------------------------------------------------------------------ 4 X2 0 0 1 1/ 2 0 0 - 1/ 2 1 4 S2 0 0 0 -7/ 4 1 0 13/4 3/2 4 S3 0 0 0 -1 0 1 1 3 4 X1 0 1 0 - 1/ 4 0 0 3/ 4 3/ 2 4 Since all the coefficient of P equation is positive So we have terminal table. The solution is : 4 X1= 1.5 X2= 1 P ( max )=9 251

252 LP Example 4 A paper company received three orders for paper rolls with the widths and lengths indicated in the following table 4 Order Number Width[m] Length[m] 4 1 5 10000 4 2 7 30000 4 3 9 20000 4 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

253 LP Example 4 4 ______________ _____________________ 4 4 Trim loss=0m Trim loss = 4 m 4 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 4*30000 + 9*10000 = 210000 m square 4 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

254 LP Example 4 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. 4 Width X11 X12 X13 X21 X22 X23 X24 X25 X26 Requirements 4 5m 2 0 0 4 2 2 1 0 0 10000 4 7m 0 1 0 0 1 0 2 1 0 30000 4 9m 0 0 1 0 0 1 0 1 2 20000 4 ___________________________________________________________________ 4 Trim loss 0 3 1 0 3 1 1 4 2 254

255 LP Example 4 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: 4 Minimize The objective function: 4 P= 3X12+X13+3X22+X24+4X25+2X25+5S1+7S2+9S3 4 Subject to: 4 2X11+4X21+2X22+2X23+X24- S1 = 10000 4 X12 +X22+ 2X24+ X25 -S2 = 30000 4 X13+X23+ X25+ 2X26 - S3 = 20000 4 Xij>=0, Si >= 0 for all i and all j 255

256 Iterative Techniques 4 A) Repeated Substitution 4 Consider the two linear equations: 4 Y = 7 – X [1] 4 X= ½ ( Y + 2 ) [2] 4 Solving it by the method of Repeated Substitution. Initially let X= 0 Then substitute in Equation [1] to give Y=7 4 Then substitute in equation [2] to give X= 9/2 4 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

257 Graphical Solution ( X=3, Y=4) 257

258 Algorithm 4 1- Read Eqns.[1] and [2] 4 2- Set X = 0 4 3- Substitute X into Eqn. [1] to give Y 4 4-Substitute value of Y from step 3 into Eqn.[2] to give X 4 5- Go to Step ( 3 ). 4 To stop the iteration calculate [ Xi+1 – Xi ] for each iteration and stop at appropriate value. [ very small value ]. 4 This method is used for nonlinear equations. 258

259 The Bisection Method 4 Consider the equation: 4 Y= 20Xpower3- 59Xpower2- 33X+90 4 The smallest positive solution to this equation is required. 4 The dominant Xpower3 term, as X becomes large and +ve 4 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. 4 259

260 Bisection Method 4 When X = 0, Y = 90 4 When X = 1, Y = 20 – 59 – 33 + 90 = + 18 4 When X = 2, Y = 160 – 236 – 66 + 90 = - 52 4 This indicate there is a root between X> 1 & X< 2. 4 We can draw the function to a much greater accuracy the section of the curve between 4 X=1 & X=2. 260

261 261

262 Bisection Method 4 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. 4 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. 4 F(L) >0 and F(U) < 0 262

263 Bisection Method 4 If the curve has +ve gradient at the root then the bounds will be given by: 4 F(L) 0 4 In which case the first decision must be change to Y<= 0 263

264 Bisection Algorithm 4 1- Let L=1 and U= 2 4 2- G = U – L 4 3- X = L + G/2 4 4- Calculate Y = F ( X ) 4 5- If Y >= 0 let L= X, go to 7 4 6- U = X 4 7- If G NOT sufficiently small Go to step 2 4 8- Print X 4 9- Stop 264

265 Numerical Integration 4 A) Trapezium Rule 265

266 Trapezium Rule 4 If the area under a curve f(x) is divided into n strips each of width w, then the area is given by: 4 Area = w [ ½(Y0+Yn) + sum of remaining Y- sticks ] 4 Where Yi is the height above the axis of the point on the curve whose x coordinate is xi. 4 PROOF: Divide the area into n parallel strips of width w. 4 Area under the curve = the sum of areas of all trapezium. 4 = w(1/2(Y0+Y1))+w( ½(Y1+Y2))+.........+w(1/2( Yn-1+ 4 Yn))= w [ 1/2Y0+Y1+Y2+............+Yn-1+1/2Yn] 4 = w[ ½(Y0+Yn)+ sum of remaining Y sticks ] 266

267 Simpson's Rule 4 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: 4 Area= (w/3)[(Y0+Y2n) +( 4* sum of odd Y-sticks) + ( 2* sum of even Y-sticks)] 4 PROOF: 4 For any three points on the curve,it can be joined by a parabola: 4 Y(x) = a *Xpower2 + b* X + c 267

268 Simpson’s Rule 268

269 Simpson’s Rule 4 The point P (-w. Y0), Q ( 0, Y1), R ( w, Y2) 4 The area under the curve is given by : 4 Area = integral f(x) dx from –w to w 4 = [ (aXpower3/3)+ (bX power2/2) +cX] from –w to w 4 ={[(a*wpower3/3)+(b*wpower2/2)+c*w]- [(- a*wpower3/3)+( b*wpower2/2) –c*w]} 4 = [ (2*a *wpower3/3) + 2* c* w ] 4 = (w/3 )* (2*a* wpower2 + 6* c ) 269

270 Simpson’s Rule 4 Substituting the known values of x to find expressions for the values of Y at the points P, Q, and R. 4 At P Y0= a* w power 2 – b* w + c 4 At Q Y1= + c 4 At R Y2= a* w power 2 + b* w + c 4 By inspection 4 2*a * w power2 +6*c = Y0+4*Y1+Y2 4 Replacing the term in Area equation 4 Area = (w/3)*( Y0 + 4* Y1 + Y2) 270

271 Simpson’s Rule 271

272 Simpson’s Rule 4 Area= sum of the area beneath the curve f(x). 4 = Sum of areas of the n pairs of strips 4 = area of 1 st pair+ area of 2sd pair +......+ area of nth pair 4 = (w/3){ (Y0+4Y1+y2)+( Y2+4Y3+Y4)+..............+ 4 (Y2n-2+4Y2n-1+Y2n)}. 4 Area= (w/3)*{( Y0+Y2n)+ ( 4* sum of odd Y sticks)+ 4 ( 2* sum of even Y- sticks )} 272

273 273 Ch. 5 Programming Languages 4 Historical perspective. 4 Traditional programming concepts. 4 Program units. 4 Language implementation. 4 Parallel computing. 4 Declarative programming.

274 274 Historical Perspective 4 Machine language - binary form direct controls the hardware. 4 Assembly language - mnemonic form of the machine language. 4 High-level programming language - English like language. 4 Evolution?

275 Programming Lag. 4 The programming process required the programmer to express all algorithms in the machine language. 4 First Generation Second Generation 4 Machine Lang. Assembly Lang. 4 15 5C LD R5, Price 4 16 6D LD R6, Shipping charge 4 50 56 ADDI R0,R5,R6 4 30 6E ST R0, Total Coast 4 C0 00 HLT 275

276 Programming Lang. 4 Disadvantages: 4 1- Program written in assembly lang. Is Machine Dependant 4 2- Programmer required to code instructions in bit pattern form. 276

277 277 Historical Perspective Compiler Assembler 1 Arch 1Arch nAssembler n HLL Machine independent Machine dependent

278 Programming Lang. [ HLL ] 4 The third generation 4 Their primitives were higher level and machine independent. 4 FORTRAN [ FORmula TRANslation ] 4 COBOL [ Common Business Oriented Language ] 4 A program called Translator, was written to translate programs into machine language programs. 4 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

279 279 Historical Perspective 4 1st-generation - machine language. 4 2nd-generation - assembly language. 4 3rd-generation - machine independent. 4 4th-generation - software packages that allow users to customize computer software to their applications without needing technical expertise. 4 5th-generation - declarative (logic) programming.

280 280 Historical Perspective 1st4th Problems solved in an environment in which the human must conform to the machine’s characteristics Problems solved in an environment in which the machine conforms to the human’s characteristics

281 Programming Lang. 4 Programming Languages are divided into four groups: 4 1- Imperative Paradigm 4 2- Functional Paradigm 4 3- Object-Oriented Paradigm 4 4- Declarative Paradigm 281

282 IMPERATIVE PARADIGM 4 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

283 Functional Paradigm 4 It views the process of program development as the construction of ( black boxes) each accepts inputs and produces outputs [ LISP, ML, Scheme ]. 4 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

284 284 Generations of programming languages

285 285 Ex. Functional Paradigm A function that computes the average of a list of numbers constructed from the simpler functions Sum, Count, and Divide

286 Object- Oriented Paradigm 4 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

287 Example 4 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. 4 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

288 Example 4 This may include procedures for: 4 Inserting a new entry in the list 4 Deleting an entry from the list 4 Detecting if the list is empty 4 Sorting the list 4 A program accessing the list does not need to contain algorithms for performing these task. 288

289 Declarative Paradigm 4 It discover and implement a general problem-solving algorithm, [ GPSS, Prolog] 4 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

290 290 Traditional Programming Concept 4 Statements in programming languages tend to fall into three categories: declarative statements, imperative statements, and comments. 4 Declarative statements - define customized terminology used in the program. 4 Imperative statements - describe steps in the underlying algorithm. 4 Comments.

291 291 The composition of a typical imperative program or program unit

292 292 Traditional Programming Concept 4 Variables, constants, and literals. 4 Data type - integer, real, Boolean, char….. 4 Data structure - array, queue, list,…….. 4 Assignment statements 4 Control statements. 4 Comments - internal documentation.

293 Variables and Data Types 4 High level language allows locations in main memory to referenced by descriptive names rather than by numeric addresses. Such names is known as variables. 4 The type of data that will be stored at the memory location associated with the variable is known as data type. 4 Integer Real Float Boolean 293

294 294 The same variable declarations in different languages

295 Data Structure 4 Data structure is the conceptual shape or arrangement of data. 4 Ex. Text is viewed as long string of characters 4 Sales Records : is viewed as a rectangular table of numeric values. 295

296 Homogenous Array 4 A block of values of the same types. 4 Ex. One dimension array 4 Two dimension array 4 The individual component can be identified by means of row and column and called INDICES. 296

297 297 A two-dimensional array with two rows and nine columns

298 Heterogeneous Array 4 It is block of data in which different elements can have different types. 4 Ex. Block of data referring to an employee may consist of: 4 1- An entry called Name ( Character ) 4 2- An entry called Age ( Integer ) 4 3- An entry called Skill Rating ( Real ) 298

299 299 Declaration of heterogeneous arrays in Pascal and C (continued)

300 300 Declaration of heterogeneous arrays in Pascal and C

301 Constant and Literals 4 When a fixed predetermined value is used in a program. Such value is called LITERAL. 4 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. 4 Constant is descriptive name to be assigned to specific, non changeable value. 301

302 Assignment Statements 4 Z = X + Y ; 4 Z := X + Y ; 4 Z  X + Y ; 302

303 Control Statement 4 Control Statement is an imperative statement that alter the execution sequence of the program. 4 The simplest control statement is GO TO 4 EX. IF statement Two options 4 WHILE statement Two options 4 CASE statement Many options 4 The loop structure 303

304 304 Control structures and their representations in C, C++, C#, and Java (continued)

305 305 Control structures and their representations in C, C++, C#, and Java

306 306 The for loop structure and its representation in Pascal, C++, C#, and Java (continued)

307 The loop 307

308 Comment 4 Programming languages provide ways of inserting explanatory statements called COMMENTS 4 Ex. /* This is a comment*/ C++,C, Java 4 // This is a comment. 4 C This is a comment. FORTRAN 308

309 309 Program Units 4 Breaking large programs into manageable units, units = modules, functions, objects. 4 Procedures and functions. 4 Parameter passing - formal parameters and actual parameter, call by address and call by value. 4 I/O statements.

310 Procedural Units 4 A procedure is a set of instructions for performing a task that can be used as an abstract tool by other program units. 4 Ex. Procedure Sort ( List ) 4 The generic term (list) is called PARAMETER 4 The terms used in writing the procedure is called formal parameter. 310

311 Procedure 4 The precise meanings assigned to these formal parameters when the procedure is applied are called actual parameters. 4 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

312 312 The flow of control involving a procedure

313 313 The procedure Project Population written in the programming

314 Example 4 Procedure Demo ( Formal ) 4 Formal = Formal + 1 314

315 315 Executing the procedure Demo and passing parameters by value (continued)

316 316 Executing the procedure Demo and passing parameters by value (continued)

317 317 Executing the procedure Demo and passing parameters by value

318 318 Executing the procedure Demo and passing parameters by reference (continued)

319 319 Executing the procedure Demo and passing parameters by reference (continued)

320 320 Executing the procedure Demo and passing parameters by reference

321 Function 4 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

322 322 The function CylinderVolume written in the programming language C

323 INPUT&OUTPUT Statement 4 EX. Read in ( value ) 4 write in ( value ) 323

324 324 An example of formatted output

325 325 Language Implementation 4 Translation - converting a program from one language to another. 4 Translation involves three activities: 1. Lexical analysis, 2. Parsing, and 3. Code generation. 4 Lexical analysis - recognizing which strings of symbols from the source program represent a single entity.

326 326 The translation process

327 Lexical Analyzer 4 Ex. 153 should not interpreted as a 1, a 5, and a3. but should be recognized as single numeric value [ 153 ] base 10. 4 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. and a 3. butLexical analyzer recognizing which strings of symbols from the source program represent a single entity. 4 should be recognized as single numeric value [ 153 ] base 10. 4 It generate a bit pattern known as token to represent the unit and hands the token to the parser. 4 During this 327

328 328 Language Implementation 4 Parsing - identifying the grammatical structure of the program and recognizing the role of each component. 4 Fixed-format languages{ FORTRAN} Vs. free-format languages { C }. 4 Key words, reserved words, syntax diagram, parse tree. 4 Coercion and strongly typed.

329 The Parser 4 The parser views the program in terms of lexical units [ tokens ] rather than individual symbols. The parser job to group these units into statement. 4 Key words [ IF, THEN, ELSE ] are called reserved words. 4 The parsing process is based on a set of syntax rules. 329

330 The Parser 4 The syntax rules defined by syntax diagrams. 4 Fixed Format Languages [ FORTRAN ] 4 Free Format Languages [ C ] 330

331 331 A syntax diagram of our if-then-else pseudo code statement

332 Syntax diagrams describing the structure of a simple algebraic expression 332

333 333 Parse tree for X+Y*Z 4 The parse tree for the string x + y  z based on the syntax diagrams

334 334 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued)

335 335 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued)

336 Coercion 4 The statement X + Y 4 If X is integer and Y is real 4 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. 4 Strongly typed: means that all activities requested by a program must involve data of agreeable types without coercion. 4 Parsers for these lang. Report all type conflicts as Errors 336

337 337 Language Implementation 4 Code generation - constructing the machine language instructions to simulate the statements recognized by the parser. 4 Code optimization. 4 Linker - links all necessary object programs to produce a complete, executable program. 4 Loader - place the program in memory for execution (what about multitasking?)

338 4 If the object program is requests services from other programs. The task of making these connections is preformed by a program called LINKER. 4 Its job to link several object programs. The result is executable program called LOAD module. 4 The module is placed in Memory by a program called a LOADER which is a part of Operating System. 338

339 339 An object-oriented approach to the translation process

340 340 The complete program preparation process

341 341 Parallel Computing 4 Developing languages for describing processes that execute simultaneously. 4 Ada. 4 Linda - tuple space (a shared storage area), in which each process in the system can deposit and retrieve data bundles.

342 Object-Oriented Programming 4 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

343 Object-Oriented 4 The object oriented approach to a problem is to identify the objects involved and describe them as self-contained units. 343

344 Classes and Objects 4 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

345 Classes and Objects 4 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. 4 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

346 346 The structure of a class describing a laser weapon in a computer game

347 CONSTRUCTORS 4 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

348 348 A class with a constructor

349 ENCAPSULATION 4 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

350 350 Our Laser-Class definition using encapsulation as it would appear in a Java or C# program

351 DECLARATIVE PROGRAMMING 4 Logical Deduction 4 Suppose we know that either 4 Ali is on stage 4 Or Ali is sick 4 And we are told that: Ali is not on stage, 4 We could the conclude that Ali must be sick 4 This is an example of a deductive-reasoning principle called RESOLUTION 351

352 Declarative Programming 4 Example: 4 Let A: Ali is a prince. 4 B: Miss Salma is an actress. 4 Then A OR B Means 4 Ali is a prince or Miss Salma is an actress. 4 And B AND ( NOT A ) 4 Miss Salma is an actress and Ali is not a prince 352

353 Example 4 And A  B ( A implies B ) 4 Ali is a prince implies Miss Salma is an actress 4 In general if : 4 P OR Q and R OR ( NOT Q ) 4 We can conclude the statement P OR R 353

354 Example 4 The two original statements resolve to form the third statement which it is called RESOLVENT. 4 Prolog Programming language is example of declarative programming 4 Prolog is Programming in logic 354

355 355 Declarative Programming 4 4 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. 4 Thus P OR Q is In clause form whereas 4 P -> Q is not.

356 356 Resolving the statements (P OR Q) and (R OR  Q) to produce (P OR R)

357 Declarative Programming 4 Inconsistent- in a collection of statements, it is impossible for all the statements to be true at the same time. 4 A simple example a statement of the form P combined with the statement NOT P. 4 The rule is that if repeated application of the resolution produces the empty clause [ the result of resolving a clause of the form with a clause of the form NOT P ] 357

358 Declarative Programming 4 Then the original collection of statements must be inconsistent. 358

359 359 Resolving the statements (P OR Q), (R OR  Q),  R, and  P

360 360 Ch. 6 Software Engineering 4 The software engineering discipline. 4 The software life cycle. 4 Modularity. 4 Development tools and techniques. 4 Documentation. 4 Software ownership and liability.

361 361 The Software Engineering Discipline 4 How to develop and manage a large program (>100K lines of code) or a huge program (>1M lines of code)??? 4 What is software engineering discipline? 4 What is the quantitative system (metrics) to measure the quality and successfulness of the underlying software development??? 4 Developing techniques for immediate applications and for future applications.

362 362 The Software Life Cycle Development Use Modification

363 363 The Software Life Cycle AnalysisDesignImplementationTesting Development phase

364 364 The Software Life Cycle 4 Waterfall model. 4 Computer-aided software engineering (CASE). 4 Prototyping.

365 365 A structure chart for a simple Internet “mail order” business

366 366 A class diagram for a simple Internet “mail order” business

367 367 A structure chart showing data coupling

368 368 A collaboration diagram of a simple Internet “mail order” business

369 369 Logical and functional cohesion within an object representing an order form in a simple Internet “mail order” business

370 370 Modularity 4 Modular implementation - structure chart. 4 Coupling - control and data coupling. 4 Implicit coupling, global data - why is not good? Side effects! 4 Cohesion - the coupling between modules. 4 Logical cohesion and functional cohesion.

371 371 The publisher-subscriber pattern

372 372 The component-container pattern

373 373 Development Tools and Techniques 4 Top-down design. 4 Bottom-up design. 4 Dataflow diagrams - a pictorial representation of data paths. 4 Entity-relationship diagrams - a pictorial representation of the items of information (entities) within the system and the relationships between these pieces of information.

374 374 A dataflow diagram of a simple Internet “mail order” business

375 375 An entity-relationship diagram

376 376 One-to-one, one-to-many, and many-to-many relationships between entities of types X and Y

377 377 Development Tools and Techniques 4 Data dictionaries - a central depository of information about the data items appearing throughout the system. 4 Enhancing communication between the potential user of the system. 4 Establishing uniformity throughout the system.

378 378 Documentation, software Ownership and Liability 4 User documentation and system documentation. 4 Copyright and patent laws.

379 379 Part III: Data Organization 4 Data structures. 4 File structures. 4 Database structures.

380 DATA STRUCTURES 4 Data structure is concerned with the various ways that data files can be organized and assembled. 4 The structures of data files will strongly influence the selection of a computational strategy for a given data processing job. 380

381 DEFINITIONS 4 1- A List is a collection of sets of data elements. LIST and FILE have the same meaning. 4 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

382 DEFINITION 4 The items within a node are required to be stored in storage locations, though the nodes themselves need not be adjacent to one another. 4 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

383 DEFINITION 4 4- The Link [ Pointer]: Contain the starting addresses of other nodes, thus creating a structural interrelationship among the nodes. 383

384 384 Novels arranged by title but linked according to authorship

385 DEFINITION 4 The link tell us that the next node in the list has starting address of xxxx. 4 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

386 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

387 LINKED LINEAR LIST 4 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

388 388 The array of Readings stored in memory starting at address

389 389 A two-dimensional array with four rows and five columns stored in row major order

390 390 Names stored in memory as a contiguous list

391 391 The structure of a linked list

392 392 Deleting an entry from a linked list

393 393 Inserting an entry into a linked list

394 394 A procedure for printing a linked list

395 MULTIPLE LINKS 4 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. 4 Each set of links establishes a separate single linked linear list. 395

396 STACKS 4 A stack is a list in which all insertions and deletions are performed at the same end of the structure. 4 Stack known as last-in, first-out [LIFO] structures. 396

397 BACKTRACKING 4 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. 4 Stack is an ideal structure for such a system. 4 This process is called Backtracking 397

398 398 Nested procedures terminating in the opposite order to that in which they were requested

399 BACKTRACKING 4 Suppose we want to print the names in a linked list in a reverse order that is last name first. 4 We can access the names only by following the link structure. Thus we need to use the stack. 399

400 400 Using a stack to print a linked list in reverse order (continue d)

401 401 Using a stack to print a linked list in reverse order

402 402 A procedure (using an auxiliary stack) for printing a linked list in reverse order

403 403 A stack in memory

404 404 Stacks 4 Last-in first-out. 4 Push and pop. 4 Using stacks for maintaining procedure calls. 4 Other applications???

405 QUEUES 4 Queue is a list in which all insertions are performed at one end while all deletions are made at the other end. 4 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

406 QUEUES 4 QUEUE uses two memory cells to use as pointers instead of just one. 4 Head Pointer 4 Tail Pointer 406

407 407 A queue implemented with head and tail pointers

408 408 A queue “crawling” through memory

409 409 A circular queue (a) containing the letters F through O as actually stored in memory

410 410 A circular queue (b) in its conceptual form in which the last cell in the block is “adjacent” to the first cell

411 411 Queues 4 First-in first-out. 4 Head and tail. 4 Circular queue.

412 TREES 4 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

413 413 An example of an organization chart

414 TREES 4 Tree consists of a collection of nodes which are interconnected by branches to form a tree like configuration, as shown below: 414

415 415 Tree terminology

416 TREES 4 The branches emanate downward from the nodes, The node is presented by a square. The top node is called the root of the tree. 4 All of the remaining nodes are called either branch or terminal nodes. 4 The branch nodes have branches emanating from them, the terminal nodes do not. 416

417 TREES 4 The degree of a node is equal to the number of sub-trees that emanate from that node. 4 Terminal nodes are therefore nodes of degree zero. 4 All trees have two or more levels. The root is the 1 st level. The subsequent nodes increase in level as they branch out from the root. 417

418 BINARY TREE 4 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: 4 Left Child Pointer 4 Right Child Pointer 418

419 419 The structure of a node in a binary tree

420 420 The conceptual and actual organization of a binary tree using a linked storage system

421 421 A tree stored without pointers

422 BINARY TREE 4 Another alternative storage system 4 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

423 BINARY TREES 4 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. 4 Node 4 ( 4+1)= 5 4 Node 3 ( 3- 1 )= 2 423

424 424 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers

425 Searching the list 4 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

426 Searching The List 4 To apply this algorithm, our storage system must allows us to find the middle entry of successively smaller portion of the list. 4 This can be done using linked binary tree. 4 Ex. The list of letters [ A, B, C, D, E, F, G, H, I, J, K, L, and M ] 426

427 427 The letters A through M arranged in an ordered tree

428 428 The binary search as it would appear if the list were implemented as a linked binary tree

429 429 The successively smaller trees considered by the procedure in when searching for the letter J

430 430 Printing a search tree in alphabetical order

431 431 A procedure for printing the data in a binary tree

432 432 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree (continued)

433 433 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree

434 434 A procedure for inserting a new entry in a list stored as a binary tree

435 435 Trees 4 Trees - an organization chart; e.g., family tree and company’s organization. 4 Root node, leaf nodes, arc, sub trees. 4 Parent, children, siblings. 4 Depth of a tree. 4 Tree implementation. 4 Binary tree.

436 436 A stack of integers implemented in C++

437 437 A stack of integers implemented in Java and C#

438 438 Our first attempt at expanding the machine language to take advantage of pointers

439 439 Loading a register from a memory cell that is located by means of apointer stored in a register

440 440 Customized Data Types 4 User-defined types - allow programmers to define additional data types using the primitive types and structures as building blocks. 4 Abstract data types - encompasses both the storage system and the associated operations. 4 Encapsulation.

441 441 The role of an operating system when accessing a file

442 442 Object-Oriented Programming 4 Objects. 4 Methods (or member functions). 4 Class. 4 Inheritance.

443 443 Ch. 8 File Structures 4 Sequential files. 4 Text files. 4 Indexed files. 4 Hashed files. 4 The role of the operating system.

444 444 Maintaining a file’s order by means of a file allocation table

445 445 Sequential Files 4 When to use it? When all the records need to be proceeded, it makes no difference which records are proceeded first. 4 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??? 4 EOF and sentinel. 4 How to update a sequential file?

446 446 Sequential Files 4 In PASCAL, statements read() and write() are used to retrieve and deposit information. Merge Transaction fileOld master file New master file Alg. See Figure8.3

447 447 Text Files 4 Text file - the size of the logical records in a sequential file to a single byte (Char). 4 How to manipulate a text file? A word processor? 4 How to use text files to define an input and an output files to a program?

448 448 Indexed Files 4 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? 4 What’s the fast way to find the subject you are interesting in from a book??? Ans. Using the index.

449 449 Indexed Files 4 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. 4 Key field. 4 An inverted file - primary key and secondary key. 4 When records are inserted and deleted, all indexes must be updated.

450 450 The structure of a simple employee file implemented as a text file

451 451 The first two bars of Beethoven’s Fifth Symphony

452 452 Converting data from two’s complement notation into ASCII for storage in a text file (continued)

453 453 Converting data from two’s complement notation into ASCII for storage in a text file

454 454 Indexed Files 4 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. 4 What if the index size is too large??? 4 The partial-index structure. 4 An index to the index.

455 455 Hashed Files 4 Sequential files - process in a serial order. 4 Indexed files - direct access (random access). Overhead: maintaining an index table. 4 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.

456 456 Opening an indexed file

457 457 An inverted file

458 458 Hashed Files 4 A particular hashing technique: 4 1. Divide the mass storage area allotted to the file into several sections called buckets. 4 2. Convert any key field value into a numeric value. 4 3. Divide any key field value stored in memory by the number of buckets. 4 4. Convert any key field value into an integer that identifies the bucket in memory.

459 459 A file with a partial index

460 460 Hashed Files 4 What is the main concern when using hashed files? 4 Distribution problems - once we have chosen the hash algorithm, we have no control over the distribution of records in mass storage. 4 Clustering problem - majority of records are placed in the same bucket and the rest of buckets contain almost no records.

461 461 The rudiments of a hashing system, in which each bucket holds those records that hash to that bucket number (continued)

462 462 The rudiments of a hashing system, in which each bucket holds those records that hash to that bucket number

463 463 Hashed Files 4 Overflow problem - unless the buckets are extremely large, overflow may occur. 4 Goal - how to select a hash algorithm that evenly distributes the records among the buckets. 4 Division method. 4 The midsquare method. 4 The extraction method.

464 464 Hashing the key field value 25X3Z to one of 40 buckets

465 465 Handling bucket overflow

466 466 Hashed Files 4 Collision - more than one record will hash to the same bucket. 4 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%!!!

467 467 A large file partitioned into buckets to be accessed by hashing

468 468 Hashed Files 4 The high probability of collisions indicates that a hashed file should never be implemented under the assumption that clustering will never occur. 4 How to handle the overflow problem? 4 Reserve an additional area of mass storage to hold overflow records. 4 Double hashing method.

469 469 The Role of the Operating System 4 Operating systems need to manipulate files to perform designated tasks. 4 Operating systems maintains a table called a file descriptor or file control block for each file being processed. 4 In PASCAL, file descriptors can be created by assign() and reset().

470 470 Ch. 9 Database Structures 4 General issues. 4 The layered approach to database implementation. 4 The relational model. 4 Object-oriented databases. 4 Maintaining database integrity.

471 471 General Issues 4 A file Vs. a database organization. 4 Why needs a database system? 4 The consolidation approach - advantage: central control, disadvantage: security. 4 Database administrator (DBA). 4 Access privileges - schema and subschema. 4 Other issues - size and scope, privacy.

472 472 The Layered Approach to Database Implementation End user Application software Database management system Actual database Data seen in terms of the applications Data seen in terms of a database model Data seen in its actual organization

473 473 The Layered Approach to Database Implementation 4 Database management system (DBMS). 4 The advantages of the separation of application software and the database management system: 4 1. Simplify the design process - for example the distributed database. 4 2. Providing a central controlling access to the database.

474 474 A file versus a database organization (continued )

475 475 A file versus a database organization

476 476 The Layered Approach to Database Implementation 4 3. Data independence - the ability to change the organization of the database itself without changing the application software. 4 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. 4 Host languages.

477 477 The Relational Model 4 Relation - tuple (row) and attribute (column). 4 How to make up the database using the relations of data? 4 Extending the relation - pro and con? 4 Dividing information into various relations (nonloss decomposition) - pro and con?

478 478 The Relational Model 4 Relational operations: 4 The SELECT operation. 4 The PROJECT operation. 4 The JOIN operation. 4 The SQL (Structured Query Language).

479 479 Object-Oriented Databases 4 Why object-oriented databases: 4 1. Data independence can be achieved by encapsulation. 4 2. The concepts of classes and inheritance fit schemas and subschemas of databases. 4 3. Intelligent data objects that can answer questions themselves. 4 4. It may overcome some of the restrictions inherent in other database models.

480 480 Maintaining Database Integrity 4 Why database integrity is important? 4 The commit/rollback protocol. 4 Cascading roll back. 4 Locking protocol - shared locks and exclusive locks. 4 Wound-wait protocol.

481 481 A relation containing employee information

482 482 A relation containing redundancy

483 483 An employee database consisting of three relations (continued)

484 484 An employee database consisting of three relations (continued)

485 485 An employee database consisting of three relations

486 486 Finding the departments in which employee 23Y34 has worked (continued)

487 487 Finding the departments in which employee 23Y34 has worked

488 488 A relation and a proposed decomposition

489 489 The SELECT operation

490 490 The PROJECT operation

491 491 The JOIN operation

492 492 Another example of the JOIN operation

493 493 An application of the JOIN operation (continued)

494 494 An application of the JOIN operation

495 495 PART IV: The Potential of Algorithmic Machines 4 Artificial Intelligence. 4 Theory of Computation.

496 496 The associations between objects in an object-oriented database

497 497 Ch. 10 Artificial Intelligence 4 Some philosophical issues. 4 Image analysis. 4 Reasoning. 4 Control system activities. 4 Using Heuristics. 4 Artificial neural networks. 4 Applications of AI.

498 498 Some Philosophical Issues 4 Machines Vs. humans. 4 Performance Vs. simulation. 4 Intelligence as an interior characteristic - Turing test and program DOCTOR (ELIZA). 4 How to create an intelligent machine?

499 499 An Intelligent puzzle-solving machine 4 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. 4 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.

500 500 Image Analysis 4 The first intelligent behavior required by the puzzle-solving machine is the extraction of information through a visual medium. 4 Perceive ability - determine the current status of the puzzle. 4 Optical character readers. 4 Character recognition based on matching the geometric characteristics.

501 501 Reasoning 4 Is possible to develop proper programs targeted to all possible initial configurations (in total 181,440 of them)? 4 Develop a program which can solve the problem itself - the ability to make decisions, draw conclusions, and in short, perform elementary reasoning activities.

502 502 Our puzzle-solving machine

503 503 The eight-puzzle in its solved configuration

504 504 Reasoning 4 A production system consists of three main components: 4 1. A collection of states - start/goal states. 4 2. A collection of productions (rules). 4 3. A control system - which consists of the logic that solves the problem of moving from the start state to the goal state. 4 State graph - conceptualizing all states, rules, and preconditions in a production system.

505 505 Reasoning Socrates is a man. All men are humans. All humans are mortal. 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. Start state Goal state

506 506 Control System Activities 4 A state-graph traversal problem. 4 Search tree. 4 How to build a search tree? 4 It is impractical to develop a full search tree for a complex problem. 4 Using depth-first construction instead of breadth-first manner. 4 Avoiding redundancy.

507 507 Using Heuristics 4 Heuristics - the use of intuition, a rule of thumb which may lead to a correct direction but offer no assurance on it. 4 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).

508 508 Artificial Neural Networks 4 Neural networks - model networks of neurons in living biological systems. Compute effective inputs Threshold value Output 0 or 1 I1W1+…+InWn

509 509 Applications of Artificial Intelligence 4 Language processing. 4 Robotics. 4 Database systems. 4 Expert systems.

510 510 A small portion of the eight-puzzle’s state graph

511 511 Deductive reasoning in the context of a production system

512 512 An unsolved eight-puzzle

513 513 A sample search tree (continued)

514 514 A sample search tree (continued)

515 515 A sample search tree (continue d)

516 516 A sample search tree

517 517 Productions stacked for later execution

518 518 An unsolved eight-puzzle

519 519 An algorithm for a control system using heuristics

520 520 The beginning of our heuristic search

521 521 The search tree after two passes

522 522 The search tree after three passes

523 523 The complete search tree formed by our heuristic system

524 524 A neuron in a living biological system

525 525 Ch. 11 Theory of Computation 4 A bare bones programming. 4 Turing machines. 4 Computable functions. 4 A noncomputable function. 4 Complexity and its measure. 4 Problem classification.

526 526 The activities within a processing unit

527 527 Representation of a processing unit

528 528 A neural network with two different programs (continued)

529 529 A Bare Bones Programming Language 4 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.

530 530 Uppercase C and uppercase T

531 531 Various orientations of the letters C and T (continued)

532 532 The structure of the character recognition system

533 533 The letter C in the field of view

534 534 The letter T in the field of view

535 535 An artificial neural network implementing an associative memory

536 536 The steps leading to a stable configuration (continued)

537 537 The steps leading to a stable configuration

538 538 Crossing two poker-playing strategies

539 539 Coding the topology of an artificial neural network (continued)

540 540 Coding the topology of an artificial neural network

541 541 A semantic net

542 542 A Bare Bones Programming Language 4 Data description statements - all variables are considered to be of type “bit pattern of any length.” => no need a declarative part. 4 Process description statements - three assignment statements: clear, incr, decr and one control structure: while-end.

543 543 An attempt to display the function that converts measurements in yards into meters

544 544 The components of a Turing machine

545 545 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;

546 546 Turing Machines 4 Turing machines - are conceptual devices for studying the power of algorithmic processes. 4 A Turing machine consists of a control unit that can read and write symbols on a tape 4 The machine must be in one of a finite number of states, start/halt states.

547 547 A Turing machine for incrementing a value

548 548 A Bare Bones program for computing X  Y

549 549 A Bare Bones implementation of the instruction “copy Today to Tomorrow”

550 550 Turing Machines 4 Today’s computers Turing machines finite memories infinite supply of tape CPU the control unit bit patterns states 4 The significance of Turing machines in theoretical computer science - the computation power of Turing machines is as great as any algorithmic system.

551 551 Computable Functions 4 How to measure computing power? 4 Goal: using Turing machines to investigate the power of the bare bones language. 4 Computing the functions is the process of determining an output of a function from its inputs. 4 If one machine is capable of computing more functions than another, the former is considered the more powerful.

552 552 Computable Functions 4 Ex. A system in which function outputs are predetermined and recorded in a table. 4 Ex. Finding function outputs would be to describe how to compute the output. 4 Computable - the functions whose output values can be determined algorithmically from their input values. 4 Noncomputable functions!

553 553 Computable Functions 4 Turing computable. 4 The Church-Turing thesis. 4 If a computational system is capable of computing all the Turing-computable functions, it is considered to be a universal system. 4 Apply the Church-Turing these to confirm that the bare bones language is a universal programming language.

554 554 A Noncomputable Function 4 Computing the Godel number. 4 The halting problem.

555 555 Complexity and Its Measure 4 Time and storage complexities (Big O). 4 Order of complexity. 4 Polynomial and nonpolynomial problems. 4 NP problems - nondeterministic polynomial problems. 4 NP-complete problems.

556 556 Testing a program for self-termination

557 557 Proving the unsolvability of the halting program (continued)

558 558 Proving the unsolvability of the halting program (continued)

559 559 Proving the unsolvability of the halting program

560 560 Roadmap to Computer Science Study 4 Fundamental courses: Physics, Mathematics, and Introduction to Computer Science. 4 Software: 4 1. Fundamental: Problem Solving and Programming, Data Structure, Algorithm, and Software Engineering. 4 2. Language: Assembly Language, Programming Language, C, and JAVA.

561 561 A procedure MergeLists for merging two lists

562 562 The merge sort algorithm implemented as a procedure MergeSort

563 563 The hierarchy of problems generated by the merge sort algorithm

564 564 Graphs of the mathematical expressions n, lg n, n lg n, and n2

565 565 A graphic summation of problem classification

566 566 Encrypting a bit pattern as a knapsack problem

567 567 Public key encryption using knapsack problems

568 568 Constructing a public key encryption system

569 569 Roadmap to Computer Science Study 4 3. Theory: Formal Language and Theory of Computation. 4 4. System: Operating System, Compiler, Networking, Database, and Multimedia. 4 Hardware: 4 1. Fundamental: Electronics, Logic Design, Digital System Design, and Computer Architecture.

570 570 Roadmap to Computer Science Study 4 2. System: Microprocessors and VLSI design. 4 Applications: 4 1. Consumer products. 4 2. Artificial Intelligence. 4 3. Networking. 4 4. Image Processing. 4 5. Computer Architecture and Compiler.

571 571 Roadmap to Computer Science Study 4 6. VLSI and Computer-Aided Design. 4 7. Biological (Medical) Computing. 4 8. Multimedia. 4 9. Databases. 4 10. Education. 4 11. Business and management. 4 12. And more!!!


Download ppt "1 Computer Science An Overview EE461 Introduction to Computer Science."

Similar presentations


Ads by Google