Click here to load reader

1 Computer Science An Overview EE461 Introduction to Computer Science

Embed Size (px)

Citation preview

  • Slide 1
  • 1 Computer Science An Overview EE461 Introduction to Computer Science
  • Slide 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.
  • Slide 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 todays computer applications as well as the foundations for tomorrows applications.
  • Slide 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.
  • Slide 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.
  • Slide 6
  • 6 The Euclidean algorithm for finding the greatest common divisor of two positive integers
  • Slide 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
  • Slide 8
  • 8 The Development of Algorithmic Machines 4 Abacus.[ Ancient Greek+ Roman Civiliz.] 4 Babbages difference engine.[1850] 4 Jacquards 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]
  • Slide 9
  • 9 Jacquards loom
  • Slide 10
  • 10 The Mark I computer
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 15
  • 15 The central role of algorithms in computer science
  • Slide 16
  • 16 The Evolution of Computer Science Algorithms Hardware Software Languages Applications
  • Slide 17
  • 17 Abstraction and Other Issues 4 Abstraction - the distinction between the external properties of a component and the internal details of the components construction. 4 Ethical issues. 4 Social issues. 4 Legal issues.
  • Slide 18
  • 18 The hierarchy of abstraction in the hardware of a typical personal
  • Slide 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.
  • Slide 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.
  • Slide 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 operations 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.
  • Slide 22
  • 22 The Boolean operations AND, OR, and XOR (exclusive or)
  • Slide 23
  • 23 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values (continued)
  • Slide 24
  • 24 A pictorial representation of AND, OR, XOR, and NOT gates as well as their input and output values
  • Slide 25
  • 25 A simple flip-flop circuit
  • Slide 26
  • 26 Setting the output of a flip-flop to 1 (continued)
  • Slide 27
  • 27 Setting the output of a flip-flop to 1 (continued)
  • Slide 28
  • 28 Setting the output of a flip-flop to 1
  • Slide 29
  • 29 Another way of constructing a flip- flop
  • Slide 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
  • Slide 31
  • 31 The hexadecimal coding system
  • Slide 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.
  • Slide 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).
  • Slide 34
  • 34 Memory cells arranged by address
  • Slide 35
  • 35 The organization of a byte-size memory cell
  • Slide 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.
  • Slide 37
  • 37 Mass Storage 4 Disk storage. 4 Compact disks and CD-ROM. 4 Tape storage. 4 Physical Vs. logical records.
  • Slide 38
  • 38 HARD DISK
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 42
  • 42 CD storage format
  • Slide 43
  • 43 A magnetic tape storage mechanism
  • Slide 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
  • Slide 45
  • 45 Logical records versus physical records on a disk
  • Slide 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.
  • Slide 47
  • 47 The message Hello. in ASCII
  • Slide 48
  • 48 The base ten and binary systems
  • Slide 49
  • 49 Decoding the binary representation 100101
  • Slide 50
  • 50 An algorithm for finding the binary representation of a positive integer
  • Slide 51
  • 51 Applying the algorithm to obtain the binary representation of thirteen
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 57
  • 57 The Binary System 4 Binary addition. 4 Fractions in binary. 4 Radix point (same as decimal point in decimal notation).
  • Slide 58
  • 58 The binary addition facts
  • Slide 59
  • 59 Decoding the binary representation 101.101
  • Slide 60
  • 60 Twos complement notation systems
  • Slide 61
  • 61 Coding the value -6 in twos complement notation using four bits
  • Slide 62
  • 62 Addition problems converted to twos complement notation
  • Slide 63
  • 63 An excess eight conversion table
  • Slide 64
  • 64 An excess notation system using bit patterns of length three
  • Slide 65
  • 65 Floating-point notation components
  • Slide 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
  • Slide 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
  • Slide 68
  • 68 Coding the value 2 5/8
  • Slide 69
  • 69 Storing Fractions 4 Floating-point notation. 4 Sign bit => Exponent => Mantissa. 4 Round-off errors.
  • Slide 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
  • Slide 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
  • Slide 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 items use. 4 Ex. Variable length codes 4 Huffman codes 72
  • Slide 73
  • DATA COMPRESSION 4 Adaptive dictionary encoding 4 Lempel-Ziv encoding 4 ABAABQB (5,4,A) (0,0,D) (8,6,B) 73
  • Slide 74
  • 74 Decompressing xyxxyzy (5, 4, x)
  • Slide 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.
  • Slide 76
  • 76 The ASCII codes for the letters A and F adjusted for odd parity
  • Slide 77
  • 77 An error-correcting code
  • Slide 78
  • 78 Decoding the pattern 010100
  • Slide 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.
  • Slide 80
  • 80 The Central Processing Unit CPU ALU Regs. Control unit Main memory Bus
  • Slide 81
  • 81 Adding values stored in memory
  • Slide 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.
  • Slide 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 computers program can be changed merely by changing the contents of the computers memory instead of rewiring the control unit.
  • Slide 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.
  • Slide 85
  • 85 Dividing values stored in memory
  • Slide 86
  • 86 The Stored-Program Concept CPU ALU Regs. Control unit Main memory Bus Program counter Instr. Reg. Address 00 FF Op-code operand
  • Slide 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.
  • Slide 88
  • 88 The machine cycle
  • Slide 89
  • 89 Decoding the instruction B258
  • Slide 90
  • 90 Figure 2.10: The program stored in main memory ready for execution
  • Slide 91
  • 91 Figure 2.11:Performing the fetch step of the machine cycle (continued
  • Slide 92
  • 92 Other Architectures 4 The design of a machines language - complex instruction set Vs. simple instruction set. 4 CISC Vs. RISC. 4 CISC micro program. 4 RISC - simple CPU design.
  • Slide 93
  • 93 Performing the fetch step of the machine cycle
  • Slide 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.
  • Slide 95
  • 95 Rotating the bit pattern A3 one bit to the right
  • Slide 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,..
  • Slide 97
  • 97 Computer-Peripheral Communication 4 Controllers handle communication between machines 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.
  • Slide 98
  • 98 Computer-Peripheral Communication CPU Peripheral device Controller Main memory Controller Peripheral device Bus
  • Slide 99
  • 99 A conceptual representation of memory-mapped I/O
  • Slide 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.
  • Slide 101
  • 101 Computer-Peripheral Communication CPU Peripheral device Controller Main memory Bus Memory-mapped I/O
  • Slide 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.
  • Slide 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.
  • Slide 104
  • 104 Ch. 3 Operating Systems and Networks 4 The evolution of operating systems. 4 Operating system architecture. 4 Coordinating the machines activities. 4 Handling Competition among processes. 4 Networks. 4 Network protocols.
  • Slide 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 machines 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.
  • Slide 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.
  • Slide 107
  • 107 Batch processing
  • Slide 108
  • 108 Software classification
  • Slide 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.
  • Slide 110
  • 110 Interactive processing
  • Slide 111
  • 111 Operating System Architecture Software ApplicationSystem Utility Operating system ShellKernel
  • Slide 112
  • 112 Operating System Architecture 4 A machines software can be divided into two categories: application software and system software. 4 Application software - the programs for performing tasks particular to the machines utilization. 4 System software - performs tasks which are common to computer systems in general.
  • Slide 113
  • 113 Operating System Architecture Software ApplicationSystem Utility Operating system ShellKernel
  • Slide 114
  • 114 The shell as an interface between users and the operating system
  • Slide 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.
  • Slide 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.
  • Slide 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.
  • Slide 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
  • Slide 119
  • OPERATING SYSTEM TASKS 4 A- Processor Management 4 1- Ensuring that each process and application receives enough of the processors time to function properly. 4 2- Using as many processor cycles for real work as is possible. 119
  • Slide 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
  • Slide 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. Its function to communicate with the controllers to carry out operations on the peripheral devices. 121
  • Slide 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
  • Slide 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
  • Slide 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.
  • Slide 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
  • Slide 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
  • Slide 127
  • BOOTSTRAP 127
  • Slide 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.
  • Slide 129
  • 129 Coordinating the Machines Activities 4 Process administration - the tasks associated with process coordination are handled by the scheduler and dispatcher within the operating systems kernel. 4 Process table - keeps information of a process when it is created (assigned memory area, the priority, the status - ready or waiting).
  • Slide 130
  • 130 Identical communication structure between clients and servers operating on the same machine and distributed among different machines
  • Slide 131
  • 131 Coordinating the Machines 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).
  • Slide 132
  • 132 Time-sharing between process A and process B
  • Slide 133
  • 133 Coordinating the Machines 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.
  • Slide 134
  • 134 The client/server model
  • Slide 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.
  • Slide 136
  • DEADLOCK 136
  • Slide 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.
  • Slide 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.
  • Slide 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.
  • Slide 140
  • 140
  • Slide 141
  • 141
  • Slide 142
  • NETWORK TOPOLOGIES 142
  • Slide 143
  • NETWORK TOPOLOGIES 143
  • Slide 144
  • The distinction between a bridge and a router 144
  • Slide 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., [email protected].
  • Slide 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).
  • Slide 147
  • A typical approach to connecting to the Internet 147
  • Slide 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
  • Slide 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
  • Slide 150
  • 150 A typical URL
  • Slide 151
  • 151 A simple Web page expressed in HTML
  • Slide 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.
  • Slide 153
  • 153 Communication over a ring network
  • Slide 154
  • 154 Communication over a bus network
  • Slide 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
  • Slide 156
  • 156 Package-shipping example
  • Slide 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
  • Slide 158
  • 158 The Internet software layers
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 163
  • 163 Application layer Network Protocols: The Internet Software Layer Transport layer Network layerLink layer Application layerTransport layer Network layerLink layer Message sourceMessage destination
  • Slide 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).
  • Slide 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
  • Slide 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
  • Slide 167
  • 4 Unauthorized access to information and vandalism 4 Passwords and data encryption 4 Virus 4 Worm 167 Networks
  • Slide 168
  • SECURITY 4 1-Password 4 2- Public-key encryption 4 3- Secure Socket Layer [ SSL ] 168
  • Slide 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
  • Slide 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
  • Slide 171
  • FIREWALL 4 It forms a protective barrier that shields the region on one side from the dangers on the other side. 171
  • Slide 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.
  • Slide 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.
  • Slide 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
  • Slide 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
  • Slide 176
  • ALGORITHM REPRESENTATION 4 PRIMITIVE = SYNTAX + SEMANTICS 4 Syntax refers to the Primitives 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
  • Slide 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.
  • Slide 178
  • 178 Folding a bird from a square piece of paper (continued)
  • Slide 179
  • 179 Folding a bird from a square piece of paper
  • Slide 180
  • 180 Origami primitives (continued)
  • Slide 181
  • 181 Origami primitives
  • Slide 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)
  • Slide 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)
  • Slide 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.
  • Slide 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.
  • Slide 186
  • EXAMPLE 4 Person A is charged with the task of determining the age of Person Bs 3 children: 4 CLUES: 4 1-The product of the childrens ages is 36 4 2- The sum of the childrens ages is given 4 Find the ages of the three children. 186
  • Slide 187
  • 187 EXAMPLE
  • Slide 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
  • Slide 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 As 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
  • Slide 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
  • Slide 191
  • EXAMPLE 2 4 C B A D OR C D A B 4 CBAD order is ruled out because Bs prediction must be false. 4 There fore finishing order was : 4 C D A B 191
  • Slide 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
  • Slide 193
  • 193 The sequential search algorithm in pseudocode
  • Slide 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.
  • Slide 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
  • Slide 196
  • 196 Components of repetitive control
  • Slide 197
  • 197 The while loop structure
  • Slide 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
  • Slide 199
  • 199 The repeat loop structure
  • Slide 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
  • Slide 201
  • 201 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued)
  • Slide 202
  • 202 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically (continued)
  • Slide 203
  • 203 Sorting the list Fred, Alice, David, Bill, and Carol alphabetically
  • Slide 204
  • 204 The insertion sort algorithm expressed in pseudocode
  • Slide 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
  • Slide 206
  • 206 Applying our strategy to search a list for the entry John
  • Slide 207
  • 207 A first draft of the binary search technique
  • Slide 208
  • 208 The binary search algorithm in pseudocode
  • Slide 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
  • Slide 210
  • 210 Binary Search Algorithm
  • Slide 211
  • 4 Let us consider the list: 4 [ Alice, Carol, Evelyn, Fred, and George ] 4 Searching for the entry ( David ) 211
  • Slide 212
  • 212 Binary Search Algorithm
  • Slide 213
  • 213 Binary Search Algorithm
  • Slide 214
  • 214 Binary Search Algorithm
  • Slide 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.
  • Slide 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
  • Slide 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
  • Slide 218
  • 218 Applying the insertion sort in a worst-case situation
  • Slide 219
  • 219 Graph of the worst-case analysis of the insertion sort algorithm
  • Slide 220
  • 220 Graph of the worst-case analysis of the binary search algorithm
  • Slide 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.
  • Slide 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
  • Slide 223
  • 223 Separating the chain using only three cuts
  • Slide 224
  • 224 Solving the problem with only one cut
  • Slide 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
  • Slide 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
  • Slide 227
  • VERIFICATION 4 Proof of correctness begins with the assumption that certain conditions, called preconditions, are satisfied at the beginning of the programs execution. 4 How the consequences of these preconditions propagate through the program. 227
  • Slide 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
  • Slide 229
  • 229 The assertions associated with a typical while structure
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 236
  • LP Graphical Solution 4 x + y
  • LP Solution 4 Max P = 300 x + 240 y 4 Subject to 4 x + y = 0 237
  • Slide 238
  • Graphical Solution 238
  • Slide 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
  • Slide 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
  • Simplex Method 4 Consider the LP problem 4 Max. P= 4*x1 + 3* x2 4 Subject to : 2x1 + 3x2 = 0 4 The basic feasible solution x1= x2= 0 Then S1= 6, S2= 3, S3= 5, and S4 =4. 243
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 257
  • Graphical Solution ( X=3, Y=4) 257
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 261
  • 261
  • Slide 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 Y0 and F(U) < 0 262
  • Slide 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
  • 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
  • Slide 265
  • Numerical Integration 4 A) Trapezium Rule 265
  • Slide 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
  • Slide 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
  • Slide 268
  • Simpsons Rule 268
  • Slide 269
  • Simpsons 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
  • Slide 270
  • Simpsons 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
  • Slide 271
  • Simpsons Rule 271
  • Slide 272
  • Simpsons 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
  • Slide 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.
  • Slide 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?
  • Slide 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
  • Slide 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
  • Slide 277
  • 277 Historical Perspective Compiler Assembler 1 Arch 1Arch nAssembler n HLL Machine independent Machine dependent
  • Slide 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
  • Slide 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.
  • Slide 280
  • 280 Historical Perspective 1st4th Problems solved in an environment in which the human must conform to the machines characteristics Problems solved in an environment in which the machine conforms to the humans characteristics
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 284
  • 284 Generations of programming languages
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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.
  • Slide 291
  • 291 The composition of a typical imperative program or program unit
  • Slide 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.
  • Slide 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
  • Slide 294
  • 294 The same variable declarations in different languages
  • Slide 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
  • Slide 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
  • Slide 297
  • 297 A two-dimensional array with two rows and nine columns
  • Slide 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
  • Slide 299
  • 299 Declaration of heterogeneous arrays in Pascal and C (continued)
  • Slide 300
  • 300 Declaration of heterogeneous arrays in Pascal and C
  • Slide 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
  • Slide 302
  • Assignment Statements 4 Z = X + Y ; 4 Z := X + Y ; 4 Z X + Y ; 302
  • Slide 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
  • Slide 304
  • 304 Control structures and their representations in C, C++, C#, and Java (continued)
  • Slide 305
  • 305 Control structures and their representations in C, C++, C#, and Java
  • Slide 306
  • 306 The for loop structure and its representation in Pascal, C++, C#, and Java (continued)
  • Slide 307
  • The loop 307
  • Slide 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
  • Slide 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.
  • Slide 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
  • Slide 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
  • Slide 312
  • 312 The flow of control involving a procedure
  • Slide 313
  • 313 The procedure Project Population written in the programming
  • Slide 314
  • Example 4 Procedure Demo ( Formal ) 4 Formal = Formal + 1 314
  • Slide 315
  • 315 Executing the procedure Demo and passing parameters by value (continued)
  • Slide 316
  • 316 Executing the procedure Demo and passing parameters by value (continued)
  • Slide 317
  • 317 Executing the procedure Demo and passing parameters by value
  • Slide 318
  • 318 Executing the procedure Demo and passing parameters by reference (continued)
  • Slide 319
  • 319 Executing the procedure Demo and passing parameters by reference (continued)
  • Slide 320
  • 320 Executing the procedure Demo and passing parameters by reference
  • Slide 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
  • Slide 322
  • 322 The function CylinderVolume written in the programming language C
  • Slide 323
  • INPUT&OUTPUT Statement 4 EX. Read in ( value ) 4 write in ( value ) 323
  • Slide 324
  • 324 An example of formatted output
  • Slide 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.
  • Slide 326
  • 326 The translation process
  • Slide 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
  • Slide 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.
  • Slide 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
  • Slide 330
  • The Parser 4 The syntax rules defined by syntax diagrams. 4 Fixed Format Languages [ FORTRAN ] 4 Free Format Languages [ C ] 330
  • Slide 331
  • 331 A syntax diagram of our if-then-else pseudo code statement
  • Slide 332
  • Syntax diagrams describing the structure of a simple algebraic expression 332
  • Slide 333
  • 333 Parse tree for X+Y*Z 4 The parse tree for the string x + y z based on the syntax diagrams
  • Slide 334
  • 334 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued)
  • Slide 335
  • 335 Two distinct parse trees for the statement if B1 then if B2 then S1 else S2 (continued)
  • Slide 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
  • Slide 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?)
  • Slide 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
  • Slide 339
  • 339 An object-oriented approach to the translation process
  • Slide 340
  • 340 The complete program preparation process
  • Slide 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.
  • Slide 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
  • Slide 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
  • Slide 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 its laser beam. 344
  • Slide 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
  • Slide 346
  • 346 The structure of a class describing a laser weapon in a computer game
  • Slide 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
  • Slide 348
  • 348 A class with a constructor
  • Slide 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
  • Slide 350
  • 350 Our Laser-Class definition using encapsulation as it would appear in a Java or C# program
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 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.
  • Slide 356
  • 356 Resolving the statements (P OR Q) and (R OR Q) to produce (P OR R)
  • Slide 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
  • Slide 358
  • Declarative Programming 4 Then the original collection of statements must be inconsistent. 358
  • Slide 359
  • 359 Resolving the statements (P OR Q), (R OR Q), R, and P
  • Slide 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.
  • Slide 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.
  • Slide 362
  • 362 The Software Life Cycle Development Use Modification
  • Slide 363
  • 363 The Software Life Cycle AnalysisDesignImplementationTesting Development phase
  • Slide 364
  • 364 The Software Life Cycle 4 Waterfall model. 4 Computer-aided software engineering (CASE). 4 Prototyping.
  • Slide 365
  • 365 A structure chart for a simple Internet mail order business
  • Slide 366
  • 366 A class diagram for a simple Internet mail order business
  • Slide 367
  • 367 A structure chart showing data coupling
  • Slide 368
  • 368 A collaboration diagram of a simple Internet mail order business
  • Slide 369
  • 369 Logical and functional cohesion within an object representing an order form in a simple Internet mail order business
  • Slide 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.
  • Slide 371
  • 371 The publisher-subscriber pattern
  • Slide 372
  • 372 The component-container pattern
  • Slide 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.
  • Slide 374
  • 374 A dataflow diagram of a simple Internet mail order business
  • Slide 375
  • 375 An entity-relationship diagram
  • Slide 376
  • 376 One-to-one, one-to-many, and many-to-many relationships between entities of types X and Y
  • Slide 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.
  • Slide 378
  • 378 Documentation, software Ownership and Liability 4 User documentation and system documentation. 4 Copyright and patent laws.
  • Slide 379
  • 379 Part III: Data Organization 4 Data structures. 4 File structures. 4 Database structures.
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 383
  • DEFINITION 4 4- The Link [ Pointer]: Contain the starting addresses of other nodes, thus creating a structural interrelationship among the nodes. 383
  • Slide 384
  • 384 Novels arranged by title but linked according to authorship
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 388
  • 388 The array of Readings stored in memory starting at address
  • Slide 389
  • 389 A two-dimensional array with four rows and five columns stored in row major order
  • Slide 390
  • 390 Names stored in memory as a contiguous list
  • Slide 391
  • 391 The structure of a linked list
  • Slide 392
  • 392 Deleting an entry from a linked list
  • Slide 393
  • 393 Inserting an entry into a linked list
  • Slide 394
  • 394 A procedure for printing a linked list
  • Slide 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
  • Slide 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
  • Slide 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
  • Slide 398
  • 398 Nested procedures terminating in the opposite order to that in which they were requested
  • Slide 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
  • Slide 400
  • 400 Using a stack to print a linked list in reverse order (continue d)
  • Slide 401
  • 401 Using a stack to print a linked list in reverse order
  • Slide 402
  • 402 A procedure (using an auxiliary stack) for printing a linked list in reverse order
  • Slide 403
  • 403 A stack in memory
  • Slide 404
  • 404 Stacks 4 Last-in first-out. 4 Push and pop. 4 Using stacks for maintaining procedure calls. 4 Other applications???
  • Slide 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