Foundations of Computing: Essential for Computing Studies, Profession And Entrance Examinations - [5 ed.] 9355512546, 9789355512543

Description If you wish to have a bright future in any profession today, you cannot ignore having sound foundation in I

469 32 11MB

English Pages 744 Year 2022

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Foundations of Computing: Essential for Computing Studies, Profession And Entrance Examinations - [5 ed.]
 9355512546, 9789355512543

Citation preview

FOUNDATIONS OF COMPUTING Fifth Edition Essential for Computing Studies, Profession and Entrance Examinations

FOUNDATIONS OF COMPUTING Fifth Edition

Essential for Computing Studies, Profession and Entrance Examinations

Pradeep K. Sinha Priti Sinha

www.bpbonline.com

FIFTH EDITION 2023 Copyright © BPB Publications, INDIA ISBN: 978-93-5551-254-3 All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication, photocopy, recording, or by any electronic and mechanical means.

LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s and publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but publisher cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners but BPB Publications cannot guarantee the accuracy of this information.

Distributors: BPB PUBLICATIONS 20, Ansari Road, Darya Ganj New Delhi-110002 Ph: 23254990/23254991

DECCAN AGENCIES 4-3-329, Bank Street, Hyderabad-500195 Ph: 24756967/24756400

MICRO MEDIA Shop No. 5, Mahendra Chambers, 150 DN Rd. Next to Capital Cinema, V.T. (C.S.T.) Station, MUMBAI-400 001 Ph: 22078296/22078297

BPB BOOK CENTRE 376 Old Lajpat Rai Market, Delhi-110006 Ph: 23861747

Published by Manish Jain for BPB Publications, 20 Ansari Road, Darya Ganj, New Delhi-110002 and Printed at Akash Press, New Delhi www.bpbonline.com

 

LETTER TO READERS………………………………………………………………………………………………………..XV PREFACE……………………………………………………………………………………………………………………………XVI ABOUT LECTURE NOTES PRESENTATION SLIDES…..………………………………..………………....XXI ABBREVIATIONS ………………………………………………….…………….………………………………………….XXIII CHAPTER 1: CHARACTERISTICS, EVOLUTION, AND CLASSIFICATION OF COMPUTERS……1 What is a Computer? ........................................................................................... 1 Characteristics of Computers ................................................................................. 2 Evolution of Computers ........................................................................................ 2 Computer Generations ......................................................................................... 4 First Generation (1942-1955) .............................................................................. 4 Second Generation (1955-1964) ........................................................................... 4 Third Generation (1964-1975) ............................................................................. 5 Fourth Generation (1975-1989) ............................................................................ 6 Fifth Generation (1989-Present) .......................................................................... 8 Classification of Computers .................................................................................. 11 Notebook Computers (Laptops) ........................................................................... 11 Personal Computers (PCs) ................................................................................. 12 Workstations................................................................................................. 13 Mainframe Systems ......................................................................................... 13 Supercomputers ............................................................................................. 15 Client and Server Computers ............................................................................. 17 Handheld Computers ....................................................................................... 18 Points to Remember…………………………………………………………………………………………………………………………20 Questions………………………………………………………………………………………………………………………………………….21

CHAPTER 2: INTERNAL DATA REPRESENTATION IN COMPUTERS .......................... 24 Number Systems Used in Computers ........................................................................ 24 Binary Number System ..................................................................................... 25  

ii   

■ Foundations of Computing

Octal Number System ...................................................................................... 26 Hexadecimal Number System ............................................................................. 26 Converting from One Number System to Another ........................................................ 26 Converting from Another Base to Decimal ............................................................. 26 Converting from Decimal to Another Base (Division-Remainder Technique) ...................... 28 Converting from a Base Other Than 10 to Another Base Other Than 10 ........................... 29 Shortcut Method for Binary to Octal Conversion ...................................................... 30 Shortcut Method for Octal to Binary Conversion ...................................................... 31 Shortcut Method for Binary to Hexadecimal Conversion ............................................. 32 Shortcut Method for Hexadecimal to Binary Conversion ............................................. 33 Fractional Numbers ........................................................................................... 34 Character Coding Schemes................................................................................... 35 BCD Code .................................................................................................... 36 EBCDIC ....................................................................................................... 38 Zoned and Packed Decimal Numbers .................................................................... 38 ASCII .......................................................................................................... 40 Unicode ...................................................................................................... 44 Collating Sequence ......................................................................................... 47 Binary Arithmetic ............................................................................................. 48 Why Binary? ................................................................................................. 49 Binary Addition ............................................................................................. 49 Binary Subtraction ......................................................................................... 50 Binary Multiplication ...................................................................................... 53 Binary Division .............................................................................................. 55 Why Do Computers Use Additive Method? .............................................................. 56 Points to Remember………………………………………………………………………………………………………………………..56 Questions………………………………………………………………………………………………………………………………………...58

CHAPTER 3: DIGITAL SYSTEMS DESIGN ......................................................... 62 Boolean Algebra ............................................................................................... 62 Fundamental Concepts of Boolean Algebra ............................................................ 62 Postulates of Boolean Algebra ........................................................................... 64 The Principle of Duality ................................................................................... 64 Theorems of Boolean Algebra ............................................................................ 65 Boolean Functions ............................................................................................. 68 Minimization of Boolean Functions by Algebraic Manipulations .................................... 69 Complement of a Function ................................................................................ 71 Canonical Forms of Boolean Functions .................................................................. 72 Conversion between Canonical Forms ................................................................... 76 Minimization of Boolean Functions by Map Simplification ........................................... 77 Logic Gates ..................................................................................................... 84 Logic Circuits .................................................................................................. 87 Converting Expressions to Logic Circuits ............................................................... 88 The Universal NAND Gate ................................................................................. 88 The Universal NOR Gate ................................................................................... 90 Design of Combinational Circuits ........................................................................... 93 Design of Half-Adder....................................................................................... 93  

 

■ Table of Contents

iii 

Design of Full-Adder........................................................................................ 94 A Parallel Binary Adder .................................................................................... 96 Flip-Flops ....................................................................................................... 97 Types of Flip-flops .......................................................................................... 97 Excitation Tables ........................................................................................... 99 Edge-Triggered Flip-Flops ............................................................................... 100 Master-Slave Flip-Flop ................................................................................... 101 Uses of Flip-flops ......................................................................................... 101 Sequential Circuits .......................................................................................... 102 Flip-flop Input Equations ................................................................................ 102 State Table ................................................................................................ 102 State Diagram ............................................................................................. 104 Design of Sequential Circuits............................................................................... 104 Design of Binary Counter ................................................................................ 105 Points to Remember……………………………………………………………………………………………………………………..107 Questions……………………………………………………………………………………………………………………………………….109

CHAPTER 4 : COMPUTER ARCHITECTURE ..................................................... 113 Basic Functions of a Computer ............................................................................ Basic Computer Organization .............................................................................. Basic Functional Units .................................................................................... System Concept ........................................................................................... Basic Processor and Memory Architecture ............................................................ CPU Architectures ........................................................................................... Basic Components of CPU ................................................................................ CPU Instruction Set ....................................................................................... CPU Registers .............................................................................................. Processor Speed ........................................................................................... Types of Processors ....................................................................................... Memory Architectures....................................................................................... Storage Evaluation Criteria ............................................................................. Main Memory Organization .............................................................................. Main Memory Capacity ................................................................................... Types of Memory Chips .................................................................................. Minimizing Memory-Processor Speed Mismatch ......................................................... Cache Memory ............................................................................................. Memory Interleaving ..................................................................................... Hybrid Approach .......................................................................................... Memory and I/O Buses ...................................................................................... Memory Buses ............................................................................................. I/O Buses ................................................................................................... Interconnection Architectures ............................................................................. Unibus Architecture ...................................................................................... Dual Bus Architecture .................................................................................... DMA Architecture ......................................................................................... Multiprocessor System Architectures ..................................................................... Shared Memory Systems .................................................................................  

113 113 114 115 116 116 116 117 117 119 119 123 123 124 126 126 128 128 130 131 131 131 132 134 134 134 135 136 137

iv   

■ Foundations of Computing

Distributed Memory Systems ............................................................................ 139 Parallel Processing Systems ................................................................................. 142 Points to Remember………………………………………………………………………………………………………………………143 Questions……………………………………………………………………………………………………………………………………….145

CHAPTER 5: SECONDARY STORAGE ............................................................ 149 Classification of Secondary Storage ....................................................................... 149 Magnetic Tapes ............................................................................................... 150 Basic Principles of Operation ............................................................................ 151 Types of Magnetic Tapes ................................................................................. 154 Advantages and Limitations of Magnetic Tapes ...................................................... 157 Uses of Magnetic Tapes ................................................................................... 157 Magnetic Disks ................................................................................................ 158 Basic Principles of Operation ............................................................................ 158 Types of Magnetic Disks .................................................................................. 163 Advantages and Limitations of Magnetic Disks ....................................................... 164 Uses of Magnetic Disks.................................................................................... 165 Optical Disks .................................................................................................. 165 Basic Principles of Operation ............................................................................ 166 Types of Optical Disks .................................................................................... 168 Advantages and Limitations of Optical Disks.......................................................... 170 Uses of Optical Disks ...................................................................................... 171 Memory Storage Devices .................................................................................... 171 Solid State Drive (SSD).................................................................................... 171 Flash Drive (Pen Drive) ................................................................................... 173 Memory Card (SD/MMC) .................................................................................. 174 RAM Disk .................................................................................................... 175 Hybrid Secondary Storage Drives .......................................................................... 175 Mass Storage Devices ........................................................................................ 175 Disk Array................................................................................................... 176 Automated Tape Library ................................................................................. 176 CD-ROM Jukebox........................................................................................... 176 RAID Storage .................................................................................................. 177 RAID Techniques ........................................................................................... 177 RAID Levels ................................................................................................. 178 Storage Interfaces............................................................................................ 179 SCSI (Small Computer System Interface) .............................................................. 179 SAS (Serial Attached SCSI) ............................................................................... 180 SATA (Serial Advanced Technology Attachment) ..................................................... 181 Fiber Channel (FC) ........................................................................................ 181 FireWire .................................................................................................... 182 iSCSI (Internet SCSI)....................................................................................... 183 FC versus iSCSI ............................................................................................. 183 DAS, SAN, and NAS ........................................................................................... 184 DAS (Direct Attached Storage) .......................................................................... 184 SAN (Storage Area Network) ............................................................................. 185 NAS (Network Attached Storage) ....................................................................... 186 Data Backup ................................................................................................... 187 What is Data Backup? ..................................................................................... 187 Why Backup Data? ......................................................................................... 187  

■ Table of Contents



Types of Backup ........................................................................................... Backup Policy .............................................................................................. Backup versus Archiving ................................................................................. Hierarchical Storage System (HSS) ........................................................................ On-line, Near-line, and Off-line Storage .............................................................. Hierarchical Storage Management (HSM) .............................................................

187 188 188 189 190 190

 

Points to Remember……………………………………………………………………………………………………………………..191 Questions………..…………………………………………………………………………………………………………………………….193

CHAPTER 6: INPUT-OUTPUT DEVICES……………………………………………………………………………197 Input Devices ................................................................................................. Keyboard Devices ......................................................................................... Point-and-Draw Devices .................................................................................. Data Scanning Devices .................................................................................... Digitizer .................................................................................................... Electronic-card Reader ................................................................................... Speech Recognition Devices ............................................................................. Vision-Input Systems ..................................................................................... Output Devices ............................................................................................... Monitors .................................................................................................... Printers ..................................................................................................... Plotters ..................................................................................................... 3D Printers ................................................................................................. Computer Output Microfilm (COM) .................................................................... Screen Image Projector .................................................................................. Voice Response Systems.................................................................................. Ergonomically Designed Devices ........................................................................ I/O Interfaces ................................................................................................ Device Controllers ........................................................................................ Serial and Parallel Ports ................................................................................. SCSI Interface.............................................................................................. USB (Universal Serial Bus) Standard ...................................................................

197 197 200 204 209 210 211 212 213 213 218 224 224 228 229 229 231 231 231 232 234 235

Points to Remember………………………………………………………………………………………………………………………236 Questions………..…………………………………………………………………………………………………………………………….238

CHAPTER 7: SOFTWARE…………………………………………………………………………………………….....242 Basic Concepts and Terminologies ........................................................................ What is Software?......................................................................................... Relationship between Hardware and Software ...................................................... Types of Software ........................................................................................ Logical System Architecture ............................................................................ Firmware ................................................................................................... Middleware ................................................................................................ Acquiring Software .......................................................................................... Buying Pre-written Software ............................................................................ Ordering Customized Software ......................................................................... Developing Customized Software ...................................................................... Downloading Public-domain Software .................................................................  

242 242 242 243 243 244 244 246 246 246 247 248

vi  ■ Foundations of Computing   Software Development Life Cycle (SDLC) ................................................................. 248 Advantages of SDLC Model ............................................................................... 250 Limitations of SDLC Model ............................................................................... 251 Lightweight SDLC Models................................................................................. 251 Software Design Approaches................................................................................ 252 Software Implementation ................................................................................... 254 Software Testing and Debugging ........................................................................... 255 What are Testing and Debugging? ....................................................................... 255 Types of Program Errors.................................................................................. 255 Debugging a Program for Syntax Errors ................................................................ 255 Debugging a Program for Logic Errors .................................................................. 256 Software Testing Concepts............................................................................... 257 Testing Methodologies .................................................................................... 258 Test-set-generation Techniques ........................................................................ 259 Test-case-selection Techniques ......................................................................... 261 Software Deployment ........................................................................................ 262 Changeover Operations ................................................................................... 262 Changeover Methods ...................................................................................... 263 System Evaluation ......................................................................................... 265 Software Maintenance ....................................................................................... 265 Definition ................................................................................................... 265 Need for Software Maintenance ........................................................................ 266 Types of Software Maintenance ......................................................................... 266 Importance of Software Maintenance .................................................................. 266 Controlling Modifications ................................................................................ 266 Tools for Effective Software Maintenance ............................................................ 267 Software Documentation .................................................................................... 267 What is Documentation? .................................................................................. 267 Need for Documentation ................................................................................. 267 Forms of Documentation ................................................................................. 268 Documentation Standard ................................................................................. 270 Software Engineering ........................................................................................ 270 What is Software Engineering? .......................................................................... 270 Need for Software Engineering.......................................................................... 270 Goals of Software Engineering .......................................................................... 271 Principles of Software Engineering ..................................................................... 271 Some Popular Application Software Packages ........................................................... 272 Word-processing Package ................................................................................ 273 Spreadsheet Package...................................................................................... 273 Graphics Package .......................................................................................... 274 Personal-assistance Package ............................................................................. 274 Education Software ....................................................................................... 274 Entertainment Software ................................................................................. 275 Points to Remember……………………………………………………………………………………………………………………..275 Questions………………………………………………………………………….....………………………………..................277

CHAPTER 8: PLANNING THE COMPUTER PROGRAM………………………………………………………280 Purpose of Program Planning ............................................................................... 280 Algorithm ...................................................................................................... 280 What is an Algorithm? .................................................................................... 280  

■ Table of Contents

vii 

Sample Algorithms ........................................................................................ Quality of Algorithms .................................................................................... Representation of Algorithms........................................................................... Flowcharts .................................................................................................... What is a Flowchart? ..................................................................................... Why Use Flowcharts? ..................................................................................... Flowchart Symbols ........................................................................................ Sample Flowcharts ........................................................................................ Levels of Flowcharts ..................................................................................... Flowcharting Rules ....................................................................................... Advantages and Limitations of Flowcharts ........................................................... Decision Tables .............................................................................................. What is a Decision Table? ................................................................................ Sample Decision Table ................................................................................... Advantages and Limitations of Decision Tables ...................................................... Pseudocode ................................................................................................... What is Pseudocode? ..................................................................................... Pseudocodes for Basic Logic (Control) Structures.................................................... Sample Pseudocode ....................................................................................... Indentation ................................................................................................ Advantages and Limitations of Pseudocode........................................................... Data Structures .............................................................................................. Types of Data Structures ................................................................................ Array ........................................................................................................ Linked List ................................................................................................. Stack ........................................................................................................ Queue ....................................................................................................... Hash Table ................................................................................................. Tree ......................................................................................................... Binary Tree ................................................................................................ Binary Search Tree ....................................................................................... Graph ....................................................................................................... Heap ........................................................................................................

281 282 282 283 283 283 283 286 293 293 294 295 295 296 297 298 298 298 301 302 302 303 303 303 307 309 310 311 313 315 318 320 328

 

Points to Remember………………………………………………………………………………………………………………………329 Questions………………………………………………………………………………………………..…………………………………….330

CHAPTER 9: PROGRAMMING LANGUAGES……………………...…………………………………………….336 Analogy with Natural Languages ........................................................................... Machine Language ........................................................................................... Advantages and Limitations of Machine Language................................................... Assembly Language .......................................................................................... Assembler .................................................................................................. Advantages of Assembly Language over Machine Language ........................................ Limitations of Assembly Language ..................................................................... Typical Uses of Assembly Language .................................................................... Assembly Languages with Macro Instructions......................................................... High-level Language ......................................................................................... Compiler ................................................................................................... Linker ....................................................................................................... Interpreter .................................................................................................  

336 337 338 339 339 341 342 343 343 344 344 347 348

viii  ■ Foundations of Computing   Intermediate Language Compiler and Interpreter ................................................... 348 Advantages and Limitations of High-level Languages................................................ 349 Object-Oriented Languages ................................................................................. 350 What is Object-Oriented Programming (OOP)? ....................................................... 350 Fundamental Concepts of OOP .......................................................................... 351 Key Elements of Object-Oriented Paradigm .......................................................... 353 Procedure-oriented versus Object-oriented Programming .......................................... 354 Advantages of OOP ........................................................................................ 355 Some High-level Languages ................................................................................. 356 Dealing with So Many High-level Languages .............................................................. 356 Why So Many High-level Languages? .................................................................... 356 Characteristics of a Good Programming Language ................................................... 361 Selecting a Language for Coding an Application ...................................................... 362 Other Types of Languages................................................................................... 362 Scripting Languages ....................................................................................... 362 Fourth and Fifth Generation Languages (4GLs and 5GLs) ........................................... 363 Markup Languages ......................................................................................... 364 Interface Definition Languages (IDL) ................................................................... 366 Other Related Concepts ..................................................................................... 366 Subprogram ................................................................................................ 366 Preprocessor ............................................................................................... 368 Postprocessor .............................................................................................. 369 Points to Remember………………………………………………………………………………………………………………………370 Questions……………………………………………………………………………………………………………………………………….372

CHAPTER 10: OPERATING SYSTEMS……………………………...………………………………………………375 Basic Concepts ................................................................................................ 375 What is an Operating System? ........................................................................... 375 Main Functions of an Operating System ............................................................... 376 Measuring System Performance ......................................................................... 377 Process Management......................................................................................... 377 Process Management in Early Systems ................................................................. 378 Multiprogramming ........................................................................................ 379 Multitasking ................................................................................................ 382 Multithreading ............................................................................................. 382 Multiprocessing ............................................................................................ 384 Time-sharing ............................................................................................... 385 Mutual Exclusion .......................................................................................... 387 Deadlock .................................................................................................... 390 Memory Management ........................................................................................ 392 Uniprogramming Memory Model ........................................................................ 392 Multiprogramming Memory Models ..................................................................... 393 Memory Fragmentation ................................................................................... 394 Paging ....................................................................................................... 395 Virtual Memory ............................................................................................ 397 File Management ............................................................................................. 398 File Structure .............................................................................................. 399 File Access Methods ....................................................................................... 399 File Operations ............................................................................................ 400 File Naming................................................................................................. 400  

■ Table of Contents

ix 

Directories ................................................................................................. Disk Space Allocation Methods .......................................................................... Device Management ......................................................................................... Controlling I/O Devices .................................................................................. Simple and Easy User Interface to I/O Devices ....................................................... Spooling .................................................................................................... Command Interpretation ................................................................................... Shell ........................................................................................................ Operating System Structure ................................................................................ Layered Structure ........................................................................................ Kernel....................................................................................................... Monolithic Kernel versus Microkernel ................................................................. Resident and Non-Resident Operating System Modules ............................................. OS Capability Enhancement Software .................................................................... Translating Programs ..................................................................................... Library Programs .......................................................................................... Utility Programs .......................................................................................... Some Popular Operating Systems.......................................................................... UNIX ......................................................................................................... MS-DOS ..................................................................................................... Microsoft Windows........................................................................................ Microsoft Windows Server (Earlier Known as Windows NT) ........................................ Linux ........................................................................................................ Mac OS ...................................................................................................... iOS .......................................................................................................... WatchOS .................................................................................................... Android OS ................................................................................................. Real-time, Network and Distributed Operating Systems ............................................... Real-time Operating Systems ........................................................................... Network and Distributed Operating Systems .........................................................

401 403 407 407 408 409 410 411 411 411 411 412 412 412 413 413 413 414 415 416 417 418 418 419 420 421 422 423 423 424

 

Points to Remember…………………………………………………………………………………………………………………….. 424 Questions……………………………………………………………………………………………………………………………………….427

CHAPTER 11: DATABASE AND DATA SCIENCE……………………………………………………………… 431 Data versus Information .................................................................................... Data Storage Hierarchy ..................................................................................... Standard Methods of Organizing Data .................................................................... File-oriented Approach .................................................................................. Database-oriented Approach ............................................................................ File Management System ................................................................................... File Types .................................................................................................. File Organizations ........................................................................................ File Utilities ............................................................................................... Database Management System ............................................................................. Database Models .......................................................................................... Main Components of a DBMS ............................................................................ Creating and Using a Database ......................................................................... Database Security ......................................................................................... Client-Server Database Systems ........................................................................ Distributed Database Systems ..........................................................................  

431 432 433 434 434 435 435 435 439 441 441 446 447 452 453 454

x   

■ Foundations of Computing

Active Database Systems ................................................................................. 455 Multimedia Database Systems .............................................................................. 455 Requirements for Multimedia Database Systems ..................................................... 455 Data Science .................................................................................................. 458 Stages in Data Science .................................................................................... 459 Data Warehousing ............................................................................................ 460 Need for a Data Warehouse .............................................................................. 461 Building a Data Warehouse .............................................................................. 461 Data Warehousing Terminologies ....................................................................... 461 Data Mining.................................................................................................... 464 Classification of Data Mining Algorithms .............................................................. 465 Data Mining Techniques .................................................................................. 467 Data Warehousing versus Data Mining ..................................................................... 469 Points to Remember………………………………………………………………………………………………………………………469 Questions……………………………………………………………………………………………………………………………………….471

CHAPTER 12: DATA COMMUNICATIONS AND COMPUTER NETWORKS………………………….474 Basic Concepts ................................................................................................ 474 Basic Elements of a Communication System .......................................................... 474 Data Transmission Modes ................................................................................ 475 Data Transmission Speed ................................................................................. 475 Data Transmission Media ................................................................................. 476 Digital and Analog Data Transmission ..................................................................... 480 Modulation Techniques ................................................................................... 480 Modems ..................................................................................................... 481 Analog versus Digital Transmission ..................................................................... 483 Data Transmission Services .............................................................................. 483 Communication Processors ................................................................................. 484 Multiplexers ................................................................................................ 484 Concentrators .............................................................................................. 486 Front-End Processors (FEP) .............................................................................. 486 Asynchronous and Synchronous Transmission ............................................................ 486 Asynchronous Transmission .............................................................................. 486 Synchronous Transmission................................................................................ 487 Switching Techniques ........................................................................................ 487 Circuit Switching .......................................................................................... 488 Message Switching......................................................................................... 489 Packet Switching .......................................................................................... 490 Routing Techniques .......................................................................................... 490 Place Where Routing Decisions are Made .............................................................. 491 Static and Dynamic Routing.............................................................................. 491 Network Topologies .......................................................................................... 491 Network Types (PAN, LAN, CAN, MAN, and WAN) ....................................................... 493 Communication Protocols ................................................................................... 495 Roles of a Communication Protocol .................................................................... 495 Concept of Layered Protocols in Network Design .................................................... 495 Network Interface Card (NIC) ........................................................................... 496 The OSI Model.............................................................................................. 496 Example of Message Transfer in the OSI Model ....................................................... 499 Internetworking Tools ....................................................................................... 500  

■ Table of Contents   Wireless Networks ........................................................................................... Types of Wireless Computing Systems ................................................................. Issues in Wireless Computing Systems ................................................................. Wireless Applications .................................................................................... Wireless Communication Technologies ................................................................ Wireless Technologies and Standards .................................................................. Distributed Computing Systems ............................................................................ Grid Computing .............................................................................................. Cloud Computing............................................................................................. Grid versus Cloud ......................................................................................... Service Layers of Cloud Computing .................................................................... Types of Clouds ...........................................................................................

xi  501 501 502 502 503 504 509 511 511 513 513 513

Points to Remember………………………………………………………………………………………………………………………513 Questions…………………………………………………………………………………………………………….....................515

CHAPTER 13: THE INTERNET AND INTERNET OF THINGS…………………………………………….518 Definition and History ....................................................................................... Its Basic Services ............................................................................................. Electronic Mail ............................................................................................ File Transfer Protocol (FTP)............................................................................. Telnet ...................................................................................................... Usenet News ............................................................................................... The World Wide Web (WWW) .............................................................................. WWW Browsers ............................................................................................ Web Services............................................................................................... Internet Search Engines..................................................................................... Major Elements of Internet Search Engines........................................................... Types of Internet Search Engines ....................................................................... Some Popular Internet Search Engines ................................................................ Uses of the Internet ......................................................................................... Other Related Concepts .................................................................................... Intranet .................................................................................................... Proxy Server ............................................................................................... Internet Telephony ....................................................................................... Microbrowser .............................................................................................. Next Generation Internet Protocol (IPV6)............................................................. Internet of Things (IoT) ..................................................................................... Benefits of IoT ............................................................................................ IoT Applications (Uses of IoT) ........................................................................... Challenges in Adoption of IoT...........................................................................

518 518 518 519 519 520 520 521 524 526 526 526 527 527 529 529 530 530 531 532 533 533 534 536

Points to Remember………………………………………………………………………………………………………………………537 Questions……………………………………………………………………………………………………………………………………….539

CHAPTER 14: MULTIMEDIA COMPUTING………………………………………………………………………..541 What is Multimedia? ......................................................................................... What is a Multimedia Computer System? ................................................................. Multimedia Components .................................................................................... Text .........................................................................................................  

541 542 542 542

xii  ■ Foundations of Computing   Graphics .................................................................................................... 543 Animation .................................................................................................. 546 Audio ........................................................................................................ 547 Video ........................................................................................................ 550 Multimedia Applications ..................................................................................... 554 Applications in Education Sector........................................................................ 554 Applications in Entertainment Sector .................................................................. 555 Applications in Corporate Sector ....................................................................... 557 Applications in Science and Engineering Sector ...................................................... 558 Data Compression ............................................................................................ 559 Types of Compression Techniques ...................................................................... 559 Basic Compression Techniques .......................................................................... 560 Some Standard Multimedia Compression Techniques ................................................ 561 Multimedia Synchronization ................................................................................ 567 Temporal Specification ................................................................................... 567 Temporal Synchronization ............................................................................... 568 Media Center Computer ..................................................................................... 569 Media Center PC Features and Functionalities ....................................................... 570 Points to Remember………………………………………………………………………………………………………………………571 Questions……………………………………………………………………………………………………………………………………….573

CHAPTER 15: INFORMATION SECURITY…………………………………………………………………………577 Security Policies versus Mechanisms ...................................................................... 577 Security Goals ................................................................................................ 577 External, Internal, and Communication Security ........................................................ 578 Potential Attacks to Computer Systems .................................................................. 578 Passive Attacks ............................................................................................ 578 Active Attacks ............................................................................................. 579 Cryptography.................................................................................................. 583 Basic Concepts and Terminologies ...................................................................... 583 Basic Requirements ....................................................................................... 584 Symmetric and Asymmetric Cryptosystems ........................................................... 584 Authentication ................................................................................................ 586 What is Authentication? .................................................................................. 586 Types of Authentication Needed ........................................................................ 586 Approaches to Authentication ........................................................................... 586 User Login Authentication ............................................................................... 587 One-way Authentication of Communicating Entities ................................................ 590 Two-way Authentication of Communicating Entities ................................................ 594 Access Control ................................................................................................ 595 What is Access Control? .................................................................................. 595 Access Control Terminologies ........................................................................... 595 Protection Domains ....................................................................................... 596 Access Matrix .............................................................................................. 597 Implementation of Access Matrix as Access Control Lists ........................................... 601 Digital Signature .............................................................................................. 602 Firewall ........................................................................................................ 603 What is a Firewall? ........................................................................................ 603 Types of Firewalls ......................................................................................... 604 Advantages and Limitations of Firewalls .............................................................. 605  

■ Table of Contents   Software Piracy Protection ................................................................................. What is Software Piracy? ................................................................................ Mechanisms to Protect Software Piracy ............................................................... e-Mail Security ............................................................................................... Pretty Good Privacy (PGP) ............................................................................... Privacy Enhanced Mail (PEM) ............................................................................ Secure/Multipurpose Internet Mail Extensions (S/MIME) ........................................... Spam E-mail and Anti-spam Software ................................................................. IP Security (IPSec) ........................................................................................... What is IPSec? ............................................................................................. IPSec Functionality ....................................................................................... IPSec Features ............................................................................................. Secure Socket Layer (SSL) and Transport Layer Security (TLS) ....................................... SSL Connection and Session ............................................................................. SSL Architecture .......................................................................................... SSL Record Protocol ...................................................................................... SSL Change Cipher Spec Protocol ....................................................................... SSL Alert Protocol ........................................................................................ SSL Handshake Protocol .................................................................................. Transport Layer Security (TLS) ......................................................................... Secure Electronic Transaction (SET) ...................................................................... Parties Involved in an Electronic Transaction ........................................................ An Electronic Transaction Process...................................................................... Security Requirements of an Electronic Transaction Process ...................................... How SET Meets These Security Requirements? ....................................................... Dual Signature Mechanism of SET ...................................................................... Management of Public Keys ................................................................................ Certification Authority (CA) ............................................................................ Public Key Infrastructure (PKI) ......................................................................... Steganography ............................................................................................... What is Steganography? .................................................................................. Mechanism to Detect Steganographically-hidden Message ......................................... Guidelines for Secure Systems Design .................................................................... Cyber Laws, Cyber Forensics, and CERT.................................................................. Cyber Laws ................................................................................................. Cyber Forensics ........................................................................................... CERT ........................................................................................................

xiii  606 606 606 607 608 609 610 612 614 614 615 616 616 617 618 618 619 619 621 624 625 626 626 627 627 628 630 630 631 632 632 633 634 635 635 635 636

Points to Remember………………………………………………………………………………………………………………………636 Questions…………………………………………………………………………………………………………….....................637

CHAPTER 16: APPLICATION DOMAINS…………………………………………………………………………..640 Electronic Governance (E-governance) ................................................................... What is E-governance? ................................................................................... Benefits of E-governance ................................................................................ Issues and Challenges in E-governance ................................................................ E-governance Applications .............................................................................. Geo-informatics .............................................................................................. Geo-informatics Applications ........................................................................... Medical Informatics ......................................................................................... Medical Informatics Applications .......................................................................  

640 640 640 642 642 643 643 644 644

xiv  ■ Foundations of Computing   Bioinformatics ................................................................................................ 645 What is Bioinformatics? .................................................................................. 645 Branches of Bioinformatics .............................................................................. 646 Points to Remember……………………………………………………………………………………………………………………..648 Questions…………………………………………………………………………………………………………….....................648

GLOSSARY…………………………………………………………………………………………………………………………650 INDEX……………………………………………………………………………………………………………………………….696 KNOW YOUR AUTHOR .……………………………………………………………………………………………………711

 

LETTER TO READERS

Dear Reader, A book that connects well with your thoughts and learning process can be written undoubtedly by an author who shares the same thoughts, understanding, and passion for learning as yours. Over three decades ago, I introduced my first book with a strong conviction to the above statement. That commitment continues even today. I am committed to writing quality books in Computer Science and associated areas for my readers. To date, I have authored six textbooks targeted towards this endeavor, and plan to author more in future. Wide popularity of my books clearly indicates the support that I have received from my readers. I express my gratitude and regards to all my readers for their support and feedback. Your support provides greater strength and inspires me to work harder towards my commitment. I look forward to your continued encouragement.

Yours truly,

January 2023

Pradeep K. Sinha

Fellow IEEE

ACM Distinguished Engineer

Fellow CSI

Audience The current edition of Foundations of Computing is based on the feedback from academia, industry, and candidates preparing for entrance examinations.

Academia Several academic institutions today offer degree/diploma/certificate programs in Computer Science (CS), Computer Applications (CA), Information Technology (IT), and other related areas. Few examples of such programs are BE (CS), BE (IT), B.Tech (CS), B.Tech (IT), MCA, MCS, MCM, M.Sc. (IT), BCA, BCS, B.Sc. (IT), DCA, PGDCA, C-DAC’s Pre-DAC and Diploma programs, and DOEACC Certificate Courses. The primary objective of these education programs is to impart knowledge of the various topics in CS, CA, and IT to their students to meet the industry’s demand for IT professionals. Hence, these programs include various foundation courses in CS, CA, and IT, such as Computer Organization, Programming Fundamentals, Digital Systems Design, Data Structures, Operating Systems, Software Engineering, Computer Networks, and Information Security. Since long time, both students and faculty members have wished for a single comprehensive book that can provide a good coverage of the essentials of these foundation courses in a consistent style. Foundations of Computing is designed to meet this requirement of academia.

Industry Different IT professionals specialize in different areas. A few such areas are System Analysis and Design, Application Programming, System Programming, Data Science, Network Management, and System Administration. A professional working in one such area often needs the understanding of other areas for effective delivery of his/her tasks. For example, a system administrator needs to refer to topics in operating systems, networking, security, and computer architecture to perform his/her job effectively. Similarly, an application programmer needs to refer to topics in software engineering, operating systems, security, networking, database management, and computer architecture to develop good applications. Often, IT professionals refer to the topics in other areas for broadening their knowledge for their professional growth. This requires them to refer to multiple books by different authors. Since long time, they have desired to have a single book that covers all these topics in sufficient depth. They expect the book to serve as a good handbook (reference material) for various topics in CS, CA, and IT to save them from the hassles of purchasing and referring to multiple books. Foundations of Computing is designed to meet this requirement of IT professionals.

■ Preface

xvii

Entrance Examination Candidates To have a bright future in any profession today, one cannot ignore having a sound foundation in IT, because IT is an integral part of all types of professions. Hence, entrance examinations for admissions to several educational institutions/programs and entrance tests for many types of jobs (such as engineering, management, banking, law, administrative services, journalism, etc.) test basic understanding of computing concepts of the candidates. For a long time, candidates preparing for such entrance tests and competitive examinations have desired for a single book that they can use to prepare for various topics in computing. Foundations of Computing is designed to meet this requirement of candidates preparing for various types of entrance examinations and tests.

Usages Although, Foundations of Computing is suitable for a wide range of readers, its four primary usages are as follows:

Textbook Foundations of Computing is suitable for use as a textbook for the various foundation courses taught in Master’s, Bachelor’s, Diploma, and Certificate programs in Computer Science (CS), Computer Applications (CA), and Information Technology (IT). Textbook style of presentation of the topics covered in the book and the Lecture Notes Presentation Slides included with the book make it suitable for use as a textbook for such courses. Hence, we recommend its use as a textbook for several foundation courses taught in CS, CA, and IT programs.

Reference Book for Students Where Foundations of Computing is not a prescribed textbook, students will still find it useful to have it as a reference book. As the book covers most of the important topics that students of CS, CA, and IT programs learn during their education programs, they will find it handy and useful as a reference book during the entire period. The book will also serve as a good reference book after they complete their education programs and enter into their professional career. Hence, we recommend every student of CS, CA, and IT programs to keep a copy of the book handy and refer to it whenever required during and even after their education programs.

Reference Book for Professionals As Foundations of Computing covers the important topics of IT profession, IT professionals will find it a useful reference book for addressing their needs. Hence, we recommend every IT professional to keep a copy of the book and refer to it whenever required during their professional career.

Preparation Book for Entrance Examination Candidates Candidates preparing for entrance examinations for admissions to several educational institutions/programs and entrance tests for many types of jobs will find the book handy and useful for preparing for various topics of CS, CA, and IT. Such candidates will find the book and its Lecture Notes Presentation Slides the most suitable material for this purpose. Once they qualify in their desired examination, they can use the book later as a good reference book while pursuing their education programs or professional career.

xviii

■ Foundations of Computing

Features Overall Features The layout, organization, and contents of the book are carefully designed to present the various topics of foundation courses in CS, CA, and IT in an interesting, logical, and informative manner. The book does not concentrate on any particular computer system or hardware. Instead, it discusses, in a general setting, the organization, functions, programming, and usage principles applicable to all types of computer systems. All concepts presented in the book are illustrated with practical examples whenever required. The book also contains numerous diagrams for better illustration. These features enable the readers to grasp the presented concepts easily and to use the book effectively for self-study. Each chapter contains a section on ‘Points to Remember’ that highlights the important points covered in the chapter. Each chapter also contains a number of review questions that test the understanding of the topics covered in the chapter. The book contains a separate list of abbreviations used in the book, and a glossary of important terms. To make the contents interesting to read and easily understandable, the style of presentation used throughout the book is motivational, non-mathematical, and explanatory in nature. The book contains a set of presentation slides for each chapter in the form of Lecture Notes Presentation Slides. It can serve as lecture aid, self-paced learning aid, and revision material. All these features make the book ideal for all types of audience mentioned earlier.

New Edition Features Readers will find this edition of the book more useful than its previous editions because:  We have added new topics and classifications to various chapters, introducing the readers to the latest trends and technologies in computing.  We have updated the contents to make it up-to-date.  We have updated the lecture notes presentation slides.  The size of the book is made more handy. Statistical data indicates that with every new edition of the book, the number of readers has soared much higher than its previous edition. This is because every new edition incorporates the suggestions received from the readers, making the book more suitable for a larger audience. We expect this edition to have a similar impact.

Contents The book begins with an introduction to computers. Chapter 1 explains the characteristics of this versatile tool, and its evolution from its early days to different types and forms in which it is available today. Chapter 2 deals with the internal data representation in computers and the manner in which computers perform various basic operations (comparison, sorting, addition, subtraction, multiplication, division, etc.) on these data. It

■ Preface

xix

begins with the fundamental concepts of number systems and examples of popular number systems that are commonly used by computer professionals. It then presents the popular coding schemes, which computers use to record data internally. Chapter 3 deals with the design of digital systems. It begins with an introduction to Boolean algebra. It then explains how Boolean algebra, logic gates and flip-flops are used to design digital circuits. It illustrates the design of digital circuits (both combinational and sequential) with suitable examples. Chapter 4 presents an overview of computer system architecture. It first introduces the basic functional units of a computer system and then deals with the architectures of processor and memory. Subsequently, it presents interconnection architectures for interconnecting the processors, memory, and I/O units. It also deals with multiprocessor system architectures. Chapter 5 presents the terminologies, principles of operation, uses, and trade-offs of different types of secondary storage devices. It also describes memory storage devices, mass storage devices, RAID storage, storage interfaces, various options available for processor-to-storage connectivity (DAS, SAN, and NAS), data backup, and Hierarchical Storage System (HSS). Chapter 6 presents the structure and functioning of various types of I/O devices. It also describes the commonly used types of I/O interfaces for connecting I/O devices to computer systems. Chapter 7 introduces the concept of software and explains the need for both hardware and software for a computer to do useful job. It describes the various types of software, and the different ways to acquire or develop software. It presents Software Development Life Cycle (SDLC) phases, software design approaches (top-down, bottom-up, and out-of-the-middle), software testing methodologies, software deployment methods, software maintenance, software documentation, and software engineering. It also introduces some popular application software packages. Chapter 8 deals with the tools that are commonly used for planning the logic of computer programs. These include flowcharts, decision tables, and pseudocodes. It also presents the various types of data structures used in programming. These include array, linked list, stack, queue, hash table, tree, binary search tree, graph, and heap. Chapter 9 deals with the programming languages that are commonly used for writing computer programs. It describes the various program development tools such as compiler, linker, interpreter, intermediate language compiler and interpreter, preprocessor, and postprocessor. It then explains how to choose a programming language for coding an application. Chapter 10 presents the need, functionalities, and major components of an operating system. It deals with the basic design principles of major components of an operating system, including process management, memory management, file management, device management, and command interpretation modules. It also introduces some popular operating systems (Unix, MS-DOS, MS-Windows, Linux, MacOS, iOS, WatchOS, Android OS), and some special types of operating systems (real-time, network, and distributed operating systems). Chapter 11 deals with database and data science. It explains the difference between data and information, and the process of converting data into information. It describes data storage hierarchy, standard methods of organizing data, difference between File Management Systems (FMS) and Database Management Systems (DBMS), and types of database systems. It also presents the basic concepts of data science and the stages involved in finding useful patterns in data to help decision makers make meaningful decisions. Finally, it introduces the concept of data warehousing and data mining, and explains the difference between them. Chapter 12 deals with data communication technologies and their use in building various types of computer networks. It describes the techniques, channels, and devices, which communication systems use to communicate data from one location to another. It then describes the various types of computer networks, communication protocols,

xx

■ Foundations of Computing

internetworking tools, wireless communication technologies, and wireless networks. It also describes a few paradigms of distributed computing systems, such as grid computing and cloud computing. Chapter 13 describes the Internet, its various uses, and tools and technologies available to the Internet users for making effective use of the resources on the Internet. It also describes the Internet of Things (IoT), the new generation of the Internet. Chapter 14 explains multimedia computing systems and their applications. It deals with the hardware and software requirements for processing various multimedia data types (text, graphics, animation, audio, and video), data compression techniques, and multimedia synchronization techniques. It also introduces media center computer, which is a popular electronic equipment used in homes. Chapter 15 deals with the security requirements of computer systems and the various policies and mechanisms, which computer systems use to deal with them. It describes potential attacks to computer systems (passive and active type attacks), cryptography (symmetric and asymmetric cryptosystems), authentication mechanisms (in stand alone and networked systems), access control mechanisms, digital signature, firewall, software piracy protection, e-mail security, IPSec., Secure Socket Layer (SSL), Transport Layer Security (TLS), Secure Electronic Transaction (SET), Public Key Infrastructure (PKI), and steganography. It also presents the guidelines for designing secure systems, and introduces cyber laws, cyber forensics, and CERT (Computer Emergency Response Team). Chapter 16 deals with a few popular application domains including e-governance, geoinformatics, medical informatics, and bioinformatics.

Acknowledgement A book of this type naturally evolves from a number of ideas from previous books dealing with the subject matter presented in this book. The authors express their thanks to all these authors, too numerous to acknowledge individually. We are indebted to all the readers and other experts who have used the earlier editions of this book and have provided valuable inputs about its contents. Their inputs have helped in gradually improving the quality of the book from one edition to another. We are thankful to Mr. Gaur Sunder for providing valuable inputs on technical contents of the book. His inputs have helped in improving the book’s quality. We are thankful to Mr. Akash Mondal and Mr. Harshit Poddar for designing the cover of this edition of the book, and to Mr. Rajeev Rudrakshi for his help in improving the quality of the Lecture Notes Presentation Slides. We are thankful to Mrs. Sushma Pawar, Mrs. Prajakta Kulkarni, Mrs. Arpita Kulkarni and Mr. Sandeep Kesavan for their support activities. We are also thankful to Mr. Manish Jain and other members of BPB Publications for their support and help in publishing the work. Finally, we would like to thank our son, Deeptanshu, for his loving support and understanding during the entire period of this long project. We dedicate the book to our parents whose sacrifices, love, and affection made us capable of carrying out such work.

Pradeep K. Sinha Priti Sinha January 2023

Foundations of Computing is widely adopted as a textbook for various courses in Computer Science, Computer Applications, Computer Engineering, Information Technology, and related areas by many universities, colleges, and training institutions. Faculty members and students have praised the book’s contents and its presentation style. They have also provided valuable feedback to increase its usefulness. Need for lecture notes in the form of presentation slides, is an important feedback received from many faculty members. On the other hand, several students have requested for a quick review material based on the book’s contents to enable them to quickly recall the knowledge gained from the book just before an examination or interview. To address these requirements, we have thoughtfully prepared and included lecture notes presentation slides with the book. It contains chapter-wise Portable Document Format (PDF) files. Each chapter’s PDF file has presentation slides covering the main points of that chapter. The lecture notes presentation slides is not a substitute for the textbook. They complement each other. Hence, real benefits can be derived when the book and lecture notes presentation slides are used as mentioned here. We believe that the book and the lecture notes presentation slides together form the best instructional package currently available to faculty members for teaching the topics covered in the book.

Use by Faculty Members Faculty members should prepare for their lectures using the book. However, to save time in drawing diagrams and writing notes on the board during a lecture, they can use the presentation slides of a chapter being taught in one of the following manner: 1.

If a projection system connected to a PC or laptop is available in the classroom, they can display the corresponding presentation slides on a board/screen while delivering the lecture.

2.

If a projection system is not available, they can take a hardcopy printout of the presentation slides and photocopy them on OHP sheets. They can then use an Overhead Projection (OHP) system in classroom to display the corresponding slides while delivering the lecture.

3.

If neither a projection system, nor an OHP system is available for use in classroom, they can print handout material containing multiple presentation slides on a single page.

Use by Students Students should primarily use the book for acquiring knowledge on the topics covered. This is because the lecture notes presentation slides cover only the main points and not full details and explanation of the subject being dealt with. Hence, students can use the lecture notes presentation slides to:

xxii

■ Foundations of Computing 1. Browse through the main points of a chapter before going to the class on the day that chapter is to be taught. This will enable them to have better understanding of the topics being taught in the class. 2. Review just before an examination or interview the main points of the topics they have already learnt through the book. Normally, students do not have sufficient time just before their examination or interview to go through the contents of the book.

How to Access the Lecture Notes Presentation Slides Follow the following steps to access the lecture notes presentation slides: 1. Scan the QR Code with your smart device 2. Google Drive will open 3. Click on Shared With Me 4. You will see the Presentation Slides 5. You can either download them or save them to your Drive Readers who do not have a smart device with the facility to scan the QR Code can type the link https://rebrand.ly/0aa3e4 in their browser and download the PDF file containing the presentation slides on their laptop/desktop/mobile phone.

1, 2, 3, 4, 5 1G 2G 3D 3G 4G 4GL 5G 5GL

First Generation Second Generation Three Dimensional Third Generation Fourth Generation Fourth Generation Language Fifth Generation Fifth Generation Language

A A/D ABC ACL ACM AHCI AI AL ALGOL ALU AM

Accumulator register Analog-to-Digital Atanasoff Berry Computer Access Control List Association for Computing Machinery Advanced Host Controller Interface Artificial Intelligence Arbitrated Loop ALGOrithmic Language Arithmetic Logic Unit Amplitude Modulation; Additive Manufacturing Advanced Micro Devices Advanced Mobile Phone System American National Standards Institute America OnLine A Programming Language Advanced Research Project Agency Network Authentication Server American Standard Code for Information Interchange Adaptive Software Development Agile Software Process Advanced Technology Attachment Automatic Teller Machine; Asynchronous Transfer Mode

A

AMD AMPS ANSI AOL APL ARPANET AS ASCII ASD ASP ATA ATM

B B2B BARC BASIC

Business to Business Bhabha Atomic Research Centre Beginners All-purpose Symbolic Instruction Code

BCD BIOS BIPS B-ISDN BLOBs BMP BNA BOT BPI BPS BSD BSNL

Binary Coded Decimal Basic Input Output System Billions of Instructions Per Second Broadband ISDN Binary Large OBjects Basic Multilingual Plan Burroughs Network Architecture Beginning-Of-Tape Bytes Per Inch Bytes Per Second Berkeley Software Distribution Bharat Sanchar Nigam Limited C

C# CA CAD CAE CAM CAN CASE CAV CBC CBQ CBR CCITT CD C-DAC CDC CDMA CDPD CD-R CD-ROM CD-RW CERT CGA CGI CHS CISC CL CLI CLR

C sharp Certification Authority Computer Aided Design Computer Aided Engineering Computer Aided Manufacturing Campus Area Network Computer Aided Software Engineering Constant Angular Velocity Cipher Block Chaining Content Based Querying Content Based Retrieval Consultative Committee for International Telephony and Telegraphy Compact Disk Centre for Development of Advanced Computing Control Data Corporation Code Division Multiple Access Cellular Digital Packet Data CD-Recordable Compact Disk Read Only Memory CD Read/Write Computer Emergency Response Team Color Graphics Adapter Common Gateway Interface Cylinder Head Sector Complex Instruction Set Computer Command Language Common Language Infrastructure; Command Line Interface Common Language Runtime

xxiv

■ Foundations of Computing

CLV CNC COBOL CODASYL COM CORBA COWs CPPM CPS CPU CRL CRT CSCW CU

Constant Linear Velocity Computer Numeric Control COmmon Business Oriented Language Conference On DAta SYstems Languages Computer Output Microfilm; Component Object Model Common Object Request Broker Architecture Cluster of Workstations Content Protection for Prerecorded Media Characters Per Second Central Processing Unit Certificate Revocation List Cathode Ray Tube Computer Supported Cooperative Working Control Unit D

D Flip-flop D/A DAB DAS DAT DBMS DBS DCBR DCE DCOM DCT DDB DDL DDS DEC DES DLP DMA DML DMLS DNA DNS DoD DOS DPI DRAM DRDO DS DSDD DSHD DSN DSS DTS DVD

Data Flip-flop Digital-to-Analog Device Address Bus Direct Attached Storage Digital Audio Tape Data Base Management System Demand Based Switching Dynamic Content Based Retrieval Distributed Computing Environment Distributed Computing Object Model Discrete Cosine Transform DNA Data Bank Data Definition Language Digital Data Storage Digital Equipment Corporation Data Encryption Standard Digital Light Processing Direct Memory Access Data Manipulation Language Direct Metal Laser Sintering Digital Network Architecture; Dexoyribonucleic Acid Domain Name System U.S. Department of Defense Distributed Operating System Dots Per Inch Dynamic RAM Defense Research and Development Organization Dual Signature Double Sided Double Density Double Sided High Density Distributed Systems Network Decision Support System Digital Theater System Digital Video/Versatile Disk

E EBCDIC

Extended Binary Coded Decimal Interchange Code ECA-rule Event Condition Action-rule ECMA European Computer Manufacturers Association EDGE Enhanced Data-rate for Global Evolution EDSAC Electronic Delay Storage Automatic Calculator EDVAC Electronic Discrete Variable Automatic Computer EEPROM Electrically EPROM EFM Eight-to-Fourteen Modulation EGA Extended Graphics Adapter E-Governance Electronic Governance EHR Electronic Health Record EISA Bus Extended Industry Standard Architecture Bus ELD Electro Luminescent Display EMBL European Molecular Biology Laboratory ENIAC Electronic Numerical Integrator And Calculator EOT End-Of-Tape EPG Electronic Programming Guide EPIC Explicitly Parallel Instruction Computing EPROM Erasable Programmable Read-Only Memory ERNET Education and Research NETwork ESDI Enhanced Small Device Interface ESMR Extended Specialized Mobile Radio ETSI European Telecommunications Standard Institute F FA FAT FC FDD FDM FEP FIFO FLOPS FM FMS FORTRAN FOSS FSK FTP

Full Adder File Allocation Table Fiber Channel Feature Driven Development Frequency Division Multiplexing Front End Processor First-In-First-Out Floating Point Operations Per Second Frequency Modulation File Management System FORmula TRANslation Free and Open Source Software Frequency Shift Keying File Transfer Protocol G

GB GEO GFLOPS GHz GIGO GIS

Giga Bytes Geosynchronous Earth Orbit Giga FLOPS Giga Hertz Garbage In Garbage Out Geographical Information System

■ Abbreviations GNU GPD GPL GPRS GPS GSM GUI

Gnu Not Unix Gas Plasma Display General Public License General Packet Radio Service Global Positioning System Global System for Mobile communication Graphical User Interface

ISAM iSCSI ISDN ISO ISP IT ITU IV

xxv

Indexed Sequential Access Method Internet SCSI Integrated Services Digital Network International Standards Organization Internet Service Provider Information Technology International Telecommunication Union Initialization Vector

H HA HDD HD-MAC HDTV HIS HP HSCSD HSM HSS HT HTML HTTP Hz

Half Adder Hard Disk Drive High Definition Multiple Analog Components High Definition Television Hospital Information System Hewlett Packard High Speed Circuit Switched Data Hierarchical Storage Management Hierarchical Storage System HyperTransport HypterText Markup Language HyperText Transport Protocol Hertz I

I I/O IaaS IBG IBM IC IDE iDEN IDL IDN IEEE IETF IIOP IMT-2000 INSAT IoT IP IPI-3 IPSec IPV4 IPV6 IQN IrDA IRG ISA ISA Bus ISAKMP

Instruction register Input and Output; I/O register Infrastructure as a Service Inter Block Gap International Business Machines Integrated Circuit Integrated Drive Electronics Integrated Digital Enhanced Network Interface Definition Language; Intermediate Definition Language Integrated Digital Networks Institute of Electrical and Electronics Engineers Internet Engineering Task Force Internet Interoperable Protocol International Mobile Telecommunications 2000 Indian National SATellite Internet of Things Internet Protocol Intelligent Peripheral Interface-Level 3 IP Security Internet Protocol Version 4 Internet Protocol Version 6 iSCSI Qualified Name Infrared Data Association Inter Record Gap Instruction Set Architecture Industry Standard Architecture Bus Internet Security Association and Key Management Protocol

J J2EE J2SE JCL JIT JK Flip-flop JPEG JRE JSP

Java 2 Enterprise Edition Java 2 Standard Edition Job Control Language Just-In-Time Jack Kilby Flip-flop Joint Photographic Experts Group Java Runtime Engine Java Server Pages

KB KDD KHz K-map

Kilo Bytes Knowledge Discovery in Databases Kilo Hertz Karnaugh map

K

L LAN LCD LED LEO LIFO LiLo LISP LMDS LPM LQ LRU LSB LSD LSI LTE

Local Area Network Liquid Crystal Display Light Emitting Diode Low Earth Orbit Last-In-First-Out Linux Loader LISt Processing Local Multipoint Distribution System Lines Per Minute Letter Quality Least Recently Used Linux Standard Base Least Significant Digit Large Scale Integration Long Term Evolution M

MAB MAC MAN MAR MB MBR MCA Bus MD MDDB MEME

Memory Address Bus Message Authentication Code Metropolitan Area Network Memory Address Register Mega Bytes Memory Buffer Register Micro Channel Architecture Bus Molecular Dynamics; Message Digest MultiDimensional DataBase Multiple Expectation Maximization for motif Elicitation

xxvi

■ Foundations of Computing

MEO MFLOPS MFT MHz MICR MIDI MIDL MIME MIMO MIPS MMC MMS MNP4 MNP5 MODEM MOLAP MP3 MPEG MPI MSCDEX MSD MS-DOS MSI MTAs MTBL MTNL MUSE MVT

Medium Earth Orbit Mega FLOPS Multiprogramming with Fixed Tasks Mega Hertz Magnetic Ink Character Recognition Musical Instrument Digital Interface Microsoft’s IDL Multiple Internet Mail Extensions Multiple Input Multiple Output Millions of Instructions Per Second Multimedia Card Multimedia Messaging Service Microcom Network Protocol Version 4 Microcom Network Protocol Version 5 MOdulator/DEModulator Multidimensional OLAP MPEG-1 Audio Layer 3 Moving Pictures Expert Group Message Passing Interface MicroSoft CD EXtension Most Significant Digit MicroSoft Disk Operating System Medium Scale Integration Mail Transfer Agents Mean Time Between Data Loss Mahanagar Telephone Nigam Limited Multiple SubNyquist Sampling Encoding Multiprogramming with Variable Tasks N

NaReGI NAS NATing NCMRWF NCQ NCSA NFC NIC NICNET NLP NLQ NOS NSF NTQ NTSC

National Research Grid Initiative Network Attached Storage Network Address Translating National Center for Medium Range Weather Forecasting Native Command Queuing National Center for Supercomputing Applications Near Field Communication National Informatics Centre; Network Interface Card National Informatics Center NETwork Natural Language Processing Near Letter Quality Network Operating System National Science Foundation Near Typeset Quality National Television Systems Committee

OMG OMR OOD OOP ORB OS OSF OSI OSS

Object Management Group Optical Mark Reader Object-Oriented Design Object-Oriented Programming Object Request Broker Operating System Open Software Foundation Open System Interconnection Open Source Software P

P2P PaaS PAL PAN PATA PB PC PCB PCI PCIe PCI-X PCS PDA PDF PDL PDP PEM PFLOPS PGP PIM PIP PKI PL/1 PM POP POS POTS PPM PPP PPU PRIMENET PROLOG PROM PSTN PVC PVM

Point to Point Platform as a Service Phase Alternating Line Personal Area Network Parallel ATA Peta Bytes Personal Computer; Program Control register Printed Circuit Board; Process Control Block Peripheral Component Interface PCI Express PCI Extended Personal Communication Services Personal Digital Assistant Portable Document Format Program Design Language Programmed Data Processor Privacy Enhanced Mail Peta FLOPS Pretty Good Privacy Personal Information Manager Peripheral Interchange Program Public Key Infrastructure Programming Language One Phase Modulation Procedure Oriented Programming Point-Of-Sale Plain Old Telephone Service Pages Per Minute Point-to-Point Protocol Peripheral Processing Unit PRIME Computers NETwork PROgramming in LOGic Programmable Read-Only Memory Public Switched Telephone Network Poly Vinyl Chloride Parallel Virtual Machine

O OCR OFDM OHA OHCI OLAP OLTP

Optical Character Recognition Orthogonal Frequency Division Multiplexing Open Handset Alliance Open Host Controller Interface On-Line Analytical Processing On-Line Transaction Processing

Q QBE QIC QoS Q-table

Query By Example Quarter Inch Cartridge Quality of Service Quantization Table

■ Abbreviations R RA RAID RAM RDD REL RGB RISC rlogin RMI RNA ROLAP ROM RPC RSA RUP

Regional Authority Redundant Array of Inexpensive Disks Random Access Memory Rights Data Dictionary Rights Expression Language Red, Green and Blue Reduced Instruction Set Computer Remote Login Remote Method Invocation Ribonucleic Acid Relational OLAP Read Only Memory Remote Procedure Call Rivest Shamir Adleman Rational Unified Process

SW

SA SaaS SAN SAS SATA SCBR SCSI SD SDK SDLC SECAM SEQUEL SERC SET SGML SHA SIMM SLIP SLS SM SMR SMS SMTP SNA SNOBOL SONET SPOOL SQL SR Flip-flop SRAM SSD SSI SSL STL

Secure/Multipurpose Internet Mail Extensions Security Association Software as a Service Storage Area Network Serial Attached SCSI Serial ATA Static Content Based Retrieval Small Computer System Interface Secure Digital Software Development Kit Software Development Life Cycle Sequential Couleur Avec Memoire Structured English QUEry Language Supercomputer Education and Research Center Secure Electronic Transaction Syntax for Generalized Markup Language Secure Hash Algorithm Single In-line Memory Module Serial Line Internet Protocol Selective Laser Sintering Subtractive Manufacturing Specialized Mobile Radio Short Message Service Simple Mail Transfer Protocol Systems Network Architecture StriNg Oriented symBOlic Language Synchronous Optical NETwork Simultaneous Peripheral Operation OnLine Structured Query Language Set-Reset Flip-flop Static RAM Solid State Drive Small Scale Integration Secure Socket Layer STereoLithography

Switched Fabric T

T Flip-flop TB TCO TCP TCP/IP TD-CDMA TDM TDMA TFLOPS TLS TQ TV

S S/MIME

xxvii

Toggle Flip-flop Tera Bytes Total Cost of Ownership Transport Control Protocol Transmission Control Protocol/Internet Protocol Time Division CDMA Time Division Multiplexing Time Division Multiple Access Tera FLOPS Transport Layer Security Typeset Quality Television U

UBE UDP ULSI UMTS UNIVAC UPC URL USB UTF UTP UVEPROM UWB

Unsolicited Bulk E-mail User Datagram Protocol Ultra Large Scale Integration Universal Mobile Telecommunication System UNIVersal Automatic Computer Universal Product Code Uniform Resource Locator Universal Serial Bus Unicode Transformation Format Unshielded Twisted Pair Ultra Violet EPROM Ultra Wide Band V

V2I V2P V2V VAN VCR VDT VGA VLSI VOD VoIP VPN VSAT VSNL VTOC

Vehicle-to-Infrastructure Vehicle-to-Person Vehicle-to-Vehicle Value Added Network Video Cassette Recorder Video Display Terminal Video Graphics Array Very Large Scale Integration Video-On-Demand Voice over Internet Protocol Virtual Private Network Very Small Aperture Terminal Videsh Sanchar Nigam Limited Volume Table Of Contents W

WAE WAN WAP W-CDMA WDP

Wireless Application Environment Wide Area Network Wireless Application Protocol Wideband Code Division Multiple Access Wireless Datagram Protocol

xxviii ■ Foundations of Computing WiMAX WLAN WLL WMA WML WORM WS WSP WTLS WTP WWN

Worldwide Interoperability for Microwave Access Wireless Local Area Network Wireless Local Loop Windows Media Audio Wireless Markup Language Write Once Read Many Web Service Wireless Session Protocol Wireless Transport Layer Security Wireless Transaction Protocol World Wide Name

WWW WYSIWYG

World Wide Web What You See Is What You Get X

X.400 X.500 XDR XHTML XML XP

Electronic Mail Protocol Directory Server Protocol eXternal Data Representation eXtensible HyperText Markup Language eXtensible Markup Language Extreme Programming

Characteristics, Evolution, and Classification of Computers

WHAT IS A COMPUTER? The original objective of inventing a computer was to create a fast calculating device. Today, we define a computer as a device that operates upon data because more than 80% of work done by today’s computers is data processing. Data can be anything like bio-data of applicants including their photographs, when computer is used for short listing candidates for recruiting; marks obtained by students in various subjects when used for preparing results; details (name, age, sex, etc.) of passengers when used for making airline or railway reservations; or number of different parameters when used for solving scientific research problems, etc. Notice from the examples that data can be numerical (only digits), alphabetic (only alphabets), alphanumeric (mixture of digits, alphabets and special characters), text, image, voice or video. A computer is often referred to as a data processor because it can store, process, and retrieve data whenever desired. The activity of processing data using a computer is called data processing. Data processing consists of three subactivities: capturing input data, manipulating the data, and managing output results. As used in data processing, information is data arranged in an order and form that is useful to people receiving it. Hence, data is raw material used as input to data processing and information is processed data obtained as output of data processing (see Figure 1.1). Data (Raw Material)

Input

Computer (Data Processor)

Output

Information (Finished Product)

Figure 1.1. A computer (also known as data processor) converts data into information.

2

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

CHARACTERISTICS OF COMPUTERS A computer’s power and usefulness are mainly due to its characteristics listed in Figure 1.2. Sr. No.

Characteristics

Description

1

Automatic

It carries out a job normally without any human intervention It can perform several billion (10 9) simple arithmetic operations per second It performs every calculation with the same accuracy

2

Speed

3

Accuracy

4

Diligence

It is free from monotony, tiredness, and lack of concentration

5

Versatility

6

Memory

7

No I. Q.

8

No Feelings

It can perform a wide variety of tasks It can store huge amount of information and can recall any piece of this information whenever required It cannot take its own decisions, and has to be instructed what to do and in what sequence It cannot make judgments based on feelings and instincts Figure 1.2. Characteristics of computers.

EVOLUTION OF COMPUTERS Researchers invented computers because of man’s search for fast and accurate calculating devices. Blaise Pascal invented the first mechanical adding machine in 1642. Later, in the year 1671, Baron Gottfried Wilhelm von Leibniz of Germany invented the first calculator for multiplication. Keyboard machines originated in the United States around 1880 and we use them even today. Around the same period, Herman Hollerith came up with the concept of punched cards that computers used extensively as input medium even in late 1970s. Business machines and calculators made their appearance in Europe and America towards the end of the nineteenth century. Charles Babbage, a nineteenth century Professor at Cambridge University, is considered the father of modern digital programmable computers. He designed a “Difference Engine” in the year 1822 that could produce reliable tables. In 1842, Babbage came out with his new idea of a completely automatic Analytical Engine for performing basic arithmetic functions for any mathematical problem at an average speed of 60 additions per minute. Unfortunately, he was unable to produce a working model of this machine because the precision engineering required to manufacture the machine was not available during that period. However, his efforts established a number of principles that are fundamental to the design of any digital programmable computer. A major drawback of the early automatic calculating machines was that their programs were wired on boards that made it difficult to change programs. In 1940s, Dr. John Von Neumann introduced the “stored program” concept that helped in overcoming hard-wired program problem. The basic idea behind this concept is that a sequence of instructions and data can be stored in memory of a computer for automatically directing flow of operations. This feature considerably influenced development of modern digital computers because of ease with which different programs can be loaded and executed on a single computer. Due to this feature, we often refer to modern digital computers as stored program digital computers. Figure 1.3 provides basic information about some of the well-known early computers.

■ Evolution of Computers

3

4

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

COMPUTER GENERATIONS “Generation” in computer talk provides a framework for the growth of computer industry based on key technologies developed. Originally, it was used to distinguish between hardware technologies but was later extended to include both hardware and software technologies. The custom of referring to computer era in terms of generations came into wide use only after 1964. There are totally five computer generations known until today. Below we describe each generation along with its identifying characteristics. In the description below, you will come across several new terminologies. Subsequent chapters will deal with these terminologies in detail. The idea here is to provide an overview of the major developments and technologies during the five generations of computers and not to explain them in detail.

First Generation (1942-1955) The early computers of Figure 1.3 and others of their time were manufactured using vacuum tubes as electronic switching device. A vacuum tube [see Figure 1.4(a)] was a fragile glass device using filaments as a source of electronics and could control and amplify electronic signals. It was the only high-speed electronic switching device available in those days. These vacuum tube computers could perform computations in milliseconds and were known as first-generation computers. Most of the first-generation computers worked on the principle of storing program instructions along with data in memory of computer (stored program concept) so that they could automatically execute a program without human intervention. Memory of these computers used electromagnetic relays, and users fed all data and instructions into the system using punched cards. Programmers wrote instructions in machine and assembly languages because of lack of high-level programming languages in those days. Since machine and assembly languages are difficult to work with, only a few specialists understood how to program these early computers.

Second Generation (1955-1964) John Bardeen, Willian Shockley, and Walter Brattain invented a new electronic switching device called transistor [see Figure 1.4(b)] at Bell Laboratories in 1947. Transistors soon proved to be a better electronic switching device than vacuum tubes. Second-generation computers were manufactured using transistors. They were more powerful, more reliable, less expensive, smaller, and cooler to operate than the first-generation computers. The second generation also experienced a change in storage technology. Memory of second-generation computers was composed of magnetic cores. Magnetic cores are small rings made of ferrite that can be magnetized in either clockwise or anti-clockwise direction. Large random access memory (having storage capacity of few tens of kilobytes) had several magnetic cores strung on a mesh of wires. In 1957, researchers introduced magnetic tape as a faster and more convenient secondary storage medium. Later magnetic disk storage was also developed, and magnetic disk and magnetic tape were the main secondary storage media used in second-generation computers. Users still used punched cards widely for preparing and feeding programs and data to a computer. On software front, high-level programming languages (like FORTRAN, COBOL, ALGOL, and SNOBOL) and batch operating system emerged during second generation. High-level programming languages made second-generation computers easier to program and use than first-generation computers. Introduction of batch operating system helped in reducing human intervention while processing multiple jobs resulting in faster processing, enhanced throughput, and easier operation of second-generation computers.

■ Computer Generations

5

In addition to scientific computations, business and industry users used second-generation computers increasingly for commercial data processing applications like payroll, inventory control, marketing, and production planning. Ease of use of second-generation computers gave birth to a new profession of programmers and systems analysts in computing that is more oriented towards usage rather than design of computers. This triggered introduction of computer science related courses in several colleges and universities.

(a) A Vacuum Tube Figure 1.4.

(b) A Transistor

(c) An Integrated Circuit (IC)

Electronics devices used for manufacturing computers of different generations.

Third Generation (1964-1975) In 1958, Jack St. Clair Kilby and Robert Noyce invented the first integrated circuit. Integrated circuits (called ICs) are circuits consisting of several electronic components like transistors, resistors, and capacitors grown on a single chip of silicon eliminating wired interconnection between components. IC technology was also known as “microelectronics” technology because it made it possible to integrate larger number of circuit components into very small (less than 5 mm square) surface of silicon, known as “chip” [see Figure 1.4(c)]. Initially the integrated circuits contained only about ten to twenty components. This technology was named small-scale integration (SSI). Later with the advancement in technology for manufacturing ICs, it became possible to integrate up to about hundred components on a single chip. This technology was known as medium scale integration (MSI). Third generation computers were manufactured using ICs. Earlier ones used SSI technology and later ones used MSI technology. ICs were smaller, less expensive to produce, more rugged and reliable, faster in operation, dissipated less heat, and consumed less power than circuits built by wiring electronic components manually. Hence, third-generation computers were more powerful, more reliable, less expensive, smaller, and cooler to operate than second-generation computers. Parallel advancements in storage technologies allowed construction of larger magnetic core based random access memory as well as larger capacity magnetic disks and tapes. Hence, third-generation computers typically had few megabytes (less than 5 Megabytes) of main memory and magnetic disks capable of storing few tens of megabytes of data per disk drive. On software front, standardization of high-level programming languages, timesharing operating systems, unbundling of software from hardware, and creation of an independent software industry happened during third generation. FORTRAN and COBOL were the most popular high-level programming languages in those days. American National Standards Institute (ANSI) standardized them in 1966 and 1968 respectively, and the standardized versions were called ANSI FORTRAN and ANSI COBOL. The idea was that as long as a programmer follows these standards in program writing, he/she could run his/her program on any computer with an ANSI FORTRAN or ANSI COBOL compiler (see Chapter 9 for details). Some more high-level programming languages were introduced during the thirdgeneration. Notable among these were PL/1, PASCAL, and BASIC. Second-generation computers used batch operating system. In those systems, users had to prepare their data and programs and then submit them to a computer centre for processing. The operator at the computer centre collected these user jobs and fed them to a computer in batches at scheduled intervals. The respective users then collected their

6

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

job’s output from the computer centre. The inevitable delay resulting from the batch processing approach was frustrating to some users, especially programmers, because often they had to wait for days to locate and correct a few program errors. To rectify this, John Kemeny and Thomas Kurtz of Dartmouth College introduced the concept of timesharing operating system, which enables multiple users to directly access and share a computer’s resources simultaneously in a manner that each user feels that no one else is using the computer. This is accomplished by using a large number of independent, relatively low-speed, on-line terminals connected to the computer simultaneously. A separate user uses each terminal to gain direct access to the computer. Timesharing operating system allocates CPU time in such a way that all user programs have a brief share (known as a time slice) of CPU time in turn. Processing speed of CPU allows it to switch from one user job to another in rapid succession and execute a small portion of each job in allocated time slice until the job is completed. Each user gets the illusion that he/she alone is using the computer. Introduction of timesharing concept helped in substantially improving the productivity of programmers and made on-line systems feasible, resulting in new on-line applications like airline reservation systems, interactive query systems, etc. Until 1965, computer manufacturers sold their hardware along with all associated software without separately charging for software. For example, buyers received language translators for all languages supported on a computer they purchased. From user’s standpoint, software was free. However, the situation changed in 1969 when IBM and other computer manufacturers began to price their hardware and software products separately. This unbundling of software from hardware gave users an opportunity to invest only in software of their need and value. For example, now buyers could purchase only the language translators they needed and not all language translators supported on the purchased computer. This led to the creation of many new software houses and the beginning of an independent software industry. Another important concept introduced during third-generation was that of backward compatible family of computers. During this period, IBM introduced its System 360 as a family of computers with backward compatibility as they were different sizes of mainframe systems based on the same machine language. This enabled businesses to upgrade their computers without incurring costs of replacing peripheral equipment and modifying programs to run on new systems. Development and introduction of minicomputers also took place during third-generation. Computers built until early 1960s were mainframe systems that only large companies could afford to purchase and use. Clearly, a need existed for low-cost smaller computers to fill the gaps left by the bigger, faster, and costlier mainframe systems. Several innovators recognized this need and formed new firms in 1960s to produce smaller computers. Digital Equipment Corporation (DEC) introduced the first commercially available minicomputer, the PDP-8 (Programmed Data Processor), in 1965. It could easily fit in the corner of a room and did not require attention of a full-time computer operator. It used timesharing operating system and a number of users could access it simultaneously from different locations in the same building. Its cost was about one-fourth the cost of a traditional mainframe system making it possible for smaller companies to afford computers. It confirmed the demand for small computers for business and scientific applications, and by 1971, there were more than 25 computer manufacturers in minicomputer market.

Fourth Generation (1975-1989) Average number of electronic components packed on a silicon chip doubled each year after 1965. This progress soon led to the era of large-scale integration (LSI) when it was possible to integrate over 30,000 electronic components on a single chip, followed by very-large-scale integration (VLSI) when it was possible to integrate about one million electronic components on a single chip. This progress led to a dramatic development – creation of a microprocessor. A microprocessor contains all circuits needed to perform arithmetic logic and control functions, the core activities of all computers, on a single chip. Hence, it became possible to build a complete computer with a microprocessor, a few additional primary storage chips, and other support circuitry. It started a new social revolution – personal computer (PC) revolution. Overnight computers became incredibly compact. They became inexpensive to make, and it became possible for many to own a computer.

■ Computer Generations

7

By 1978, Apple II from Apple Computer Inc. and the TRS-80 model from the Radio Shack Division of Tandy Corporation were dominant personal computers. By 1980, IBM realized that the personal computer market was too promising to ignore and came out with its own PC in 1981, popularly known as IBM PC. Several other manufacturers used IBM’s specification and designed their own PCs, popularly known as IBM compatible PCs or clones. The IBM PC and its clones became a popular standard for the PC industry during the fourth generation. During fourth generation, semiconductor memories replaced magnetic core memories resulting in large random access memories with fast access time. Hard disks became cheaper, smaller, and larger in capacity. In addition to magnetic tapes, floppy disks became popular as a portable medium for porting programs and data from one computer to another. Significant advancements also took place during fourth generation in the area of large-scale computer systems. In addition to improved processing and storage capabilities of mainframe systems, the fourth-generation saw the advent of supercomputers based on parallel vector processing and symmetric multiprocessing technologies. A supercomputer based on parallel vector processing technology contains a small number of custom-designed vector processors which are connected to a number of high-speed data access shared memory modules through a custom-designed, highbandwidth crossbar switch network. On the other hand, a supercomputer based on symmetric multiprocessing technology uses commodity microprocessors connected to a shared memory through a high-speed bus or a crossbar switch network. Primary builders of supercomputers of the former category included Cray Research and ETA Systems, whereas of the latter category included IBM, Silicon Graphics, and Digital Equipment Corporation. High-speed computer networking also developed during fourth-generation. This enabled interconnection of multiple computers for communication and sharing of data among them. Local area networks (LANs) became popular for connecting computers within an organization or within a campus. Similarly, wide area networks (WANs) became popular for connecting computers located at larger distances. This gave rise to network of computers and distributed systems. On software front, several new developments emerged to match the new technologies of fourth generation. For example, vendors developed several new operating systems for PCs. Notable ones among these were MS-DOS, MSWindows, and Apple’s propriety Mac OS. Since PCs were for individuals who were not computer professionals, companies developed graphical user interfaces for making computers user friendly (easier to use). A graphical user interface (GUI) provides icons (pictures) and menus (list of choices) that users can select with a mouse. PC manufacturers and application software developers developed several new PC-based applications to make PCs a powerful tool. Notable among these were powerful word processing packages that allowed easy development of documents, spreadsheet package that allowed easy manipulation and analysis of data organized in columns and rows, and graphics packages that allowed easy drawing of pictures and diagrams. Another useful concept that became popular during fourth-generation was multiple windows on a single terminal screen, which allowed users to see the status of several applications simultaneously in separate windows on the same terminal screen. In the area of software for large-scale computers, key technologies that became popular included multiprocessing operating systems and concurrent programming languages. With multiprocessing operating systems, a mainframe system could use multiple processors (a main processor and several subordinate processors) in such a manner that the subordinate processors could manage the user terminals and peripheral devices, allowing the main processor to concentrate on processing the main program, improving the overall performance. Supercomputers also used multiprocessing operating system to extract the best performance from the large number of processors used in these systems. Concurrent programming languages further helped in using the multiprocessing capabilities of these systems by allowing programmers to write their applications in such a way that different processors could execute parts of the application in parallel. The most ambitious language of this type was ADA. During fourth-generation, the UNIX operating system also became popular for use on large-scale systems. Additionally, due to proliferation of computer networks, several new features were included in existing operating systems to allow multiple computers on the same network to communicate with each other and share resources.

8

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

Some other software technologies that became popular during fourth-generation are C programming language, objectoriented software design, and object-oriented programming. C language combines features of high-level programming languages with efficiency of an assembly language. The primary objectives of object-oriented software design are to make programs generalized and to build software systems by combining reusable pieces of program codes called objects. To facilitate object-oriented software design, several object-oriented programming languages were introduced, out of which, C++ emerged as the most popular one.

Fifth Generation (1989-Present) The trend of further miniaturization of electronic components, dramatic increase in power of microprocessor chips, and increase in capacity of main memory and hard disk continued during fifth generation. VLSI technology became ULSI (Ultra-Large-Scale Integration) technology in fifth generation, resulting in production of microprocessor chips having ten million electronic components. In fact, the speed of microprocessors and the size of main memory and hard disk doubled almost every eighteen months. As a result, many features found in the CPUs of large mainframe systems of third- and fourth-generation systems became part of microprocessor architecture in fifth generation. This resulted in availability of powerful and compact computers becoming available at cheaper rates and death of traditional large mainframe systems. Subsequently, processor manufacturers started building multicore processor chips instead of increasingly powerful (faster) single-core processor chips. The multicore chips improve overall performance by handling more work in parallel. Due to this fast pace of advancement in computer technology, we see more compact and more powerful computers being introduced almost every year at more or less the same price or even cheaper. Notable among these are portable notebook computers that give the power of a PC to their users even while traveling, powerful desktop PCs and workstations, powerful servers, powerful supercomputers, and handheld computers. Storage technology also advanced making larger main memory and disk storage available in newly introduced systems. Currently, PCs having few Gigabytes (GB) of main memory and few Terabytes (TB) of hard disk capacity are common. Similarly, workstations having 4 to 64 Gigabytes of main memory and few tens of Terabytes of hard disk capacity are common. RAID (Redundant Array of Inexpensive Disks) technology enables configuration of a bunch of disks as a single large disk. It, thus, supports larger hard disk space with better in-built reliability. During fifth generation, optical disks (popularly known as Compact Disks or CDs) and Solid State Disks (SSD) emerged as popular portable mass storage media. In the area of large-scale systems, fifth-generation saw the emergence of more powerful supercomputers based on parallel processing technology. They used multiple processors and were of two types – shared memory and distributed memory parallel computers. In a shared memory parallel computer, a high-speed bus or communication network interconnects a number of processors to a common main memory, whereas in a distributed memory parallel computer, a communication network interconnects a number of processors, each with its own memory. These systems use parallel programming technique to break a problem into smaller problems and execute them in parallel on multiple processors of the system. Processors of a shared memory parallel computer use memory access mechanism for communication, whereas those of a distributed memory parallel computer use message-passing mechanism for communication. Distributed memory parallel computers have better scalability (can grow larger in capability) than shared memory parallel computers, and are now built by clustering together powerful commodity workstations by using a high-speed commodity switched network. This is known as clustering technology.

■ Computer Generations

9

During fifth generation, the Internet emerged with associated technologies and applications. It made it possible for computer users sitting across the globe to communicate with each other within minutes by use of electronic mail (known as e-mail) facility. A vast ocean of information became readily available to computer users through the World Wide Web (known as WWW). Moreover, several new types of exciting applications like electronic commerce, virtual libraries, virtual classrooms, distance education, etc. emerged during the period. The tremendous processing power and the massive storage capacity of fifth-generation computers also made them a useful and popular tool for a wide range of multimedia applications dealing with information containing text, graphics, animation, audio, and video data. In general, data size for multimedia information is much larger than plain text information because representation of graphics, animation, audio, or video media in digital form requires much larger number of bits than that required for representation of plain text. Because of this, multimedia computer systems require faster processor, larger storage devices, larger main memory, good graphics terminal, and input/output devices required to play any audio or video associated with a multimedia application program. The availability of multimedia computer systems resulted in a tremendous growth of multimedia applications during fifth-generation. In the area of operating systems, some new concepts that gained popularity during fifth-generation include microkernels, multithreading, multicore operating systems and operating systems for hand-held mobile devices. Microkernel technology enabled designers to model and design operating systems in a modular fashion. This makes operating systems easier to design and implement, easier to modify or add new services, and allows users to implement and use their own service. Multithreading technology is a popular way to improve application performance through parallelism. In traditional operating systems, the basic unit of CPU scheduling is a process, but in multithreading operating systems, the basic unit of CPU scheduling is a thread. In such operating systems, a process consists of an address space containing its instructions and data, and one or more threads sharing the same address space. Hence, these systems can create a new thread, switch CPU between threads, and share resources between threads of same process more efficiently than between processes, resulting in faster execution and better overall system performance. A multicore operating system can run multiple programs at the same time on a multicore chip with each core handling a separate program. With the advent of smart phones, tablets, smart watches and other handheld smart electronic devices, special operating systems for these devices were designed. In the area of programming languages, concepts that gained popularity during fifth generation are JAVA programming language, and parallel programming libraries like MPI (Message Passing Interface) and PVM (Parallel Virtual Machine). JAVA is used primarily on the World Wide Web. It supports Java-based applets allowing web pages to have dynamic information and more interactivity with users of web information. MPI and PVM libraries enable development of standardized parallel programs, so that a programmer can easily port and execute a parallel program developed for one parallel computer on other parallel computers. MPI is used for distributed memory parallel computers and PVM is used for shared memory parallel computers. Recently, programming languages for programming Data Analytics and Artificial Intelligence (AI) applications were developed. Python and R are two such languages. ____________________________

Figure 1.5 summarizes the key technologies and features of five computer generations. Although there is a certain amount of overlap between different generations, the approximate period shown against each are normally accepted. Description of history of computing divided into five generations shows how quickly things have changed in the last few decades. Technological progress in this area is continuing. In fact, the fastest-growth period in the history of computing may be still ahead.

10 Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

■ Classification of Computers

11

CLASSIFICATION OF COMPUTERS Traditionally, computers were classified as microcomputers, minicomputers, mainframes, and supercomputers based on their size, processing speed, and cost. However, this classification is no longer relevant because with rapidly changing technology, new models of computers are introduced every few months having much higher performance and costing less than their preceding models. A recently introduced small system can outperform large models of a few years ago both in cost and performance. Hence, today computers are classified based on their mode of use. According to this classification, computers are classified as notebook computers, personal computers, workstations, mainframe systems, supercomputers, client and server computers, and handled computers.

Notebook Computers (Laptops) Notebook computers are portable computers mainly meant for use by people who need computing resource wherever they go. Their size is about the same as the size of an 8½ x 11 inch notebook or smaller, and their weight is around 2 Kg or less. They are also known as laptop PCs (laptop personal computers or simply laptop) because they are as powerful as a PC, and their size and weight are such that they can be used by placing them on ones lap. A notebook computer uses an almost full-size keyboard, a flat screen liquid crystal display, and a trackball, stick, or touchpad (instead of a mouse because notebook computers are often used without a desk) (see Figure 1.6). It also has an inbuilt hard disk and ports for connecting peripheral devices such as printer, pen drive, portable disk, etc. The lid with display screen is foldable in a manner that when not in use, a user can fold it to flush with keyboard to convert the system into notebook form. When in use, the lid with display screen is folded open as shown in the figure. Many models of laptops can be “docked” on a docking station (device with additional battery, hard disk, I/O ports, etc.) or port replicator (device with additional I/O ports) to take advantage of big monitor, storage space, and other peripherals such as a printer. Users can connect their laptop to a network and download data (read files) from other computers on the network, or access the Internet. Design of most laptops enables their users to establish wireless connectivity with other stationary computers using WiFi and Bluetooth. Bluetooth is an industrial specification for short-range wireless connectivity using globally unlicensed short-range radio frequency. It provides a way to establish wireless connectivity between devices such as PCs, laptops, printers, mobile phones, and digital cameras for exchange of information between them.

Foldable flat screen

Keyboard, trackball, hard disk, I/O ports, etc. are in this unit

Figure 1.6. A notebook computer (Laptop).

We can use laptops even at places where there is no external power source available (for example while traveling in a train or airplane) because they can operate with chargeable batteries. With a fully charged battery, a laptop can operate for a few hours. Laptops normally run MS-DOS, MS WINDOWS, Mac OS, or Linux operating system. Normally, users use them for word processing, spreadsheet computing, data entry, Internet browsing, accessing and sending e-mails, and preparing presentation materials while traveling. People also often use them to make presentations at locations away from their working places by plugging them into an LCD (liquid crystal display) projection system.

12

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

Processing capability of a laptop is normally as good as an ordinary PC (personal computer) because both use the same type of processor. However, microprocessors for laptops are designed to dynamically adjust their performance with available power to provide maximum power saving. In fact, design of a laptop is such that its each device uses little power and remains suspended if not used. A laptop generally has lesser hard disk storage than a PC to keep its total weight to around two Kg. A laptop is more expensive (2 to 3 times) than a normal PC with similar configuration.

Personal Computers (PCs) A PC is a non-portable, general-purpose computer that fits on a normal size office table (leaving some writing space to keep writing pads and other office stationary), and is used by one person at a time (single-user-oriented). As the name implies, users use PCs for their personal computing needs (such as professional work, personal work, education, and entertainment) either at their work places or at their homes. Hence, PCs can be found in offices, classrooms, homes, hospitals, shops, clinics, etc. A PC has several chips (CPU chip, RAM chips, ROM chips, I/O handling chips, etc.) neatly assembled on a main circuit board called system board or motherboard. Motherboard is what distinguishes one PC from another. Sometimes, we differentiate between two PCs based on the microprocessor chip used as CPU. Most modern PCs use microprocessor chips manufactured by Intel, AMD (Advanced Micro Devices), or Apple. System configuration of PCs varies depending on their usage. However, the most commonly used configuration consists of a system unit, a monitor (display screen), a keyboard, and a mouse (see Figure 1.7) System unit, in the form of a box, consists of main circuit board (consisting of CPU, memory, etc.), hard disk storage, any special add-on cards (such as network interface card), and ports for connecting peripheral devices such as printer, pen drive, portable disk, etc.

Monitor

Mouse

System Unit Keyboard

Figure 1.7. A personal computer (PC).

System unit of a PC has expansion slots where we can plug in a wide variety of special-function add-on boards (also called add-on cards). These add-on boards contain electronic circuitry for a wide variety of computer-related functions. Number of available expansion slots varies from computer to computer. Some popular add-on boards are: 1. Network Interface Card (NIC). It enables connecting a PC to a network. For example, a user needs an Ethernet card to connect his/her PC to an Ethernet LAN. 2. Fax modem card. It enables transferring of images of hard-copy documents from a PC to a remote computer via telephone lines just as we do using a fax (facsimile) machine. 3. Color and graphics adapter card. It enables interfacing a PC with graphics and/or color video monitor. For example, a user needs a VGA (video graphics array) card to interface his/her PC with a high-resolution monitor. 4. Motion video card. It enables integration of full-motion color video/audio with other output on monitor’s screen. Since it accepts multiple inputs, videos can be shown full-screen (one video input) or in windows (multiple video inputs). System unit of a PC also has I/O ports (both serial and parallel ports) for connecting external I/O or storage devices (such as a printer and other devices external to the system unit box) to the PC in much the same way as you plug electric equipment into an electrical socket.

■ Classification of Computers

13

Popular operating systems for PCs are MS-DOS, MS-Windows (comprising Windows XP, Vista), Linux, and UNIX. Apple’s Macintosh PCs run Apple’s propriety OS called Macintosh OS or Mac OS. These operating systems support multitasking enabling a user to switch between tasks. PCs generally cost from a few tens of thousands to about a lakh of rupees, depending on configuration. Some major PC manufacturers are Lenovo, Apple, Dell, HCL, Siemens, Toshiba, and Hewlett-Packard.

Workstations A workstation is a powerful desktop computer designed to meet computing needs of engineers, architects, and other professionals who need greater processing power, larger storage, and better graphics display facility than what normal PCs provide. For example, users use workstations commonly for computer-aided design (CAD), simulation of complex scientific and engineering problems, visualization of results of simulation, and multimedia applications such as for creating special audio-visual effects in movies or television programs. A workstation is similar to a high-end PC, and typically, only one person uses it at a time (like a PC). Characteristics used to differentiate between the two are: 1. Processing power. Processing power of a workstation is more than that of an average PC. 2. Storage capacity. Workstations have larger main memory (typically few tens of GB) as compared to PCs (typically few GB). Hard disk capacity of a workstation is also much more (typically few TB) as compared to that of PCs (typically few hundreds of GB). 3. Display facility. Most workstations have a large-screen monitor (21 inch or more) capable of displaying high-resolution graphics. PCs normally use monitors having smaller screen (19 inch or less). 4. Processor design. PCs normally use CPUs based on CISC technology, whereas workstations use CPUs based on RISC technology. 5. Operating system. Unlike PCs that run any desktop OS, all workstations generally run server version of Windows, Mac OS, Linux or UNIX operating system. Unlike most operating systems for PCs that are singleuser oriented, operating systems for workstations support multi-user environment, making them suitable for use as a server in network environment. 6. Expansion slots. Workstations usually have more expansion slots than PCs providing greater flexibility of supporting additional functionality. For example, a workstation can have two or more NICs plugged into it to enable it to communicate on two different networks (say, Ethernet and ATM). Workstations generally cost from few lakhs to few tens of lakhs of rupees depending on configuration. Some manufacturers of workstations are Apple, IBM, Dell, and Hewlett-Packard (HP).

Mainframe Systems Several organizations such as banks, insurance companies, hospitals, railways, etc., need on-line processing of large number of transactions, and require computer systems having massive data storage and processing capabilities. Moreover, often a large number of users need to share a common computing facility such as in research groups, educational institutions, engineering firms, etc. Mainframe systems are used for meeting the computing needs of such organizations. Figure 1.8 shows a configuration of a mainframe system. It consists of the following components: 1. Host, front-end, and back-end computers. A mainframe system usually consists of several subordinate computers in addition to the main or host computer. Host computer carries out most computations, and has direct control of all other computers. Other computers relieve the host computer of certain routine processing requirements. For example, a front-end computer handles all communications to/from all user terminals, thus

14

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers relieving host computer of communications-related processing requirements. Similarly, a back-end computer handles all data I/O operations, thus relieving host computer of locating an I/O device and transferring data to/from it. Host and other computers are located in a system room to which entry is restricted to system administrators and maintenance staff only (see Figure 1.8). 2. Console(s). One or more console terminals (located in system room) connect directly to the host computer. System administrators use them to monitor the system’s health, or perform some system administration activities such as changing system configuration, installing new software, taking system backup, etc. 3. Storage devices. For large volume data storage, users connect several magnetic disk drives (located in system room) directly to the back-end computer. Host computer accesses data on these disks via the back-end computer. In addition, there are few tape drives and a magnetic tape library for backup/restoration of data to/from magnetic tapes. System administrators use the tape library (located in system room) to backup data from magnetic disks to magnetic tapes. Tape drives (located in users’ room) enable users to bring their input data on tape for processing, or to take their output data on tape after processing. USERS ROOM (Entry restricted to authorized users) SYSTEM ROOM (Entry restricted to system administrators and maintenance staff) Magnetic tape library Magnetic disk drives Magnetic tape drive

Back-end processor Plotter

Host processor Console

Front-end processor

User terminal

User terminal

User terminal

Figure 1.8. A mainframe system. System room is shaded.

Printer

■ Classification of Computers

15

4. User terminals. User terminals serve as access stations. Users use them to work on the system. Although, the figure shows all user terminals in users’ room, some of them may be located at geographically distributed locations. Since mainframe systems allow multiple users to use the system simultaneously (through user terminals), their operating systems support multiprogramming with timesharing. This enables all users to get good response time, and an illusion that the system is attending to their jobs. 5. Output devices. User terminals also serve the purpose of soft copy output devices. However, for hard copy outputs, there are one or more printers and one or more plotters connected to back-end computer. These output devices are also located in users’ room so that users can easily access them to collect their outputs. Configuration of a mainframe system depends a lot on the type of its usage and the kind of its users. The example of Figure 1.8 is just one possible configuration. A mainframe system looks like a row of large file cabinets, and needs a large room with closely monitored humidity and temperature. It may cost anywhere from few tens of lakhs to few crores of rupees depending on configuration. Mainframe systems having smaller configuration (slower host and subordinate computers, lesser storage space, and fewer user terminals) are known as minicomputers, but there is no well-defined boundary for differentiating between the two. Two major vendors of mainframe systems are IBM and Fujitsu.

Supercomputers Supercomputers are the most powerful and expensive computers available at any given time. Users use them primarily for processing complex scientific applications requiring enormous processing power. Scientists often build models of complex processes and simulate them on a supercomputer. For example, in nuclear fission, when a fissionable material approaches a critical mass, scientists may want to know exactly what will happen during every millisecond of a nuclear chain reaction. Such scientists use a supercomputer to model actions and reactions of literally millions of atoms as they react. A scientific application like this involves manipulation of a complex mathematical model, often requiring processing of trillions of operations in a reasonable time, necessitating use of a supercomputer. Some supercomputing applications (applications that need supercomputers for processing) are: 1. Petroleum industry uses supercomputers to analyze volumes of seismic data gathered during oil-seeking explorations to identify areas where there is possibility of getting petroleum products inside the earth. This helps in more detailed imaging of underground geological structures so that expensive resources for drilling and extraction of petroleum products from oil wells can be effectively channelized to areas where analysis results show better possibility of getting petroleum deposits. 2. Aerospace industry uses supercomputers to simulate airflow around an aircraft at different speeds and altitude. This helps in producing effective aerodynamic designs to develop aircrafts with superior performance. 3. Automobile industry uses supercomputers to do crash simulation of an automobile design before releasing it for manufacturing. Doing so is less expensive, more revealing, and safer than crashing a real model. This helps in producing better automobiles that are safer to ride. 4. Structural mechanics industry uses supercomputers to solve complex structural engineering problems that designers of various types of civil and mechanical structures need to deal with to ensure safety, reliability, and cost effectiveness. For example, designer of a large bridge has to ensure that the bridge must work in various atmospheric conditions and pressures from wind velocity, etc., and under different load conditions. Actual construction and testing of such expensive structures is prohibitive in most cases. Using mathematical modeling techniques, various combinations can be tried out on a supercomputer without going for actual construction/manufacturing of such structures and optimum design can be picked up for final implementation. 5. Meteorological centers use supercomputers for weather forecasting. They feed weather data, supplied by a worldwide network of space satellites, airplanes, and ground stations, to a supercomputer. The supercomputer analyzes the data using a series of computer programs to arrive at forecasts. This analysis involves solving of complex mathematical equations modeling atmosphere and climate processes. For example, in India, the

16

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers National Center for Medium Range Weather Forecasting (NCMRWF), located in New Delhi, uses supercomputer for medium range weather forecasts that is crucial for Indian agriculture. 6. Material scientists and physicists use supercomputers to design new materials. Nanostructure technology requires microscopic investigation of mechanical, electrical, optical, and structural properties of materials having dimensions of the order of nanometer. For this, scientists need to simulate nano-scale materials like clusters of atoms, quantum dots, quantum wires, etc. using principles of molecular dynamics technique. Such simulations are compute-intensive as they combine complexity of molecular dynamics and electronic structure. Hence, they need supercomputers to complete them in a reasonable time. 7. Film and TV industries use supercomputers to create special effects for movies and TV programs. Supercomputers help in producing computer-generated images using advanced graphics features in a short time. Movies or TV programs incorporate the produced images in them to create special effects. Thus, supercomputers substantially reduce the time needed to produce a full-length feature film having several special effects.

Supercomputers use multiprocessing and parallel processing technologies to solve complex problems faster. That is, they use multiple processors, and parallel processing enables dividing a complex problem into smaller problems that different processors can process in parallel. A parallel program breaks up a problem into smaller computational modules so that different processors can work independently and cooperate to solve it faster. Hence, if the problem takes 100 hours to process on a single-processor system and if it can be broken into 100 smaller computational modules, a supercomputer having 100 processors can theoretically solve it in about one hour. Since modern supercomputers use parallel processing technology, they are also known as parallel computers or parallel processing systems. They are also known as massively parallel processors because they use thousands of processors. We measure speed of modern supercomputers in teraflops and petaflops. A teraflop is 10 12 floating-point arithmetic operations per second and a petaflop is 1015 floating-point arithmetic operations per second. A supercomputer, due to its specialized nature and huge cost, is often treated as a national resource that is shared by several academic and research organizations. For developing countries, it is not economically viable to have many such systems because of the cost involved in setting up a supercomputing facility, maintaining the facility, and fast obsolescence of technology. Major vendors of supercomputers include Cray Research Company, IBM, Silicon Graphics, Fujitsu, NEC, Hitachi, Hewlett-Packard, and Intel. Realizing the importance of supercomputers in a country’s overall progress, national effort to build indigenous supercomputers has been underway in India. Development of PARAM series of supercomputers by the Centre for Development of Advanced Computing (C-DAC), Anupam series of supercomputers

Figure 1.9. C-DAC’s PARAM Padma supercomputer [reproduced with permission from C-DAC].

■ Classification of Computers

17

by the Bhabha Atomic Research Centre (BARC), and PACE series of supercomputers by the Defence Research and Development Organization (DRDO), Hyderabad are results of this effort. Figure 1.9 shows the PARAM Padma supercomputer (one of the PARAM systems) developed by C-DAC. Cost of a supercomputer may range from few tens of lakhs to few hundreds of crores of rupees depending on configuration.

Client and Server Computers With increased popularity of computer networks, it became possible to interconnect several computers that can communicate with each other over a network. In such a computing environment, multiple users can share several resources/services for cost-effective usage. Moreover, the shared resources/services can be best managed/offered centrally. A few examples of such resources/services are: 1. File server. It provides a central storage facility to store files of several users on a network. 2. Database server. It manages a centralized database, and enables several users on a network to have shared access to the same database. 3. Print server. It manages one or more printers, and accepts and processes print requests from any user in a network. 4. Name server. It translates names into network addresses enabling different computers on a network to communicate with each other. In these cases, it is usual to have one process that “owns” a resource or service and is in charge of managing it. This process accepts requests from other processes that want to use the resource or service. The process that owns the resource and does this management is called a server process, and the computer on which the server process runs is called a server computer because it services requests for use of the resource. Other processes that send service requests to the server are called client processes, and computers on which client processes run are called client computers. Note that there may be multiple client computers sending service requests to the same server computer. Figure 1.10 shows a generic client-server computing environment. It is comprised of the following entities: 1. Client. A client is generally a single-user system (laptop, PC, workstation, or hand-held computer) that provides user-friendly interface to end users. It runs client processes that send service requests to a server. Generally, there are multiple clients in a client-server computing environment and each client has its own system-specific user interface for allowing users to interface with the system. 2. Server. A server is a relatively powerful system (workstation, mainframe, or supercomputer) that manages a shared resource and/or provides a set of shared user services to clients. It runs a server process that services client requests for use of the shared resource managed by the server. Hence, a server’s operating system has features to handle multiple client-requests simultaneously. Servers are headless machines not having monitor, keyboard, and mouse attached to them as users do not directly interact with them and use them over network. 3. Network. A network interconnects all clients and servers of a client-server computing environment. It may be a LAN, WAN, or an Internet of networks. A set of computers interconnected together to form a client-server computing environment is collectively known as a distributed computing system or distributed system. Client-server computing involves splitting an application into tasks and putting each task on a computer, which can handle it most efficiently. This usually means putting processing for presentation on user’s machine (the client) and data management and storage on a server. Depending on the application and software used, all data processing may occur on client or be split between client and server. Server software accepts a request for service from a client and returns the results of processing that request to the client. The client then manipulates the received results and presents it in proper format to the end user.

18

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

Notice that in client-server computing, the central idea is allocation of application-level tasks between clients and servers. Computers and operating systems of a client and server may be different. For example, a client may be a PC running MS-Windows OS, whereas a server may be a mainframe system running UNIX OS. In fact, a client-server computing environment may have several different types of client computers with different operating systems and several different types of server computers with different operating systems. As long as a client and server share a common communication protocol and support the same applications, these lower-level differences are irrelevant. The communication protocol enables a client and server to inter-operate even when they are different types of computers running different operating systems. One such standard communication protocol is TCP/IP. In client-server computing environment, it is common for a server to use services of another server, and hence, be both a client and a server at the same time. For example, let us assume that a client-server computing environment has clients, a file server, and a disk block server. Any client can send a file access request to the file server. On receiving such a request, the file server checks access rights, etc. of the user making the request. However, instead of reading/writing the file blocks itself; it sends a request to the disk block server for accessing requested data blocks. Disk block server returns requested data blocks to the file server, which then extracts the desired data from the data blocks and returns it to the client. In this scenario, the file server is both a server and a client. It is a server for clients, but a client for the disk block server. Hence, the concept of client and server computers is purely role-based, and may change dynamically as the role of a computer changes.

PC (Client) File server

PC (Client) LAN or WAN or an Internet of Networks PC (Client)

Database server

Workstation (Client) Workstation (Client) Figure 1.10. A generic client-server computing environment.

Handheld Computers A handheld computer, or simply handheld, is a small computing device that can be used by holding in hand (need not be kept on a table or lap to be operated). Obviously, its size, weight, and design are such that a user can use it by holding it in hand. It is also known as palmtop because it can be kept on palm and operated. Handheld computers are computing devices of choice for people requiring computing power anytime, anywhere. There are many types of handheld computers available today. Some popular ones are described here.

Tablet PC A tablet PC is a miniaturized laptop. It usually provides all features of a laptop with the following differences or enhancements:

■ Classification of Computers

19

1. Light weight. A tablet PC is much lighter than a laptop. For weight reduction, their designers remove from their basic structure a few infrequently used devices and provide them as separate add on. 2. Screen flip. A user can rotate, turn around, and flip the screen of a tablet PC over the keyboard area. When a user flips the screen over the keyboard, it hides the keyboard and leaves only the screen visible and usable. In this configuration, the user holds the tablet PC in hand and uses it as digital tablet. The display on the screen shows the content in portrait mode in this configuration (from normal landscape layout mode when using keyboard). 3. Handwriting recognition. Usually, a tablet PC comes with a specially designed pen that a user can use to write directly on the screen. Underlying OS translates the pen movements to smooth plot lines that running application can understand as handwritten input. 4. Voice recognition. Usually, tablet PCs have voice recognition feature that allows voice input capable applications to accept audio/voice commands. This feature also enables input of voice data. 5. Special design for tablet use. When a user flips the screen in tablet mode, he/she cannot use the keyboard because the screen hides it. Apart from voice and handwriting recognition, some quick access hardware keys and some on-screen programmable software keys are present. A user can use these keys to invoke predefined actions that he/she cannot make with pen, or finds it difficult to make with pen.

PDA/Pocket PC Personal Digital Assistant (PDA) was originally introduced as a Personal Information Manager (PIM) device. PIM features include contact list, calendar, task list, e-mail, pocket word-processing application, pocket spreadsheet application, presentation viewer, and host of other applications that come in handy while on the move. PDA has a decent size LCD touch screen with a pen for handwriting recognition. It usually has a PC based synchronization utility that a user can use to transfer and synchronize identified data between PC and PDA. With add-on memory cards, a user can increase its storage as required. Some PDAs also provide USB extension port, which a user can use to connect to external devices for extended features like external monitor, LCD Projector, etc. Almost all PDAs have some digital camera capability as well. Newer PDAs also pack network capability using WiFi, Bluetooth, etc. Due to network connectivity option, PDAs have applications in many domains such as medicine, teaching/training, data collection, sports, and Global Positioning System (GPS) based location and route finder. Several PDAs also provide GSM/GPRS service connectivity and, thus, their users can use them as phone for making and receiving cell phone calls, SMS, etc. PDAs come with several options of operating systems ranging from MS-Windows Mobile, iOS, PalmOS, SymbianOS, Linux, Blackberry OS, etc.

Smartphone Smartphone is a fully functional mobile phone with computing power. The major distinction between a PDA and a smartphone is that while PDA is mostly a computing platform like PC with optional phone capability, smartphone is a cell phone with PDA-like capability. In essence, smartphone is voice centric whereas, PDA is data centric. Normally, smartphones are smaller than PDAs. A user can use a smartphone with one hand, whereas PDAs usually require both hands for operation. Figure 1.11 shows samples of some handheld computers.

20

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

(a) Tablet PC

(b) PDA/Pocket PC

(c) Smartphone

Figure 1.11. Samples of handheld computers.

Points to Remember 1.

A computer is a fast calculating device. It is also known as a data processor because it can store, process, and retrieve data whenever desired.

2.

The activity of processing data using a computer is called data processing. Data is raw material used as input to data processing and information is processed data obtained as output of data processing.

3.

Key characteristics of computers are: automatic, speed, accuracy, diligence, versatility, memory, lack of intelligence, and lack of feelings.

4.

Charles Babbage is considered the father of modern digital programmable computers.

5.

Some of the well-known early computers are: MARK I (1937-44), ABC (1939-42), ENIAC (1943-46), EDVAC (1946-52), EDSAC (1947-49), UNIVAC I (1951), IBM-701 (1952), and IBM-650 (1953).

6.

Dr. John Von Neumann introduced the “stored program” concept that considerably influenced the development of modern digital computers. Due to this feature, we often refer to modern digital computers as stored program digital computers.

7.

“Generation” in computer talk provides a framework for the growth of computer industry based on key technologies developed. Originally, it was used to distinguish between hardware technologies but was later extended to include both hardware and software technologies.

8.

Till date, there are five computer generations – first, second, third, fourth, and fifth.

9.

Figure 1.5 summarizes the key hardware and software technologies and key characteristics of computers of five computer generations.

10. Traditionally, computers were classified as microcomputers, minicomputers, mainframes, and supercomputers based on their size, processing speed, and cost. However, with rapidly changing technology this classification is no longer relevant. 11. Today, computers are classified based on their mode of use. According to this classification, computers are classified as notebook computers, personal computers, workstations, mainframe systems, supercomputers, client and server computers, and handheld computers. 12. Notebook computers (or Laptops) are portable computers that are small enough to fit inside a briefcase, light enough to carry around easily, and operate with chargeable batteries so that users can use them even at places with no external power source available. They normally run MS-DOS, MS-WINDOWS, Mac OS or Linux operating system. Users use them commonly for word processing, spreadsheet computing, data entry, Internet browsing, accessing and sending e-mails, and preparing presentation materials while a person is travelling. 13. A personal computer is a non-portable, general-purpose computer that fits on a normal size office table, and only one person uses it at a time. PCs meet personal computing needs of individuals either at their work places or at their homes. They normally run MS-DOS, MS-Windows (comprising Windows XP, Vista), Mac OS, Linux, or UNIX operating system, and support multitasking enabling a user to switch between tasks. 14. A workstation is a powerful desktop computer designed to meet computing needs of engineers, architects, and other professionals, who need greater processing power, larger storage, and better graphics display facility than what normal PCs



Questions

21

provide. Users use workstations commonly for computer-aided design, multimedia applications, simulation of complex scientific and engineering problems, and visualization of results of simulation. Workstations generally run server version of Windows, Mac OS, Linux or UNIX operating system and support multi-user environment. 15. Mainframe systems are used for meeting the computing needs of mid to large size organizations such as banks, insurance companies, hospitals, railways, etc. They are also used in such environments where a large number of users need to share a common computing facility such as in research groups, educational institutions, engineering firms, etc. A typical configuration of a mainframe system consists of a host computer, a front-end computer, a back-end computer, one or more console terminals, several magnetic disk drives, a few tape drives, a magnetic tape library, several user terminals, several printers, and one or more plotters. Mainframe systems having smaller configuration (slower host and subordinate computers, lesser storage space, and fewer user terminals) are known as minicomputers. 16. Supercomputers are the most powerful and expensive computers available at any given time. Users use them primarily for processing complex scientific applications requiring enormous processing power. Some supercomputing applications are analysis of large volumes of seismic data, simulation of airflow around an aircraft, crash simulation of an automobile design, solving complex structural engineering problems, genome sequence analysis in bioinformatics, design of new materials, creation of special effects in movies, and weather forecasting. 17. Modern supercomputers use multiprocessing and parallel processing technologies to solve complex problems faster, and hence, they are also known as parallel computers or parallel processing systems. They are also known as massively parallel processors because they use thousands of processors. 18. A handheld computer is a device whose size, weight, and design are such that a user can use it by holding it in hand. It is also known as palmtop because it can be kept on palm and operated. Some popular handheld computers are tablet PC, PDA/Pocket PC, and smartphone. 19. In client-server computing environment, a client is generally a single-user system that provides user-friendly interface to end users. It runs client processes that send service requests to a server. A server is a relatively powerful system that manages a shared resource and/or provides a set of shared user services to the clients. It runs a server process that services client requests for use of the shared resource managed by it. 20. A set of computers interconnected together to form a client-server computing environment is collectively known as a distributed computing system or distributed system. 21. Client-server computing involves splitting an application into tasks and putting each task on a computer, which can handle it most efficiently. Computers and operating systems of a client and server may be different. As long as a client and server share a common communication protocol and support the same applications, these lower-level differences are irrelevant. 22. In a client-server computing environment, it is common for one server to use the services of another server, and hence, be both a client and a server at the same time. Hence, the concept of client and server computers is purely role-based and may change dynamically as the role of a computer changes.

Questions 1.

What is a computer? Why it is also known as a data processor?

2.

What is data processing? Differentiate between data and information. Which is more useful to people and why?

3.

List and explain some important characteristics of a computer.

4.

Who is known as the father of modern digital programmable computers and why?

5.

Who invented the concept of stored program? Why is this concept so important?

6.

What is “generation” in computer terminology? List various computer generations along with key characteristics of computers of each generation.

7.

List the key hardware technologies used in building computers of each of the five generations.

8.

List the key software technologies used in building computers of each of the five generations.

9.

What are the advantages of transistors over vacuum tubes?

10.

What is an IC? How it helps in reducing the size of computers?

22

Chapter 1 ■ Characteristics, Evolution, and Classification of Computers

11.

List the advantages of IC technology over transistor technology.

12.

Why were first- and second-generation computers more difficult and costlier to produce commercially than computers of subsequent generations?

13.

List the technologies used for constructing main memory in first-, second-, third-, and fourth-generation computers.

14.

List the secondary storage media popularly used in first-, second-, third-, fourth-, and firth-generation computers.

15.

Which key feature of third generation computers made them a highly productive tool for programmers and why?

16.

Why was it not possible to take a program written for one computer and run it on another computer in the first and secondgeneration computers?

17.

In what ways did the concept of unbundling of software from hardware affect computer manufacturers and users of computers?

18.

What new types of computer applications emerged during third, fourth, and fifth computer generations and what were the main driving technologies behind each?

19.

What is meant by backward compatible family of computers? How is this concept useful for computer users?

20.

What is a microprocessor? How it revolutionized the computer industry?

21.

Name two new types of computers, which became popular during fourth and fifth computer generations.

22.

List some applications that emerged due to emergence of computer networks.

23.

List some applications that emerged due to emergence of the Internet.

24.

List some representative computer systems of each of the five computer generations.

25.

List the parameters that were used traditionally to classify computers. What major types of computers were there based on this classification scheme? Why this classification scheme is no longer relevant?

26.

Write the basis on which computers are classified today. What major types of computers are there based on this classification scheme?

27.

What is a notebook computer? Why it is so called? What are its main uses?

28.

What is a laptop PC? Why it is so called? Describe a typical configuration of a laptop PC.

29.

What is a docking station? Why it is used?

30.

What operating systems do notebook computers normally use?

31.

What features make a notebook computer portable?

32.

What is a personal computer? What are its main uses?

33.

Describe a typical configuration of a PC.

34.

How are a microprocessor, a motherboard, and a personal computer related?

35.

What is an expansion slot? How it is useful for a buyer of a PC?

36.

What is an add-on card? List four functional enhancements possible by inserting one or more add-on cards into expansion slots of a PC.

37.

What operating systems do PCs normally use?

38.

What is a workstation? What are its common uses?

39.

Write the major differences between a PC and a workstation.

40.

What operating systems do workstations normally use?

41.

What is a mainframe system? What are its main uses?

42.

Describe a typical configuration of a mainframe system.

43.

Differentiate among host, front-end, and back-end computers of a mainframe system.

44.

What is the purpose of a console in a mainframe system?

■ 45.

What various types of storage devices are used normally in a mainframe system?

46.

What various types of input/output devices are used normally in a mainframe system?

Questions

47.

What is a minicomputer system?

48.

Describe how subordinate computers of a mainframe system help in improving overall performance of the system.

49.

What is a supercomputer? What are its main uses?

50.

Write examples of at least three supercomputing applications. Explain why these applications require a supercomputer.

51.

Explain two key technologies that modern supercomputers employ for solving complex problems faster.

52.

What is parallel processing? Explain with an example how parallel processing can help solve a complex problem faster.

53.

Why modern supercomputers are also known as massively parallel processors?

54.

What is the main difference between a supercomputer and a mainframe system?

55.

Write the main components of a client-server computing environment. Describe the roles of each component.

56.

Write three examples of resources/services that can be handled by a server in a client-server computing environment.

57.

What is a palmtop? Why it is so called?

23

58.

What is a tablet PC? How it is different from a laptop? List the features supported in a tablet PC.

59.

What is a Personal Digital Assistant (PDA)? What are its main uses? List the features supported in a PDA.

60.

What is a smartphone? What is the major distinction between a PDA and a smartphone?

61.

In a client-server computing environment, is it possible for a computer to be both a client and a server at the same time? If no, explain why. If yes, write an example of such a scenario.

62.

List the key desirable features of an operating system for each of the following types of computers: (a) (b) (c) (d)

Workstations Supercomputers Client computers Server computers

(e) Notebook computers (f) Personal computers (g) Mainframe systems

Internal Data Representation in Computers

In this chapter, you will learn how computers internally represent data, and how they perform various basic operations (comparison, sorting, addition, subtraction, multiplication, division, etc.) on these data. The chapter first explains the fundamental concepts of number system and introduces some number systems commonly used by computer professionals and relationship among them. It then presents the commonly used coding schemes to record data in computers. It finally explains how computers perform various basic operations internally.

NUMBER SYSTEMS USED IN COMPUTERS Number systems are of two types – non-positional and positional. In non-positional number system, we have symbols such as I for 1, II for 2, III for 3, IIII for 4, IIIII for 5, etc. Each symbol represents the same value regardless of its position in a number, and to find the value of a number, one has to count the number of symbols present in the number. Since it is difficult to perform arithmetic with such a number system, positional number systems were developed. In a positional number system, there are only a few symbols called digits. These symbols represent different values, depending on the position they occupy in a number. The following three considerations determine the value of each digit in such a number: 1. The digit itself, 2. The position of the digit in the number, and 3. The base of the number system. Base is defined as the total number of digits in the number system. The first digit is always zero. Hence, the maximum value of a single digit is always equal to one less than the value of the base.

■ Number Systems Used in Computers

25

As an illustration, let us consider decimal number system that we use in our day-to-day life. In this system, base is equal to 10 because there are ten symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9). Each position represents a specific power of the base (10). For example, decimal number 2586 (written as 2586 10) consists of digit 6 in unit position, 8 in tens position, 5 in hundreds position, and 2 in thousands position, and its value can be written as: (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100) = 2000 + 500 + 80 + 6 = 2586 Observe that the same digit signifies different values, depending on the position it occupies in the number. For example, In 258610 the digit 6 signifies 6 x 100 = 6 In 256810 the digit 6 signifies 6 x 101 = 60 In 265810 the digit 6 signifies 6 x 102 = 600 In 625810 the digit 6 signifies 6 x 103 = 6000 Hence, we can represent any number by using the available digits and arranging them in various positions. The principles that apply to decimal number system, also apply to any other positional number system. It is important to keep track of only the base of the number system in which we are working. Below, we illustrate this for some positional number systems used in computer design and by computer professionals.

Binary Number System In binary number system, the value of base is 2. Hence, it has only two symbols or digits (0 and 1), the largest single digit being 1 (one less than the base). Each position in a binary number represents a power of the base (2). Hence, in this system, the rightmost position is units (2 0) position, the second position from the right is 2’s (2 1) position, and proceeding in this way, we have 4’s (22) position, 8’s (23) position, 16’s (24) position, and so on. Therefore, decimal equivalent of binary number 10101 (written as 101012) is: (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20) = 16 + 0 + 4 + 0 + 1 = 21 To be specific about which system we are referring to, it is a common practice to indicate the base as a subscript. Hence, we write: 101012 = 2110 Bit is the short form of “binary digit”. Hence, a “bit” in computer terminology means either a 0 or 1. An n-bit number is a binary number consisting of ‘n’ bits. Any decimal number in the range 0 to 2n-1 can be represented in binary form as an n-bit number. Figure 2.1 lists all 3-bit numbers (total = 8 = 23) along with their decimal equivalent.

Binary

Decimal equivalent

000 001 010 011 100 101 110 111

0 1 2 3 4 5 6 7

Figure 2.1. 3-bit numbers with their decimal values.

Every computer stores numbers, letters, and other special characters in binary form. Computer professionals need to know raw data contents of a computer’s memory on several occasions. A commonly used way of doing this is to print/display raw memory contents, which is called memory dump. Working with memory dumps in binary form would be difficult and error prone for computer professionals. Hence, computer professionals often use octal and hexadecimal number systems, as shortcut notations for binary. They are described here.

26

Chapter 2 ■ Internal Data Representation in Computers

Octal Number System In octal number system, the base is 8. Hence, there are only eight symbols or digits: 0, 1, 2, 3, 4, 5, 6, and 7 (8 and 9 do not exist in this system). The largest single digit is 7 (one less than the base 8). Each position in an octal number represents a power of the base (8). Therefore, decimal equivalent of octal number 2057 (written as 2057 8) is: (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80) = 1024 + 0 + 40 + 7 = 1071 Hence, 20578 = 107110 Since there are only 8 digits in octal number system, 3 bits (2 3 = 8) are sufficient to represent any octal number in binary (see Figure 2.1).

Hexadecimal Number System In hexadecimal number system, the base is 16. Hence, there are 16 symbols or digits. The first 10 digits are the same digits of decimal number system – 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The remaining six digits are the symbols A, B, C, D, E, and F, representing decimal values 10, 11, 12, 13, 14, and 15, respectively. Hence, the largest single digit is F or 15 (one less than the base 16). Each position in hexadecimal number system represents a power of the base (16). Therefore, decimal equivalent of hexadecimal number 1AF (written as 1AF 16) is: (1 x 162) + (A x 161) + (F x 160) = (1 x 256) + (10 x 16) + (15 x 1) = 256 +160 + 15 = 431 Hence, 1AF16 = 43110 Since there are only 16 digits in hexadecimal number system, 4 bits (2 4 = 16) are sufficient to represent any hexadecimal number in binary.

CONVERTING FROM ONE NUMBER SYSTEM TO ANOTHER Input data fed to computers and final output values are to be in decimal because decimal numbers are more meaningful to us than are numbers expressed in any other number system. Hence, computer professionals are often required to convert numbers in other number systems to decimal and vice-versa. They use various methods to convert numbers from one base to another. A method of converting from another base to decimal, and a method of converting from decimal to another base are described here.

Converting from Another Base to Decimal We use the following steps to convert a number in any other base to a base 10 (decimal) number: Step 1: Determine the column (positional) value of each position of the digit and the base of the number system).

digit

(this

depends

Step 2: Multiply the obtained column values (in Step 1) by the digits in the corresponding columns. Step 3: Sum up the products calculated in Step 2. The total is the equivalent value in decimal.

on

the

■ Converting from One Number System to Another

Example 2.1.

Example 2.2.

110012 = ?10

47068 = ?10

Solution:

Solution:

Step 1: Determine column values

Step 1: Determine column values

Column Number Column Value (from right) 20 = 1 21 = 2 22 = 4 23 = 8 24 = 16

1 2 3 4 5

Step 2: Multiply the column values by the corresponding column digits 16 x1

8 x1

16

8

Column Number Column Value (from right)

Step 2: Multiply column values by the corresponding column digits 512 x4

64 x7

8 x0

1 x6

2048 448

0

6

4 2 1 x0 x0 x1 0

0

80 = 1 81 = 8 82 = 64 83 = 512

1 2 3 4

1 Step 3: Sum up the products

Step 3: Sum up the products 16 + 8 + 0 + 0 + 1 = 25

2048 + 448 + 0 + 6 = 2502 Hence, 47068 = 250210

Hence, 110012 = 2510

Example 2.3. 1AC16 = ?10 Solution: 1AC16 = 1 x 162 + A x 161 + C x 160 = 1 x 256 + 10 x 16 + 12 x 1 = 256 + 160 + 12 = 42810

Example 2.5. 40526 = ?10 Solution: 40526 = 4 x 63 + 0 x 62 + 5 x 61 + 2 x 60 = 4 x 216 + 0 x 36 + 5 x 6 + 2 x 1 = 864 + 0 + 30 + 2 = 89610

Example 2.4. 40527 = ?10 Solution: 40527 = 4 x 73 + 0 x 72 + 5 x 71 + 2 x 70 = 4 x 343 + 0 x 49 + 5 x 7 + 2 x 1 = 1372 + 0 + 35 + 2 = 140910

Comparing this result with the result obtained in Example 2.4, we find that although the digits (4052) are same for both the numbers, their decimal equivalents are different. This is because the number in Example 2.4 is in base 7 number system, whereas the number in Example 2.5 is in base 6 number system.

27

28

Chapter 2 ■ Internal Data Representation in Computers

Converting Technique)

from

Decimal

to

Another

Base

(Division-Remainder

We use the following steps to convert a base 10 (decimal) number to a number in another base: Step 1: Divide the decimal number by the value of the new base. Step 2: Record the remainder from Step 1 as the rightmost digit (least significant digit) of the new base number. Step 3: Divide the quotient of the previous division by the new base. Step 4: Record the remainder from Step 3 as the next digit (to the left) of the new base number. Example 2.6. 2510 = ?2 Solution: Steps 1 and 2: Steps 3 and 4: Steps 3 and 4: Steps 3 and 4: Steps 3 and 4:

25/2 = 12 and remainder 1 12/2 = 6 and remainder 0 6/2 = 3 and remainder 0 3/2 = 1 and remainder 1 1/2 = 0 and remainder 1

As mentioned in Steps 2 and 4, we now arrange the remainders in reverse order, making the first remainder the least significant digit (LSD) and the last remainder the most significant digit (MSD). Hence, 2510 = 110012 Compare the result with the result obtained in Example 2.1. Repeat Steps 3 and 4, recording remainders from right to left, until the quotient becomes zero in Step 3. Note that the last remainder, thus obtained, will be the most significant digit of the new base number. Example 2.7.

Example 2.8.

4210 = ?2

95210 = ?8

Solution: 2

Solution: 42

Remainders

8

952

Remainders

21

0

119

0

10

1

14

7

5

0

1

6

2

1

0

1

1

0

0

1

Hence, 4210 = 1010102

Hence, 95210 = 16708

■ Converting from One Number System to Another Example 2.9.

Example 2.10.

42810 = ?16

10010 = ?5

Solution: 16

29

428

Remainders in hexadecimal

Solution: 5

100

Remainders

26

12 = C

20

0

1

10 = A

4

0

0

1=1

0

4

Hence, 42810 = 1AC16

Hence, 10010 = 4005

Compare the result with the result obtained in Example 2.3.

Converting from a Base Other Than 10 to Another Base Other Than 10 We use the following steps to convert a number in a base other than 10, to a number in another base other than 10: Step 1: Convert the original number to a base 10 (decimal) number. Step 2: Convert the decimal number obtained in Step 1 to the new base number. Example 2.11.

Example 2.12.

5456 = ?4

1011102 = ?8

Solution:

Solution:

Step 1: Convert from base 6 to base 10 2

1

545 = 5 x 6 + 4 x 6 + 5 x 6 = 5 x 36 + 4 x 6 + 5 x 1 = 180 + 24 + 5 = 20910

0

1011102 = 1 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 1 x 2 1 + 0 x 2 0 = 32 + 0 + 8 + 4 + 2 + 0 = 4610 Step 2: Convert 4610 to base 8

Step 2: Convert 20910 to base 4 4

Step 1: Convert 1011102 to base 10

209

Remainders

52

8

46

Remainders

1

5

6

13

0

0

5

3

1

0

3 4610 = 568

20910 = 31014

Therefore, 1011102 = 4610 = 568

Therefore, 5456 = 20910 = 31014

Hence, 1011102 = 568

Hence, 5456 = 31014

30

Chapter 2 ■ Internal Data Representation in Computers

Example 2.13. 110100112 = ?16 Solution: Step 1: Convert 110100112 to base 10 110100112 = 1 x 27 + 1 x 26 + 0 x 25 + 1 x 24 + 0 x 23 + 0 x 22 + 1 x 2 1 + 1 x 20 = 1 x 128 + 1 x 64 + 0 x 32 + 1 x 16 + 0 x 8 + 0 x 4 + 1x2+1x1 = 128 + 64 + 0 + 16 + 0 + 0 + 2 + 1 = 21110 Step 2: Convert 21110 to base 16 16

Remainders

211 13

3 = 3 in Hexadecimal

0

13 = D in Hexadecimal

Therefore, 110100112 = 21110 = D316 Hence, 110100112 = D316 Example 2.12 illustrates the method of converting a binary number to an octal number. Similarly, Example 2.13 shows how to convert a binary number to a hexadecimal number. However, these are lengthy procedures and we can use shortcut methods when we desire such conversions. These shortcut methods are described here.

Shortcut Method for Binary to Octal Conversion We use the following steps in this method: Step 1: Divide the binary digits into groups of three (starting from the right). Step 2: Convert each group of three binary digits to one octal digit. Since there are only 8 digits (0 to 7) in octal number system (refer to Figure 2.1), 3 bits (2 3 = 8) are sufficient to represent any octal number in binary. Moreover, since decimal digits 0 to 7 are equal to the octal digits 0 to 7, we use binary to decimal conversion method in this step.

■ Converting from One Number System to Another

Example 2.14. 1011102 = ?8 Solution: Step 1: Divide the binary digits into groups of 3, starting from right (LSD). 101

110

Step 2: Convert each group into one digit of octal (use binary-to-decimal conversion method). 1012 = 1 x 22 + 0 x 21 + 1 x 20 =4+0+1 = 58

1102 = 1 x 22 + 1 x 21 + 0 x 20 =4+2+0 = 68

Hence, 1011102 = 568 Compare the result with the result obtained in Example 2.12.

Example 2.15. 11010102 = ?8 Solution: 11010102 = 001

101

010 (Group of 3 digits from right)

= 1528 (Convert each group to an octal digit) Hence, 11010102 = 1528

Shortcut Method for Octal to Binary Conversion We use the following steps in this method: Step 1: Convert each octal digit to a 3 digit binary number (the octal digits may be treated as decimal numbers for this conversion). Step 2:

Combine all the resulting binary groups (of 3 digits each) into a single binary number.

31

32

Chapter 2 ■ Internal Data Representation in Computers

Example 2.16.

Example 2.17.

5628 = ?2 Solution:

67518 = ?2 Solution: 67518 = 110 111 101 001 6 7 5 1 = 1101111010012

Step 1: Convert each octal digit to 3 binary digits. 58 = 1012 68 = 1102 28 = 0102

Hence, 67518 = 1101111010012

Step 2: Combine the binary groups. 5628 = 101 110 010 5 6 2 Hence, 5628 = 1011100102

Shortcut Method for Binary to Hexadecimal Conversion We use the following steps in this method: Step 1: Divide the binary digits into groups of four (starting from the right). Step 2: Convert each group of four binary digits to one hexadecimal digit. Remember that hexadecimal digits 0 to 9 are equal to decimal digits 0 to 9 and hexadecimal digits A to F are equal to decimal values 10 to 15. Hence, for this step, we use binary to decimal conversion procedure and represent decimal values 10 to 15 as hexadecimal A to F. Example 2.18. 110100112 = ?16 Solution: Step 1: Divide the binary digits into groups of 4, starting from the right (LSD). 1101 0011 Step 2: Convert each group of 4 binary digits to 1 hexadecimal digit. 11012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 =8+4+0+1 = 1310 = D16

00112 = 0 x 23 + 0 x 22 + 1 x 21 + 1 x 20 =0+0+2+1 = 316

Hence, 110100112 = D316 Compare the result with the result of Example 2.13.

■ Converting from One Number System to Another Example 2.19. 101101011002 = ?16 Solution: 101101011002 = 0101

1010

1100 (Group 4 digits from right)

= 5AC (Convert each group to a hexadecimal digit) Hence, 101101011002 = 5AC16

Shortcut Method for Hexadecimal to Binary Conversion We use the following steps in this method: Step 1: Convert decimal equivalent of each hexadecimal digit to 4 binary digits. Step 2: Combine all resulting binary groups (of 4 digits each) into a single binary number. Example 2.20.

Example 2.21.

2AB16 = ?2

ABC16 = ?2

Solution: Step 1: Convert the decimal equivalent of each hexadecimal digit to 4 binary digits. 216 = 210 = 00102 A16 = 1010 = 10102 B16 = 1110 = 10112 Step 2: Combine the binary groups. 2AB16 = 0010 1010 1011 2 A B Hence, 2AB16 = 0010101010112

Solution: ABC16 = 1010 1011 1100 A B C = 1010101111002 Hence, ABC16 = 1010101111002

33

34

Chapter 2 ■ Internal Data Representation in Computers

Figure 2.2 summarizes the relationship among decimal, hexadecimal, binary, and octal number systems. Note that the maximum value of a single digit of octal (7) is equal to the maximum value of three digits of binary. Hence, the value range of one digit of octal is equivalent to the value range of three digits of binary. Therefore, octal shortcut notation is a one-to-three reduction in space and time required for memory dump. Similarly, hexadecimal shortcut notation is a one-to-four reduction in space and time required for memory dump because the maximum value of one digit in hexadecimal (F) is equal to the maximum value of four digits in binary.

Decimal

Hexadecimal

Binary

Octal

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

0 1 2 3 4 5 6 7 8 9 A B C D E F 10

0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000

0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20

Figure 2.2. Relationship among Decimal, Hexadecimal, Binary, and Octal number systems.

FRACTIONAL NUMBERS In binary number system, fractional numbers are formed in the same way as in decimal number system. For example, in decimal number system, 0.235 = (2 x 10-1) + (3 x 10-2) + (5 x 10-3)

and

68.53 = (6 x 101) + (8 x 100) + (5 x 10-1) + (3 x 10-2)

and

10.01

Similarly, in binary number system, 0.101 = (1 x 2-1) + (0 x 2-2) + (1 x 2-3)

2 1)

= (1 x (1 x 2-2)

+

(0

x

20)

+

(0

x

2-1)

+

Hence, binary point serves the same purpose as decimal point. Some positional values in binary number system are given here. Binary Point Position

4

3

2

Position Value

4

3

2

2

2

Quantity Represented

16

8

4

1 2

2

0 1

2

2

. 0

1

In general, a number in a number system with base b is written as: an an-1… a0 . a-1 a-2 … a-m and is interpreted to mean

-1

-2

-1

-2

2

2

½

1

/4

-3

-4

-3

2

2-4

1

/8

1

/16

■ Character Coding Schemes

35

an x bn + an-1 x bn-1 + … + a0 x b0 + a-1 x b-1 + a-2 x b-2 + … + a-m x b-m The symbols an, an-1, …, a-m used in the above representation should be one of the b symbols allowed in the number system. Hence, as per the above mentioned general rule, 46.328 = (4 x 81) + (6 x 80) + (3 x 8-1) + (2 x 8-2)

and

5A.3C16 = (5 x 161) + (A x 160) + (3 x 16-1) + (C x 16-2) Example 2.22.

Example 2.23.

Find the decimal equivalent of the binary number 110.101 Solution:

Find the decimal equivalent of the octal number 127.54 Solution:

110.1012 = 1 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3 = 4 + 2 + 0 + 0.5 + 0 + 0.125 = 6 + 0.5 + 0.125 = 6.62510

127.548 = 1 x 82 + 2 x 81 + 7 x 80 + 5 x 8-1 + 4 x 8-2 = 64 + 16 + 7 + 5/8 + 4/64 = 87 + 0.625 + 0.0625 = 87.687510

Example 2.24. Find the decimal equivalent of the hexadecimal number 2B.C4 Solution: 2B.C416 = 2 x 161 + B x 160 + C x 16-1 + 4 x 16-2 = 32 + B + C/16 + 4/256 = 32 + 11 + 12/16 + 4/256 = 43 + 0.75 + 0.015625 = 43.76565210

CHARACTER CODING SCHEMES Character coding schemes (also known as computer codes) are standards for representing characters in computers. They enable easy transfer/exchange of data between computers, and between computers and peripheral devices connected to computers. They also enable independent development of several hardware and software components for a variety of computers. Although many coding schemes have evolved over the years, we will discuss here only the most commonly used. Numeric data is not the only form of data handled by a computer. We often require to process alphanumeric data also. An alphanumeric data is a string of symbols, where a symbol may be one of the letters A, B, C, …, Z, or one of the digits 0, 1, 2, …, 9, or a special character, such as + - * / , . ( ) = (space or blank) etc. An alphabetic data consists of only the letters A, B, C, …, Z, and blank character. Similarly, numeric data consists of only the digits 0, 1, 2, …, and 9. However, the bits 0 and 1 must represent any data internally. Hence, computers use binary coding schemes to represent data internally. In binary coding, a group of bits represents every symbol that appears in the data. The group of bits used to represent a symbol is called a byte. To indicate the number of bits in a group, sometimes, a byte is

36

Chapter 2 ■ Internal Data Representation in Computers

referred to as “n-bit byte”, where the group contains n bits. However, the term “byte” commonly means an 8-bit byte (a group of 8 bits) because most modern computers use 8 bits to represent a symbol.

BCD Code In Binary Coded Decimal (BCD) code, each digit of a decimal number is represented by its binary equivalent instead of converting the entire decimal value to a binary number. This makes the conversion process easier. Figure 2.3 shows BCD equivalent of each decimal digit. Since 8 and 9 require 4 bits, all decimal digits are represented in BCD by 4 bits. In Example 2.7, we saw that 42 10 is equal to 1010102. Converting 4210 into BCD, however, produces the following result: 4210 = 0100 0010 4 2

or

01000010 in BCD

Note that each decimal digit is converted independently to a 4-bit binary number, and hence, the conversion process is easy. Also note that when four bits are used, altogether 16 (24) combinations are possible (refer to hexadecimal number system). However, from Figure 2.3 you can see that only the first 10 of these combinations are used to represent decimal digits. The remaining six arrangements (1010, 1011, 1100, 1101, 1110, and 1111) have decimal values from 10 to 15. BCD coding does not use these arrangements. That is, 1010 does not represent 1010 in BCD. Instead, 1010 = 0001 0000 1 0

or

00010000 in BCD

Decimal digits

BCD equivalent

0 1 2 3 4 5 6 7 8 9

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Figure 2.3. BCD equivalent of decimal digits.

Similarly, 1510 = 0001 0101 or 1 5

00010101 in BCD

In the discussion above, we have used a group of four bits to represent a digit (character) in BCD. 4-bit BCD coding system can represent only decimal numbers because four bits are insufficient to represent the various characters used by a computer. Hence, instead of using four bits with only 16 possible characters, computer designers commonly use six bits to represent characters in BCD code. 6-bit BCD code retains the four BCD numeric place positions, but adds two additional zone positions. With six bits, it is possible to represent 64 (2 6) different characters. This is sufficient to code the decimal digits (10), alphabetic letters (26), and other special characters (28). Figure 2.4 illustrates coding of alphabetic and numeric characters in BCD.

■ Character Coding Schemes

Character

BCD code

A B C D E F G H I

Zone 11 11 11 11 11 11 11 11 11

Digit 0001 0010 0011 0100 0101 0110 0111 1000 1001

J K L M N O P Q R

10 10 10 10 10 10 10 10 10

0001 0010 0011 0100 0101 0110 0111 1000 1001

Octal equivalent 61 62 63 64 65 66 67 70 71 41 42 43 44 45 46 47 50 51

Character

BCD code

S T U V W X Y Z

Zone 01 01 01 01 01 01 01 01

Digit 0010 0011 0100 0101 0110 0111 1000 1001

0 1 2 3 4 5 6 7 8 9

00 00 00 00 00 00 00 00 00 00

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

37

Octal equivalent 22 23 24 25 26 27 30 31 00 01 02 03 04 05 06 07 10 11

Figure 2.4. Alphabetic and numeric characters in BCD along with their Octal equivalent.

In the previous section, we saw the use of octal and hexadecimal number systems as shortcut notations for binary. Since BCD is a 6-bit code, we can divide it into two 3-bit groups, and use one octal digit for representing each of these 3-bit groups. Hence, computer professionals use octal number system as shortcut notation for memory dump in computers that use BCD code for internal representation of characters. This results in a one-to-three reduction in volume of memory dump. Figure 2.4 also shows the octal equivalent of alphabetic and numeric characters coded in BCD. Example 2.25.

Example 2.26.

Write the binary digits used to record the word BASE in BCD.

Solution:

Solution: In BCD binary notation (refer to Figure 2.4): B = 110010 A = 110001

Using octal notation, write the BCD coding for the word DIGIT.

S = 010010 E = 110101

Hence, the binary digits 110010 110001 010010 110101 B A S E will record the word BASE in BCD.

In BCD octal notation (refer to Figure 2.4): D = 64 I = 71 G = 67

I = 71 T = 23

Hence, the BCD coding for the word DIGIT in octal notation will be 64 71 67 71 23 D I G I T

38

Chapter 2 ■ Internal Data Representation in Computers

EBCDIC BCD code can represent only 64 (26) different characters. This is not sufficient for providing decimal numbers (10), lowercase (small) letters (26), uppercase (capital) letters (26), and a number of other special characters (28+). Hence, researchers extended BCD code from a 6-bit code to an 8-bit code. The added two bits are used as additional zone bits, expanding the zone to four bits. The resulting code is called the Extended Binary-Coded Decimal Interchange Code (EBCDIC). In this code, it is possible to represent 256 (2 8) different characters. In addition to the character requirements mentioned above, this also allows a variety of printable characters and several non-printable control characters. System designers enable use of control characters to control such activities as printer vertical spacing, movement of cursor on terminal screen, etc. Out of 256 possible combinations, several are still available for new characters assignment. Hence, the code can still grow, as new requirements develop. Since EBCDIC is an 8-bit code, we can divide it into two 4-bit groups and use one hexadecimal digit for representing each of these. Hence, computer professionals use hexadecimal number system as shortcut notation for memory dump in computers that use EBCDIC for internal representation of characters. This results in a one-to-four reduction in volume of memory dump. Figure 2.5 shows the alphabetic and numeric characters in EBCDIC along with their hexadecimal equivalent. Developed by IBM, most IBM models use EBCDIC code. Many other computers also use EBCDIC code.

A B C D E F G H I

EBCDIC code Zone Digit 1100 0001 1100 0010 1100 0011 1100 0100 1100 0101 1100 0110 1100 0111 1100 1000 1100 1001

J K L M N O P Q R

1101 1101 1101 1101 1101 1101 1101 1101 1101

Character

0001 0010 0011 0100 0101 0110 0111 1000 1001

Hexadecimal equivalent

S T U V W X Y Z

EBCDIC code Zone Digit 1110 0010 1110 0011 1110 0100 1110 0101 1110 0110 1110 0111 1110 1000 1110 1001

0 1 2 3 4 5 6 7 8 9

1111 1111 1111 1111 1111 1111 1111 1111 1111 1111

Character

C1 C2 C3 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6 D7 D8 D9

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Hexadecimal equivalent E2 E3 E4 E5 E6 E7 E8 E9 F0 F1 F2 F3 F4 F5 F6 F7 F8 F9

Figure 2.5. Alphabetic and numeric characters in EBCDIC along with their Hexadecimal equivalent.

Zoned and Packed Decimal Numbers Observe from Figure 2.5 that in the EBCDIC code, digit values are the same as numeric characters – 0 through 9 (0000 – 1001). However, numeric values need some special consideration because we must have a way to indicate whether a number is positive, negative, or unsigned (implies positive). Hence, when a numeric value is represented in EBCDIC, a sign indicator is used in the zone position of the rightmost digit. A sign indicator of hexadecimal C is a plus sign, hexadecimal D is a minus sign, and hexadecimal F means the number is unsigned. Figure 2.6 illustrates the representation of numeric values in EBCDIC. Note that the only zone affected by the sign is the zone of the rightmost

■ Character Coding Schemes

39

digit. All other zones remain as F, the zone value for numeric characters in EBCDIC. Since each decimal digit has a zone with it, numbers coded in EBCDIC are called zoned decimal numbers. Numeric data input to a computer are usually zoned decimal numbers. Printers can print only those numeric characters that are in a zoned-decimal format. Most computers cannot perform arithmetic operations on zoned-decimal data. Hence, before a computer can perform any arithmetic operation on the data, it must convert it to a format on which arithmetic operations are possible. One such acceptable format is the packed decimal format. A system uses the following steps to convert a zoned decimal number to a packed decimal number: Step 1: The zone half and the digit half of moves the sign to the extreme right of the number.

the

rightmost

byte

are

reversed.

This

Step 2: All remaining zones are dropped out. Figure 2.7 illustrates the conversion process of zoned decimal data to packed data. Observe that packed data requires less number of bytes (group of 8 bits) as compared to zoned data. In zoned format, there is only one digit per byte (each digit along with the zone requires 8 bits). However, there are two digits in each byte in packed format (each digit requires 4 bits). If the packing process does not completely fill a byte, it fills it with a zero. For example, zoned data F3F4F5F6 will convert to packed data 03456F. Observe that in this example, zoned data requires four bytes and packed data requires only three bytes. Numeric value

EBCDIC

Sign indicator

345 +345 -345

F3F4F5 F3F4C5 F3F4D5

F for unsigned C for positive D for negative

Figure 2.6. Numeric values in EBCDIC in Hexadecimal notation.

Numeric value

Zoned format

Packed format

345 +345 -345 3456

F3F4F5 F3F4C5 F3F4D5 F3F4F5F6

345F 345C 345D 03456F

Figure 2.7. Zoned and packed decimal numbers.

Example 2.27. Write the EBCDIC coding for the word “BIT” in both binary and hexadecimal notations. How many bytes are required to store this word using this coding? Solution: In EBCDIC (refer to Figure 2.5): B = 1100 0010 in binary and C2 in hexadecimal I = 1100 1001 in binary and C9 in hexadecimal T = 1110 0011 in binary and E3 in hexadecimal Hence, the EBCDIC coding for the word “BIT” will be 11000010 11001001 B I C2 B

C9 I

11100011 in binary and T E3 T

in hexadecimal

Since each character in EBCDIC requires one byte for its representation and there are three characters in the word “BIT”, three bytes will be required to store this word using this coding.

40

Chapter 2 ■ Internal Data Representation in Computers

Example 2.28. Write the EBCDIC zoned-decimal coding for the value +256 (use hexadecimal). How many bytes are required for this representation? Solution: +256 = F2F5C6 in EBCDIC Each hexadecimal digit requires 4 bits and there are altogether 6 hexadecimal digits. Therefore, 6 x 4 = 24 bits or 3 bytes (8 bits = 1 byte) will be required for this representation. We may also write that since each digit requires 1 byte for its representation in the EBCDIC zoned decimal coding and there are 3 digits in the given number, 3 bytes will be required for this representation.

Example 2.29. Write -128 as packed decimal number (use hexadecimal). How many bytes are required for this representation? Solution: -128 = F1F2D8 in EBCDIC = 128D in packed format Each hexadecimal digit requires 4 bits and there are altogether 4 hexadecimal digits. Therefore, 4 x 4 = 16 bits or 2 bytes (1 byte = 8 bits) will be required for this representation.

ASCII Another widely used computer code is the American Standard Code for Information Interchange (ASCII). Several American computer manufacturers have adopted ASCII as their computers’ internal code. This code is popular in data communications, is used almost exclusively to represent data internally in microcomputers, and is frequently found in larger computers produced by some vendors. American National Standards Institute (ANSI) published ASCII standard in 1963. However, the standard lacked lowercase letters and ANSI subsequently revised ASCII in 1967. Subsequent revisions brought it to its present form. Today, ASCII is one of the most popular and widely supported character-encoding standards. ASCII is of two types – ASCII-7 and ASCII-8. ASCII-7 is a 7-bit code that can represent 128 (2 7) different characters. Computers using 8-bit byte (group of 8 bits for 1 byte) and the 7-bit ASCII either set the 8 th bit (leftmost bit) of each byte as zero or use it as a parity bit. ASCII-8 is an extended version of ASCII-7. It is an 8-bit code that can represent 256 (2 8) different characters. It adds the additional bit to the left of the 7th bit (leftmost bit) of ASCII-7 codes. Figure 2.8 shows coding of characters in ASCII-7 and ASCII-8. ASCII-7 uses only 7 bits (the leftmost bit shown shaded is not used) whereas all the 8 bits are used in ASCII-8 (including the leftmost bit shown shaded). Hence, the codes of first 128 characters (symbols) are identical in ASCII-7 and ASCII-8. Notice from the figure that ASCII-8 codes for digits 0 to 9 are 0011 0000 (31 in hexadecimal) to 0011 1001 (39 in hexadecimal), for uppercase alphabets A to Z are 0100 0001 (41 in hexadecimal) to 0101 1010 (5A hexadecimal), and for lowercase alphabets a to z are 0110 0001 (61 in hexadecimal) to 0111 1010 (7A in hexadecimal). The figure also shows ASCII codes for special characters (such as +, -, *, /, $, %, >, =, ?

0011 0000 0011 0001 0011 0010 0011 0011 0011 0100 0011 0101 0011 0110 0011 0111 0011 1000 0011 1001 0011 1010 0011 1011 0011 1100 0011 1101 0011 1110 0011 1111

30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F

Character

Figure 2.8. ASCII-7 and ASCII-8 codes along with their Hexadecimal equivalent for alphanumeric, special, and non-printable characters. The leftmost bit (shown shaded) is used only in ASCII-8 (not in ASCII-7). Codes from 0000 0000 (0 in hexadecimal) to 0010 0000 (20 in hexadecimal) and 0111 1111 (7F in hexadecimal) are for non-printable characters (their abbreviations are given). (Continued on next page…)

■ Character Coding Schemes

@ A B C D E F G H I J K L M N O

ASCIIcode 0100 0000 0100 0001 0100 0010 0100 0011 0100 0100 0100 0101 0100 0110 0100 0111 0100 1000 0100 1001 0100 1010 0100 1011 0100 1100 0100 1101 0100 1110 0100 1111

(Hexadecimal) 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F

P Q R S T U V W X Y Z [ \ ] ^ _

0101 0000 0101 0001 0101 0010 0101 0011 0101 0100 0101 0101 0101 0110 0101 0111 0101 1000 0101 1001 0101 1010 0101 1011 0101 1100 0101 1101 0101 1110 0101 1111

50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F

Character

Character ` a b c d e f g h i j k l m n 0 p q r s t u v w x y z { | } ~ DEL

ASCIIcode 0110 0000 0110 0001 0110 0010 0110 0011 0110 0100 0110 0101 0110 0110 0110 0111 0110 1000 0110 1001 0110 1010 0110 1011 0110 1100 0110 1101 0110 1110 0110 1111

Hexadecimal) 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F

0111 0000 0111 0001 0111 0010 0111 0011 0111 0100 0111 0101 0111 0110 0111 0111 0111 1000 0111 1001 0111 1010 0111 1011 0111 1100 0111 1101 0111 1110 0111 1111

70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F

Figure 2.8. ASCII-7 and ASCII-8 codes along with their Hexadecimal equivalent for alphanumeric, special, and non-printable characters. The leftmost bit (shown shaded) is used only in ASCII-8 (not in ASCII-7). Codes from 0000 0000 (0 in hexadecimal) to 0010 0000 (20 in hexadecimal) and 0111 1111 (7F in hexadecimal) are for non-printable characters (their abbreviations are given).

43

44

Chapter 2 ■ Internal Data Representation in Computers

Unicode Need for Unicode As computers became popular across the world, their usage could not be limited to English language users only. Hence, people started developing computer systems that could allow interaction and processing of data in local languages of users (e.g., Hindi, Japanese, Chinese, Korean, etc.) This required support of local language characters and other language-specific symbols on these computer systems. ASCII or EBCDIC did not have enough number of bits to accommodate all the characters and language-specific symbols of a local language, in addition to English alphabet characters and special characters. Hence, different groups designed encoding systems to cater to this requirement of different local languages. In the process, hundreds of different encoding systems came into existence. Although, this looked fine initially, it later led to a chaotic state of affairs due to the following reasons: 1. No single encoding system had enough bits and an adequate mechanism to support characters of all types of languages used in the world. Hence, supporting of characters from multiple languages on a single computer system became tedious since it required supporting of multiple encoding systems on the computer. With hundreds of different encoding systems in use across the world, it became impossible to support all of them on a single system. 2. Different encoding systems developed independently conflicted with one another. That is, two encoding systems often used the same code for two different characters or used different codes for the same character. Due to this, whenever data transfer took place between computer systems or software using different encoding systems, the data was at the risk of corruption. As a result, it became difficult to exchange text files internationally. The Unicode standard was designed to overcome these problems. It is a universal character-encoding standard used for representation of text for computer processing. The official Unicode web site (www.unicode.org/standard/WhatIsUnicode.html) states that it is an encoding system that “provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language”.

Unicode Features Today, Unicode is a universally accepted character-encoding standard because: 1. It provides a consistent way of encoding multilingual plain text. This enables data transfer through different systems without the risk of corruption. 2. It defines codes for characters used in all major languages of the world used for written communication. This enables a single software product to target multiple platforms, languages, and countries without reengineering. 3. It also defines codes for special characters (such as various types of punctuation marks), mathematical symbols, technical symbols, and diacritics. Diacritics are modifying character marks such as tilde (~), that are used in conjunction with base characters to represent accented letters (indicating different sound – for example, ñ). 4. It has the capacity to encode as many as a million characters. This is large enough for encoding all known characters including all historic scripts of the world as well as common notational systems. 5. It assigns each character a unique numeric value and name, keeping character coding simple and efficient. 6. It reserves a part of the code space for private use to enable users to assign codes for their own characters and symbols. 7. It affords simplicity and consistency of ASCII. Unicode characters that correspond to the familiar ASCII character set have the same byte values as that of ASCII. This enables use of Unicode in a convenient and

■ Character Coding Schemes

45

backward compatible manner in environments designed around ASCII, like UNIX. Hence, Unicode is usable with existing software without extensive software rewrites. 8. It specifies an algorithm for presentation of text with bi-directional behavior. For example, it can deal with a text containing a mixture of English (which uses left-to-right scripts) and Arabic (which uses right-to-left scripts). For this, it includes special characters to specify changes in direction when scripts of different directions are mixed. For all scripts, Unicode stores a text in logical order within the memory representation corresponding to the order of typing on the keyboard. Unicode has a lot of room to accommodate new characters. Moreover, its growth process is strictly additive in the sense that new characters can be added easily, but existing characters cannot be removed. This feature ensures that interpretation of data once encoded in Unicode standard will remain in the same way by all future implementations that conform to original or later versions of the Unicode standard.

Unicode Encoding Forms In addition to defining the identity of each character and its numeric value (also known as code point), characterencoding standards also define internal representations (also known as encoding forms) of each character (how its value is represented in bits). Unicode standard defines the following three encoding forms for each character: 1. UTF-8 (Unicode Transformation Format-8). This is a byte-oriented format having all Unicode characters represented as a variable length encoding of one, two, three or four bytes (remember, 1 byte = 8 bits). This form is useful for dealing with environments designed around ASCII because the Unicode characters that correspond to the familiar ASCII character set have the same byte values as that of ASCII. This form is also popular for HTML and similar protocols. 2. UTF-16 (Unicode Transformation Format-16). This is a word-oriented format having all Unicode characters represented as a variable length encoding of one or two words (remember, 1 word = 16 bits). This form is useful for environments that need to balance efficient access to characters with economical use of storage. This is because all the heavily used characters can be represented by and accessible via a single word (16-bit code unit), while all other characters are represented by and accessible via a pair of words. Hence, this encoding form is compact and efficient, yet provides support for larger number of characters. 3. UTF-32 (Unicode Transformation Format-32). This is a double-word oriented format having all Unicode characters represented as a fixed length encoding of two words (remember, 1 word = 16 bits). That is, a double word (32-bit code unit) encodes each character. This form is useful for environments where memory space is not a concern, but users desire fixed width (single code unit) access to characters. Notice that at most 4 bytes (32 bits) are required for each character in all three forms of encoding. With the three forms of encoding supported, transmission of the same data in a byte, word, or double-word format (i.e., in 8, 16, or 32-bits per code unit) is possible, depending on its usage environment. Unicode standard also provides the facility to transform Unicode encoded data from one form to another without loss of data.

Handling of Text Elements by Unicode A text consists of words and sentences, which are created using text elements. The concept of text element may be different for different languages used in the world. For example, in English, we use letters (A, B, C…a, b, c…) as text elements; and in Chinese language, we use ideographs (which represents full word or concepts) as text elements. Moreover, the definition of text elements also depends on the process handling the text. For example, when sorting is done for historic Spanish language, “II” is treated as a single text element, whereas, it is treated as two separate text elements – “I” and “I”, when Spanish words are typed. To avoid deciding what is (and what is not) a text element in different processes used for handling text, the Unicode standard defines code elements (also known as characters) instead of text elements. For most languages, code

46

Chapter 2 ■ Internal Data Representation in Computers

elements correspond to the commonly used text elements. Moreover, the Unicode standard defines each “I” of the Spanish “II” as a separate code element and leaves the task of combining two “I” together for alphabetic sorting to the text processing software.

Handling of Various Types of Characters by Unicode Since Unicode is an encoding system for supporting all types of languages used in the world, it has to deal with many different types of characters and character sequences used in different languages. Some of the commonly encountered types of characters and character sequences along with the manner in which Unicode handles them are given here. 1. Simple characters. Unicode treats a simple character (like the letter “A”) as a code element. It assigns a single member to each of these characters. Each of these numbers is called a code point. When referred to in text, a code point is listed in hexadecimal form following the prefix “U”. For example, the code point for character “A” is U+0041, where 0041 is the hexadecimal number (equal to the decimal number 65). 2. Unicode also assigns a unique name to each character, which it uses to identify it uniquely. For example, it assigns the unique name “LATIN CAPITAL LETTER A” to “A”. Other examples of unique names assigned to characters by Unicode are “BENGASLI DIGIT 5” and “GURUMUKHI LETTER CHA”. 3. Composite characters. Composite characters (like the characters “ü” and “ n ”) are often used in Latin. They are also known as precomposed characters. The Unicode standard encodes composite characters as single character (encoded as a single code point) and defines the decompositions for all composite characters as the base character (encoded as a code point) followed by the non-spacing character (encoded as another code point). For example, the composite character “ü” is encoded as the single code point U+00FC, and can be decomposed as the base character “u” (having the code point U+0075) followed by the non-spacing character “..” (having the code point U+0308). 4. Unicode defines decomposition of composite characters for consistency and analysis. For example, while alphabetical sorting of a list of names, the character “ü “ may be decomposed into a “ü” followed by the nonspacing character “..”. Once the character has been decomposed, it may be easier for the sorting routine to work with the character because it can be processed as a “ü” with modifications. This allows easier alphabetical sorting for languages where character modifiers do not affect alphabetical order. 5. Duplicate characters in multiple languages. Different languages, which have a common origin, often use many common characters. For example, Chinese, Japanese, and Korean languages share many thousands of identical characters because their ideograph sets evolved from the same source. To avoid duplicate encoding of such characters, the Unicode Standard unifies characters within scripts across languages and assigns a single code to each such character. That is, it assigns a single code point to characters, which are equivalent in form across multiple languages. 6. Glyphs. A glyph is a visual representation of a character, when the character is displayed on screen or printed on paper. We often come across the same character displayed or printed in different sizes, shapes and styles in printed documents or displayed text. For example, capital “A” appears as “A” in Helvetica font and as “A” in Courier font. The Unicode standard does not define glyphs (the size, shape, or style of displayed or printed forms of characters). It only defines how characters are interpreted, not how glyphs are rendered. It is the responsibility of the software or hardware-rendering engine of a computer to deal with the appearance of characters, when the computer displays or prints them.

■ Character Coding Schemes

47

Partitions of Unicode Codespace The Unicode standard (Version 4.0) defines codes (code points) for about 96,500 characters from the world’s alphabets, ideograph sets, and symbol collections. The entire range of already defined code points along with the space reserved for code points for private use as well as those for future expansions form the Unicode codespace. In Unicode codespace, characters are grouped together by scripts in code blocks. A script is a set of related characters. For example, all the characters used in Devnagari form the Devnagari script. Similarly, there are Arabic, Greek, Hebrew, and other scripts. If a script defines an order of the characters (for example, A, B, C, ... is the alphabetic ordering of the characters A…Z), the Unicode Standard maintains the same order whenever possible in its code space. That is, the code points assigned to the set of characters in the script are in the same order (for example, U+0041 for A, U+0042 for B, U+0043 for C, and so on). All the code points assigned to the characters of a script form a code block. Since the number of characters in different scripts varies greatly, the code blocks also vary greatly is size. For example, the code block for the Cyrillic script has 256 code points, while the code block for the combined ideographs of Chinese, Japanese and Korean languages (to avoid duplication) contains thousands of code points. In Unicode codespace, coding starts at U+0000 with the standard ASCII characters, and continues with Greek, Cyrillic, Hebrew, Arabic, Indic, and other scripts. Code point for symbols and punctuations follow these. Hiragana, Katakana, Bopomofo, Hangul and the unified ideographs of Chinese, Japanese, and Korean languages form the subsequent code blocks of codespace. Basic Multilingual Plan (BMP in short) is an area of codespace that contains code points for the commonly used characters (about 64K code points), and space for about 6,300 unused code points for future expansion. Towards the end of the BMP, there is space for 6,400 code points, reserved for private use. A range of compatibility characters follows this. These encoded character variants enable transcoding to earlier standards and old implementations that made use of them. Private use area of the codespace is for characters specific to a program or a group of users. Vendors or end users can assign these internally for their own characters and symbols, or use them with specialized fonts. For example, a group of choreographers may design a set of characters for dance notation and encode the characters using code points in the private use area. Similarly, a set of page-layout programs may use the same code points as control codes to position text on the page. These code points have no universal meaning, as the Unicode standard does not assign any meaning to them. There are 6,400 code points, on the BMP and another 131,068 supplementary private use code points, should 6,400 be insufficient for some applications.

Collating Sequence Data processing operations often use alphanumeric and alphabetic data elements. Obviously, we do not intend to perform any arithmetic operation on such data, but we frequently perform comparison operations on them, like arranging them in some desired sequence. Now, if we want a computer to compare alphabetic values A and B, which one will the computer treat as greater. Answering such questions necessitates having some assigned ordering among the characters used by a computer. This ordering is known as collating sequence. Data processing operations mostly adopt case sensitive dictionary collating sequence. Collating sequence may vary from one computer system to another depending on the type of character coding scheme (computer code) used by a computer. To illustrate this, let us consider the computer codes already discussed in this chapter. Observe from Figures 2.4 and 2.5 that the zone values of characters A through 9 decrease in BCD code from the equivalent of decimal 3 down to 0, while the zone values of characters A through 9 increase in EBCDIC from the equivalent of decimal 12 to 15. Hence, a computer that uses BCD code will treat alphabetic characters (A, B, …, Z) to be greater than numeric characters (0, 1, …9), while a computer that uses EBCDIC will treat numeric characters to be greater than alphabetic characters. Similarly, observe from Figures 2.8 that during a sort (ascending), a computer using ASCII will place numbers ahead of letters because numbers have values less than that for letters. Due to similar reason, it will place uppercase letters ahead of lowercase letters.

48

Chapter 2 ■ Internal Data Representation in Computers

However, whatever may be the type of computer code used, in most collating sequences, the following rules are observed: 1. Letters are considered in alphabetic order (A < B < C < … < Z) and (a < b < c < … < z) 2. Digits are considered in numeric order (0 < 1 < 2 < … < 9) Example 2.32. A computer uses EBCDIC as its internal representation of characters. In which order will this computer sort the strings 23, A1, and 1A? Solution: In EBCDIC, numeric characters have values greater than alphabetic characters (refer to Figure 2.5). Hence, in the said computer, numeric characters will be placed after alphabetic characters and the given strings will be sorted as: A1 < 1A < 23 Therefore, the sorted sequence will be: A1, 1A, and 23

Example 2.33. A computer uses ASCII for its internal representation of characters. In which order will this computer sort the strings 23, A1, 1A, a2, 2a, aA, and Aa? Solution: In ASCII, alphabetic characters have values greater than numeric characters and lower-case letters have values greater than upper-case letters (refer to Figure 2.8). Hence, the said computer will place numeric characters before upper-case letters, and it will place lower-case letters after upper-case letters, causing sorting of the given strings as: 1A < 23 < 2a < A1 < Aa < a2 < aA Therefore, the sorted sequence will be: 1A, 23, 2a, A1, Aa, a2, and aA

BINARY ARITHMETIC In the previous section, we saw that computers store numbers, letters, and other characters in coded form in binary number system. In this section, you will learn why computers use binary numbers instead of decimal numbers, and how they perform basic arithmetic operations internally with binary numbers. Actually, binary arithmetic is simpler to learn because binary number system deals with only two digits – 0 and 1. Since all binary numbers are made up of only 0s and 1s, when arithmetic operations are performed on these numbers, the results are also in 0s and 1s.

■ Binary Arithmetic

49

Why Binary? We saw that use of a number system with smaller base often requires more positions to represent a given value (recall the reason for using octal and hexadecimal notations). For example, 9 10 = 10012. Here, four positions are required instead of one to represent decimal number 9 in binary form. In spite of this, almost all computers use binary numbers. Hence, the obvious question is ‘Why are binary numbers used instead of decimal numbers?’ The reasons are as follows: 1. Information is handled by computer’s electronic/electrical components such as transistors, semiconductors, wires, etc., and all these can indicate only two states or conditions – ON (state 1) or OFF (state 0). Transistors are either conducting (state 1) or non-conducting (state 0), magnetic materials are either magnetized (state 1) in one or opposite direction or non-magnetized (state 0), a pulse or voltage is present (state 1) or absent (state 0) in wire. Information is represented within a computer by the presence or absence of these types of signals. Binary number system having only two digits (0 and 1) is most suitable for expressing the two possible states. Figure 2.9 illustrates the concept of binary components.

Binary state

ON (1)

OFF (0)

Bulb

Switch

Circuit Pulse Figure 2.9. Examples of devices that work in binary mode. These devices can only represent two states – ON (state 1) or OFF (state 0).

2. By using binary numbers, computer circuits only have to handle two binary digits rather than ten decimal digits. This greatly simplifies the internal circuit design of computers resulting in less expensive and more reliable circuits. 3. Finally, all possible operations in decimal number system are also possible in binary number system.

Binary Addition Since binary number system has only two digits, the addition table for binary arithmetic consists of only four entries: 0+0=0 0+1=1 1+0=1 1 + 1 = 0 plus a carry of 1 to next higher column

50

Chapter 2 ■ Internal Data Representation in Computers

Example 2.34.

Since 1 is the largest digit in binary number system, any sum greater than 1 requires a digit to be carried over. For instance, 10 plus 10 binary requires addition of two 1s in the second position. Since 1 + 1 = 0 plus a carryover of 1, the sum of 10 + 10 is 100 in binary.

Add binary numbers 10011 and 1001 in both decimal and binary forms. Solution: Binary carry

By repeated use of the above rules, we can add any two binary numbers by adding two bits at a time. The examples given here illustrate the procedure.

Decimal

11 10011 +1001

carry 1 19 +9

11100

28

In this example, a carry is generated for the first and second columns.

Example 2.35. Add binary numbers 100111 and 11011 in both decimal and binary forms. Solution: Binary carry

11111 100111 +11011

Decimal carry

1000010

1 39 +27 66

In this example, we face a new situation (1 + 1 + 1) brought about by the carryover of 1 in the second column. We can handle this by using the same four rules for binary addition. The addition of three 1s can be broken up into two steps. First, we add only two 1s giving 10 (1 + 1 = 10). The third 1 is now added to this result to obtain 11 (a 1 sum with a 1 carry). Hence, 1 + 1 + 1 = 1, plus a carry of 1 to next higher column.

Binary Subtraction The principles of decimal subtraction hold good for subtraction of numbers in other number systems. It consists of two steps, repeated for each column of the numbers. The first step is to determine, if it is necessary to borrow. If the subtrahend (the lower digit) is larger than the minuend (the upper digit), it is necessary to borrow from the column to the left. Note that the value borrowed depends upon the base of the number system and is always the decimal equivalent of the base. Hence, in decimal 10 is borrowed, in binary 2 is borrowed, in octal 8 is borrowed, and in hexadecimal 16 is borrowed. The second step is to subtract the lower value from the upper value. The complete table for binary subtraction is as follows: 0-0=0 0 - 1 = 1 with a borrow from the next column 1-0=1 1-1=0 The only case in which it is necessary to borrow is when we subtract 1 from 0. The examples given here illustrate the procedure.

■ Binary Arithmetic

51

Example 2.36. Subtract 011102 from 101012. Solution: Borrow

12 0202 10101 - 01110 00111

In the first column (from right to left), 0 is subtracted from 1. No borrow is required in this case and the result is 1. In the second column, we have to subtract 1 from 0. A borrow is necessary to perform this subtraction. Hence, a 1 is borrowed from the third column that becomes 2 (binary 10) in the second column because the base is 2. The third column now becomes 0. Now in the second column, we subtract 1 from 2 giving 1. Since the third column is 0 due to earlier borrow, we have to subtract 1 from 0 for which borrow is required. The fourth column contains a 0 and hence, has nothing to borrow.

Therefore, we have to borrow from the fifth column. Borrowing 1 from the fifth column gives 2 in the fourth column and the fifth column becomes 0. Now the fourth column has something to borrow. When 1 of the 2 in the fourth column is borrowed, it becomes 2 in the third column and 1 remains in the fourth column. Now in the third column, we subtract 1 from 2, giving 1. Subtraction of the fourth column is now 1 from 1, giving 0 and in the fifth column, subtraction is 0 from 0, giving 0. Hence, the result of subtraction is 00111 2. The result may be verified by subtracting 1410 (= 011102) from 2110 (=101012), which gives 710 (= 001112). Example 2.37. Subtract 01110002 from 10111002. Solution: Borrow

2 1011100 -0111000 0100100

Verify the result by subtracting 5610 (= 01110002) from 9210 (= 10111002), which gives 3610 (= 01001002).

Additive Method of Binary Subtraction The method of subtraction by using the borrow concept seems to be easiest when we perform subtraction with paper and pencil. However, when we implement subtraction by means of digital components, this method is less efficient than additive method of subtraction. It may sound surprising to perform even subtraction by using an additive method. Additive method of subtraction is known as complementary subtraction. To understand complementary subtraction, it is necessary to know what complement of a number is. For a number having n digits, its complement is the difference between the number and the base raised to the n th power minus one. The following examples illustrate this: Example 2.38. Find the complement of 3710. Solution:

Example 2.39. Find the complement of 68. Solution:

Since the number has 2 digits and the value of base is 10, (Base)n - 1 = 102 - 1 = 99 Now, 99 - 37 = 62

Since the number has 1 digit and the value of base is 8, (Base)n - 1 = 81 - 1 = 710 = 78 Now, 78 - 68 = 18

Hence, the complement of 3710 = 6210.

Hence, the complement of 68 = 18.

52

Chapter 2 ■ Internal Data Representation in Computers

Example 2.40. Find the complement of 101012. Solution: Since the number has 5 digits and the value of base is 2, (Base)n - 1 = 25 - 1 = 3110 = 111112 Now, 111112 - 101012 = 010102 Hence, the complement of 101012 = 010102.

In case of binary numbers, it is not necessary to go through the usual process of obtaining complement. A quicker way to obtain the complement of a binary number is to transform all its 0s to 1s and all its 1s to 0s. For example, the complement of 1011010 is 0100101. Observe this in case of Example 2.40. Hence, we can easily design the circuit for obtaining the complement of a number in binary number system at less expense.

Performing subtraction by using complementary method involves the following steps: Step 1: Find the complement of the number you are subtracting (subtrahend) Step 2: Add this to the number from which you are taking away (minuend) Step 3: If there is a carry of 1, add it to obtain the result; if there is no carry, recomplement the sum and attach a negative sign to obtain the result. To illustrate the procedure, let us first consider a few examples for decimal numbers. Example 2.42.

Example 2.41. Subtract 5610 from 9210 complementary method.

using

Subtract 3510 from 1810 complementary method.

using

Solution:

Solution: Step 1: Complement of 5610 = 102 - 1 - 56 = 99 - 56 = 4310

Step 1: Complement of 3510 = 102 - 1 - 35 = 99 - 35 = 6410

Step 2:

92 +43 (complement of 56) 135

Step 2:

Step 3:

1 (add the carry of 1)

Result = 36 Verify the result by using the method of normal subtraction: 92 - 56 = 36.

18 +64 (complement of 35) 82

Step 3: Since there is no carry, recomplement the sum and attach a negative sign to obtain the result. Result = -(99 - 82) = -17 Verify the result by using the method of normal subtraction: 18 - 35 = -17

Let us re-work these examples by using binary numbers.

■ Binary Arithmetic

53

Example 2.44.

Example 2.43. Subtract 01110002 (5610) from 10111002 (9210) using complementary method.

Subtract 1000112 (3510) from 0100102 (1810) using complementary method. Solution:

Solution: 1011100 +1000111 (complement of 0111000) 10100011

010010 +011100 (complement of 100011) 101110

1 (add the carry of 1)

Since there is no carry, we have to complement the sum and attach a negative sign to it. Hence,

0100100 Result = 01001002 = 3610 Verify the result with the results of Example 2.37 and Example 2.41.

Result = -0100012 (complement of 1011102) = -1710 Verify the result with the result of Example 2.42.

Binary Multiplication The table for binary multiplication has only four entries, instead of 100 entries necessary for decimal multiplication. It is as follows: 0x0=0 0x1=0 1x0=0 1x1=1 The example given here illustrates the method of binary multiplication. It is only necessary to copy the multiplicand, if the digit in the multiplier is 1 and to copy all 0s, if the digit in the multiplier is 0. The ease with which a system can perform each step of the operation is apparent. Example 2.45. Multiply binary numbers 1010 and 1001. Solution: 1010 Multiplicand x1001 Multiplier 1010 0000 0000 1010

Partial Product Partial Product Partial Product Partial Product

1011010

Final Product

Note that a partial product is obtained by copying the multiplicand when multiplier digit is 1 and by copying all 0s when the multiplier digit is 0. As in decimal multiplication, each partial product is shifted one place to the left from the previous partial product. The final product is obtained by adding all the partial products according to binary addition rules.

54

Chapter 2 ■ Internal Data Representation in Computers

In actual practice, whenever a 0 appears in the multiplier a separate partial product consisting of a string of 0s need not be generated. Instead, only a left shift will do. As a result, Example 2.45 reduces to 1010 x1001 1010 1010SS (S = left shift)

A computer would also follow this procedure in performing multiplication. Verify the result of this multiplication by multiplying 1010 (10102) by 910 (10012), which produces a result of 9010 (10110102).

1011010

It may not be obvious how to handle the addition, if the result of multiplication gives columns with more than two 1s. We can handle them as pairs or by adjusting the column to which the carry is placed (see Example 2.46). Example 2.46. Multiply binary numbers 1111 and 111. Solution:

1

1 x

1 1

1 1

1 1

1 1 1

1 1

1

1 1 1

1

1 1

1

0

1

0

0

1

We can handle the addition in column 3 above in any one of the following two ways: Addition handled as pairs (Column 3)

Addition handled as single carry (Column 3)

1

1

1 1

Sum = 4

1 1

1

1

From problem

Carry from column 2

0 Add two carries to column 4

From problem

1 1

Carry from column 2

100 Carry to column 4 Carry to column 5

■ Binary Arithmetic

55

Additive Method of Binary Multiplication Most computers perform multiplication operation by the way of addition only. For example, we can obtain the result of 4 x 8 by adding the digit 8 four times (8 + 8 + 8 + 8). We may use the same method to perform multiplication operations in binary number system.

Binary Division The table for binary division is as follows: 0÷0 0÷1 1÷0 1÷1

= Divide by zero error = 0 = Divide by zero error =1

Note that since division by zero in any number system is meaningless, computers deal with this problem by raising an error condition called ‘Divide by zero’ error. As in decimal division, the rules for binary division are: 1. Start from the left of the dividend. 2. Perform a series of subtractions, in which the divisor is subtracted from the dividend. 3. If subtraction is possible, put a 1 in the quotient and subtract the divisor from the corresponding digits of dividend. 4. If subtraction is not possible (divisor greater than remainder), record a 0 in the quotient. 5. Bring down the next digit to add to the remainder digits. Proceed as before in a manner similar to long division. The example here illustrates this method. Example 2.47. Divide 1000012 by 1102. Solution:

110

0101

(Quotient)

100001 110

(Dividend) 1

Divisor greater than 100, hence, put 0 in quotient

1000 110

2 3

Add digit from dividend to group used above Subtraction possible, hence, put 1 in quotient

100 110

4 5

Remainder from subtraction plus digit from dividend Divisor greater, hence, put 0 in quotient

1001 110

6 7

Add digit from dividend to group used above Subtraction possible, hence, put 1 in quotient

11

(Remainder)

Verify the result by dividing 3310 (1000012) by 610 (1102), which gives a quotient of 510 (1012) and a remainder of 310 (112).

56

Chapter 2 ■ Internal Data Representation in Computers

Additive Method of Binary Division Most computers perform division operation by repeating complementary subtraction method (additive method). For example, we can obtain the result of 35 ÷ 5 as follows: 35 - 5 = 30 30 - 5 = 25 25 - 5 = 20 20 - 5 = 15 15 - 5 = 10 10 - 5 = 5 5-5= 0

That is, the divisor is subtracted repeatedly from the dividend until the result of subtraction becomes less than or equal to zero. The total number of times we perform subtraction, gives the value of the quotient. In this example, the value of quotient is 7 because the divisor (5) was subtracted 7 times from the dividend (35) until the result of subtraction became zero. If the result of last subtraction is zero, then there is no remainder for the division. However, if it is less than zero, then we ignore the last subtraction and take the result of the previous subtraction as the value of remainder. In this case, we do not count the last subtraction operation for evaluating the value of quotient. The example here illustrates the process.

Example 2.48. Divide 3310 by 610 using the method of addition. Solution: 33 - 6 = 27 27 - 6 = 21 21 - 6 = 15 15 - 6 = 9 9-6= 3 3 - 6 = -3

Total number of subtractions = 6. Since the result of the last subtraction is less than zero, Quotient = 6 - 1 (ignore last subtraction) = 5 Remainder = 3 (result of previous subtraction) Hence, 33 ÷ 6 = 5 with a remainder 3.

Why Do Computers Use Additive Method? We have demonstrated how we can carry out all arithmetic operations by additive method. How this simplifies matter can only be understood in the context of binary (not in decimal). The number of individual steps may indeed increase, if all computer arithmetic is reduced to addition and complementation operations. However, a computer can carry out binary addition and complementation operations at such great speed that this is not a disadvantage. This also saves the labour and expense of designing complicated circuits.

Points to Remember 1.

Number systems are of two types – non-positional and positional.

2.

In a non-positional number system, each symbol represents the same value regardless of its position in the number and to find the value of a number, one has to count the number of symbols present in the number. It is difficult to perform arithmetic with such a number system.

3.

In a positional number system, there are only a few symbols called digits. These symbols represent different values depending on the position they occupy in a number. The value of each digit in such a number is determined by three considerations:  The digit itself,  The position of the digit in the number, and  The base of the number system (where base is the total number of digits in the number system).

■ Points to Remember

57

4.

In our day-to-day life, we use the decimal number system. In this system, base is equal to 10 because there are ten symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9).

5.

Some positional number systems that are used in computer design and by computer professionals are binary (having base 2), octal (having base 8), and hexadecimal (having base 16).

6.

Figure 2.2 shows the relationship among decimal, hexadecimal, binary, and octal number systems.

7.

Readers must know the techniques for the following types of conversions to convert numbers from one base to another:  Converting from another base to decimal  Converting from decimal to another base  Converting from a base other than 10 to another base other than 10  Shortcut method for binary to octal conversion  Shortcut method for octal to binary conversion  Shortcut method for binary to hexadecimal conversion  Shortcut method for hexadecimal to binary conversion

8.

Fractional numbers are formed in the same way as in decimal number system. In general, a number in a number system with base b is written as: an an-1… a0 . a-1 a-2 … a-m and is interpreted to mean an x bn + an-1 x bn-1 + … + a0 x b0 + a-1 x b-1 + a-2 x b-2 + … + a-m x b-m The symbols an, an-1, …, a-m b symbols allowed in the number system.

9.

used

in

the

above

representation

should

be

one

of

the

Computers use binary coding schemes to represent data internally. In binary coding, a group of bits represents every symbol that appears in the data. The group of bits used to represent a symbol is called a byte. Most modern computers use 8 bits to represent a symbol. Hence, the term byte commonly means a group of 8 bits.

10. BCD, EBCDIC, ASCII, and Unicode are the commonly used computer codes for representing characters internally in computers. 11. BCD (Binary Coded Decimal) is a 6-bit code that can represent 64 different characters. 12. EBCDIC (Extended Binary-Coded Decimal Interchange Code) is an 8-bit code that can represent 256 different characters. 13. ASCII (American Standard Code for Information Interchange) is one of the most popular and widely supported computer codes. It is of two types – ASCII-7 and ASCII-8. ASCII-7 is a 7-bit code that can represent 128 different characters and ASCII-8 is an 8-bit code that can represent 256 different characters. 14. Unicode provides a consistent way of encoding multilingual plain text. It has the capacity to encode as many as a million characters. Unicode has three types of encoding forms – UTF-8, UTF-16, and UTF-32. 15. Collating sequence is ordering of symbols in an encoding standard. 16. Almost all computers use binary numbers for internal computations because we can design and implement electronic circuits for performing arithmetic operations in binary mode more easily, reliably, and inexpensively than those required for performing arithmetic operations in decimal mode. 17. The rules for binary addition are as follows: 0+0=0 0+1=1 1+0=1 1 + 1 = 0 plus a carry of 1 to next higher column 18. The rules for binary subtraction are as follows: 0-0=0 0 - 1 = 1 with a borrow from the next column 1-0=1 1-1=0

58

Chapter 2 ■ Internal Data Representation in Computers 19. For a number having n digits, its complement is the difference between the number and the base raised to the n th power minus one. 20. A quick way to obtain the complement of a binary number is to transform all its 0s to 1s, and all its 1s to 0s. 21. Complementary subtraction is an additive approach of subtraction. 22. The rules for binary multiplication are as follows: 0x0=0 0x1=0 1x0=0 1x1=1 23. The rules for binary division are as follows: 0 ÷ 0 = Divide by zero error 0÷1=0 1 ÷ 0 = Divide by zero error 1÷1=1 24. ‘Divide by zero’ is an error condition raised by the computer when it divides any number by zero. 25. Most computers use the additive approach for performing subtraction, multiplication, and division operations.

Questions 1.

Differentiate between positional and non-positional number systems. Write examples of both types of number systems.

2.

What is base of a number system? Write examples to illustrate the role of base in positional number systems.

3.

What is the value of base for decimal, hexadecimal, binary, and octal number systems?

4.

Write an example for octal number system to show that the same digit may signify different values depending on the position it occupies in the number.

5.

What will be the total number of different symbols or digits and the maximum value of a single digit for the following number systems: (a) Number system with base 5 (c) Number system with base 9 (b) Number system with base 20 (d) Number system with base 12

6.

What is a ‘bit’ in computer terminology? How many different patterns of bits are possible with (a) 6 bits (b) 7 bits (c) 8 bits

7.

Explain the meaning of the term “memory dump”.

8.

Why do we use octal and/or hexadecimal number systems as shortcut notations?

9.

Write the decimal equivalent of the following binary numbers: (e) 1110101 (a) 1101011 (f) 1000 (b) 11010 (c) 10110011 (g) 10110001100 (h) 110001 (d) 11011101

(i) 1010101100 (j) 111

10. Write the octal equivalent of the binary numbers of Question 9. 11. Write the hexadecimal equivalent of the binary numbers of Question 9. 12. Convert the following numbers to decimal numbers: (c) 2A3B16 (a) 1101102 (b) 25736 (d) 12349 13. Convert the following decimal numbers to binary numbers: (a) 43510 (c) 3210 (b) 169410 (d) 13510 14. Convert the decimal numbers of Question 13 to octal numbers.

Questions

59

15. Convert the decimal numbers of Question 13 to hexadecimal numbers. 16. Carry out the following conversions: (a) 1256 = ?4 (b) 249 = ?3

(c)

ABC16 = ?8

17. Convert the following numbers to their binary equivalent: (a) 2AC16 (c) 26148 (b) FAB16 (d) 5628 18. Write the decimal equivalent of the following numbers: (a) 111.012 (c) 247.658 (b) 1001.0112 (d) 2B.D416 19. Define the term ‘byte’. What is the difference between a bit and a byte? 20. Write 4-bit BCD code for the following numbers: (a) 2510 (c) 12810 (b) 6410 (d) 102410 21. Write BCD code for the following words using binary notation: (a) BIT (c) CODE (b) BYTE (d) ZERO 22. Write BCD code for the following words using octal notation: (a) COMPUTER (c) VIDEO (b) INPUT (d) OUTPUT 23. Why BCD code was extended to EBCDIC? 24. How many different characters are possible in the following encoding schemes: (a) BCD (c) ASCII-7 (b) EBCDIC (d) ASCII-8 25. Why octal and hexadecimal shortcut notations are used? Identify shortcut notations used for each of the following computer codes: (a) BCD (c) ASCII-7 (b) EBCDIC (d) ASCII-8 26. Why do we have a packed decimal format? How does it differ from a zoned decimal format? 27. A newly designed computer code uses 9 bits. How many different characters are possible in this code? 28. Write EBCDIC code for the following words in both binary and hexadecimal notations: (a) SUN (c) CAT (b) MOON (d) DOG How many bytes are required to store each of these words using this coding? 29. Write EBCDIC code for the following words in hexadecimal notation: (a) PROGRAM (c) BYTE (b) OUTPUT (d) OCTAL How many bytes are required to store each of these words using this coding? 30. Write EBCDIC code for the following words in binary notation: (a) ZONE (c) SKY (b) BOY (d) TAPE How many bytes are required to store each of these words using this coding? 31. Using hexadecimal notation, write the zoned-decimal coding for the following numbers: (a) 1256 (c) -63 (b) +439 (d) -786 How many bytes are required for each of these representations? 32. Using hexadecimal notation, write the packed-decimal coding for the following numbers: (a) 12915 (c) 872 (b) +9876 (d) -256 How many bytes are required for each of these representations?

60

Chapter 2 ■ Internal Data Representation in Computers 33. List the similarities and differences between 7-bit and 8-bit ASCII. 34. Write ASCII-7 and ASCII-8 codes for the following words using binary and hexadecimal notations: (a) DRY (c) DAMP (b) WET (d) TERM How many bytes are required to store each of these words in ASCII? 35. Write ASCII-7 and ASCII-8 codes for the following words using binary notation: (a) PRINT (c) RUB (b) TYPE (d) GIVE How many bytes are required to store each of these words in ASCII? 36. What is Unicode? What motivated its development? 37. Why it was difficult to exchange text files internationally before development of Unicode? How did Unicode help in overcoming this problem? 38. Why Unicode was developed? 39. List some key features of Unicode. 40. Describe the three encoding forms defined by Unicode standard and the environment for which each of them is most suitable. 41. Explain the meaning of the term “collating sequence”. 42. A computer uses EBCDIC as its internal representation of characters. In which order will this computer sort the following strings? (a) ABC (c) 245 (b) 123 (d) ADD 43. A computer uses ASCII. In which order will this computer sort the following strings? (a) BED (c) ADD (e) BaD (b) 512 (d) 2good (f) a1B2 44. Write full form of the following abbreviations: (a) BCD (c) ASCII (b) EBCDIC (d) UTF 45. Why computers use the binary number system? 46. Add binary numbers 1011 and 101 in both decimal and binary forms. 47. Add binary numbers 1010110 and 1011010. 48. Add binary numbers 10111 and 1011. 49. Find the complement of the following numbers: (a) 49510 (c) 48 (b) 2910 (d) C16 50. Find the complement of the following binary numbers: (d) 011011 (a) 10 (e) 10110001 (b) 101 (f) 001101001110 (c) 101101 51. Subtract 01101112 from 11011102. 52. Subtract 010102 from 100002. 53. Subtract 0110112 from 1101112. 54. Subtract 2510 from 5010 using complementary method. 55. Subtract 2510 from 2010 using complementary method. 56. Subtract 23410 from 58810 using complementary method. 57. Subtract 21610 from 17210 using complementary method. 58. Subtract 010102 from 100002 using complementary method.

(e) 25 (f) 324

■ Questions

61

59. Subtract 1101112 from 1011102 using complementary method. 60. Subtract 0110112 from 1101112 using complementary method. 61. Subtract 11112 from 11002 using complementary method. 62. Multiply binary numbers 1100 and 1010. 63. Multiply binary numbers 01101 and 1001. 64. Multiply binary numbers 101111 and 111. 65. Divide 110012 by 1012. 66. Divide 01101112 by 01112. 67. What happens when a computer divides a number by zero? 68. Explain how a computer performs multiplication and division operations in a computer by using additive approach. 69. What is the primary advantage of performing subtraction by complementary method in digital computers? 70. Discuss the advantages and disadvantages of performing various arithmetic operations by additive method in a digital computer.

Digital Systems Design

Digital computers use several interconnected digital components, which in turn use digital circuits in the design. Logic gates and flip-flops are the building blocks of all digital circuits in a computer. As digital circuits conform to the arithmetic and logic operations of binary numbers, the algebra that deals with binary number system is used in the design of digital circuits. This algebra is called Boolean algebra. This chapter deals with the design of digital systems. It introduces Boolean algebra, logic gates, and flip-flops. It then explains and illustrates with suitable examples how to use Boolean algebra, logic gates, and flip-flops to design digital circuits (both combinational and sequential).

BOOLEAN ALGEBRA In mid 1800, George Boole (1815-1864), an English mathematician, developed an algebra known as Boolean algebra for simplifying the representation and manipulation of propositional logic. Later, in the year 1938, Claude E. Shannon proposed the use of Boolean algebra in the design of relay switching circuits. The basic techniques described by Shannon were adopted universally for the design and analysis of switching circuits. Owing to analogous relationship between the action of relays and modern electronic circuits, computer designers still use the same techniques. Boolean algebra provides an economical and straightforward approach to the design of relay and other types of switching circuits. Like the basic theorems of algebra help in simplifying an ordinary algebraic expression, Boolean algebra helps in simplifying an expression describing a switching circuit. Today, computer designers use Boolean algebra for designing the electronic circuits of computers.

Fundamental Concepts of Boolean Algebra Fundamental concepts of Boolean algebra are described here.

■ Boolean Algebra

63

Use of Binary Digits In a normal algebraic expression, a variable can take any numerical value. For example, in the expression 3A  7B = C, each of the variables A, B, and C may have any value from the entire field of real numbers. Since, Boolean algebra deals with binary number system, the variables used in Boolean equations may have only two possible values (0 or 1). For example, in the Boolean equation A  B = C, the variables A, B, and C may have only the values 0 or 1.

Logical Addition (OR Operator) The symbol ‘’ is used for logical addition (OR) operator. We can define the  symbol (OR operator) by listing all possible combinations of A and B with the resulting value of C for each combination in the equation A  B = C. Since the variables A and B can have only two possible values (0 or 1), only four (22) combinations of inputs are possible (see the table in Figure 3.1). The table gives resulting output values for each of the four input combinations. Such a table is known as a truth table. Hence, Figure 3.1 is the truth table for logical OR operator.

Inputs A  B 0 0 0 1 1 0 1 1

Output = C 0 1 1 1

Figure 3.1. Truth table for logical OR () operator.

The result is 0, only when both input variables are 0. It is 1, when any one or both of the input variables are 1. This is the reason why the symbol ‘’ does not mean normal arithmetic addition, but means logical addition. Boolean algebra extends this concept of logical addition to multiple variables. For example, in the equation A  B  C  D = E, even if A, B, C, and D, all had the value of 1, the sum of the values (the result E) would be 1 only. The equation A  B = C is normally read as “A or B equals C”.

Logical Multiplication (AND Operator) The symbol ‘’ is used for logical multiplication (AND) operator. Figure 3.2 shows the truth table for logical AND operator. The result C is equal to 1 only when both input variables A and B are 1, otherwise it is 0. The equation A  B = C is normally read as “A and B equals C”.

Inputs A  0 0 1 1

B 0 1 0 1

Output =

C 0 0 0 1

Figure 3.2. Truth table for logical AND ( ) operator.

Complementation (NOT Operator) OR and AND are binary operations because they operate on two variables. Complementation is a unary operation defined on a single variable. The symbol ‘’ is used for complementation operator. Hence, we write A meaning, “complement of A”, or

Input

Output

AB.”

A

A

Complementation of a variable is the reverse of its value. Hence, if A = 0, then A = 1 and if A = 1, then A = 0. Figure 3.3 shows the truth table for logical NOT () operator. A is read as “complement of A” or “not of A”.

0 1

1 0

 A  B

meaning,

“complement

of

Figure 3.3. Truth table for logical NOT () operator.

64

Chapter 3 ■ Digital Systems Design

Operator Precedence Does A  B  C mean (A  B)  C or A  (B  C)? The two generate different values for A = 1, B = 0, and C = 0 because we have (1  0)  0 = 0 and 1  (0  0) = 1. Hence, we need operator precedence rules to evaluate Boolean expressions correctly. The precedence rules for Boolean operators are as follows: 1. The expression is scanned from left to right. 2. Expressions enclosed within parentheses are evaluated first. 3. All complement (NOT) operations are performed next. 4. All ‘’ (AND) operations are performed after that. 5. Finally, all ‘’ (OR) operations are performed in the end. According to these rules, A + B  C should be evaluated as A + (B  C). Similarly, for the expression A  B , complement of A and B are both evaluated first and the results are then ANDed. Again, for the expression A  B , the expression inside the parenthesis (A + B) is evaluated first and the result is then complemented.





Postulates of Boolean Algebra Postulate 1:

Postulate 4: Associative Law

(a) A = 0, if and only if, A is not equal to 1 (b) A = 1, if and only if, A is not equal to 0 Postulate 2:

(a) x  (y  z) = (x  y)  z (b) x  (y  z) = (x  y)  z Postulate 5: Distributive Law

(a) x  0 = x (b) x  1 = x

(a) x  (y  z) = x  y  x  z (b) x  (y  z) = (x  y)  (x  z)

Postulate 3: Commutative Law

Postulate 6:

(a) x  y = y  x (b) x  y = y  x

(a) x  x = 1 (b) x  x = 0

These postulates are the basic axioms of the algebraic structure that need no proof. They are used to prove the theorems of Boolean algebra.

The Principle of Duality In Boolean algebra, there is a precise duality between the operators  (AND) and  (OR) and the digits 0 and 1. For instance in Figure 3.4, the second row is obtainable from the first row and vice-versa by interchanging ‘’ with ‘’ and ‘0’ with ‘1’. This property is known as the principle of duality in Boolean algebra.

Row 1 Row 2

Column 1

Column 2

Column 3

11=1 00=0

1+0=01=1 01=10=0

00=0 11=1

Figure 3.4. Illustrating the principle of duality in Boolean algebra.

■ Boolean Algebra

65

The implication of this principle is that any theorem in Boolean algebra has its dual obtainable by interchanging ‘’ with ‘’ and ‘0’ with ‘1’. Hence, if we prove a theorem, its dual theorem also holds, which we need not prove separately.

Theorems of Boolean Algebra Some important theorems of Boolean algebra are stated below along with their proof. Theorem 1 (Idempotent law) (a) x  x = x (b) x  x = x

Proof of (a) L.H.S. =xx = (x  x)  1 = (x  x)  (x + x ) =xx x =x0 =x = R.H.S.

Proof of (b)

by postulate 2(b) by postulate 6(a) by postulate 5(b) by postulate 6(b) by postulate 2(a)

L.H.S. =xx =xx0 =xxx x = x  (x + x ) =x1 =x = R.H.S.

by postulate 2(a) by postulate 6(b) by postulate 5(a) by postulate 6(a) by postulate 2(b)

Note that Theorem 1(b) is the dual of Theorem 1(a) and each step of the proof in part (b) is the dual of part (a). We can derive any dual theorem from the proof of its corresponding pair in a similar manner. Hence, from now onwards, the proof of only part (a) will be given. Interested readers can apply the principle of duality to various steps of the proof of part (a) to obtain the proof of part (b) for any theorem. Theorem 2 (a) x  1 = 1 (b) x  0 = 0

Proof of (a) L.H.S. =x1 = (x  1)  1 by postulate 2(b) = (x + 1)  (x + x ) by postulate 6(a) =x1 x by postulate 5(b) by postulate 3(b) =x x 1 by postulate 2(b) =x+ x =1 by postulate 6(a) = R.H.S.

Theorem 3 (Absorption law) (a) x  x  y  x (b) x . (x + y)  x

Proof of (a) L.H.S. =xxy =x1xy = x  (1  y) = x  (y  1) =x1 =x = R.H.S.

by postulate 2(b) by postulate 5(a) by postulate 3(a) by theorem 2(a) by postulate 2(b)

Proof of (b) holds by duality.

Proof of (b) holds by duality.

Proof by the Method of Perfect Induction We can also prove the theorems of Boolean algebra by means of truth tables. In a truth table, we need to check if both sides of the relation yield identical results for all possible combinations of variables involved. In principle, it is

66

Chapter 3 ■ Digital Systems Design

possible to enumerate all possible combinations of variables involved because Boolean algebra deals with variables having only two values. This method of proving theorems is called exhaustive enumeration or perfect induction. For example, Figure 3.5 is a truth table for proving Theorem 3(a) by perfect induction method. Similarly, Figure 3.6 proves Theorem 3(b) by perfect induction method. =

= x

y

xy

xxy

x

y

xy

x  (x  y)

0 0 1 1

0 1 0 1

0 0 0 1

0 0 1 1

0 0 1 1

0 1 0 1

0 1 1 1

0 0 1 1

Figure 3.5. Truth table for proving Theorem 3(a) by the method of perfect induction.

Figure 3.6. Truth table for proving Theorem 3(b) by the method of perfect induction.

Theorem 4 (Involution Law)

x =x Proof The truth table below proves this theorem by the method of perfect induction. = x

x

x

0 1

1 0

0 1

Note that Theorem 4 has no dual because it deals with a unary operator (NOT).

Theorem 5 (a) x  ( x + y ) = x  y (b) x + x  y = x  y

Proof of (a)

Proof of (b)

The truth table below proves this theorem by the method of perfect induction.

The truth table below proves this theorem by the method of perfect induction.





x

y

x

x+y

x  ( x  y)

xy

x

y

x

x y

x+ x y

x+y

0 0 1 1

0 1 0 1

1 1 0 0

1 1 0 1

0 0 0 1

0 0 0 1

0 0 1 1

0 1 0 1

1 1 0 0

0 1 0 0

0 1 1 1

0 1 1 1

■ Boolean Algebra

67

Theorem 6 (De Morgan’s Law) (a)

xy = x  y

(b) x  y = x + y

Proof of (a) The truth table below proves this theorem by the method of perfect induction.  x

y

x+y

xy

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 0

x  y

x

y

1 1 0 0

1 0 1 0

1 0 0 0

Proof of (b) The truth table below proves this theorem by the method of perfect induction. 

x

y

xy

xy

0 0 1 1

0 1 0 1

0 0 0 1

1 1 1 0

x

y

1 1 0 0

1 0 1 0

x  y

1 1 1 0

Theorems 6(a) and 6(b) are known as De Morgan’s law. They can be extended to n variables as given below:

X1  X 2  X 3  ...  X n  X1  X 2  X 3  …  X n X1  X2  X3  ...  Xn  X1 + X 2 + X 3 + … + X n Figure 3.7 summarizes the basic Boolean identities. Readers should become conversant with the identities given in this table to use the algebra effectively.



68

Chapter 3 ■ Digital Systems Design

Sr. No.

Identities

Dual identities

1

A+0=A

A1=A

2

A+1=1

A0=0

3

A+A=A

AA=A

4

A+A =1

A A =0

5 6

A = A A+B=B+A

AB=BA

7

(A + B) + C = A + (B + C)

(A  B)  C = A  (B  C)

8

A  (B + C) = A  B + A  C

A + B  C = (A + B)  (A + C)

9

A+AB=A

A  (A + B) = A

10

A+ A B=A+B

A  ( A  B) = A  B

11

AB= A  B

AB= A  B

Figure 3.7. Summary of basic Boolean identities.

BOOLEAN FUNCTIONS A Boolean function is an expression formed with binary variables, Boolean operators (OR, AND, and NOT), parentheses, and equal to sign. Each variable can be either 0 or 1, and for a set of values of the variables the value of the function can also be either 0 or 1. For example, consider the equation W=X+ Y Z Here W is a function of the variables X, Y, and Z, written as W = f(X, Y, Z), and the right hand side of the equation is called an expression. X, Y, and Z are referred to as literals of this function. This Boolean function is in the form of an algebraic expression. A truth table with 2n rows can also represent a Boolean function, where n is the number of literals (binary variables) in the function. The combinations of 0s and 1s for the rows of this table are obtained from the binary numbers by counting from 0 to 2n - 1. The value of the function corresponding to each row of the table is listed in a separate column of the table. Figure 3.8 shows such a truth table for the function W = X + Y  Z.

X

Y

Z

W

0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1

0 1 0 0 1 1 1 1

Figure 3.8. Truth table for the Boolean function W = X +

Y  Z.

Observe that there are (23) possible combinations for assigning bits to three variables. The column labeled W is either a 0 or 1 for each of these combinations. Out of eight, there are five combinations for which W = 1. A usual question is – “Is an algebraic expression for a Boolean function unique?” In other words, “Is it possible to find two algebraic expressions specifying the same Boolean function?” The answer is yes. In Boolean algebra we often deal with the problem of finding simpler expressions for a given expression. For example, Figure 3.9 shows the truth table for two equal Boolean functions:

■ Boolean Functions

F1  x  y  z  x  y  z  x  y

69

and

F2  x  y  x  z Function F2 is the same as function F1 since both have identical 0s and 1s for each combination of values of the three binary variables x, y, and z. In general, two functions of n binary variables are equal, if they have the same value for all possible 2 n combinations of the n literals.

x

y

z

F1

F2

0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1

0 1 0 1 1 1 0 0

0 1 0 1 1 1 0 0

Figure 3.9. Truth table for the Boolean functions:

F1  x  y  z  x  y  z  x  y F2  x  y  x  z

and

Minimization of Boolean Functions by Algebraic Manipulations Logic gates (discussed later in this chapter) are used to implement Boolean functions. In such implementations, each term of a function is implemented with a gate and each literal of the term forms an input to the gate. Hence, for a given Boolean function, minimization of the number of literals and the number of terms results in a circuit with fewer components. For example, since functions F1 and F2 of Figure 3.9 are equal Boolean functions and F2 has fewer terms, it is more economical to implement the F 2 form than the F1 form. One must know how to simplify Boolean expressions to obtain equal and simpler expressions. What constitutes the best form of a Boolean function depends on the application, but here we will consider only the criterion of component minimization achieved by literal minimization. Two commonly used methods to minimize the number of literals in a Boolean function are algebraic manipulations and map simplification. The algebraic manipulations method is described here and the map simplification method is described in a later sub-section. The algebraic manipulations method uses cut-and-try procedure by repeated application of the postulates and basic theorems of Boolean algebra. There is no specific rules or guidelines to be followed guaranteeing the final answer. Following examples illustrate this method. Note that in Example 3.1, functions Fa and Fb are the dual of each other and use dual expressions in corresponding minimization steps. Function Fc shows the equality of functions F1 and F2 of Figure 3.9. Function Fd illustrates the fact that an increase in the number of literals sometimes leads to a final simpler expression. Observe that function F e is the dual of function Fd. Hence, its minimized expression can be derived directly from the dual of the steps used to derive function Fd.

70

Chapter 3 ■ Digital Systems Design

Example 3.1. Simplify the following Boolean functions to a minimum number of literals. (a) Fa = x + x  y (b) Fb = x  ( x + y) (c) Fc = x  y  z + x  y z + x  y (d) Fd = x  y + x  z + y z (e) Fe = (x + y)  ( x + z)  (y + z)

Solution: (a) Fa = x + x . y = (x + x )  (x + y)

by postulate 5(b)

= 1  (x + y)

by postulate 6(a)

= (x + y)  1

by postulate 3(b)

=x+y

by postulate 2(b)

(b) Fb = x  ( x + y) = xx + x y

by postulate 5(a)

=0+xy

by postulate 6(b)

=xy+0

by postulate 3(a)

=xy

by postulate 2(a)

(c) Fc = x  y  z + x  y  z + x  y = x  z  ( y + y) + x  y

by postulate 5(a)

= x  z  (y + y ) + x  y

by postulate 3(a)

= x z1+x y

by postulate 6(a)

= x z+x y

by postulate 2(b)

(d) Fd = x  y + x  z + y  z =xy+ x z+yz1

by postulate 2(b)

= x  y + x  z + y  z  (x + x )

by postulate 6(a)

=xy+ x z+yzx+yz x

by postulate 5(a)

=xy+ x z+xyz+ x yz

by postulate 3(b)

=xy1+ x z+xyz+ x yz

by postulate 2(b)

=xy1+xyz+ x z+ x yz = x  y  (1 + z) + x  z  (1 + y) = x  y  (z + 1) + x  z  (y + 1) =xy1+ x z1 =xy+ x z (e) Fe = (x + y)  ( x + z)  (y + z) = (x + y)  ( x + z )

by postulate 3(a) by postulate 5(a) by postulate 3(a) by theorem 2(a) by postulate 2(b) by duality from (d)

■ Boolean Functions

71

Complement of a Function Complement of a Boolean function F is F . It is obtained by interchanging 0s for 1s and 1s for 0s in the truth table defining the function. For example, Figure 3.10 defines the function F = x  y + x  z and its complement F . Algebraically, we can derive the complement of a function from De Morgan’s theorems whose generalized forms are as follows:

A1  A2  A3  ...  An  A1  A 2  A 3  …  A n

A1  A2  A3 ...  An  A1 + A 2 + A 3 + … + A n

x

y

z

F

F

0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1

0 1 0 1 1 1 0 0

1 0 1 0 0 0 1 1

Figure 3.10. Truth table for the function F = x  y +

x

 z and its complement F .

These theorems state that the complement of a function is obtained by interchanging OR and AND operators and complementing each literal. Example 3.2 illustrates this method. A simpler method to derive the complement of a function is to take the dual of the function and then complement each literal. This method follows from the generalized De Morgan’s theorems. Recall that the dual of a function is obtained by interchanging OR and AND operators and 0s and 1s. Example 3.3 illustrates this method. Example 3.2. Find the complement of following functions: (a)

F1  x  y  z  x  y  z

(b)

F2  x  ( y  z  y  z )

Solution: Applying De Morgan’s theorems, as many times as necessary, the complements are obtained as follows: (a) F1  x  y  z  x  y  z 

x  y  z   x  y  z

=

x  y  z   x  y  z 

=

 x  y  z   x  y  z 

(b) F2 = x  y  z  y  z 

  = x  y  z   y  z  = x  yz  yz

=

x  y  z   y  z 

=

x  y  z   y  z 

72

Chapter 3 ■ Digital Systems Design

Example 3.3. Find the complement of the functions F1 and F2 of Example 3.2 by taking their dual and complementing each literal. Solution: (a) F1  x  y  z  x  y  z The dual of

(b)

F1 is:  x  y  z    x  y  z 

Complementing each literal, we get

F2  x  y  z  y  z  The dual of F2 is:

x  y  z  y  z

Complementing each literal, we get F2 = x  y  z  y  z 

F1   x  y  z    x  y  z 

Canonical Forms of Boolean Functions Minterms and Maxterms A binary variable may appear either in its normal form (x) or in its complement form x  . Now, consider two binary variables x and y combined with an AND operator. Since each variable may appear in either of the two forms, there are four possible combinations:

x  y,

x  y,

x  y,

Each of these four AND terms is called a minterm or a standard product.

xy

Similarly, we can combine n variables to form 2n minterms. We can determine the 2n different minterms by a method similar to the one shown in Figure 3.11 for three variables. The binary numbers from 0 to 2 n - 1 are listed under the n variables. Each minterm is obtained from an AND term of the n variables with each variable being primed, if the corresponding bit of the binary number is 0, and unprimed, if it is a 1. Variables

Minterms

Maxterms

x

y

z

Term

Designation

Term

Designation

0

0

0

x  yz

m0

xyz

M0

0

0

1

0

1

0

x  yz x  yz

m1 m2 m3

x yz x yz x yz

M4

x yz

M5

x yz

M1 M2

0

1

1

x  yz

1

0

0

x  yz

1

0

1

x  yz

m4 m5

1

1

0

x yz

M6

1

1

x  yz x  y z

m6

1

m7

x yz

M7

M3

Figure 3.11. Minterms and Maxterms for three variables.

■ Boolean Functions

73

The figure also shows a symbol for each minterm. It is of the form mj, where j denotes the decimal equivalent of the binary number of the minterm designated. Similarly, n variables forming an OR term, with each variable being primed or unprimed, provide 2 n possible combinations called maxterms or standard sums. Figure 3.11 shows the eight maxterms for three variables and their symbolic designations. Any 2 n maxterms for n variables may be determined similarly. Each maxterm is obtained from an OR term of the n variables, with each variable being unprimed, if the corresponding bit is a 0, and primed, if it is a 1. Note that each maxterm is the complement of its corresponding minterm and vice-versa.

Sum-of-Products A sum-of-products expression is a single product term (minterm) or several product terms (minterms) logically added (ORed) together. For example, expression x  y  x  y is a sum-of-products expression. Following are all sum-ofproducts expressions: Following steps are followed to express a Boolean function in its sum-of-products form:

x x+y x+yz

1. Construct a truth table for the given Boolean function.

xy+z

2. Form a minterm for each combination of the variables that produces a 1 in the function.

x  y  x  yz

3. The desired expression is the sum (OR) of all minterms obtained in Step 2. For example, in case of function F1 of Figure 3.12, following three combinations of the variables produce a 1: 001,

100,

and

111

Their corresponding minterms are

x  y  z,

x  yz ,

and

x  yz

Taking the sum (OR) of these minterms, we can express function F1 in its sum-of-products form as:

F1  x  y  z  x  y  z  x  y  z or F2  m1  m4  m7

x

y

z

F1

F2

0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1

0 1 0 0 1 0 0 1

0 0 0 1 0 1 1 1

Figure 3.12. Truth table for functions F 1 and F2.

Similarly, we can express function F2 of Figure 3.12 in its sum-of-products form as:

F2  x  y  z  x  y  z  x  y  z  x  y  z F2  m3  m5  m6  m7

or

It is sometimes convenient to express a Boolean function in its sum-of-products form. If it is not in this form, we can convert it into this form by first expanding the expression into a sum of AND terms. We then inspect each term to see if it contains all the variables. If it misses one or more variables, we AND it with an expression of the form (x + x ), where x is one of the missing variables. Following example illustrates this procedure.

74

Chapter 3 ■ Digital Systems Design

Example 3.4. Express the Boolean function F = A + B C in sum-of-minterms (products) form. Solution: The function has three variables A, B, and C. The first term A is missing two variables (B and C), therefore, A = A  (B + B ) = A  B + A B This is still missing one variable (C), therefore, A = A  B  (C + C ) + A  B  (C + C ) = A  B  C + A  B C + A B  C + A  B  C The second term B  C is missing one variable (A), therefore,

B  C = B  C  (A + A ) =A BC+ A  BC Now, by combining all the terms we get F = A  B  C + A  B C + A B  C + A B C + A B  C +A B  C However, the term A B C appears twice in this expression and according to Theorem 1(a) we have x + x = x. Hence, removing one of them and rearranging the minterms in ascending order we obtain:

F  AB C  A  B C  A  B C  A  BC  A  B C = m1  m4  m5  m6  m7 We often use a shortcut notation to express a Boolean function in its sum-of-minterms form. We can represent the result of Example 3.4 in this notation as: F (A, B, C) =  (1, 4, 5, 6, 7)

Product-of-Sums A product-of-sums expression is a single sum term (maxterm) or several sum terms (maxterms) logically multiplied (ANDed) together. For example, expression ( x + y)  (x + y ) is a product-of-sums expression. Following are all product-of-sums expressions:

■ Boolean Functions x ( x + y) (x + y)z (x + y )  ( x + y )  ( x + y ) (x + y)  ( x + y + z )

75

Following steps are followed to express a Boolean function in its product-of-sums form: 1. Construct a truth table for the given Boolean function. 2. Form a maxterm for each combination of the variables that produce a 0 in the function. 3. The desired expression is the product (AND) of all maxterms obtained in Step 2.

For example, in case of function F1 of Figure 3.12, following five combinations of the variables produce a 0: 000, 010, 011, 101, and 110 Their corresponding maxterms are: (x + y + z), (x + y + z), (x + y + z ), ( x + y + z ), and ( x + y + z) Taking the product (AND) of all these maxterms, we can express function F1 in its product-of-sums form as:

F1   x  y  z    x  y  z    x  y  z    x  y  z    x  y  z 

or

F2  M0  M2  M3  M5  M6 Similarly, we can express function F2 of Figure 3.12 in its product-of-sums form as: F2 = (x + y + z)  (x + y + z )  (x + y + z)  ( x + y + z)

or

F2 = M 0  M1  M 2  M 4

To express a Boolean function in its product-of-sums form, we must first express it as a product of OR terms. We do this by using the distributive law. For example, x + y  z = (x + y)  (x + z) Then we OR any missing variable (say x) in each OR term with the form x  x . Following example illustrates the procedure. The sum-of-products and product-of-sums forms of Boolean expressions are known as standard forms. They are preferred for logic circuit design because of their straightforward conversion into simpler logic gate networks. In their simplest form, they go into two-level networks in which the longest path for any signal to pass from input to output is through two gates.

76

Chapter 3 ■ Digital Systems Design

Example 3.5. Express the Boolean function F = x  y + x  z in product-of-maxterms (sums) form. Solution: At first, we convert the function into product of OR terms by using distributive law: F=xy+ x z = (x  y + x )  (x  y + z) = (x + x )  (y + x )  (x + z)  (y + z) = ( x + y)  (x + z)  (y + z) The function has three variables (x, y, and z) and each OR term is missing one variable. Therefore,

x + y = x + y + z  z = ( x + y + z)  ( x + y + z ) x + z = x + z + y  y = (x + z + y)  (x + z + y ) = ( x + y + z)  ( x + y + z ) y + z = x  x + y + z = (x + y + z)  ( x + y + z) Now by combining all the terms and retaining only one instance of those that appear more than once, we obtain: F = (x + y + z)  (x + y + z)  ( x + y + z)  ( x + y + z ) = M0  M2  M4  M5 We may represent this in shortcut notation as: F (x, y, z) =  (0, 2, 4, 5) The product symbol  represents ANDing of the maxterms. The numbers following it are the maxterms of the function.

Conversion between Canonical Forms Complement of a function, expressed as sum-of-minterms, equals the sum-of-minterms missing from the original function. This is because the original function is expressed by those minterms that make the function equal to 1, while its complement is a 1 for those minterms for which the function is a 0. For example, the function F (A, B, C) =  (1, 4, 5, 6, 7) = m1  m 4  m 5  m 6  m 7

has its complement expressed as: F (A, B, C) =  (0, 2, 3) = m 0  m 2  m 3

Taking the complement ofF by De Morgan’s theorem, we obtain F back in a different form: F=

m0  m 2  m3

= m0  m 2  m3 = M 0  M 2  M3

■ Boolean Functions

77

=  (0, 2, 3)

The last conversion follows from the definition of minterms and maxterms shown in Figure 3.11. From the figure, it is clear that the following relation holds true:

mj  Mj That is, the maxterm with subscript j is a complement of the minterm with the same subscript j and vice-versa. The last example has demonstrated the conversion of a function, expressed as sum-of-minterms, into its equivalent function in product-of-maxterms form. The conversion from product-of-maxterms form to sum-of-minterms form is similar. We now state a general conversion procedure: “To convert from one canonical form to another, interchange the symbol ( with  or  with ) and list those numbers (from all possible numbers in the range 0 to 2 n-1, where n is the number of binary variables in the function) missing from the original form.” For example, the function F (x, y, z) =  (0, 2, 4, 5) is expressed in product-of-maxterms form. Its conversion to sum-of-minterms form is: F (x, y, z) =  (1, 3, 6, 7) In this case, there are three variables (x, y, and z). Hence, n = 3 and the total number of minterms or maxterms are 2 3 = 8 (0 to 7). The missing terms in product-of-maxterms form (1, 3, 6, and 7), therefore, become part of sum-ofminterms form.

Minimization of Boolean Functions by Map Simplification Map simplification method (also known as Karnaugh map or K-map) of minimizing Boolean functions requires us to represent a Boolean function in the form of a K-map. We have already seen how to represent a Boolean function in the form of a truth table or in canonical forms – sum-of-products and product-of-sums. We will now see how to represent a Boolean function in the form of a K-map.

What is K-map? K-map is a pictorial representation of a Boolean function. It consists of squares, with each square representing one minterm. Hence, the number of squares in a map of n variables is 2n. Figure 3.13 shows K-maps for Boolean functions of two, three, and four variables. Each square is assigned a minterm number as shown in the figure. Notice that minterm numbers are assigned in such a manner that the binary equivalent of minterm numbers of adjacent squares differ by one bit only. For example, notice that in case of four-variable map, the squares in the first column are assigned the minterm numbers 0, 1, 3, 2 from top to bottom instead of 0, 1, 2, 3. This is because binary equivalent of numbers 1 (0001) and 2 (0010) differ by two bits, but binary equivalent of numbers 1 (0001) and 3 (0011) as well as 3 (0011) and 2 (0010) differ by one bit only. The variable names (A, B, C, D) of the Boolean function are listed across both sides of the diagonal line in the upper left hand corner of the map. The 0s and 1s marked along each row and each column designate the value of the corresponding variables for the squares in that row or column. Additionally, the rows and columns are divided into sets (non-disjoint) marked by curly brackets and each set is designated by one of the variables of the Boolean function. Notice that each variable associated with such a set of squares (written on the curly brackets) contains half of the squares in the map where that variable appears uncomplemented. The variable appears complemented in the remaining half of the squares.

78

Chapter 3 ■ Digital Systems Design

Minterm numbers assigned to squares Binary Decimal equivalent 0 00 1 01 2 10 3 11

A A B 0 B

1

0

1

0

2

1

3

(a) Two-variable map

Minterm numbers assigned to squares Binary Decimal equivalent 0 000 1 001 2 010 3 011 4 100 5 101 6 110 7 111

AB

C

Term

Designation

AB

m0 m1 m2 m3

AB AB AB

(a) Corresponding minterm table

A C

Corresponding minterms

00

01

11

10

0

0

2

6

4

1

1

3

7

5

B (b) Three-variable map

Corresponding minterms Term

Designation

ABC

m0 m1 m2 m3 m4 m5 m6 m7

ABC ABC ABC ABC

ABC ABC ABC

(b) Corresponding minterm table

A AB 00

01

11

10

0

4

12

8

01

1

5

13

9

11

3

7

15

11

10

2

6

14

10

CD 00

D

(c) Corresponding minterm table can be drawn in a similar manner as those for two-variable and threevariable maps.

C

B (c) Four-variable map Figure 3.13. Maps for two-, three-, and four-variable Boolean functions. Corresponding minterm tables are shown here only for the purpose of understanding. They need not be drawn during simplification of Boolean functions. Only the map should be drawn.

Notice from the tables by the side of the maps in the figure that the minterm represented by a square is determined from the binary values of the variables in the corresponding row and column. For example, in the three-variable map, the binary values of the variables corresponding to the last square (last row, last column) are A = 1, B = 0 and C = 1. Hence, the minterm represented by the square is ABC , and this is the reason why the square is assigned the minterm number 5 (decimal equivalent of binary 101). Similarly, in the four-variable map, the minterm represented by the square having number 13 is ABCD because the binary values of the variables corresponding to that square are A = 1, B = 1, C = 0 and D = 1.

■ Boolean Functions

79

Adjacent Squares in K-map Minimization of Boolean functions by map simplification deals with grouping adjacent squares that contain 1s. For doing this, it is important to understand the definition of adjacency of squares in K-maps, which is as follows: “Any two squares whose binary values of minterms differ by a single bit are adjacent.” According to this definition, the following squares are adjacent: 1. The square to the immediate left of a square (for example, square 3 is adjacent to 7) 2. The square to the immediate right of a square (for example, square 6 is adjacent to 2) 3. The square immediately above a square (for example, square 4 is adjacent to 5) 4. The square immediately below a square (for example, square 1 is adjacent to 0) 5. The squares at the extreme ends of the same horizontal row (for example, in three-variable map, square 0 is adjacent to 4 and square 1 is adjacent to 5) 6. The squares at the top and bottom of the same column (for example, in four-variable map, 0 and 2, 4 and 6, 12 and 14, and 8 and 10 are adjacent) 7. The four corner squares (for example, in three-variable map, 0-1-4-5 are adjacent, and in four-variable map, 0-2-8-10 are adjacent)

Obtaining Simplified Boolean Function with a K-map The following procedure is used to obtain a simplified Boolean function with a K-map: 1. Draw an n-variable K-map depending on the number of variables (n) in the given Boolean function. 2. From the truth table of the given Boolean function, insert 1s in those squares of the map whose corresponding minterms are 1. 3. Combine the squares containing 1s in groups of adjacent squares. These groups must contain a number of squares that is an integral power of 2. The groups are not disjoint sets of squares in the sense that one or more squares of a group may also belong to another group. 4. Each group of squares represents an algebraic term. All these terms are ORed to obtain the simplified algebraic expression of the given Boolean function. The following examples illustrate the procedure. Example 3.6 Simplify the Boolean function F  x y z  x y z  x y Solution: At first, we must convert the function into sum-of-minterms. Hence,

F  x yz  x yz x y  x y z  x y z  x y (z  z) x yz  x yz x yzx y z = m1 + m3 + m5 + m4

(Continued on next page …)

80

Chapter 3 ■ Digital Systems Design Hence, F (x, y, z) = ∑ (1, 3, 4, 5) Now we plot the minterms on a three-variable map and combine the squares containing 1s in groups of adjacent squares. x xy z

00

01

11

10

0 z

1

1 1

1

1

xy (set of two adjacent squares 4 and 5)

y xz (set of two adjacent squares 1 and 3)

We then represent each group as an algebraic term and take the OR of those terms. Hence, F  x y  x z is the simplified form of the given Boolean function. Verify the result with the result of function Fc of Example 3.1. Example 3.7 Simplify the Boolean function

F  x y  x z  yz

Solution: At first, we must convert the function into sum-of-minterms. Hence,

F  x y xz yz  x y (z  z)  x z (y  y)  y z (x  x) x yz  x y z x yz x yzx yz x yz  (x y z  x y z)  (x y z  x y z)  x y z  x y z x yzx yzx y z x yz = m7 + m3 + m6 + m1 Hence, F (x, y, z) = ∑ (1, 3, 6, 7) Now we plot the minterms on a three-variable map and combine the squares containing 1s in groups of adjacent squares. x xy 00

z

01

11

0 z

1

1 1

1

10

xy (set of two adjacent squares 6 and 7)

1 y

xz (set of two adjacent squares 1 and 3)

We then represent each group as an algebraic term and take the OR of those terms. Hence, F  x y  x z is the simplified form of the given Boolean function. Verify the result with the result of function Fd of Example 3.1.

■ Boolean Functions Example 3.8 Simplify the Boolean function F (A, B, C) = ∑ (1, 5, 6, 7) Solution: Plot the minterms on a three-variable map and combine the squares containing 1s in groups of adjacent squares. A AB C

00

01

11

0 C

10

AB (set of two adjacent squares 6 and 7)

1

1

1

1

1

BC (set of two adjacent squares 1 and 5)

B

Represent each group as an algebraic term and take the OR of those terms. Hence, F  A B  BC is the simplified form of the given Boolean function.

Example 3.9 Simplify the Boolean function F (A, B, C) = ∑ (0, 1, 3, 4, 5) Solution: Plot the minterms on a three-variable map and combine the squares containing 1s in groups of adjacent squares. A AB C

C

00 0

1

1

1

01

11

10 1

1

B (set of four adjacent squares 0, 1, 4, and 5)

1 B

AC (set of two adjacent squares 1 and 3)

Represent each group as an algebraic term and take the OR of those terms. Hence, F  B  A C is the simplified form of the given Boolean function.

81

82

Chapter 3 ■ Digital Systems Design

Example 3.10 Simplify the Boolean function F (A, B, C, D) = ∑ (0, 2, 4, 6, 8, 9 10) Solution: Plot the minterms on a four-variable map and combine the squares containing 1s in groups of adjacent squares. A AB CD 00

00

01

1

1

11

10 1

01

ABC (set of two adjacent squares 8 and 9)

1 D

11 C 10

1

1

1

BD (set of four adjacent squares 0, 2, 8 and 10)

B

AD (set of four adjacent squares 0, 2, 4 and 6)

Represent each group as an algebraic term and take the OR of those terms. Hence, F  A D  BD  A BC is the simplified form of the given Boolean function.

Product-of-Sums Simplification We have seen how to simplify Boolean functions expressed in sum-of-products form by using K-maps. We will now see how to simplify functions expressed in product-of-sums form by using K-maps. The following procedure is used: 1. Draw an n-variable K-map depending on the number of variables (n) in the given Boolean function. 2. From the truth table of the given Boolean function, insert 0s in those squares of the map whose corresponding maxterms are 1 (which is the same as corresponding minterms being 0). 3. Combine the squares containing 0s in groups of adjacent squares. These groups must contain a number of squares that is an integral power of 2. The groups are not disjoint sets of squares in the sense that one or more squares of a group may also belong to another group. 4. Each group of squares represents an algebraic term, which are ORed to obtain the simplified complemented function. 5. Take the complement of the function obtained in Step 4 to obtain the simplified function in product-of-sums form. Example 3.11 illustrates the procedure.

■ Boolean Functions

83

Example 3.11 Simplify the Boolean function F (A, B, C, D) = ∏ (1, 3, 7, 9, 11, 12, 13, 14, 15) Solution: Plot the maxterms with 0s on a four-variable map and combine the squares containing 0s in groups of adjacent squares. A AB CD

00

01

11

00 01

10

AB (set of four adjacent squares 12, 13, 14 and 15)

0 0

0

BD (set of four adjacent squares 1, 3, 9 and 11)

0 D

11

0

0

0

0

CD (set of four adjacent squares 3, 7, 11 and 15)

C 10

0 B

Represent each group as an algebraic term and take the OR of those terms. Hence, F  AB  BD  CD

Hence, F  AB  B D  CD  AB  BD  CD  (A  B)  (B  D)  (C  D)  (A  B)  (B  D)  (C  D) is the simplified Boolean function in product-of-sums form.

Don’t Care Conditions When representing a Boolean function as a truth table, we have seen until now that the output values for each of the 2 n combinations (minterms) of the n variables are either 0 or 1. There are occasions when it does not matter if the function produces an output of 0 or 1 for a given minterm. Such minterms are called don’t-care conditions because we do not care whether the function’s output is 0 or 1. Squares in a K-map corresponding to such minterms are marked with a cross mark (X). During simplification of the function, these squares are used as follows in the map: 1. While making groups of adjacent squares, the Xs may be assumed to be either 0 or 1, whichever gives the simplest expression. That is, it can be grouped with squares having 1s (when dealing with sum-of-products simplification) or squares having 0s (when dealing with product-of-sums simplification), if its inclusion in the group gives a simpler expression. 2. An ‘X’ need not be included in any group if it does not contribute to the simplification of the function. In short, the choice of including a square containing ‘X’ in a group is optional and depends only on its contribution to the simplification of the function. The example here illustrates this.

84

Chapter 3 ■ Digital Systems Design

Example 3.12 Simplify the Boolean function F (A, B, C) = ∑ (0, 4, 5), whose minterms (2, 3, 6) are don’t-care minterms. Solution: Plot the minterms (0, 4, 5) with 1s and minterms (2, 3, 6) with Xs on a three-variable map and combine the squares containing 1s and Xs in groups of adjacent squares. Include a square containing ‘X’ in a group only if it contributes to the simplification of the function. A AB C 0 C

1

00

01

11

10

1

x

x

1

x

1

AB (set of two adjacent squares 4 and 5)

B

C (set of four adjacent squares 0, 2, 4 and 6)

Represent each group as an algebraic term and take the OR of those terms. Hence, F  AB  C is the simplified form of the given Boolean function. Note that don’t care minterm 3 was not included in any group because it does not contribute to the simplification of the function. Also note that if the don’t care minterms 2 and 6 were not included in the group of four adjacent squares, the minterms 0 and 4 would have formed a group of two adjacent squares, representing an algebraic term B C . Hence, the simplified expression for the function in this case would have been

F  AB  BC This form of the function is not as simplified as the expression obtained previously. Hence, choosing to include the don’t-care minterms 2 and 6 in group formation produces the simplest Boolean expression.

LOGIC GATES A computer carries out all operations internally by means of combinations of signals passing through standard blocks of built-in circuits known as logic gates. In other words, a logic gate is an electronic circuit that operates on one or more input signals to produce standard output signals. These logic gates are the building blocks of electronic circuits in a computer. Digital computers use a variety of logic gates in their design. Each gate has a standard graphic symbol, and a Boolean function (expression) describes its operation. We can represent the input-output relationship of the binary variables for each gate in the form of a truth table. Figure 3.14 lists the names, graphic symbols, Boolean functions, and truth tables of seven commonly used logic gates. Their description is given here. 1. AND gate. An AND gate is the physical realization of logical multiplication (AND) operation. It is an electronic circuit that generates an output signal of 1, only if all input signals are also 1, otherwise the output is 0 (see Figure 3.14(a)]. Two or more switches connected in series behave as an AND gate.

■ Logic Gates

85

AND gates may have more than two inputs, and by definition, the output will be 1, if and only if all inputs are 1. Hence, the output of an AND gate with three inputs A, B, and C will be 1 only if all three inputs are 1, so that we write the output as A  B  C. 2. OR gate. An OR gate is the physical realization of logical addition (OR) operation. It is an electronic circuit that generates an output signal of 1, if any of the input signals is 1 or both are 1, otherwise the output is 0 [see Figure 3.14(b)]. Two or more switches connected in parallel behave as an OR gate. OR gates may have more than two inputs, and by definition, the output will be 1, if any input is 1. Hence, the output of an OR gate with three inputs A, B, and C will be 1, if any one of the inputs is 1, so that we write the output as A+B+C. 3. NOT gate. A NOT gate is the physical realization of complementation operation. It is an electronic circuit, which generates the reverse of the input signal as output signal [see Figure 3.14(c)]. It is also known as an inverter because it inverts the input. The small circle in the output of the graphic symbol of an inverter designates a logic complement. A NOT gate always has a single input because complementation operation is unary operation defined on a single variable. Two NOT gates connected in series give an output equal to the input. This is the gating counterpart to the law of double complementation, A  A. 4. NAND gate. A NAND gate is a complemented AND gate. That is, the output of NAND gate will be 1, if any one of the inputs is a 0, and it will be 0, only when all inputs are 1 [see Figure 3.14(d)]. Its name is derived from the abbreviation of NOT-AND. Hence, its graphic symbol consists of an AND graphic symbol followed by a small circle (inverter or NOT). The symbol ‘  ’ is usually used to represent a NAND operation in Boolean expressions. Hence,

A  B  A  B  A  B . A NAND gate may have more than two inputs, and the output is always the complement of the AND function of all inputs. Hence, a three-input NAND gate with inputs A, B, and C will have an output equal to A  B  C or A  B  C meaning that the output will be 1, if any of the inputs is a 0, and it will be 0, only when all three inputs are 1. 5. NOR gate. A NOR gate is a complemented OR gate. That is, the output of a NOR gate will be 1, only when all inputs are 0, and it will be 0, if any input is a 1 [see Figure 3.14(e)]. Its name is derived from the abbreviation of NOT-OR. Hence, its graphic symbol consists of an OR graphic symbol followed by a small circle (inverter or NOT). The symbol ‘  ’ is usually used to represent a NOR operation in Boolean expressions. Hence, A  B =

A  B  A  B . A NOR gate may have more than two inputs, and the output is always the OR function of all inputs. Hence, a three-input NOR gate with inputs A, B, and C will have an output equal to A  B  C or

A  B  C meaning that the output will be 1, only when all three inputs are 0, and it will be 0, if any of the three inputs is a 1.

86

Chapter 3 ■ Digital Systems Design

Sr. No.

Name

Graphic symbol

(a)

AND

A B

(b)

OR

A B

(c)

NOT

A

(d)

(e)

(f)

(g)

A B

NAND

NOR

A B

Exclusive-OR (XOR)

A B

Exclusive-NOR or Equivalence

A B

C

C

Boolean functions C=AB or C = AB

C=A+B

A 0 0 1 1 A 0 0 1 1

Truth table B 0 1 0 1 B 0 1 0 1 A 0 1

C 0 0 0 1 C 0 1 1 1

C

C= A or C = A

C

C =A  B or C= A  B or C= A  B

A 0 0 1 1

B 0 1 0 1

C 1 1 1 0

C

C= A  B or C= A  B or C= A  B

A 0 0 1 1

B 0 1 0 1

C 1 0 0 0

C

C = AB or C = A B  AB or C = AB AB

A 0 0 1 1

B 0 1 0 1

C 0 1 1 0

C

C=AB or C = AB or C = AB  AB or C = AB AB

A 0 0 1 1

B 0 1 0 1

C 1 0 0 1

A 1 0

Figure 3.14. Commonly used logic gates.

6. Exclusive-OR (XOR) gate. Exclusive-OR, denoted by , is a binary operator that performs the following Boolean function: A  B = A B  A  B Notice from the truth table of Figure 3.14(f) that the output of an Exclusive-OR gate is 1, if any input is 1 but excludes the combination when both inputs are 1. ODD function would had been a better name for ExclusiveOR operation because its output is 1, if an odd number of inputs are 1. Hence, for a three-input Exclusive-OR gate, the output will be 1, if only one input is 1, or if all three inputs are 1. Exclusive-OR gates are commonly

■ Logic Gates

87

available with two inputs only. They are rarely available with three or more inputs. Since Exclusive-OR operation is both commutative and associative, we have:

 A  B  C  A   B  C   A  B  C Graphic symbol of Exclusive-OR gate is similar to OR gate with a curved line on the input side. 7. Exclusive-NOR (Equivalence) gate. Exclusive-NOR (Equivalence), denoted by , is a binary operator that performs the following Boolean function: AB=AB+ A B Notice from the truth table of Figure 3.14(g) that the output of an Equivalence gate is 1, only if both inputs are equal to 1, or both inputs are equal to 0. Also, notice that Equivalence is the complement of ExclusiveOR. Hence, graphic symbol of Equivalence is similar to Exclusive-OR gate with a small circle (inverter). Equivalence gates are also commonly available with two inputs only. They are rarely available with three or more inputs. Since Equivalence operation is both commutative and associative, we have: (A  B)  C = A  (B C) = A  B  C Only a limited number of Boolean expressions can be expressed exclusively in terms of Exclusive-OR or Equivalence operations. Nevertheless, these expressions emerge quite often during the design of digital systems. The two functions are particularly useful in arithmetic operations and error detection and correction.

LOGIC CIRCUITS We seldom use logic gates alone. Normally, we use them in combinations to form gating/logic networks known as combinational logic circuits. We can derive Boolean algebra expression for a given logic circuit by systematically progressing from input to output on its gates. The example here illustrates this.

Example 3.13. Find the Boolean expression for the output of the logic circuit given below. A B

1

4 6 E

C

2 5

D

3

88

Chapter 3 ■ Digital Systems Design

Solution: At point 1, the output of the OR gate is A + B

-------------

(a)

At point 2, the output of the NOT gate is C At point 3, the output of the NOT gate is D

-------------------------

(b) (c)

Inputs to the AND gate at point 4 are (A + B), C, and D. Hence, its output will be (A + B)  C  D -------------

(d)

Inputs to the AND gate at point 5 are (A + B), C , and D . Hence, its output will be (A + B)  C  D -------------

(e)

Finally, inputs to the OR gate at point 6 are (d) and (e). Hence, its output will be A  B C  D  A  B C  D Hence, E  A  B C  D  A  B C  D is the Boolean expression for the output of the given logic circuit.

Converting Expressions to Logic Circuits The three logic gates – AND, OR, and NOT are said to be logically complete because any Boolean expression can be realized using these three gates only. The example here illustrates the method of constructing logic circuits for Boolean expressions, by using these three gates only. Example 3.14. Construct a logic circuit for the Boolean expression (x + y + z)  (x + y )  ( x  y ) Solution: x

x+y+z

z

y

y

x

xy

x  y  z  x  y  x  y 

xy

The desired logic circuit is shown above and is self-explanatory.

The Universal NAND Gate NAND gate is a universal gate because it is alone sufficient to implement any Boolean expression. To show this, we need to show that the logical operations AND, OR, and NOT can be implemented with NAND gates only. Figure 3.15 shows this.

■ Logic Gates AA  A  A  A

A

A

89

AB AB

A B

B (b) AND gate implementation.

(a) NOT gate implementation.

A

AA  A

AB  A  B  A  B B

B B  B

(c) OR gate implementation. Figure 3.15. Implementation of NOT, AND, and OR gates by NAND gates.

We can implement Boolean expressions with NAND gates only by carrying out the following steps in sequence: Step 1:

From the given Boolean expression, draw a logic diagram with AND, OR, and NOT gates. Assume that both normal (A) and complement A  inputs are available.

Step 2:

Draw a second logic diagram with equivalent NAND logic substituted for each AND, OR, and NOT gate.

Step 3:

Remove all pairs of inverters connected in cascade from the diagram because double inversion does not perform any logical function. Also, remove inverters connected to single external inputs and complement the corresponding input variable. The new logic diagram, so obtained, is NAND gates implementation of the Boolean expression.

The example here illustrates this process. Example 3.15.





Construct a logic circuit for the Boolean expression A  E   B  C  D  using NAND gates only. Solution: Step 1: We first draw the AND/OR implementation for the given Boolean expression [Figure 3.16(a)]. Step 2: Now, we substitute the NAND equivalent of each AND and each OR gate, resulting in Figure 3.16(b). Note that Figure 3.16(b) has six inverters (single input NAND gates) and four two-input NAND gates. Step 3: We now remove one pair of cascaded inverters. We also complement the three external inputs A, B, and E going directly to inverters, and remove the corresponding inverters. Figure 3.16(c) shows the final NAND gate implementation, so obtained. The number inside each NAND gate of Figure 3.16(c) corresponds to the NAND gate of Figure 3.16(b) having the same number.

For this example, the number of NAND gates required is equal to the number of AND/OR gates plus an additional inverter at the output (NAND gate number 5). In general, the number of NAND gates required to implement a Boolean expression equals the number of AND/OR gates except for an occasional inverter. This is true only when

90

Chapter 3 ■ Digital Systems Design

both normal and complement inputs are available because the conversion forces complementation of certain input variables. AE

A E

C D

CD

2

A  E B  C  D

B

B CD (a) AND/OR implementation.

OR

A

AE

1

E

A  E B  C  D AND

C

OR

2

D

AND

CD 4

3

5

B B+CD (b) Substituting equivalent NAND functions.

A E

1

C D

2

B

3

4

5

A  E B  C  D

(c) NAND implementation. Figure 3.16. Step-by-step NAND implementation for the Boolean expression of Example 3.15.

The Universal NOR Gate The NOR function is the dual of the NAND function. Hence, all procedures and rules for NOR logic form a dual of the corresponding procedures and rules for NAND logic. Like NAND gate, NOR gate is also universal because it is alone sufficient to implement any Boolean expression. To show this, we need to show that the logical operations AND, OR, and NOT can be implemented with NOR gates only. Figure 3.17 shows this.

■ Logic Gates

91

A A  AA  A A (a) NOT gate implementation.

A B

AB

AB AB

(b) OR gate implementation.

AB A

B

AAA

AB  AB

B B B (c) AND gate implementation.

Figure 3.17. Implementation of NOT, OR, and AND gates by NOR gates.

We can implement Boolean expressions with NOR gates only by carrying out the following steps in sequence: Step 1: For the given Boolean expression, draw the logic diagram with AND, OR, and NOT gates. Assume that both normal (A) and complement A inputs are available.



Step 2: Draw a second logic diagram with equivalent NOR logic substituted for each AND, OR, and NOT gate. Step 3: Remove all pairs of inverters connected in cascade from the diagram because double inversion does not perform any logical function. Also, remove inverters connected to single external inputs and complement the corresponding input variable. The new logic diagram, so obtained, is the NOR gate implementation of the given Boolean expression. Example 3.16. Construct a logic diagram for the Boolean expression A  B  C  A  B  D using NOR gates only. Solution: Step 1: We first draw the AND/OR implementation for the given Boolean expression [Figure 3.18(a)]. Step 2: Now, we substitute each OR gate with two NOR gates [as in Figure 3.18(b)] and each AND gate with three NOR gates [as in Figure 3.18(c)]. Figure 3.18(b) shows the resulting logic diagram. Note that Figure 3.18(b) has eight inverters (single input NOR gates) and five two-input NOR gates. Step 3: We now remove one pair of cascaded inverters (from the OR box to AND box). We also complement the five external inputs A, B , B, D, and C going directly to inverters and remove the corresponding inverters. The final NOR gate implementation, so obtained, is shown in Figure 3.18(c). The number inside each NOR gate of Figure 3.18(c) corresponds to the NOR gate of Figure 3.18(b) having the same number. The number of NOR gates in this example equals the number of AND/OR gates plus an additional inverter in the output (NOR gate number 6). In general, the number of NOR gates required to implement a Boolean expression

92

Chapter 3 ■ Digital Systems Design

equals the number of AND/OR gates except for an occasional inverter. This is true only if both normal and complement inputs are available. Otherwise, we need to use inverters to generate any required complemented input. Combinational circuits are more frequently constructed with NAND or NOR gates than with AND, OR, and NOT gates because NAND and NOR gates can be easily constructed with transistor circuits and Boolean expressions can be easily implemented with them. Moreover, NAND and NOR gates are considered superior to AND and OR gates because they supply outputs maintaining the signal value without loss of amplitude. OR and AND gates sometimes need amplitude restoration after the signal travels through a few levels of gates. A B

A B

A  B  C  A  B  D

BD

B D

A  B D

A C  A  B  D 

C

(a) AND/OR implementation AND

A 1

A B

B

A  B  C  A  B  D

OR AND

B

5

6

BD 2

D OR

AND

3

A

4

C

C  (A+ B  D)

A  B D (b) Substituting equivalent NOR functions

A B

1

A  B  C  A  B  D 5

B D A C

6

2 3 4

(c) NOR Implementation Figure 3.18. Step-by-step NOR implementation for the Boolean expression of Example 3.16.

■ Design of Combinational Circuits

93

DESIGN OF COMBINATIONAL CIRCUITS Design of a combinational circuit starts from the verbal outline of the problem and ends in a logic circuit diagram. The procedure involves the following steps: 1. State the given problem completely and exactly. 2. Interpret the problem to determine available input variables and required output variables. 3. Assign a letter symbol to each input variable and each output variable. 4. Design a truth table that defines the required relations between inputs and outputs. 5. Obtain simplified Boolean expression for each output. 6. Draw a logic circuit diagram to implement the Boolean expressions. The design procedure is illustrated here with the design of adder circuits because addition is the most basic arithmetic operation for any computer system. The following four rules summarize addition in binary system: 0+0=0 0+1=1 1+0=1 1 + 1 = 10 The first three operations produce a single-digit sum, but when both augend and addend bits are equal to 1, the sum consists of two digits. The higher significant bit of this result is called a carry. When the augend and addend numbers contain more than one digit, the carry obtained from the addition of two bits at any stage is added to the next pair of significant bits. A combinational circuit that performs the addition of two bits is called a half-adder. One that performs the addition of three bits (two significant bits and previous carry) is called a full-adder. The name of the former comes from the fact that we can implement a full-adder by using two half-adders.

Design of Half-Adder From the definition given above, a half-adder needs two binary inputs and two binary outputs. Input variables designate augend and addend bits whereas output variables produce sum and carry bits. Let A and B be the two inputs and S (for sum) and C (for carry) be the two outputs. The truth table of Figure 3.19 defines the function of a halfadder.

Boolean expressions for the two outputs (obtained from the truth table) are:

S  AB AB C  AB

Inputs A 0 0 1 1

B 0 1 0 1

Outputs C 0 0 0 1

S 0 1 1 0

Figure 3.19. Truth table for a half-adder.

Figure 3.20 shows the logic circuit diagram to implement these expressions.

94

Chapter 3 ■ Digital Systems Design

A

AB

A

S  AB AB

B

B

AB A B

C  AB Figure 3.20. Logic circuit diagram for a half-adder.

A half-adder can add only two single bits. Although, it generates a carry for the next higher pair of significant bits, it cannot accept a carry generated from the previous pair of lower significant bits. A full-adder solves this problem.

Design of Full-Adder A full-adder forms the arithmetic sum of three input bits. Hence, it consists of three inputs and two outputs. Two of the input variables (A and B) represent augend and addend bits and the third input variable (D) represents carry from the previous lower significant position. Two outputs are necessary because the sum of three binary digits ranges from 0 to 3 and binary 2 and 3 need two digits. Symbols S (for sum) and C (for carry) represent these two outputs. Truth table of Figure 3.21 defines the function of a full-adder. The 1s and 0s for the output variables are determined from the arithmetic sum of the three input variables. When all input variables are 0, the output is 0 for both C and S. The S output is equal to 1, when only one input is equal to 1, or when all three inputs are equal to 1. The C output is 1, if two or three inputs are equal to 1. Inputs

We can directly obtain sum-of-products expressions for the two outputs from the truth table as:

A 0 0 0 0 1 1 1 1

S  A  B D  A  B D  A  B D  A  B D C  A  B D  A  B D  A  B D  A  B D Although, it is not possible to simplify the expression for S, we can simplify the expression for C as follows:

B 0 0 1 1 0 0 1 1

Outputs D 0 1 0 1 0 1 0 1

C 0 0 0 1 0 1 1 1

S 0 1 1 0 1 0 0 1

Figure 3.21. Truth table for a full-adder.

C  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D

       A  A   B  D   B  B  A  D   D  D   A  B

 A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  B D  A  D  A  B  A  B  A  D  B D



■ Design of Sequential Circuits We can also simplify the expression for C by map simplification method (see Figure 3.22). A AB D 00

01

11

0 D

10

1

1

1

1

AB (set of two adjacent squares 6 and 7)

AD (set of two adjacent squares 5 and 7)

1

B

BD (set of two adjacent squares 3 and 7)

Original C = ABD  ABD  ABD  ABD Simplified C = AB + AD + BD Figure 3.22. Simplifying expression for C (carry) of a full-adder by map simplification method.

Hence, we obtain the following expressions for the two outputs:

S  A  B D  A  B D  A  B D  A  B D C  A  B  A  D  B D Figure 3.23 shows the logic circuit diagrams to implement these expressions. A B D

A  B D

A B D A B D

A  B D

A

AB

B A S

A B D

A  B D

D

A  B D

B

AD

C

BD

D (a) Logic circuit diagram for sum.

(b) Logic circuit diagram for carry.

Figure 3.23. Logic circuit diagrams for a full-adder.

We can also implement a full-adder with two half-adders and one OR gate as Figure 3.24 shows. AB

A B

HA

AB AB  A B

 A  B  D

C

ABD

S

HA D

Figure 3.24. Implementation of a full-adder with two half-adders and one OR gate.

95

96

Chapter 3 ■ Digital Systems Design

S output from the second half-adder is the Exclusive-OR of D and the output of the first half-adder giving:





S   A  B  A  B   D  A  B  A  B  D

      A  B  A  B  D  A  B D  A  B D        A  B    A  B   D  A  B  D  A  B  D    

     A  A  A  B  A  B  B  B  D  A  B  D  A  B  D   A  B  A  B  D  A  B  D  A  B  D

 A  B  A  B  D  A  B D  A  B D

 A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D  A  B D

.

In addition, we have carry output as:





C  AB AB D  AB



 A  B D  A  B D  A  B D  D



 A  B D  A  B D  A  B D  A  B D We can simplify this, as before, to

C  A  B  A  D  B D

A Parallel Binary Adder We use parallel binary adders to add two binary numbers. For example, if we want to add two four-bit numbers, we need to construct a parallel four-bit binary adder as Figure 3.25 shows. Such an adder requires one half-adder (denoted by HA) and three full-adders (denoted by FA). Here, the adder adds binary numbers A4 A3 A2 A1 and B4 B3 B2 B1, and the answer is: A4 B4

+ A 4 A 3 A 2 A1 B4 B3 B2 B1 S5 S4 S3 S2 S1

FA

S5

S4

Carry

A3 B3

FA

S3

Carry

A2 B2

FA

Carry

S2

A1 B1

HA

S1

Figure 3.25. A parallel four-bit binary adder.

The first column requires only a half-adder. For any column above the first one, there may be a carry from the preceding column. Therefore, we must use a full adder for each column above the first one.

■ Flip-Flops

97

To illustrate how the adder of Figure 3.25 works, let us see how it will add two numbers say, 9 and 11. The binary equivalent of decimal 9 is 1001 and that of decimal 11 is 1011. Figure 3.26 shows the binary adder with these inputs.

Carry FA

1

0

0

1

1

0

1

1

0

1

1

Carry

FA

Sum 1

0

Carry

FA

Sum 1

Carry

HA Sum

Sum 0

0

Figure 3.26. Example of adding two four-bit numbers using a parallel binary adder.

As shown in the figure, the half-adder adds 1 + 1 to give a sum of 0 and a carry 1. The carry goes into the first fulladder, which adds 0 + 1 + 1 to get a sum of 0 and a carry of 1. This carry goes into the next full-adder, which adds 0 + 0 + 1 to get a sum of 1 and a carry of 0. The last full-adder adds 1 + 1 + 0 to get a sum of 0 and a carry of 1. The final output of the system is 10100. The decimal equivalent of binary 10100 is 20, which is the correct decimal sum of 9 and 11. The parallel binary adder of Figure 3.26 has limited capacity. The largest binary numbers that it can add are 1111 and 1111. Hence, its maximum capacity is: 15 + 15

1111 + 1111

30

11110

We can increase its capacity by connecting more fulladders to the left end of the system. For instance, to add six-bit numbers we must connect two more full-adders, and to add eight-bit numbers we must connect four more fulladders to the leftmost full-adder of Figure 3.26.

FLIP-FLOPS Combinational circuits do not have the capability to store anything because they do not have any storage component. Hence, their outputs at any given time depend on their inputs at that time. Most digital systems design use combinational circuits with storage components. Digital circuits comprised of both combinational circuits and storage components are called sequential circuits. The most commonly used storage components in sequential circuits are flip-flops. A flip-flop is a clocked device that has two stable states and is, thereby, capable of storing one bit of information. It has two outputs, one for the normal value and one for the complement value of the bit stored in it. A flip-flop maintains its current binary state until directed by a clock pulse to switch its state. Hence, sequential circuits use a clock pulse generator that produces clock pulses at fixed intervals. A sequential circuit distributes the clock pulses throughout in such a way that only arrival of the clock pulses affects its flip-flops.

Types of Flip-flops There are several types of flip-flops available. They differ in the number of inputs they possess and in the manner in which the inputs affect the binary state. SR (set-reset), D (delay), T (toggle), and JK (Jack-Kilby) are the most commonly known types. They are described here.

98

Chapter 3 ■ Digital Systems Design

It is customary to represent the operational behaviour of a particular type of flip-flop in terms of a characteristic equation, which derives the next (after the next clock pulse) output [Qnext or Q(t+1)] in terms of the input signal(s) and/or the current output (Q or Q(t)). This behaviour is also often summarized in the form of a characteristic table, which shows the relations among Q, Q(t+1), and the input signal(s). Each type of flip-flop also has a graphic symbol (see Figure 3.27)

SR (Set-Reset) Flip-flop As Figure 3.27(a) shows, SR flip-flop has three inputs labeled S (for set), R (for reset), and C (for clock). It has two outputs labeled Q (for normal output) and Q (for complemented output). The arrowhead for C input designates a dynamic input and denotes the fact that the flip-flop responds to a positive transition of the input clock signal (when C changes from 0 to 1). If there is no signal at the clock input C, the output of the flip-flop does not change irrespective of the values of inputs S and R. The output of the flip-flop is affected according to the values of inputs S and R only when the clock signal C changes from 0 to 1. Sr. No.

a

b

Name (Type)

SR (SetReset)

D (Data)

Graphic symbol

Q

S C R

Q

D

Q

Characteristic equation

If S = R = 0 Q(t + 1) = Q(t)

Characteristic table S 0 0 1 1

D 0 1

Q(t + 1) = D

C Q

c

d

J K (JackKilby)

T (Toggle)

J

Q

K

Q

T

Q

Q(t  1)  JQ(t)  KQ(t)

Q (t 1)  Q (t)  T

or C Q

Q(t  1)  TQ(t)  TQ(t)

R 0 1 0 1

J 0 0 1 1

K 0 1 0 1

T 0 1

Q(t + 1) Q(t) 0 1 ?

Q(t + 1) 0 1

Q(t + 1) Q(t) 0 1 Q(t)

Q(t + 1) Q(t) Q(t)

Remarks No change Clear to 0 Set to 1 Indeterminate

Remarks Clear to 0 Set to 1

Remarks No change Clear to 0 Set to 1 Complement

Remarks No Change Complement

Figure 3.27. Commonly used flip-flops.

Characteristic table of Figure 3.27(a) summarizes the operation of SR flip-flop. If S = R = 0, the next state remains as current state on a clock transition (no change of state). If S = 0 and R = 1, the flip-flop goes to the 0 (clear) state, while if S = 1 and R = 0, the flip-flop goes to the 1 (set) state on a clock transition. If S = R = 1, the flip-flop produces an indeterminate next state on a clock transition (the output is unpredictable and may be either 0 or 1, depending on internal timing delays within the circuit). Hence, it should not be pulsed when S = R = 1. Due to this reason, SR flipflop is difficult to manage. Therefore, we seldom use it in practice.

■ Flip-Flops

99

D (Data) Flip-flop As Figure 3.27(b) shows, D flip-flop has two inputs labeled D (for data) and C (for clock). It has two outputs Q and Q . The output of the flip-flop is affected only when the clock signal C changes from 0 to 1. Notice from characteristic table of Figure 3.27(b) that if D = 0, the flip-flop goes to the 0 (clear) state, while if D = 1, the flip-flop goes to the 1 (set) state on a clock transition (when C changes from 0 to 1). Hence, the characteristic equation Q(t+1) = D is used to represent the operation of D flip-flop.

JK (Jack Kilby) Flip-flop JK flip-flop was designed to overcome the problem of indeterminate behaviour of SR flip-flop when S = R = 1. Hence, like SR flip-flop, it has three inputs labeled J (which corresponds to S input of SR flip-flop), K (which corresponds to R input of SR flip-flop), and C (for clock). It has two outputs Q and Q . The output of the flip-flop is affected only when the clock signal C changes from 0 to 1. Notice from characteristics table of Figure 3.27(c) that the behaviour of JK flip-flop is similar to that of SR flip-flop with inputs J and K corresponding to inputs S and R respectively, except that when J = K = 1, Q(t + 1) = Q(t) . The characteristic equation Q(t + 1) = JQ (t) + KQ (t) is used to represent the operation of JK flip-flop.

T (Toggle) Flip-flop As Figure 3.27(d) shows, T flip-flop has two inputs labeled T (for toggle) and C (for clock). It has two outputs Q and Q. Notice from characteristic table of Figure 3.27(d) that when T = 0, a clock transition (change of C from 0 to 1) does not change the state of the flip-flop. However, when T = 1, a clock transition changes the state of the flip-flop. Hence, the characteristic equation Q (t  1)  Q(t)  T or Q(t  1)  TQ(t)  TQ(t) is used to represent the operation of T flip-flop.

Excitation Tables In Figure 3.27, the characteristic tables for flip-flops specify the next state when the inputs and the present state are known. In actual design of digital circuits, designers usually know what should be the next state and need to find out the flip-flop input conditions that will cause transition from present to next state. Hence, designers use excitation tables for flip-flops that list all possible state changes and the input combinations for each state change. Figure 3.28 shows excitation tables for the four types of flip-flops described above. Notice from the figure that there are four possible transitions from present state Q(t) to next state Q(t + 1). Hence, each excitation table has four rows. For each transition, the tables show the required input conditions, which are derived from the respective characteristic tables. The don’t-care conditions (denoted by the symbol x) for certain inputs in the tables indicate that it does not matter whether those inputs to the flip-flop are 0 or 1. For example, in a JK flip-flop, transition from Q(t) = 0 to Q(t + 1) = 0 can be achieved by having inputs J = K = 0, or J = 0 and K = 1. That is, J must be 0, but K can be 0 or 1 for the required transition to occur. Hence, K input is marked as x against this transition, and it is left to the designer to choose either 0 or 1 for K input, whichever is more convenient.

100

Chapter 3 ■ Digital Systems Design

Q(t) 0 0 1 1

SR Flip-flop Q(t + 1) S 0 0 1 1 0 0 1 x

Q(t) 0 0 1 1

JK Flip-flop Q(t + 1) J 0 0 1 1 0 x 1 x

x 0 1 0

Q(t) 0 0 1 1

D Flip-flop Q(t + 1) 0 1 0 1

D 0 1 0 1

K x x 1 0

Q(t) 0 0 1 1

T Flip-flop Q(t + 1) 0 1 0 1

T 0 1 1 0

R

Figure 3.28. Excitation tables for SR, D, JK, and T flip-flops.

Edge-Triggered Flip-Flops In this type of flip-flop, output transitions occur only at a specific level (threshold level) of the clock pulse. When clock pulse level reaches the threshold level, output transition occurs and then the flip-flop becomes unresponsive to any further changes in inputs until the clock pulse returns to 0 and another pulse occurs. Two types of edge-trigged flip-flops are: 1. Positive edge-triggered in which output transition occurs when the rising edge of clock signal reaches the threshold level [see Figure 3.29(a)]. 2. Negative edge-triggered in which output transaction occurs when the falling edge of clock signal reaches the threshold level [see Figure 3.29(b)]. Figure 3.29 shows examples of a positive-edge-triggered D flip-flop and a negative-edge-triggered D flip-flop. The small circle at the input of clock signal C in Figure 3.29(b) indicates that it is a negative-edge-triggered flip-flop. Notice from Figure 3.29(a) that in a positive-edge-triggered D flip-flop, output transition occurs when clock pulse level rises from level 0 to level 1. The output cannot change when 1. Clock pulse is at level 1. 2. Clock pulse is in transition from level 1 to level 0. 3. Clock pulse is at level 0. 4. Clock pulse is in transition from level 0 to level 1 (the output changes as soon as the clock pulse reaches level 1, the threshold value in this example). The period covering 1, 2, and 3 above is called hold time, and that of 4 is called setup time. Similarly, notice from Figure 3.29(b) that in a negative-edge-triggered D flip-flop, output transition occurs when clock pulse level falls from level 1 to level 0 (the output changes as soon as the clock pulse reaches level 0, the threshold value in this example). The output cannot change otherwise.

■ Flip-Flops

101

Threshold level (output transition occurs) D

Q Clock pulse

C Q

Time

Setup time (During which positive clock transition occurs)

Hold time (During which output cannot change)

(a) Positive-edge-triggered D flip-flop

Threshold level (output transition occurs) D

Q

Clock pulse

C Q

Time Hold time (During which output cannot change)

Setup time (During which negative clock transition occurs)

(b) Negative-edge-triggered D flip-flop Figure 3.29. Edge-triggered flip-flops.

Master-Slave Flip-Flop A master-slave flip-flop is an interconnected circuit of two flip-flops in such a manner that the first one (master flipflop) responds to the positive level of clock signal, and the second one (slave flip-flop) responds to the negative level of clock signal. The result is that the output changes during the transition of the clock signal from level 1 to level 0. Figure 3.30 shows a master-slave D flip-flop created by connecting two D flip-flops in series, and inverting the clock signal input C for one of them. It behaves as a master-slave flip-flop because the second (slave) flip-flop in the series, changes only in response to a change in the first (master) flip-flop. Master D

Q

Slave D

C Q

Q

C Q

Figure 3.30. A master-slave D flip-flop.

Uses of Flip-flops Some popular uses of flip-flops are: 1. We can use a single flip-flop to store one bit of data. 2. We can use any one type of flip-flop to build any other type of flip-flop.

102

Chapter 3 ■ Digital Systems Design 3. Static RAMs use flip-flops in their design. Static RAM is the primary type of memory used in registers and in many caches. 4. Various types of counters and sequencers use flip-flops in their design. 5. Finite state machines use flip-flops and electronic logic circuits in their design. The flip-flops remember the machine’s previous state, and the electronic logic circuit uses that state to calculate the next state. 6. We can also use a chain of T flip-flops for frequency division of an input by 2 n, where n is the number of flipflops used between the input and the output.

SEQUENTIAL CIRCUITS Digital circuits that use both logic gates and flip-flops are known as sequential circuits. The logic gates constitute a combinational circuit. Hence, we also say that sequential circuits are digital circuits comprised of a combinational circuit and flip-flops. Inputs to the combinational circuit are external binary inputs and outputs of flip-flops. On the other hand, outputs of the combinational circuit serve as inputs to the flip-flops or are used as external outputs. After each clock transition, the binary value to be stored in the flip-flops is determined by the combinational circuit’s input to the flip-flops. Outputs of the sequential circuit include outputs of the combinational circuit and that of the flip-flops. The behaviour of a sequential circuit, therefore, depends on external inputs, outputs of its flip-flops, and binary states of the flip-flops. Hence, a sequential circuit is specified by a time sequence of external inputs, external outputs, and binary states of the flip-flops.

Flip-flop Input Equations We know that in a sequential circuit, outputs of its combinational circuit serve as inputs to its flip-flops. Moreover, we can express each output of a combinational circuit as a Boolean expression. Hence, inputs to the flip-flops of a sequential circuit can be described by a set of Boolean expressions. These Boolean expressions are called flip-flop input equations of the sequential circuit. An example can best explain the concept. Let us consider the sequential circuit of Figure 3.31(a). It has one input variable x and one output variable y. The AND, OR, and NOT gates form its combinational circuit. Its two clocked D flip-flops are named a and b. The input to D flip-flop a is designated as Da and its outputs are A and A . Similarly, the input to D flip-flop b is designated as Db and its outputs are B and B . C is the clock pulse input to both the flip-flops. From the figure, we can derive the flip-flop input equations as: Da = A  x  B  x Db = A  x In addition, we can derive the expression for output y as: y = A  x  B x

State Table We often express the behaviour of a sequential circuit in the form of a state table that consists of the following four sections: 1. Present state. It shows the states of flip-flops at any given time t. A sequential circuit with m flip-flops will contain m columns for present state. 2. Inputs. It gives a value of input variables for each possible present state. A sequential circuit with n input variables will have n columns for inputs.

■ Sequential Circuits

103

3. Next state. It shows the states of the flip-flops one clock period later at time t+1. A sequential circuit with m flip-flops will contain m columns for next state. 4. Outputs. It gives a value of output variables for each possible present state and inputs condition. A sequential circuit with p output variables will contain p columns for outputs. The present state and input columns are combined and under them, we list the 2 m+n binary combinations from 0 through 2m+n-1. The next-state and output columns are functions of the present state and input values. They are derived directly from the circuit or the Boolean equations that describe the circuit. As an example, Figure 3.31(b) gives the state table of the sequential circuit of Figure 3.31(a). We first list all possible binary combinations (000 to 111) of present states (A and B) of the two flip-flops (a and b respectively) and the single input (x). We then calculate the next state values (A and B) of the two flip-flops from their input equations. Hence, the values in next state column A are obtained by application of the input equation Da = A  x  B  x to each row, and that of column B are obtained by application of the input equation Db = A  x . Finally, we obtain the value of y in the output column by application of the expression y = A  x  B  x .

1

x

A·x

A xB x D

5 2

B·x C

Q

a

Q

A

D

A

C 7

3

Ax

C

b

Q

B

B

Ax

A  x  B x

6 4

Q

y

B x

clock pulse

Da  A  x  B  x

Db  A  x

y  A  x  B x

(a) A sequential circuit

Present state A B 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1

Next state

Input x 0 1 0 1 0 1 0 1

A 0 0 0 1 0 1 0 1

Output B 0 1 0 1 0 0 0 0

(b) State table of sequential circuit of (a)

y 0 0 1 0 1 0 1 0

0/0 00

1/0

0/1 1/0

0/1

10

01

0/1 1/0

1/0 11

(c) State diagram of sequential circuit of (a)

Figure 3.31. A sequential circuit with its state table and state diagram.

104

Chapter 3 ■ Digital Systems Design

State Diagram State diagram of a sequential circuit is a graphical representation of its behaviour. The graph represents a state by a circle, and transitions between states by directed lines connecting the circles. Since both state table and state diagram are two different forms of representing a sequential circuit, we can derive the state diagram of a sequential circuit from its state table. Figure 3.31(c) shows the state diagram of the sequential circuit of Figure 3.31(a), whose state table is shown in Figure 3.31(b). In the state diagram, each circle denotes a state of the flip-flops and has a binary number inside it to identify the state. Each directed line has a label of the form “input/output” in binary. For example, the directed line labeled 1/0 from state 00 to 01 indicates that when the sequential circuit is in the present state 00 and the input is 1, the output is 0, and the circuit goes to the next state 01 on a clock transition. We can verify this transition of the circuit from the entries in the 2 nd row of the state table. Similarly, we can transform each row of the state table into a directed line of the state graph to obtain the complete state graph of the sequential circuit. A directed line connecting a circle with itself indicates that no change of state occurs. Notice from the above that state table of a sequential circuit is easier to derive from its logic diagram, and we can easily derive its state diagram from the state table. It is easier for us to interpret circuit operation from state diagram as compared to that from state table. For example, it can be seen from the state diagram of Figure 3.31(c) that when the sequential circuit is in the present state 11, then (a) if input is 0, next state will be 00 and output will be 1; and (b) if input is 1, next state will be 10 and output will be 0.

DESIGN OF SEQUENTIAL CIRCUITS Design of a sequential circuit starts from its specifications and ends in a circuit diagram. The procedure involves the following steps: 1. From the specifications of the sequential circuit, we first translate its behaviour into a state diagram. 2. We then convert the state diagram into a state table. 3. We then choose the flip-flop type to be used in the circuit and extend the state table to an excitation table by including columns for each input of each flip-flop. Figure 3.28 shows the excitation tables for the four types of flip-flops. 4. The excitation table provides the truth table for the combinational circuit part of the sequential circuit. The present-state and input columns constitute the inputs in the truth table, while the flip-flop input conditions constitute the outputs. 5. We then use map simplification method to obtain a set of flip-flop input equation for the combinational circuit. 6. Finally, we convert each flip-flop input equation into an equivalent logic diagram, whose output is connected to one of the flip-flop inputs. The combinational circuit so obtained, together with the flop-flops, constitutes the sequential circuit. We illustrate the design procedure here with the design of a binary counter because several electronic devices (clocks, ovens, microwave ovens, music systems, etc.) use counters.

■ Design of Sequential Circuits

105

Design of Binary Counter For simplicity, we first design a sequential circuit for a two-bit binary counter. Such a counter goes through a sequence of (22 = 4) binary states 00, 01, 10, 11. After 11, the counter repeats counting from 00. The counter changes state only when an external input x is equal to 1. It remains in the same state when x = 0. Hence, x serves as count enable input. From the above specifications of the 2-bit binary counter, we draw its state diagram [see Figure 3.32(a)]. The counter needs two flip-flops and four states to represent the two bits. We label the edges of the state diagram with input values only because this sequential circuit has no external outputs. The state of the flip-flops is the outputs of the counter. We then convert the state diagram of Figure 3.32(a) into the state table (first five columns) of Figure 3.32(b). Figure 3.32(b) is actually the excitation table (state table plus flip-flop inputs) obtained by extending the state table with the choice of two JK flip-flops for the design. The two flip-flops are named ‘a’ and ‘b’. Accordingly, their inputs are (J a, Ka) and (Jb, Kb) respectively, while their outputs are represented by ‘A’ and ‘B’. We extend the state table (first five columns) of Figure 3.32(b) to excitation table by adding the last four columns in the following manner: 1. In rows 1, 2 and 3 of excitation table of Figure 3.32(b), we have a transition for flip-flop ‘a’ from 0 in the present state (column 1) to 0 in the next state (column 4). In Figure 3.28, we find that a transition of states from Q(t) = 0 to Q(t+1) = 0 in a JK flip-flop requires that input J = 0 and input K = X. Hence, 0 and X are entered in columns 6 (Ja) and 7 (Ka) respectively of rows 1, 2 and 3 in excitation table of Figure 3.32(b). Due to same reason, for flip-flop ‘b’, 0 and X are entered in columns 8 (J b) and 9 (Kb) respectively of rows 1 and 5. 2. In row 4 of excitation table of Figure 3.32(b), we have a transition for flip-flop ‘a’ from 0 in the present state (column 1) to 1 in the next state (column 4). In Figure 3.28, we find that a transition of states from Q(t) = 0 to Q(t+1) = 1 in a JK flip-flop requires that input J = 1 and input K = X. Hence, 1 and X are entered in columns 6 (Ja) and 7 (Ka) respectively of row 4 in excitation table of Figure 3.32(b). Due to same reason, for flip-flop ‘b’, 1 and X are entered in columns 8 (J b) and 9 (Kb) respectively of rows 2 and 6. 3. In rows 5, 6 and 7 of excitation table of Figure 3.32(b), we have a transition for flip-flop ‘a’ from 1 in the present state (column 1) to 1 in the next state (column 4). In Figure 3.28, we find that a transition of states from Q(t) = 1 to Q(t+1) = 1 in a JK flip-flop requires that input J = X and input K = 0. Hence, X and 0 are entered in columns 6 (Ja) and 7 (Ka) respectively of rows 5, 6 and 7 in excitation table of Figure 3.32(b). Due to same reason, for flip-flop ‘b’, X and 0 are entered in columns 8 (Jb) and 9 (Kb) respectively of rows 3 and 7. 4. In rows 5, 6 and 7 of excitation table of Figure 3.32(b), we have a transition for flip-flop ‘a’ from 1 in the present state (column 1) to 1 in the next state (column 4). In Figure 3.28 we find that a transition of states from Q(t) = 1 to Q(t+1) = 1 in a JK flip-flop requires that input J = X and input K = 0. Hence, X and 0 are entered in columns 6 (Ja) and 7 (Ka) respectively of rows 5, 6 and 7 in excitation table of Figure 3.32(b). Due to same reason, for flip-flop ‘b’, X and 0 are entered in columns 8 (J b) and 9 (Kb) respectively of rows 3 and 7. 5. In row 8 of excitation table of Figure 3.32(b), we have a transition for flip-flop ‘a’ from 1 in the present state (column 1) to 0 in the next state (column 4). In Figure 3.28, we find that a transition of states from Q(t) = 1 to Q(t+1) = 0 in a JK flip-flop requires that input J = X and input K = 1. Hence, X and 1 are entered in columns 6 (Ja) and 7 (Ka) respectively of row 8 in excitation table of Figure 3.32(b).

106

Chapter 3 ■ Digital Systems Design Due to same reason, for flip-flop ‘b’, X and 1 are entered in columns 8 (J b) and 9 (Kb) respectively of rows 4 and 8 in excitation table of Figure 3.32(b). x=0

Present state A B 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1

x=0 x=1

00

01

x=1

x=1

11

10

x=1

x=0

x=0

Next state A B 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0

Input x 0 1 0 1 0 1 0 1

(a) State diagram

Flip-flop inputs Ja 0 0 0 1 X X X X

(b) Excitation table

A

A AB

AB 00

x

01

11

10

X

X

X

X

0 x

1

1

00

01

0

X

X

1

X

X

x

x

11

1

Ka = B · x A

A AB

AB 00

01

11

X

X

X

X

0 x

1

10

B

B Ja = B · x

x

Ka X X X X 0 0 0 1

1

x

10

x

1

00

0

X

1

X

01

11

10 X

1

1

X

B

B Kb = x

Jb = x

(c) K-maps to obtain simplified flip-flop input equations (Ja, Ka, Jb and Kb)

A

B B·x

x J C K C

b

Q

J

Q

C K

Q

a

Q

clock pulse (d) Sequential circuit diagram Figure 3.32. Design of a 2-bit binary counter.

Jb 0 1 X X 0 1 X X

Kb X X 0 1 X X 0 1

■ Points to Remember

107

The excitation table of Figure 3.32(b) obtained in this manner provides the truth table for the combinational circuit part of the sequential circuit for 2-bit binary counter. The present state and input columns (columns 1, 2 and 3) constitute the inputs in the truth table, while the flip-flop input conditions (columns labeled J a, Ka, Jb and Kb) constitute the outputs. Using this information, we now draw four 3-variable K-maps in Figure 3.32(c) and obtain the four simplified flip-flop input equations as: Ja = B  x Ka = B  x

Jb = x Kb = x

We now convert each of these flip-flop input equation into an equivalent logic diagram, whose output is connected to one of the flip-flop inputs. Figure 3.32(d) shows the combinational circuit so obtained, together with the flip-flops. This is the sequential circuit for the 2-bit binary counter. Note that inputs J and K determine the next state of the counter when a clock pulse occurs. If both J and K are equal to 0, a clock pulse will not have any effect (the state of flip-flops will not change). Hence, where x = 0, all four inputs to the flip-flops are equal to 0 and the state of the flip-flops do not change even if clock pulses are applied continuously. Synchronous binary counters have a regular pattern. Hence, the sequential circuit diagram of Figure 3.32(d) can be extended to design a n-bit binary counter with n JK flip-flops and n-1 AND gates. The chain of AND gates generates the required logic for the J and K inputs. Based on this idea, Figure 3.33 shows the sequential circuit diagram of a 4bit binary counter, which can count from 0000 to 1111 in binary number system. It goes through a sequence of (2 4 = 16) binary states 0000, 0001, 0010, …, 1111. After 1111, the counter repeats counting from 0000. The counter changes state only when the count-enable input (x) is equal to 1. It remains in the same state when x = 0. Count-enable input (x)

D

J C K

d

C

Q

J

Q

C K

c

B

Q

J

Q

C K

b

A

Q

J

Q

C K

Q

a

Q

Clock pulse (C) Figure 3.33. Sequential circuit of a 4-bit binary counter.

Points to Remember 1.

Boolean algebra deals with binary number system. That is, variables used in Boolean equations may have only two possible values (0 and 1).

2.

In Boolean algebra, ‘OR’ operator used for logical addition is represented by the symbol ‘+’; ‘AND’ operator used for logical multiplication is represented by the symbol ‘’; and ‘NOT’ operator used for complementation is represented by the symbol ‘’.

3.

As regards precedence of Boolean operators, ‘NOT’ takes precedence over ‘AND’ and ‘OR’; and ‘AND’ takes precedence over ‘OR’.

4.

Postulates of Boolean algebra are: (a) A = 0, if and only if, A is not equal to 1 (b) A = 1, if and only if, A is not equal to 0 (c) x  0 = x

(d) x  1 = x (e) x  y = y  x (f) x  y = y  x

108

Chapter 3 ■ Digital Systems Design (g) x  (y  z) = (x  y)  z (h) x  (y  z) = (x  y)  z (i) x  (y  z) = x  y  x  z

5.

(j) x  y  z = (x  y)  (x  z) (k) x  x = 1 (l) x  x = 0

In Boolean algebra, there is a precise duality between the operators  (AND) and + (OR) and the digits 0 and 1. This property is known as the principle of duality.

6.

Figure 3.7 summarizes the basic Boolean identities. They are helpful while dealing with Boolean algebra.

7.

A Boolean function is an expression formed with binary variables, the two binary operators OR and AND, the unary operator NOT, parentheses, and equal to sign.

8.

Complement of a Boolean function F isF and is obtained by interchanging 0s for 1s and 1s for 0s in the truth table defining the function.

9.

A sum-of-products expression is a single product term (minterm), or several product terms (minterms) logically added (ORed) together. For example, x y + x y is a sum-of-products expression.

10. A product-of-sums expression is a single sum term (maxterm), or several sum terms (maxterms) logically multiplied (ANDed) together. For example, ( x + y)  (x + y ) is a product-of-sums expression. 11. Sum-of-products and product-of-sums forms of Boolean expressions are known as standard forms. They are preferred for logic circuit design because of their straightforward conversion to simple gating networks. 12. K-map (Karnaugh map or simply map) is a pictorial representation of a Boolean function. It consists of squares, with each square representing one minterm. Hence, the number of squares in a map of n variable is 2 n. We use K-map for minimization of Boolean functions. 13. A logic gate is an electronic circuit that operates on one or more input signals to produce standard output signals. Logic gates are building blocks of electronic circuits in a computer. 14. Commonly used logic gates are AND, OR, NOT, NAND, NOR, Exclusive-OR (XOR), and Exclusive-NOR (Equivalence). Figure 3.14 shows their graphic symbols, Boolean functions, and truth tables. 15. Logic gates are interconnected to form gating or logic networks known as combinational logic circuits. 16. AND, OR, and NOT gates are logically complete because any Boolean expression may be realized using these three gates. 17. NAND gate is a universal gate because it is alone sufficient to implement any Boolean expression. Similarly, NOR gate is also a universal gate. 18. Most digital systems design use combinational circuits with storage components. Digital circuits comprised of both combinational circuits and storage components are called sequential circuits. 19. The most commonly used storage components in sequential circuits are flip-flops. A flip-flop is a clocked device that has two stable states and is, thereby, capable of storing one bit of information. 20. Different types of flip-flops differ in the number of inputs they possess and in the manner in which the inputs affect the binary state. SR (set-reset), D (delay), T (toggle), and JK (Jack-Kilby) are the most commonly known types. Figure 3.27 shows their graphic symbols, characteristic equations, and characteristic tables. Figure 3.28 shows their excitation tables. 21. In an edge-triggered flip-flop, output transactions occur only at a specific level (threshold level) of the clock pulse. Two types of edge-triggered flip-flop are: (a) positive edge-triggered in which output transition occurs when the rising edge of clock signal reaches the threshold level, and (b) negative edge-triggered in which output transition occurs when the falling edge of clock signal reaches the threshold level. 22. A master-slave flip-flop is an interconnected circuit of two flip-flops in such a manner that the first one (master flip-flop) responds to the positive level of clock signal, and the second one (slave flip-flop) responds to the negative level of clock signal. 23. Design of a combinational circuit or a sequential circuit starts from its problem specifications and ends in a circuit diagram. The circuit diagram of a combinational circuit consists of logic gates, while that of a sequential circuit consists of logic gates and flip-flops.

■ Questions

109

Questions 1.

Explain the principle of duality in Boolean algebra. How it is useful?

2.

Write the dual of the following Boolean expressions:

(a) A  B

(d) A  B

(b) A  B  C

(e) A   A  B 

(c) A  B  A  B

(f ) A  A  B

3.

Write the dual of the rule A  A  B  A  B .

4.

Prepare truth tables for the following Boolean expressions: (a) A  B  A  B (e) A  B  C

(b) A  B  C  B  C

(f ) A  B  C  A  B  C

(c) A  B

(g)  A  B   A  C    B  C 

(d) A  B  C

(h) A  C  A  C

5.

State and prove the two basic De Morgan’s theorems.

6.

Prove the following rules by the method of perfect induction:

(a) A  B  A  B  A



(e)  A  B   A  B  A  B  A  B

(c) A   A  C   A 7.



(d)  A  B  A  B  A  B  B  A

(b) A  A  B  A  B

Simplify the following Boolean expressions and draw logic circuit diagrams for your simplified expressions by using AND, OR, and NOT gates:

(a) x  y  z  x  y  z  x  y  z  x  y  z

(d) A  B  C  A  B  C  A  B  C  A  B  C  A  B  C

(b) x  y  z  x  y  z  x  y  z  x  y  z

(e)  A  B  C    A  B  C    A  B  C    A  B  C 

(c) A  C  A  B  A  B  C  B  C

(f )  A  B  C    A  B  C  A  B  C  A  B  C



8.

Let F  x  y  z  x  y  z  x  y  z be a Boolean function. (a) Prepare a truth table for F. (b) Draw a logic circuit diagram for original F by using AND, OR, and NOT gates. (c) Simplify F using K-map. (d) Prepare a truth table for the simplified expression and prove that it is the same as the truth table of part (a). (e) Draw a logic circuit diagram for the simplified expression by using AND, OR, and NOT gates. Compare the total number of gates of this logic diagram and that of part (b).

9.

Find the complement of the following Boolean expressions: (a) A  B  A  C (e)  A  B   B  C    A  C 

(b) A  B  A  B (c) A   B  C  B  C  (d) A   B  C  10.

(f ) A   B  C    C  D  (g) A  B   A  B   B  C  B  C 

Let F  x  y  x  y  z be a Boolean function. Find F and prove that (a) F  F  0 (b) F  F 1

110 11.

12.

Chapter 3 ■ Digital Systems Design Express the following Boolean expressions in their sum-of-products form. Ensure that each term has all the literals.

(a) A   B  C 

(d)  A  B   A  B  C  A  C 

(b)  A  B   B  C 

(e)  A  C    A  B  C    A  B

(c)  A  B  C

(f )  A  C    A  B  A  C  B  C 

Express the following Boolean expressions in their product-of-sums form. Ensure that each term has all the literals.

(a) A  B  C

(d)  A  B    A  C  B  C 

(b) A  B  C

(e)  A  B    B  C 

(c) A  B  C

(f ) A  A  B  A  C

13.

Simplify the following Boolean functions using K-maps: (a) F (x, y, z) = Σ (0, 2, 3, 4, 6) (c) F (w, x, y, z) = Σ (3, 7, 11, 13, 14, 15) (b) F (x, y, z) = Σ (1, 2, 3, 6, 7) (d) F (w, x, y, z) = Σ (0, 1, 2, 4, 5, 7, 11, 15)

14.

Let F  AC  BD  ACD  ABCD be a Boolean expression. Find the simplified expression for F in (a) Sum-of-products form and (b) Product-of-sums form.

15.

Using K-map, simplify the Boolean function F (w, x, y, z) = Σ (0, 2, 4, 5, 6, 7, 8, 10, 13, 15) and draw logic diagrams for the simplified expression by using (a) AND-OR-NOT gates (b) NAND gates only

16.

Using K-map, simplify the Boolean function F (A, B, C, D) = Π (0, 1, 8, 9, 10, 12, 13) and draw logic diagrams for the simplified expression by using (a) AND-OR-NOT gates (b) NOR gates only

17.

Simplify the Boolean function F (A, B, C, D) = Σ (0, 1, 2, 3, 7, 8, 10) together with the don’t care conditions d (A, B, C, D) = Σ (5, 6, 11, 15) and draw logic diagram for the simplified expression by using AND-OR-NOT gates.

18.

What will be the outputs of the following logic circuits?

(a) A C

A B C D

B D

(b) A B

A C

B C

■ Questions

111

(c) A

B A B C D

B D 19.

Construct logic circuit diagrams for the following Boolean expressions by using AND, OR, and NOT gates:

(a)  A  B   A  C    B  C  (b) A  B   A  B   B  C  B  C  (c)  A  B   A  C    A  B 20.

“AND, OR, and NOT gates are logically complete”. Discuss.

21.

Why are NAND and NOR gates called universal gates?

22.

Draw the implementation of logical operations AND, OR, and NOT with (a) NAND gates only, and (b) NOR gates only.

23.

Construct logic circuit diagrams for Boolean expressions of Question 19 by using (a) NAND gates only, and (b) NOR gates only.

24.

Construct logic circuit diagram for a half-adder by using NAND gates only.

25.

Construct logic circuit diagram for a half-adder by using NOR gates only.

26.

Why combinational circuits are constructed more frequently with NAND or NOR gates than with AND, OR, and NOT gates?

27.

Prove that (a)  A  B  C  A   B  C  (b) (A  B)  C = A  (B C)

28.

Using DeMorgen’s theorem, prove that (a)

 x + y   x  y   0

(b) x  x  y  x  y 1 29.

Construct logic circuit diagrams for Exclusive-OR function by using (a) NAND gates only, and (b) NOR gates only.

30.

Construct logic circuit diagrams for Equivalence function by using (a) NAND gates only, and (b) NOR gates only.

31.

A logic circuit has three inputs, A, B, and C. It generates an output of 1 only when A = 0, B = 1, C = 0, or when A = 1, B = 1, C = 0. Design a combinational circuit for this system.

32.

A logic circuit has three inputs, A, B, and C. It generates an output of 1 only under the following conditions: A = 0, B = 0, C = 0 A = 0, B = 1, C = 1 A = 1, B = 0, C = 1 A = 1, B = 1, C = 1 Design a combinational circuit for this system.

112

Chapter 3 ■ Digital Systems Design

33.

Design a gating network that will have outputs 0 only when A = 0, B = 0, C = 0; A = 1, B = 0, C = 0; A = 1, B = 1, C = 0. The outputs are to be 1 for all other cases.

34.

A three-bit message is to be transmitted with an odd parity. An odd parity generator generates a parity bit (say P) to make the total number of 1s odd (including P). That is, P = 1, only when the number of 1s in the input string is even. Design a combinational logic circuit for such a parity generator.

35.

Design a combinational logic circuit to generate an even parity for hexadecimal digits.

36.

Design a combination circuit for a three-input majority function. A majority function generates on output of 1 if the input variables have more 1s than 0s, otherwise the output is 0.

37.

A sequential circuit has two D flip-flops ‘a’ and ‘b’, two inputs x and y, and one output z. The inputs to flip-flops ‘a’ and ‘b’ are designated as Da and Db respectively, and their outputs are designated as (A, A ) and (B, B ) respectively. The flipflop input equations are Da = x  y  x  A Db =

x  B x  A

and the expression for output z is z =B Draw the sequential circuit diagram and tabulate the state table. 38.

Design a sequential circuit for a 2-bit count down counter. Such a counter goes through a sequence of binary states 11, 10, 01, 00. After 00, the counter repeats counting from 11. The counter changes state only when an external input x is equal to 1. It remains in the same state when x = 0.

Computer Architecture

This chapter provides an overview of computer system architecture. It first introduces the basic functional units of a computer system and then provides detail architectures of processor and memory. Subsequent chapters provide details of other units (secondary storage and I/O devices). This chapter also provides details of interconnection architectures used for interconnecting processor, memory, and I/O units. Finally, it also provides details of multiprocessor system architectures, which use multiple processors and memory units to form powerful computer systems.

BASIC FUNCTIONS OF A COMPUTER All computer systems perform the following five basic functions for converting raw input data into useful information and presenting it to a user: 1. Inputting. It is the process of entering data and instructions into a computer system. 2. Storing. It is the process of saving data and instructions to make them readily available for initial or additional processing as and when required. 3. Processing. Performing arithmetic operations (add, subtract, multiply, divide, etc.), or logical operations (comparisons like equal to, less than, greater than, etc.) on data to convert them into useful information is known as processing. 4. Outputting. It is the process of producing useful information or results for a user, such as printed report or visual display. 5. Controlling. Directing the manner and sequence in which the above operations are performed is known as controlling.

BASIC COMPUTER ORGANIZATION Even though the size, shape, performance, reliability, and cost of computers have been changing over the last several years, the basic logical structure (based on stored program concept), as proposed by Von Neumann, has not changed.

Chapter 4 ■ Computer Architecture

114

Figure 4.1 shows a block diagram of basic computer organization. In this figure, solid lines indicate flow of instruction and data, and dotted lines represent control exercised by control unit.

Basic Functional Units Figure 4.1 shows the four basic functional units of a digital computer system – input unit, storage unit, central processing unit, and output unit. Their functions are: 1.

Input unit. An input unit performs inputting operation. It carries out the following functions: (a) It accepts (or reads) instructions and data from outside world. (b) It converts these instructions and data to computer acceptable form. Units called input interfaces accomplish this task. (c) It supplies the converted instructions and data to the storage unit for storage and further processing.

2.

Output unit. An output unit performs outputting operation. It carries out the following functions: (a) It accepts the produced results, which are in coded form. We cannot understand the coded results easily. (b) It converts these coded results to human acceptable (readable) form. Units called output interfaces accomplish this task. (c) It supplies the converted results to outside world.

3.

Storage unit. A storage unit performs storing operation. Specific functions of the storage unit are to hold (store): (a) The data and instructions required for processing (received from input units). (b) Intermediate results of processing. (c) Final results of processing, before the system releases them to an output unit. Storage unit of all computers is comprised of the following two types of storage: (a) Primary storage. Primary storage of a computer system, also known as main memory, stores pieces of program instructions and data, intermediate results of processing, and recently produced results of those job(s) on which the computer system is currently working. The central processing unit can access these pieces of information directly at a very fast speed. However, primary storage is volatile, and it loses the information in it as soon as the computer system switches off or resets. Moreover, primary storage normally has limited storage capacity because it is very expensive. Primary storage of modern computer systems is made up of semiconductor devices. (b) Secondary storage. Secondary storage of a computer system, also known as auxiliary storage, takes care of the limitations of primary storage. It supplements the limited storage capacity and volatile characteristic of primary storage. This is because secondary storage is much cheaper than primary storage and it can retain information even when the computer system switches off or resets. A computer system uses secondary storage to store program instructions, data, and information of those jobs on which the computer system is currently not working but needs to hold them for processing later. The most commonly used secondary storage medium is magnetic disk.

4.

Central Processing Unit (CPU). CPU performs processing and controlling operations. It is the brain of a computer system. In a human body, the brain takes all major decisions and other parts of the body function as directed by the brain. Similarly, in a computer system, the CPU performs all major calculations and comparisons, and also activates and controls the operations of other units of the computer system. The two components of a CPU are Arithmetic Logic Unit (ALU) and Control Unit (CU). Their functions are: (a) Arithmetic Logic Unit. A computer performs all calculation and comparison (decision-making) operations in the ALU. During processing of a job, the computer transfers data and instructions stored

■ Basic Computer Organization

115

in its primary storage to ALU as and when needed. ALU does the processing and the computer temporarily transfers the intermediate results generated there back to primary storage until needed later. Hence, data may move back and forth several times between primary storage and ALU before processing of the job is over. The engineering design of a computer’s ALU determines the type and number of arithmetic and logic operations that a computer can perform. However, almost all ALUs are designed to perform the four basic arithmetic operations (add, subtract, multiply, and divide) and logic operations or comparisons such as, less than, equal to, and greater than. (b) Control Unit. A computer’s control unit does not perform any actual processing of jobs, but acts as the central nervous system for other components of the computer system. It manages and coordinates the operations of all other components. It obtains instructions from a program stored in main memory, interprets the instructions, and issues signals causing other units of the system to execute them. Storage unit

Program and data

Input unit

Secondary storage Primary storage

Output unit

Information (Results)

Control Unit Arithmetic Logic Unit Central Processing Unit (CPU)

Indicates flow of instructions and data Indicates the control exercised by the control unit

Figure 4.1. Basic organization of a computer system.

System Concept We often refer to a computer as a system (computer system). This is because a system is a group of integrated parts having a common purpose of achieving some objective(s). Hence, a system has the following three characteristics: 1.

It has more than one element.

2.

All its elements are related logically.

3.

All its elements are controlled in a manner to achieve the system goal.

Since a computer has integrated components (input unit, output unit, storage unit, and CPU), which work together to perform the steps called for in an executing program, it is a system. Input and output units cannot function until they receive signals from the CPU. Similarly, storage unit or CPU alone is of no use. Usefulness of each unit depends on other units and is realizable only when we integrate all units to form a system. Hence, we refer to a computer as a system (computer system).

116

Chapter 4 ■ Computer Architecture

Basic Processor and Memory Architecture Figure 4.1 presented the basic organization of a computer system showing its major functional units. Figure 4.2 shows the basic architecture of a computer’s main processor and main memory. These two functional units are located on the main circuit board (motherboard) of a computer. As Figure 4.2 shows, the secondary storage and I/O devices are usually in the form of independent units connected to the motherboard. ROM

EPROM

PROM Main memory (RAM) Cache memory

S E C O N D A D R E Y V I S C T E O S R A G E

Storage interfaces

Decoder

Accumulator register

Program control register

General-purpose register

Instruction register

General-purpose register

I/O

I/O interfaces

Memory address register Memory buffer register

D E V I C E S

I/O register General-purpose register

General-purpose register

Control Unit

Arithmetic Logic Unit

Central Processing Unit Figure 4.2. Processor and memory architecture of a computer system.

CPU ARCHITECTURES CPU is the brain of a computer system. It performs all major calculations and comparisons, and also activates and controls the operations of other units of the computer system. Hence, no other single component of a computer determines its overall performance as much as its CPU. To evaluate a computer’s capabilities, it is important to know how CPUs are internally structured, how different CPUs differ from each other, and how to evaluate CPU speed. These and other related concepts are described here.

Basic Components of CPU Control Unit (CU) and Arithmetic Logic Unit (ALU) are the two basic components of a CPU. Their functions are:

■ CPU Architectures

117

1.

Control Unit (CU). The control unit of a CPU selects and interprets program instructions and then coordinates their execution. As Figure 4.2 shows, it has some special purpose registers (whose functions are described in a later subsection) and a decoder to perform these activities. The special purpose registers named instruction register and program control register, respectively, hold the current instruction and the next instruction for execution, and in this way help the control unit in instruction selection. On the other hand, the decoder has necessary circuitry to decode and interpret the meaning of every instruction supported by the CPU. Each instruction is accompanied by microcode – basic directions that tell the CPU how to execute the instruction.

2.

Arithmetic Logic Unit (ALU). ALU of a CPU is the place where execution of instructions takes place during data processing. When the control unit encounters an instruction that involves an arithmetic operation (such as add, subtract, multiply, divide) or a logic operation (such as less than, equal to, greater than) it passes control to the ALU. As Figure 4.2 shows, the ALU has some special purpose registers (whose functions are described in a later subsection) and necessary circuitry to carry out all arithmetic and logic operations included in the set of instructions supported by the CPU. For example, control unit might load two numbers into ALU registers and then tell the ALU to add them (an arithmetic operation) or to check if they are equal (a logical operation). When entire CPU (both CU and ALU) is contained on a single tiny silicon chip, it is called a microprocessor.

CPU Instruction Set Every CPU has built-in ability to execute a set of machine instructions called its instruction set. Most CPUs have 200 or more instructions (such as add, subtract, and compare) in their instruction set. The list of instructions supported by a CPU in its instruction set forms the basis for designing the machine language for the CPU. Since each processor has a unique instruction set, machine language programs written for one computer will not run on another computer with a different CPU. CPUs made by different manufacturers have different instruction sets. In fact, different CPU models of the same manufacturer may have different instruction sets. However, manufacturers tend to group their CPUs into “families” having similar instruction sets. When they develop a new CPU, they ensure that its instruction set includes all instructions in the instruction set of its predecessor CPU plus some new ones. This manufacturing strategy is known as backward compatibility and the new CPU is said to be backward compatible with its predecessor. This feature allows software written for a computer with a particular CPU to work on computers with newer processors of the same family. In turn, it allows users of these computer systems to upgrade their systems without worrying about converting all their existing software.

CPU Registers As a computer’s CPU interprets and executes instructions, there is movement of information between various units of the computer. To handle this process and to speed up the rate of information transfer, the CPU uses a number of special memory units called registers. These registers hold information on a temporary basis and are part of CPU (not main memory). Length of a register is equal to the number of bits it can store. Hence, we refer to a register that can store 8 bits as an 8-bit register. Most CPUs sold today have 32-bit, 64-bit or 128-bit registers. The length of registers of a computer is sometimes called its word size. The bigger the word size, the faster a computer can process a set of data. With all other parameters being same, a CPU with 32-bit registers can process data twice as large as one with 16-bit registers. Although, the number of registers varies from computer to computer, there are some registers common to all computers. Functions of these registers are described here. Each of these registers possesses the ability to receive information, hold it temporarily, and pass it on as directed by the control unit.

Chapter 4 ■ Computer Architecture

118 1.

Memory Address Register (MAR). It holds the address of the active memory location. It is loaded from program control register when the system reads an instruction from memory.

2.

Memory Buffer Register (MBR). It holds the contents of the accessed (read/written) memory word. The system transfers an instruction word placed in this register to instruction register. A data word placed in this register is accessible for operation with accumulator register or for transfer to I/O register. To store a word in a memory location, the system first transfers it to MBR and then writes it in memory from MBR.

3.

Program Control register (PC). It holds the address of the next instruction for execution. Normally, a system stores instructions of a program in consecutive memory locations, and executes them in sequence unless it encounters a branch instruction. A branch instruction is an operation that causes a transfer to a nonconsecutive instruction. The system transfers address part of a branch instruction to PC register so that it becomes the address of the next instruction.

4.

Accumulator register (A). It holds the data on which the system has to operate, intermediate results, and results of operations performed. The system uses it during the execution of most instructions. The system returns the result of an arithmetic operation to accumulator register for transfer to main memory through memory buffer register. Many computers have more than one accumulator registers.

5.

Instruction register (I). It holds the current instruction under execution. As soon as the instruction is stored in this register, its operation and address parts (see Chapter 9) are separated. The system sends the address part of the instruction to MAR, while it sends operation part to control unit, where it is decoded and interpreted. Finally, the control unit generates and sends command signals to the appropriate unit for carrying out the task specified in the instruction.

6.

Input/Output register (I/O). The system uses it to communicate with input/output devices. An input device transfers all input information (such as instructions and data) to this register. Similarly, the system transfers all output information to this register and an output device picks up data for output from here.

Figure 4.3 summarizes the functions of these registers. Sl. No.

Name of register

1

Memory Address (MAR)

2

Memory Buffer (MBR)

Holds information on its way to and from memory

3

Program Control (PC)

Holds address of the next instruction to be executed

4

Accumulator (A)

Accumulates results and data to be operated upon

5

Instruction (I)

Holds an instruction while it is being executed

6

Input/Output (I/O)

Communicates with I/O devices

Function Holds address of the active memory location

Figure 4.3. Functions of various registers.

Execution of an instruction by the CPU during program execution normally involves the following steps: 1.

The control unit takes the address of the next program instruction for execution from program control register and reads the instruction from corresponding memory address into the instruction register of control unit.

2.

The control unit then sends the operation and address parts of the instruction to the decoder and memory address register, respectively.

3.

The decoder interprets the instruction and accordingly the control unit sends command signals to the appropriate unit for carrying out the task specified in the instruction. For example, if it is an arithmetic or logic operation, the control unit sends signal to ALU. In this case, the control unit also ensures that the data corresponding to the address part of the instruction is loaded in a suitable register in ALU, before it sends the

■ CPU Architectures

119

signal to ALU. The ALU performs the operation on the data and signals the control unit as soon as it has finished. 4.

As the system executes each instruction, it loads the address of the next instruction for execution in program control register, and repeats Steps 1 to 4.

Processor Speed CU and ALU perform operations at incredible speed. These operations are synchronized with the help of a built-in electronic clock (known as system clock), which emits millions of regularly spaced electric pulses per second (known as clock cycles). A processor fetches, decodes, and executes instructions at proper intervals with intervals timed by a specific number of clock cycles. One cycle is the time it takes to perform one operation such as moving a byte of data from one memory location to another. Normally, several clock cycles are required to fetch, decode, and execute a single program instruction. Shorter the clock cycle, faster the processor. Hence, the speed at which a computer executes an instruction depends on the computer’s built-in clock speed, which is the number of pulses produced per second. We measure clock speed in megahertz (MHz) or gigahertz (GHz), where mega means 10 6, giga means 109, and hertz means cycles per second. Over the years, clock speeds of processors have increased steadily. Most of today’s personal computers have clock speeds in 500 MHz (0.5 GHz) to 4000 MHz (4.0 GHz) range. However, effort to build processors with even faster ratings continues. With all other parameters being equal (although they never are), a CPU operating at 3 GHz can process data thrice as fast as one operating at 1 GHz. Number of operations performed per clock cycle also affects CPU performance. Most CPUs perform one operation per cycle. However, the new processors use superscalar architecture, which can execute more than one instruction in each clock cycle. It achieves this by having multiple ALUs on a single CPU chip so that it can execute two or more instructions simultaneously. Normally, we measure the processing speed of personal computers in MHz or GHz; that of workstations, mini computers, and mainframe systems in MIPS (Millions of Instructions Per Second) or BIPS (Billions of Instructions Per Second); and that of supercomputers in MFLOPS (Millions of Floating Point Operations Per Second), GFLOPS (gigaflops, which refers to a billion FLOPS), TFLOPS (teraflops, which refers to 10 12 FLOPS), or PFLOPS (petaflops, which refers to 1015 FLOPS). This is because personal computers generally employ a single microprocessor chip as their CPU, but the other classes of computers often employ multiple processors to speed up their overall performance. Thus, a workstation, minicomputer, or mainframe having a speed of 500-MIPS can execute 500 million instructions per second. Similarly, a supercomputer having a speed of 500 TFLOPS can execute 500 x 1012 floating-point operations per second. We measure the speed of supercomputers in terms of FLOPS because supercomputer applications, which are often scientific, frequently involve floating-point operations. Floating-point operations deal with very small or very large numbers, which require high precision data processing.

Types of Processors CISC Processors One of the earlier goals of CPU designers was to provide more and more instructions in the instruction set of a CPU to ensure that the CPU supports more functions. This makes it easier to translate high-level language programs to machine language and ensures that the machine language programs run more efficiently. Of course, every additional instruction in the instruction set of a CPU requires additional hardware circuitry to handle that instruction, adding more complexity to the CPU’s hardware circuitry. Another goal of CPU designers was to optimize the usage of expensive memory. To achieve this, designers tried to pack more instructions in memory by introducing the concept of variable-length instructions such as half-word, one-and-half-word, etc. For example, an operand in an immediate instruction needs fewer bits, and hence, a CPU designer can design it as a half-word instruction. Additionally, designers originally designed CPUs to support a variety of addressing modes (discussed later in this chapter during the discussion of memory). CPUs with large instruction set, variable-length instructions, and a variety of addressing modes are called CPUs based on CISC (Complex Instruction Set Computer) architecture. Since CISC processors

120

Chapter 4 ■ Computer Architecture

possess so many processing features, they make the job of machine language programmers easier. However, they are complex and expensive to produce.

RISC Processors In early 1980s, some CPU designers realized that many instructions supported by a CISC-based CPU are rarely used. Hence, they came up with the idea of reducing the design complexity of a CPU by implementing in hardware circuitry only bare minimum basic set of instructions and some of the frequently used instructions. The instruction set of the CPU need not support other complex instructions because a computer can implement them in software by using the basic set of instructions. While working on simpler CPU design, the designers also came up with the idea of making all instructions of uniform length so that decoding and execution of all instructions becomes simple and fast. Furthermore, to speed up computation and to reduce the complexity of handling a number of addressing modes, they decided to design all instructions in such a way that they retrieve operands stored in registers in CPU rather than from memory. These design ideas resulted in producing faster and less expensive processors. CPUs with a small instruction set, fixed-length instructions, and reduced references to memory to retrieve operands are called CPUs based on RISC (Reduced Instruction Set Computer) architecture. Since RISC processors have a small instruction set, they place extra demand on programmers who must consider how to implement complex computations by combining simple instructions. However, RISC processors are faster for most applications, less complex, and less expensive to produce than CISC processors because of simpler design. Popular RISC processors used in workstations are POWER (used in IBM workstations), SPARC (used in SUN workstations), and PA-RISC (used in HP workstations). Supporters of RISC technology claim that increased processing speed and lower cost of RISC processors offset the limitations of a reduced instruction set. However, critics of RISC technology are of the opinion that a RISC processor has to process more of these simple programmed instructions to complete a task, placing additional burden on system software. There seems to be no clear answer as to which technology is better. The answer may be that each technology lends itself best to certain applications, and so both technologies will coexist.

EPIC Processors Explicitly Parallel Instruction Computing (EPIC) architecture uses three key techniques for improved performance – explicit parallelism, predication, and speculation. These terminologies are explained here. 1. Explicit parallelism. EPIC technology breaks through the sequential nature of conventional processor architectures by allowing the software to communicate explicitly to the processor when the system can perform an operation in parallel. For this, it uses tighter coupling between compiler and processor. It enables the compiler to extract maximum parallelism in original code and explicitly describe it to the processor. At compile time, the compiler detects which of the instructions can the system execute in parallel. It then reorders them and groups them in such a way that the system can execute instructions belonging to separate groups in parallel. At runtime, the processor exploits this explicit parallelism information provided by the compiler to execute the instructions faster. 2. Predication. Predication technique improves performance by reducing the number of branches and branch mispredicts. The system first takes the help of compiler to reorder the instructions to reduce the number of branches as much as possible at compile time. Conventional processors use “branch prediction” technique in which the processor predicts which way a branch will fork and speculatively executes instructions along the predicted path. At the time of execution of the branch instruction, if the system finds the prediction to be correct, the processor gains performance improvement because instructions lying in the path to be executed now have already been executed and the processor can use their results directly. However, if the system finds the prediction to be wrong, it discards the results of execution of the predicted path and takes up the instructions of the correct path for execution.

■ CPU Architectures

121

However, EPIC technology uses “branch predication” instead of “branch prediction”. In this technique, instead of predicting and executing one of the paths of a branch, the processor executes instructions of all the paths of the branch exploiting as much parallelism as possible. Now when the processor discovers the actual branch outcome, it retains the valid results and discards other results. Thus, branch predication effectively removes the negative affect of branch prediction technique in cases of branch mispredict. 3. Speculation. Speculation technique improves performance by reducing the effect of memory-to-processor speed mismatch. Memory access speed is much slower than processor speed. Speculative data loading technique takes care of this by loading a piece of data and keeping it ready before the processor requires it. It not only allows the processor to load a piece of data from memory before a program needs it, but it also postpones the reporting of exceptions, if the loaded data is illegal. We can also implement speculation technique by taking help of compiler. For this, the compiler analyses a program at compile time, looking for any instructions that will need data from memory. It inserts speculative load instructions in the instructions stream of the program well ahead of the instructions that need data from memory. It also inserts a matching speculative check instruction immediately before the instructions that need data from memory. It now reorders the surrounding instructions so that the processor can dispatch them in parallel. Now when the processor encounters a speculative load instruction at runtime, it retrieves and loads the data from memory. When the processor encounters the speculative check instruction, it verifies the load before allowing the program to use the loaded data in the next instruction. If the load is invalid, the processor does not immediately report an exception. It postpones exception reporting until it encounters a check instruction that matches the speculative load. If the load is valid, the system behaves as if the exception never happened. Speculation technique combined with predication technique gives the compiler more flexibility to reorder instructions and increase parallelism. Notice that all three techniques are based on the availability of an intelligent compiler and closed coupling between compiler and processor. Hence, performance of processors based on EPIC technology comes from both hardware and software. Processors based on EPIC architecture are simpler and more powerful than traditional CISC or RISC processors. These processors are mainly for 64-bit or higher, high-end server and workstation market (not for personal computer market). Intel’s IA-64 (code-named Itanium) was the first EPIC processor.

Multicore Processors The approach used earlier for building faster processors was to keep reducing the size of chips, while increasing the number of transistors they contain. Although, this trend continued in computing industry for several decades, it was later realized that transistors cannot shrink forever. Transistor technology limits the ability to continue making singlecore processors more powerful due to the following reasons: 1.

As a transistor gets smaller, the gate, which switches the electricity ON and OFF, gets thinner and less able to block flow of electrons. Thus, small transistors tend to use electricity all the time, even when they are not swithcing. This wastes power.

2.

Increasing clock speeds causes transistors to switch faster and generate more heat and consume more power.

These and other challenges forced processor manufacturers to research for new approaches for building faster processors. In response, manufacturers came out with the idea of building multicore processor chips instead of increasingly powerful (faster) single-core processor chips. In this new architecture, a processor chip has multiple cooler-running, more energy-efficient processing cores, instead of one increasingly powerful core. The multicore chips do not necessarily run as fast as the highest performing single-core models, but they improve overall performance by handling more work in parallel. For instance, a dual-core chip running multiple applications is about 1.5 times faster than a chip with just one comparable core.

Chapter 4 ■ Computer Architecture

122

Operating system (OS) controls overall assignment of tasks in a multicore processor. In a multicore processor, each core has its independent cache (though in some designs all cores share the same cache), thus providing the OS with sufficient resources to handle multiple applications in parallel. When a single-core chip runs multiple programs, the OS assigns a time slice to work on one program and then assigns different time slices for other programs. This can cause conflicts, errors, or slowdowns when the processor must perform multiple tasks simultaneously. However, a multicore chip can run multiple programs at the same time with each core handling a separate program. The same logic holds for running multiple threads of a multithreaded application at the same time on a multicore chip, with each core handling a separate thread. Based on this, either the OS or a multithreaded application parcels out work to multiple cores. Multicore processors have the following advantages over single-core processors: 1.

They enable building of computers with better overall system performance by handling more work in parallel.

2.

For comparable performance, multicore chips consume less power and generate less heat than single-core chips. Hence, multicore technology is also referred to as energy-efficient or power-aware processor technology.

3.

Because the chips’ cores are on the same die in case of multicore processors architecture, they can share architectural components, such as memory elements and memory management. They thus have fewer components and lower costs than systems running multiple chips (each a single-core processor).

4.

Also, signaling between cores can be faster and use less electricity than on multichip systems.

Multicore processors, however, currently have the following limitations: 1.

To take advantage of multicore chips, we must redesign applications so that the processor can run them as multiple threads. Note that it is more challenging to create software that is multithreaded.

2.

To redesign applications, programmers must find good places to break up the applications, divide the work into roughly equal pieces that can run at the same time, and determine the best times for the threads to communicate with one another. All these add to extra work for programmers.

3.

Software vendors often charge customers for each processor that will run the software (one software license per processor). A customer running an application on an 8-processor machine (multiprocessor computer) with single-core processors would thus pay for 8 licenses. A key issue with multicore chips is whether software vendors should consider a processor to be a single core or an entire chip. Currently, different vendors have different views regarding this issue. Some consider a processor as a unit that plugs into a single socket on the motherboard, regardless of whether it has one or more cores. Hence, a single software license is sufficient for a multicore chip. On the other hand, others charge more to use their software on multicore chips for perprocessor licensing. They are of the opinion that customers get added performance benefit by running the software on a chip with multiple cores, so they should pay more. Multicore-chip makers are concerned that this type of non-uniform policy will hurt their products’ sales.

Chip makers like Apple, Intel, AMD, IBM, and Sun have already introduced multicore chips for servers, desktops, and laptops. The current multicore chips are dual-core (2 cores per chip), quad-core (4 cores per chip), 8 cores per chip, 16 cores per chip, 32 cores per chip, 64 cores per chip, and so on.

■ Memory Architectures

123

Power-Efficient Processors Traditionally, a system’s performance was measured in terms of its processing power. However, excessive power consumption by computing systems has now become a matter of concern for most organizations. Cost of operating computing systems often far exceeds the cost of purchasing them. Hence, considering total cost of ownership (TCO), a new measure that has become popular for measuring the performance of computing systems is power consumption to processing power ratio. Manufacturers of computing systems have therefore made attempts at all levels in computer architecture to reduce power consumption of systems. Processor manufacturers have come out with new processor architectures to reduce power consumption right at processor level. For example, Intel Xeon processor offers a technology called Demand Based Switching (DBS) for reduced power consumption. A traditional processor operates only at a single frequency and voltage, regardless of its workload. Therefore, it is always ON and always consumes full power. Processors based on DBS technology are designed to run at multiple frequency and voltage settings. In conjuction with an Operating System (OS) and Basic Input Output System (BIOS) that support DBS, such processors automatically switch to and operate at the lowest setting that is consistent with optimal application performance. The OS monitors processor utilization multiple times per second and down-shifts/up-shifts to a lower/higher frequency and voltage as appropriate. Therefore, power usage is automatically tailored to match dynamically changing system workload, which substantially reduces power wastage with minimal impact on peak performance capabilities of the processor.

MEMORY ARCHITECTURES We saw that a computer’s CPU contains necessary circuitry for data processing and controlling other components of the computer. However, one thing it does not have built into it is the place to store programs and data needed during data processing. We also saw that the CPU contains several registers for storing data and instructions, but they can store only a few bytes at a time. They are just sufficient to hold one or two instructions with corresponding data. If instructions and data of an executing program were to reside in secondary storage like a disk, and fetched and loaded one-by-one into CPU registers as the program execution proceeded, this would lead to the CPU being idle most of the time. This is because there is a large speed mismatch between the rate at which CPU can process data and the rate at which the system can transfer data from disk to CPU registers. For example, a CPU can process data at a rate of about 5 nanoseconds/byte and a disk reader can read data at a speed of about 5 microseconds/byte. Hence, within the time in which a disk can supply one byte of data, a CPU can process 1000 bytes. This would lead to poor overall performance even for a computer having a fast CPU. To overcome this problem, there is a need to have a reasonably large storage space that can hold instructions and data of the program(s) on which the CPU is currently working. The time to fetch and load data from this storage space into CPU registers must also be considerably less as compared to that from disk storage to reduce the speed mismatch problem with CPU speed. Every computer has such a storage space known as primary storage, main memory, or simply memory. Instructions and data of a program reside mainly in this area when CPU is executing the program. Physically, this memory consists of some integrated circuit (IC) chips either on the motherboard or on a small circuit board attached to the motherboard of a computer system. This built-in memory allows CPU to store and retrieve data quickly. The rate of fetching data from this memory is of the order of 50 nanoseconds/byte. Hence, the rate of data fetching from main memory is about 100 times faster than that from a highspeed secondary storage like disk.

Storage Evaluation Criteria A storage unit of a computer system is characterized and evaluated based on the following properties: 1.

Storage capacity. It is the amount of data, which the storage unit can store. Larger storage capacity is desirable. As compared to secondary storage units, primary storage units have less storage capacity.

Chapter 4 ■ Computer Architecture

124 2.

Access time. It is the time required to locate and retrieve stored data from the storage unit in response to a program instruction. Faster access time is preferable. As compared to secondary storage units, primary storage units have faster access time.

3.

Cost per bit of storage. It refers to the cost of a storage unit for a given storage capacity. Lower cost is desirable. As compared to secondary storage units, primary storage units have higher cost per bit of storage.

4.

Volatile. If a storage unit can retain data stored in it even in case of power off or interruption of power, it is called non-volatile storage. On the other hand, if a storage unit loses data stored in it in case of power off or interruption of power, it is called volatile storage. Obviously, non-volatile storage is desirable. In almost all computer systems, primary storage units are volatile and secondary storage units are non-volatile.

5.

Random access. If the time taken to access a piece of data from a storage unit is independent of the location of the data in the storage unit, it is called random access storage or random access memory (RAM). Each location of a RAM is as easy to access as any other location and takes the same amount of time. In almost all computer systems primary storage units have random access property and secondary storage units have either pseudo-random access (access time is nearly same for all locations but not exactly same) or sequential access (access time depends on the location of the data) property.

Main Memory Organization Main memory of a computer system consists of several small storage areas called locations or cells. Each of these locations can store a fixed number of bits called word length of the memory. Hence, as Figure 4.4 shows, a given memory is divided into N words, where N is generally some power of 2. Each word or location has a built-in and unique number assigned to it. This number is called address of the location and is used to identify the location. Each location can hold either a data item or an instruction and its address remains the same, regardless of its contents. The first address starts at 0 and the highest address equals the number of words that can be stored in the memory minus 1. For example, if a memory has 1024 locations, its address ranges between 0 and 1023. Hence, at address 0 we find a word, at address 1 a second word, at address 2 a third word, and so on, up to the final word at the last address (1023).

Addresses of a memory

0 1 2 3 4 5

Words of a memory

N-2 N-1 Bit 1 Bit 2

Each word contains the same number of bits = word length

Figure 4.4. Organization of a main memory having N words.

There is an important difference between address of a memory location and its content. A memory is like a large cabinet having as many drawers as there are addresses in memory. Each drawer contains a word and address of each word is written on the drawer. If we write or store a word, say 10101010 at address 125, it is like placing the word 10101010 in the drawer labeled 125. Later, reading from address 125 is like looking in that drawer to see its content, which is 10101010. We do not remove the word at an address when we read its content, but its content changes when we store or write a new word in it. Hence, entering data into a storage location is destructive of previous content, but retrieving data from a location is non-destructive. The act of entering data into a storage location is called memory

■ Memory Architectures

125

write operation, and the act of retrieving data from a storage location is called memory read operation. Hence, read is a non-destructive operation and write is a destructive operation.

Why More Bits? You might have heard about 16-bit computers, 32-bit computers, 64-bit computers, etc. They refer to memory word length (total number of bits per memory word) of a computer. Word length of small computers is 8, 16, or 32 bits, whereas that of large computers is 64 bits or more. The obvious question that arises is – “What is the advantage of having more number of bits per word, instead of having more words of smaller size (length)?” For an answer to this question, imagine a highway with eight lanes and a heavy flow of traffic. If we expand it to sixteen lanes, traffic flow speeds up considerably. “8 bits” is analogous to number of “lanes” on a microchip. More bits mean a more rapid flow of electronic signals, in other words, a faster computer. Hence, the amount of data that an 8-bit computer can transfer to and from memory in one minute, a 32-bit computer may transfer in a few seconds. Data and instructions move to and from memory as one or more words at a time. Therefore, even if the electronic circuits used are comparable in speed, computers having smaller word length will be slower in operation than computers having larger word length. This difference is analogous to providing the user of a computer having smaller word length with a small data shovel and the user of a computer having larger word length with a large data shovel. Even though they both may be shoveling at comparable speeds, the user with smaller shovel will be slower because he/she needs more shovelfuls to move the same amount of data.

Fixed and Variable Word-length Memory Main memory of some computers can store a fixed number of characters (equal to its word-length in bytes) in each numbered address location. Such computers are said to be word-addressable and they employ fixed-word-length memory approach. These computers always allocate storage space in multiples of word-length. Therefore, if a wordaddressable computer has fixed word-length of 4 bytes (4 characters), it will require one word (4 bytes) to store the word “CAT” and two words (8 bytes) to store the word “BOMBAY”. In many computers, main memory is designed to store a single character (A, B, 1, 2, +, -, etc.) at each numbered address. Computers designed in this manner are said to be character-addressable and they employ variable-wordlength memory approach. Hence, in these computers only 3 bytes are required to store the word “CAT” and 6 bytes to store the word “BOMBAY”. Figure 4.5 summarizes the difference between fixed-word-length and variable-wordlength memory approaches. Both fixed and variable word-length memory systems have their own merits and demerits. Normally, large scientific computers use fixed-word-length approach for gaining speed of calculation, while small business computers use variable-word-length approach for optimizing use of storage space. For example, let us consider a fixed-word-length memory computer with a word size of eight characters. If most of the data words to be stored are of less than five characters, more than half of its storage space will remain unused. This will not happen in case of a computer with variable-word-length memory because it can place a character in every storage cell. However, word-addressable computers possess faster calculating capability because they can add two data words in a single operation. If word length of a computer that uses fixed-word-length approach is eight characters, it can add two eight-digit numbers in a single operation. On the other hand, a character-addressable computer can add only one digit in each number during a single operation, and would need eight steps to add two eight-digit numbers. We can design a computer to employ either fixed-word-length or variable-word-length memory organization. These computers have an instruction set, using which we can operate them as either variable- or fixed-word-length memory computers. However, with memory becoming cheaper and larger day-by-day, most modern computers employ fixedword-length memory organization.

126

Chapter 4 ■ Computer Architecture

Word

Address numbers

0501 0502

B

O M B A Y D E L H I

0503 1024

Address numbers

0025 0026 0027

B O M

0028 0029

B A

0030 0031

Y

4096 (a) Fixed-word-length memory.

0051 D 0052 E 0053 L Address numbers

0054 H 0055 I 0056

4096

(b) Variable-word-length memory.

Figure 4.5. Fixed-word-length memory compared with variable-word-length memory.

Main Memory Capacity Main memory capacity of a computer is defined as number of bytes that can be stored in its main memory. It is stated normally in terms of kilobytes (KB), which is equal to 1024 (2 10) bytes of storage, or megabytes (MB), which is equal to 1,048,576 (220) bytes of storage, or gigabytes (GB), which is equal to 1,073,741,824 (230) bytes of storage. Therefore, a computer having 2 GB of memory is capable of storing 2 x 1073741824 = 2,147,483,648 bytes or characters. Notice that 1 KB is about 103 bytes, 1 MB is about 106 bytes, and 1 GB is about 109 bytes hence, the origin of the prefixes kilo (thousand), mega (million) and giga (billion). Sometimes, we also state memory capacity of a computer system in terms of number of words. In this case, we specify total number of bits per word along with total number of words. Therefore, a memory having 2 15 words with each word of 16 bits is called a “32 K, 16-bit memory”. If word size of a memory is 8 bits (equal to a byte), it becomes immaterial whether memory capacity is expressed in terms of bytes or words. Hence, a memory having 2 16 words with each word of 8 bits is simply referred to as a 64 K memory (word size of 8-bits is implicit here). Memory capacity continues to increase rapidly and it is only a matter of time before we start stating memory capacity in terms of terabytes (TB), which is about one trillion (1012) bytes. Today, we frequently use GB, TB and PB (petabytes = 1015 bytes) to refer to the capacity of secondary storage of computer systems.

Types of Memory Chips Memory chips are classified based on their capability to retain stored data when power is turned off or interrupted, and how easily stored data can be altered (overwritten). Figure 4.6 shows various types of memory chips. They are described here.

Random Access Memory (RAM) When people talk about computer memory, they usually mean the volatile RAM memory. Physically, this memory consists of some integrated circuit (IC) chips (see Figure 1.1) either on the motherboard or on a small circuit board attached to the motherboard of the computer. A computer’s motherboard usually has the flexibility to add more memory chips for enhancing the memory capacity of the system. Hence, if a user decides to have more memory than his/her computer currently has, he/she can buy more memory chips and plug them into the empty memory slots on the motherboard. Normally, service engineers do this job. Additional RAM chips, which plug into special sockets on the motherboard, are known as single in-line memory modules (SIMMs).

■ Memory Architectures

127

Memory chips

Volatile and writable

Static (SRAM)

Dynamic (DRAM)

Non-volatile and read-only

Manufacturerprogrammed (ROM)

User-programmed

PROM

UVEPROM

EPROM

EEPROM

Figure 4.6. Various types of memory chips.

RAM chips are of two types – dynamic and static. Dynamic RAM (DRAM) uses an external circuitry to periodically “regenerate” or refresh storage charge to retain the stored data, while static RAM (SRAM) does not need any special regenerator circuit to retain the stored data. Since it takes more transistors and other devices to store a bit in a static RAM, these chips are more complicated and take up more space for a given storage capacity than dynamic RAMs do. Moreover, a static RAM is faster, costlier, and consumes more power than dynamic RAM. Due to these reasons, large memories use dynamic RAM, and static RAM is used for specialized applications. The main memory of most computers uses dynamic RAM.

Read-Only Memory (ROM) A special type of RAM, called read-only memory (ROM), is a non-volatile memory chip in which data is stored permanently. Usual programs cannot alter this data. In fact, storing data permanently into this kind of memory is called “burning in of data” because data in such memory is stored by using fuse-links. Once we burn fuse-links for some data, it is permanent. We can only read and use data stored in a ROM chip (we cannot change them). This is the reason why it is called read-only memory (ROM). Since ROM chips are non-volatile, a ROM chip does not lose its stored data in case of power off or interruption of power. This is unlike a volatile RAM chip. ROMs are also known as field stores, permanent stores, or dead stores. System designers use ROMs to store those programs and data, which do not change and are used frequently. A computer carries out most of its basic operations by wired electronic circuits. However, several higher-level operations used frequently, require complicated electronic circuits for their implementation. Hence, instead of building electronic circuits for these operations, designers use special programs to perform them. These programs are called micro-programs because they deal with low-level machine functions and are essentially substitutes for additional hardware. Computer manufacturers store these micro-programs in ROMs so that users cannot modify them. A good example of micro-program is the “system boot program”, which contains a set of start-up instructions that are executed when a system is powered on to check if the system hardware (like memory, I/O devices, etc.) is functioning properly. It looks for an operating system and loads its core part in the volatile RAM of the system to produce the initial display-screen prompt. Note that a computer needs this micro-program every time it is switched on, and the computer must retain it even when it is switched off. Hence, the computer’s ROM is an ideal storage for this microprogram.

128

Chapter 4 ■ Computer Architecture

Programmable Read-Only Memory (PROM) There are two types of read-only memory (ROM) – manufacturer-programmed and user-programmed. A manufacturer-programmed ROM is one in which data is burnt in by the manufacturer of the electronic equipment in which it is used. For example, a personal computer manufacturer may store the system boot program permanently in a ROM chip located on the motherboard of each PC manufactured by it. Similarly, a printer manufacturer may store the printer controller software in a ROM chip located on the circuit board of each printer manufactured by it. It is not possible for users of such equipment to modify the programs or data stored in the ROM chip. On the other hand, a user-programmed ROM is one in which a user can load and store “read-only” programs and data. That is, it is possible for a user to “customize” a system by converting his/her programs to micro-programs and storing them in a user-programmed ROM chip. Such a ROM is known as Programmable Read-Only Memory (PROM) because a user can program it. Once the user programs are stored in a PROM chip, the system can execute them in a fraction of the time previously required. A special device known as PROM-programmer is used to program a PROM chip (record information in it). However, once a user programs a PROM chip, it becomes a ROM because the information recorded in it can only be read (it cannot be changed). PROM is also non-volatile storage, i.e., information stored in it remains intact even in case of power off or interruption of power.

Erasable Programmable Read-Only Memory (EPROM) Once information is stored in a ROM or PROM chip, a user cannot alter it. Erasable Programmable Read-Only Memory (EPROM) chip overcomes this problem by allowing users to reprogram it to store new information. R&D personnel (experimenters) often use EPROMs because they frequently change micro-programs to test a system’s efficiency with new programs. EPROMs are also useful for those applications in which one may like to store a program in a ROM that would normally not change, but under some unforeseen conditions one may like to alter it. When an EPROM is in use, the user can only “read” the information stored in it, and the information remains in the chip until the user erases it. EPROM chips are of two types – Ultra Violet EPROM (UVEPROM), which requires exposing the chip for some time to ultraviolet light for erasing information stored in it, and Electrically EPROM (EEPROM), which requires use of high voltage electric pulses for erasing information stored in it. It is easier to alter information stored in an EEPROM chip as compared to an UVEPROM chip. EEPROM is also known as flash memory because of the ease with which a user can alter programs stored in it. Many new I/O and storage devices like USB (Universal Serial Bus) pen drive and MP3 music player use flash memory.

MINIMIZING MEMORY-PROCESSOR SPEED MISMATCH We saw that the use of main memory helps in minimizing the disk-processor speed mismatch to a large extent because the rate of data fetching by CPU from main memory is about 100 times faster than that from a high-speed secondary storage like disk. Still the rate at which CPU can fetch data from memory is about 10 times slower than the rate at which CPU can process data. Performance of processors often gets limited due to this memory-processor speed mismatch, and we can improve the overall system performance by minimizing the memory-processor speed mismatch. Two approaches used commonly for doing this are use of cache memory (pronounced “cash” memory) and memory interleaving. These techniques are described here.

Cache Memory Cache memory is an extremely fast, small memory between the CPU and main memory whose access time is closer to the processing speed of CPU. It acts as a high-speed buffer between CPU and main memory and computer systems use it to temporarily store active data and instructions during processing. Since cache memory is faster than main memory, system’s performance improves considerably when the system makes those data and instructions available in cache that processes need during present processing.

■ Minimizing Memory-Processor Speed Mismatch

129

The obvious question is how the system knows in advance, which data and instructions it needs in present processing to make it available beforehand in the cache. The answer to this question comes from the principle of locality of reference. According to this principle, during the course of execution of programs, memory references by the processor for both instructions and data tend to cluster. That is, if the system executes an instruction, there is a likelihood of the system executing the same instruction again soon. This is true because typically most programs contain a number of iterative loops (such as while and for loops). Once a program enters a loop during its execution, there are repeated references to a small set of instructions (i.e., the instructions in the loop are executed repeatedly several times). A branch instruction (such as a go to statement) upsets the locality of reference to instructions, but such instructions do not occur frequently in well-written programs. Locality of reference is true not only for references to program instructions, but also for references to data. For example, operations on tables, arrays, and records in a file involve access to a clustered set of data words. Over a long period, the instructions, or data clusters in use change, but over a short period, the processor works primarily with fixed clusters of instructions and data resulting in clustered memory references. Based on the feature of locality of reference, a system makes effective use of a cache in the following manner. As Figure 4.7 shows, cache memory acts as a small, fast-speed buffer between the CPU and main memory. It contains a copy of a portion of main memory contents. When the CPU attempts to read a memory word (instruction or data) during execution of a program, the system checks whether the word is in the cache. If so, the system delivers the word to the CPU from the cache. If not, the system reads a block of main memory, consisting of some fixed number of words including the requested word, into the cache and then delivers the requested word to the CPU. Because of the feature of locality of reference, when the system fetches a block of memory words into the cache to satisfy a single memory reference, it is likely that there will soon be references to other words in that block. That is, the next time the CPU attempts to read a word, it is likely that it finds it in the cache and saves the time needed to read the word from main memory. You might think that the odds of the CPU finding the word it needs in the cache are small, but statistics shows that in more than 90% of time, the needed word is available in the cache. As the name implies, cache memory is a memory in hiding (the word “cache” literally means a hiding place for treasure or stores) and is not addressable by normal users of the computer system. The hardware transfers the needed instructions/data between the cache and main memory without any programmer intervention. In fact, application programmers are unaware of its presence and use. Main memory (Slower in speed and larger in size than cache memory) Address of accessed word when the word is not found in cache

Block of words including the accessed word

Cache memory Address of accessed word

Accessed word CPU

Figure 4.7. Illustrating the operation of cache memory.

Figure 4.7 illustrates the general concept of cache memory usage. Actual systems may have some variations. For example, many computer systems have two separate cache memories called instruction cache and data cache. They use instruction cache for storing program instructions and data cache for storing data. This allows faster identification of availability of accessed word in cache memory and helps in further improving system’s performance. Many computer systems also have multiple levels of caches (such as level one and level two caches, often referred to as L1

130

Chapter 4 ■ Computer Architecture

and L2 caches). L1 cache is smaller than L2 cache and the system uses it to store more frequently accessed instructions/data as compared to those in L2 cache. Designers need to address several design issues to use cache memory. A detailed discussion of cache design is beyond the scope of this book. Key design issues are summarized here. 1. Cache size. Cache memory is expensive as compared to main memory and hence its size is normally small. Statistical studies indicate that reasonably small caches can have a significant impact on overall system performance. Hence, designers usually decide cache memory size on the basis of statistical studies of program behavior, and choose cache size in such a way that the probability of the system finding the needed instruction/data in cache is more than 90%. As a typical example of cache size, a system having 1 GB of main memory may have about 1 MB of cache memory. 2. Block size. Block size refers to the unit of data (few memory words) exchanged between cache and main memory. As we increase block size, hit ratio (fraction of time that referenced instruction/data is found in cache) first increases because of the principle of locality since more and more useful words are brought into the cache. However, hit ratio begins to decrease if we increase block size further because the probability of using the newly fetched words becomes less than the probability of reusing the words that the system must move out of the cache to make room for the new block. Hence, the designer must suitably choose block size to maximize hit ratio. 3. Replacement policy. When the system has to fetch a new block into the cache, it may have to replace another one to make room for the new block. The replacement policy decides which block to replace in such situation. Obviously, it will be best to replace a block that the system is least likely to need again in the near future. Although, it is impossible to identify such a block, a reasonably effective strategy is to replace the block that has been in the cache longest with no reference to it. This policy is known as least recently used (LRU) algorithm. The system needs hardware mechanisms to identify the least recently used block. 4. Write policy. If the system alters the contents of a block, then it is necessary to write it back to main memory before replacing it. The write policy decides when the system writes back the altered words of a block to main memory. At one extreme, the system writes an updated word of a block to main memory as soon as such updates occur in the block. At the other extreme, the system writes all updated words of the block to main memory only when it replaces the block from the cache. The latter policy minimizes memory write operations but temporarily leaves main memory in an inconsistent (obsolete) state. This can interfere with multipleprocessor operation when multiple processors share a common memory and cache. It can also interfere with direct memory access by input/output modules. Several other write policies that are somewhere in between these two extremes are also in use. Normally, the designer of a computer’s architecture makes the choice of a suitable write policy for its cache.

Memory Interleaving In this method, the system’s main memory has n equal size modules, and the CPU has separate MAR and MBR registers for each memory module. In addition, the CPU has n instruction registers and a memory access system. When a program is loaded into main memory, its successive instructions are stored in successive memory modules. For example, if n = 4 and the four memory modules are M 1, M2, M3 and M4, the 1st instruction is stored in M1, 2nd in M2, 3rd in M3, 4th in M4, 5th in M1, 6th in M2, and so on. Now during program execution, when the CPU issues a memory fetch command, the memory access system creates n consecutive memory addresses and places them in the n MARs in the right order. A memory read command reads all the n memory modules simultaneously, retrieves the n consecutive instructions, and loads them into the n instruction registers. Thus, each fetch for a new instruction results in loading of n consecutive instructions in the n instruction registers of the CPU. Since the system normally executes instructions of a program in sequence, availability of n successive instructions in the CPU avoids memory access after each instruction execution, and total execution time speeds up. Obviously, the fetched successive instructions are not useful when the system encounters a branch instruction during program execution. This is because the system will

■ Memory and I/O Buses

131

load the new set of n successive instructions, starting from the location of the instruction to which the control branches, into the n instruction registers, overwriting the previously stored instructions that it loaded earlier but some of which were not executed. However, the method is quite effective in minimizing memory-processor speed mismatch because branch instructions do not occur frequently in a program. Figure 4.8 illustrates memory interleaving architecture with a 4-way (n = 4) interleaved memory system. Central Processing Unit (CPU) Other registers and other components of CPU Four instruction registers

I1

I2

I3

I4

Memory access system Four memory address and memory buffer registers

MAR1

Four memory modules

MBR1

M1

MAR2

MBR2

MAR3

M2

MBR3

MAR4

M3

MBR4

M4

Main memory Figure 4.8. Illustrating a 4-way interleaved memory system.

Hybrid Approach This method uses both cache memory and memory interleaving. It uses cache memory to reduce speed mismatch between CPU and main memory, and memory interleaving to reduce speed mismatch between CPU and cache memory. This approach further helps in improving total system performance.

MEMORY AND I/O BUSES Memory Buses We saw that a system stores in memory the data and instructions of a program in execution, and fetches and loads them into CPU registers as the program execution proceeds. That is, the CPU and memory interact frequently. To enable this interaction, the two units of a computer system need some type of connectivity between them. This connectivity channel is known as a bus. Physically, a bus is a set of wires, which carries a group of bits in parallel and has an associated control scheme. Width of a bus is defined as the number of parallel lines (wires) in the bus. Every computer system has the following three types of buses for interconnecting the CPU and memory: 1.

Data bus. A system uses data bus to transfer data between CPU and memory. When people refer to the bus of a computer system, they usually mean the data bus.

Chapter 4 ■ Computer Architecture

132

Width of data bus is an important parameter that affects the overall performance of a computer system. This is because each wire of a bus can transfer one bit at a time. Hence, an 8-bit bus (one having 8 parallel wires) can transfer 8 bits (one byte), a 16-bit bus can transfer two bytes, and a 32-bit bus can transfer four bytes at a time. A wider data bus enables more bits of data to be transferred simultaneously, resulting in faster exchange of data. This is analogous to a multi-lane highway, the wider the highway, the more traffic can flow simultaneously. 2.

Address bus. In order to retrieve some data from memory, it is necessary to specify the address of the location where the data is stored. A system uses address bus to carry the address of a memory location whenever it has to transfer data to or from memory. Obviously, width of address bus must be equal to the number of bits in memory address register (MAR) of the system. Width of address bus is an important parameter for a computer system because it determines the maximum number of memory locations that the computer system can have. For example, if address bus is 8 bits wide, the CPU can address only 256 bytes of memory. Early personal computers had 20-bit wide address buses, so the CPU could address 220 bytes, or 1 MB, of memory. Today, most systems have 64-bit wide address buses so that the CPU can address 264 bytes of memory.

3.

Control bus. In addition to sending addresses and exchanging data with memory, the CPU also needs to send control signals to memory to specify whether to read or write the data to the specified address location. The control bus carries such signals, which are in the form of READ/WRITE commands.

Thus, a memory access by the CPU involves all three buses – control bus carries memory access command, address bus carries memory address, and data bus carries the data. Figure 4.9 shows the three buses used for interconnecting the CPU and main memory for enabling this. Data bus CPU

Address bus

Main memory

Control bus

Figure 4.9. Three types of buses used between the CPU and main memory.

I/O Buses We saw that in addition to flow of data between CPU and memory, data flows between CPU and I/O devices. Hence, computer systems also use buses for interconnecting the CPU with I/O devices. A system uses the same three types of buses used for interconnecting CPU and memory for interconnecting CPU with I/O devices. Their roles in context of I/O devices are described here. 1.

Data bus. A system uses data bus to transfer data between the CPU and I/O devices. A wider data bus enables faster exchange of data between the CPU and I/O devices. A system normally uses industry standard data buses to connect cards of peripheral I/O devices to the system’s motherboard. Some industry standard data buses that older computer systems used are ISA (Industry Standard Architecture), MCA (Micro Channel Architecture), EISA (Extended Industry Standard Architecture), and AGP (Accelerated Graphics Port). Industry standard data buses used in modern computer systems are: (a) PCI (Peripheral Component Interface). PCI bus has a fixed width of 32 bits with maximum signaling frequency of 33.33 MHz. Hence, its peak data transfer rate is 133 MB/sec (133 Mega (million) Bytes

■ Memory and I/O Buses

133

per second) (33.33 MHz x 32 bits ÷ 8 bits/byte = 133 MB/sec). For years, PCI has been a versatile, functional way to connect sound, video, and network cards to a motherboard. (b) PCI-X (PCI Extended). PCI-X doubles the bus width to 64 bits and increases the maximum signaling frequency to 133 MHz. Hence, its peak data transfer rate is 1014 MB/sec. A newer version of PCI-X further increases the maximum signaling frequency to 266 MHz. Hence, its peak data transfer rate is 2035 MB/sec. All PCI-X versions are backward compatible with PCI. (c) PCIe (PCI Express). PCI and PCI-X are bus-based standards in which all devices connected to the 32bit or 64-bit bus share the same bidirectional, parallel signal path. This requires “arbitrating” the bus or waiting for the bus to be free. Unlike PCI and PCI-X, PCIe is a point-to-point bus. It is built around pairs of serial (1-bit), unidirectional point-to-point connections called lanes. Hence, PCIe is a serial connection that operates more like a network than a bus. Instead of one bus that handles data of multiple devices connected to it, PCIe has a switch that controls several point-to-point serial connections. In this manner, each device gets its own dedicated connection, so devices no longer share bandwidth as they do on a normal bus. Each PCIe slot has 1, 2, 4, 8, 16, or 32 lanes between the motherboard and the card. It is customary to write number of lanes with an ‘x’ prefix. For example, x1, x2, x3, …, x32 refer to one-lane, two-lane, three-lane, …, thirty-two-lane cards respectively. Each lane contains two pairs of wires, one for sending, and one for receiving. Packets of data move across a lane at a rate of one bit per cycle. Therefore, an x1 link has one lane made up of four wires and transmits one bit per cycle in each direction. An x2 link has two lanes made up of eight wires and transmits two bits at once, an x4 link transmits four bits at once, and so on. The latest available version of PCI-Express is PCTe 5.0. The bandwidth for each PCIe 5.0 lane is 4 GB/sec. Hence, a PCI-Express 5.0 x16 device will have up to 64 GB/sec bandwidth. PCIe slots come in different physical sizes referred to by the maximum number of lanes they support. A PCIe card fits into a slot of its size or bigger, but not into a smaller PCIe slot. PCI, PCI-x, and PCIe are all compatible. Because PCIe has faster data transfer rate than PCI and PCIX, and it is compatible with them, it is likely that PCIe will eventually replace PCI and PCI-X. (d) HT (HyperTransport). HT is a packet-based point-to-point bus. It has at least two unidirectional links. Each link can be of 2, 4, 8, 16, or 32 bits width with maximum signaling frequency of 800 MHz. Hence, peak data transfer rate for a pair of 8 bits links is 1.6 GB/sec (800 MHz x 2 x 8 bits ÷ 8 bits/byte = 1.6 GB/sec). This gives aggregate bandwidth of 3.2 GB/sec in both directions for a pair of 8 bits links. A system can double or quadruple aggregate bandwidth by using 16 bits or 32 bits links respectively. Currently, some systems use HT bus in conjunction with AMD processors. 2.

Address bus. Normally, a computer system has multiple I/O devices like disk, tape, network, etc. simultaneously connected to it. Each I/O device has a unique identifier (or address) associated with it. The system uses address bus to carry the address of the I/O device, which the CPU needs to access.

3.

Control bus. A system uses control bus to carry commands such as START, READ, WRITE, REWIND TAPE, etc., from CPU to I/O devices. It also carries status information of I/O devices to CPU.

Thus, an I/O device access by CPU involves all three buses – control bus carries device access command, address bus carries device address, and data bus carries the data. Figure 4.10 shows the three buses used for interconnecting the CPU and I/O devices for enabling this. Each device has a controller, which controls the operation of the device. It also temporarily stores the data transferred between the CPU and the device in a local data register.

134

Chapter 4 ■ Computer Architecture

Data bus CPU

Address bus Control bus

I/O devices and associated controllers

Figure 4.10. Three different types of buses used between the CPU and I/O devices.

INTERCONNECTION ARCHITECTURES We saw the use of buses in interconnecting the CPU with memory and I/O devices. Interconnection architecture of a computer defines the manner in which these functional units of the computer are connected to each other. Accessing mechanism and flow of data from one unit to another depends on interconnection architecture. The three commonly used interconnection architectures are described here.

Unibus Architecture In unibus architecture, there is a single data bus, a single address bus, and a single control bus for interconnecting the CPU with both memory and I/O devices (see Figure 4.11). That is, both memory and I/O devices share the buses for data transfer between CPU and memory, and between CPU and I/O devices. As a result, data transfer can take place at a time only between the CPU and memory, or between the CPU and an I/O device. Obviously, this architecture leads to slow data transfer. Hence, small computers (where performance is not an issue) use unibus architecture. The main advantage of this architecture is its simple design and ease of programming of I/O device accesses. In this case, I/O devices do not require any special I/O instructions because they use the same memory address space. Hence, a WRITE instruction with an address corresponding to an output device will write information to that device. Another advantage of this architecture is that it allows easy addition of new I/O devices to the system, as no new instructions specific to the device are required. Data bus

Address bus

Control bus

I/O devices with associated controllers

CPU

Memory

Figure 4.11. Unibus interconnection architecture.

Dual Bus Architecture In dual bus architecture, there are separate sets of buses for interconnecting the CPU with memory and I/O devices (see Figure 4.12). Hence, a system having this architecture transfers data between the CPU and memory by using one set of buses, while it transfers data between the CPU and I/O devices by using another set of buses. In this case, a system uses one of the following two mechanisms for data transfer between the CPU and an I/O device:

■ Interconnection Architectures

I/O devices with associated controllers

Data bus Address bus Control bus

135

Data bus CPU

Address bus

Memory

Control bus

Figure 4.12. Dual bus interconnection architecture.

1.

Busy wait. In this method, the CPU sends the I/O request (say a data READ request) to the device via the buses. It sends the command and the device address associated with the READ request by using control bus and address bus respectively. As soon as the device controller receives the request, it first sets ON a “device busy” indicator so that the system will not accept any further I/O request for the device. It then executes the request and stores the data for transfer in its local data register. As soon as it completes the request processing, it sets ON another indicator called “data ready” indicator. After issuing the READ request, the CPU continuously keeps checking the “data ready” indicator of the device and waits until this indicator is set to ON. As soon as the CPU finds this indicator to be ON, it reads the data from the data register of the device controller into its own register. It then sends a data received acknowledgment signal to the device. On receiving this signal, the device controller resets its “device busy” and “data ready” indicators to OFF, which indicates that it is now ready to accept new I/O requests.

2.

Interrupt. In busy wait method, after issuing an I/O request, the CPU remains busy in checking for completion of the request until request processing is over. That is, from the time of issuing an I/O request until completion of the request, the CPU does not do anything else. This is inefficient use of CPU because I/O devices are about 1000 times slower than a CPU. Interrupt mechanism was devised to overcome this problem. In this method, after issuing the READ request to the I/O device, the CPU does not wait for the “data ready” indicator of the device to be set ON. Rather, it suspends the job that made the READ request and takes up another job that is ready for execution and starts executing this job while the device controller is busy processing the READ request. When the device controller completes processing the request and the data for transfer is ready in its local data register, it sends an interrupt signal to the CPU. When the CPU receives the interrupt signal, it knows that the data it requested is now ready. Hence, it suspends the job that it is currently executing, transfers the data from the data register of the device controller to its own register and resumes execution of the job that had made the I/O request. Interrupt mechanism is more difficult to implement than busy wait mechanism because it requires a mechanism to suspend a currently executing job and resume it later. How this is done will be discussed in a later chapter. Moreover, in case of multiple I/O devices, it also requires a mechanism to distinguish among the interrupt signals of different devices and to attend to them based on some priority rules because various devices can initiate interrupt signals independent of each other.

DMA Architecture Computer systems use I/O devices either to input or to output data. Most of the time, this involves either reading data from an input device and storing it in main memory, or reading data from main memory and outputting it to an output device. That is, data transfer takes place between main memory and I/O devices. We saw in the previous two interconnection architectures that the CPU carries out every data transfer to or from an I/O device. Hence, the CPU is involved in every data transferred between main memory and I/O devices. This leads to inefficient usage of CPU. Direct Memory Access (DMA) architecture, which minimizes CPU’s participation in I/O data transfer, overcomes this problem.

Chapter 4 ■ Computer Architecture

136

DMA architecture uses an additional hardware called DMA controller [also known as Peripheral Processing Unit (PPU)]. All I/O devices connect to the DMA controller (see Figure 4.13). A set of buses connect the CPU and memory. Another set of buses connect the DMA controller with both the CPU and memory so that the system can carry out data transfer to or from I/O devices directly either with the CPU or memory. An additional address bus connects the CPU and DMA controller. Out of the two address buses, one carries memory address and the other carries device address. Hence, the figure shows them as Memory Address Bus (MAB) and Device Address Bus (DAB). DMA controller has a data register to temporarily store the data for transfer; a memory address register to keep track of the memory location from/to where data transfer takes place; a counter to keep track of how many memory words to transfer; a “busy” indicator to indicate that it is currently busy and cannot accept any new I/O requests now; and a “data ready” indicator to indicate to the CPU that the requested data is ready in its data register for transfer. Data transfer in this case takes place in the following manner: 1.

The CPU sends the I/O request (say a data READ request) to DMA controller. It sends device address of the device from which to read data, memory location at which to store data, and the READ command along with the number of memory words to read by using the device address bus, the memory address bus, and the control bus respectively. After sending the request, the CPU continues with its normal execution since it has no further direct role in processing this I/O request.

2.

On receiving the request, the DMA controller sets its “busy” indicator to ON and stores the received memory address and number of memory words to be read in its memory address register and counter respectively.

3.

It then reads the first memory word to be transferred from the specified I/O device into its data register and sets the “data ready” indicator to ON.

4.

It now sends an interrupt signal to the CPU.

5.

On receiving the interrupt signal, the CPU completes execution of the instruction that it is currently executing, then yields the memory address and data buses to the DMA controller for one memory cycle.

6.

DMA controller then transfers the data in its data register to the memory location specified by the contents of its memory address register. It then decrements the value of its counter by one and increments the value stored in its memory address register by one.

7.

DMA controller now reads the next word from the I/O device and stores it in its data register. It then interrupts the CPU, which yields a memory cycle and the memory address and data buses to the DMA controller to enable it to transfer the word from its data register to the appropriate memory location. DMA controller then decrements its counter value and increments the value stored in its memory address register. It repeats this procedure until the DMA controller’s counter value becomes zero.

This procedure of the DMA controller taking a memory cycle from the CPU to enable it to transfer data directly to memory is known as cycle stealing. DMA architecture leads to efficient CPU utilization because the DMA controller processes an I/O request without direct participation of the CPU. However, this advantage requires provisioning of an extra hardware (DMA controller) and an additional bus (device address bus).

MULTIPROCESSOR SYSTEM ARCHITECTURES Multiprocessor systems consist of multiple processors (CPUs). They are broadly classified as shared memory systems (also called tightly-coupled systems) and distributed memory systems (also called loosely-coupled systems). They are described here.

■ Multiprocessor System Architectures

137

Memory address bus CPU

Data bus

Main memory

Control bus

Data bus

Device address bus

Control bus

DMA controller (Peripheral Processing Unit)

I/O devices Figure 4.13. Direct Memory Access (DMA) interconnection architecture.

Shared Memory Systems These systems have a single system-wide primary memory, which all processors share (see Fig. 4.14). If any processor writes, for example, value 100 to memory location x, any other processor subsequently reading from location x will get the value 100. Therefore, in these systems, any communication between processors usually takes place through the shared memory.

CPU

CPU

Systemwide shared memory

CPU

CPU

Interconnection hardware Figure 4.14. Basic architecture of a shared memory multiprocessor system.

The interconnection hardware of Figure 4.14 can be organized in several different ways. Depending on this, some commonly known architectures of shared memory systems are: 1.

Shared bus architecture. As Figure 4.15(a) shows, a system having this architecture connects multiple CPUs through a common bus to memory unit (comprised of multiple memory modules). Physically, the system uses a high-speed backplane to insert CPU and memory cards. The CPUs time-share the common bus for memory accesses. That is, only one processor can access the memory at a time (the processor that is in control of the bus at the time). This means that when one processor is communicating with the memory, all other processors are either busy with internal operations or must be idle waiting for the bus. As the number of processors increases, contention for the shared bus increases and system overhead for conflicts resolution considerably goes up, resulting in significant drop in overall system performance. Hence, this architecture does not scale beyond a few CPUs (cannot support large number of processors).

2.

Shared bus with cache memory architecture. As Figure 4.15(b) shows, a system having this architecture uses a high-speed cache memory between each CPU and the bus to reduce contention for the shared bus.

138

Chapter 4 ■ Computer Architecture Each cache memory holds the most recently accessed words by its own CPU and all memory access requests of a CPU go through its cache. If a CPU finds an accessed memory word in its cache (case of cache hit), it services the access request from the cache itself and does not make any bus request. Hence, if cache memories are large enough, cache hit rates will be high, resulting in reduced contention for the shared bus. Systemwide shared memory

Systemwide shared memory MM

MM

MM

MM

MM

MM

Shared bus P

P

P

P

(a) Shared bus architecture

cache

cache

cache

cache

P

P

P

P

(b) Shared bus with cache memory architecture

Systemwide shared memory

Systemwide shared memory MM

MM

MM

MM

MM

MM

MM

MM

P

P

P

P

P

P

P

P

(c) Multiport memory architecture

(d) Crossbar switch architecture

Systemwide shared memory MM

MM

MM

MM

2 x 2 switch P

P

P

MM

Memory Modules

P

CPUs

P

(e) Omega switching network architecture Figure 4.15.

A few examples of different architectures of shared memory multiprocessor systems depending on the type of interconnection hardware used.

Since this architecture reduces contention for the shared bus, it may first appear that it is highly scalable (can support large number of processors). However, this is not true because cache memories introduce the requirement of dealing with incoherent memory. That is, if a system using this architecture caches the same memory word in cache memories of two or more CPUs, and if one of the CPUs overwrites the word, it must invalidate the word in cache memories of all other CPUs to prevent other CPUs from getting the old value from their own caches. System overhead involved in dealing with this cache consistency issue increases with the number of caches (CPUs). Hence, this architecture also does not scale beyond a few more CPUs than the shared bus architecture.

■ Multiprocessor System Architectures 3.

139

Multiport memory architecture. As Figure 4.15(c) shows, a system having this architecture avoids contention for a single shared bus by having a separate bus between each memory module and each CPU. It uses multi-port memory modules to make this possible. The memory modules also have internal control logic to resolve when two or more CPUs simultaneously access memory words in the same memory module. This architecture enables fast memory access by multiple CPUs because of availability of multiple paths between processors and memory. However, it requires expensive memory control logic and a large number of cables and connectors. Hence, the complexity and cost of hardware grows rapidly with the increase in number of processors. Therefore, this architecture also does not scale well and is suitable only for systems with a small number of CPUs.

4.

Crossbar switch architecture. The bus-based architectures are suitable for multiprocessor systems having few tens of processors. Multiprocessor systems having few hundreds of processors use switch-based architecture instead of bus-based architecture. Figure 4.15(d) shows one such architecture, which is known as crossbar switch architecture. In this architecture, there is a connection coming out of each CPU and each memory module and the system uses an electronic switch at every intersection point of the connections between CPUs and memory modules. Each switch has control logic to establish the transfer path between a processor and memory module and to resolve simultaneous access requests from multiple CPUs to the same memory module on a predetermined priority basis. This architecture supports simultaneous memory accesses by multiple CPUs because there is a separate path between each CPU and memory module. Hence, the architecture supports good scalability.

5.

Omega switching network architecture. Notice from Figure 4.15(d) that in the crossbar switch architecture, total 16 switches are required to interconnect 4 CPUs and 4 memory modules. In general, n2 switches are required to interconnect n CPUs and n memory modules. Since the number of switches required grows exponentially with n, and because switches are costly electronic component, overall cost of a multiprocessor system using this architecture becomes prohibitive for large n. Hence, multi-stage switching network architectures have been proposed and used to build large multiprocessor systems with fewer switches. One such architecture [shown in Figure 14.5(e)] is the Omega switching network architecture. In this architecture, only 4 switches are used to interconnect 4 CPUs and 4 memory modules as compared to 16 switches required in the crossbar switch architecture of Figure 14.5(d). Each switch is a 2x2 switch – has two inputs and two outputs with the capability to establish interconnection between any input to any output and to arbitrate between conflicting requests (if there are simultaneous requests from both the inputs to connect to the same output, only one of the them will be connected and the other will be blocked). With proper setting of switches, the system can establish a path between any CPU and memory module to enable memory access operation(s) between the two. Multi-stage switching network architectures can support large number of processors and memory modules with fewer switches. However, for large systems, a path between a CPU and memory module may have several switching stages, resulting in increase in memory access time. Memory access operations being critical to overall system performance, a system usually keeps the number of switching stages low.

Distributed Memory Systems We saw that shared memory systems can have only a small number of processors due to various constraints imposed by different architectures. Distributed memory systems are more scalable and can have almost unlimited number of processors. Moreover, in contrast to shared memory systems, processors of distributed memory systems can be located far from each other to cover a wider geographical area. These systems consist of multiple computers interconnected together by a communication network. Hence, they are also known as multicomputer systems. As Figure 4.16 shows, each individual computer can itself be a multiprocessor system (a shared memory system). As interconnected computers do not share a common memory (each one has its own local memory), all physical communication between them takes place by passing messages across the communication network that interconnects them. That is, all interactions between processes running on different computers takes place by message passing. Hence, distributed memory systems are also known as message-passing systems. They use exchange of messages to transfer data and work, and to synchronize actions among processes. If any computer of a distributed memory system

Chapter 4 ■ Computer Architecture

140

is a shared-memory multiprocessor system, interactions among processes running on that computer can still take place through its shared memory. For a particular computer, its own resources are local, whereas the other computers and their resources are remote. In a distributed memory system, usually we call a computer and its resources as a node, site, or machine. Computers and communication network of Figure 4.16 can take different forms. Moreover, roles of different computers and the manner in which they interact with each other may also differ from one distributed memory system to another. Hence, there are many types of distributed memory systems. Two commonly used types are:

P1

Computer 1

Computer 2

Local

Local

P2 . . . Pi

P2 . . . Pj

P1

j≥1

i≥1 Communication network k≥1

l≥1 Local

Local ...

P1

P2 . . . Pk Computer 3

P1

P2 . . . Pl Computer n Each P indicates a CPU i, j, k, and l ≥ 1 n≥2

Figure 4.16. A distributed memory multiprocessor system (also known as multicomputer system).

1.

Cluster of Workstations (COWs). COWs use off-the-shelf components. Hence, a COW consists of several standard workstations (or personal computers) interconnected with a standard network such as InfiniBand or Gigabit Ethernet. Due to the use of off-the-shelf components (nodes and network), no special measure is taken in hardware architecture to tolerate failure of one or more communication links or nodes. However, COWs often implement fault tolerance features in software to tolerate failure of one or more nodes. Moreover, COWs sometimes use multiple networks to tolerate network failures. For example, a cluster may simultaneously have both Myrinet and Gigabit Ethernet so that if one of the networks fails, the cluster can still function with the other one. Multiple networks are also useful for different applications performance because of their varying bandwidth and latency requirements. Hence, some applications may perform better on one network than on the other network. Usually, a system based on COW neatly mounts its nodes and network(s) in one or more racks (see Figure 4.17).

2.

Blade servers. There has been a rapid growth during the last few years in usage of information technology in all types of organizations. Due to this, organizations are experiencing tremendous growth in the information that they have to handle and are looking for better options to manage their data. Organizations are facing the following challenges in scaling of traditional data centers, which are built of multiple rack-mounted servers:

■ Multiprocessor System Architectures

(a) Front view

141

(b) Back view

Figure 4.17. Off-the-shelf components (nodes and network(s)) of a small Cluster of Workstations (COW) neatly mounted in a rack. Larger clusters use higher racks to accommodate more number of nodes in a single rack. Very large clusters use many racks kept side-by-side to accommodate large number of nodes.

(a) (b) (c) (d)

Power consumption and associated cooling requirements of a data centre grows fast as it scales up. Traditional servers also need more floor space. They require complex cabling, which in turn weakens system reliability. They are more difficult to manage and require expensive, skilled support resources, leading to high total cost of ownership (TCO).

Computer vendors designed blade servers to address these challenges. Blade servers are multi-processor systems, which offer a standardized method of deploying multiple processors, memory, and I/O resources by placing them on plug-in boards that slide into a standard chassis. They reduce cost as compared to separate server systems by sharing common resources like power, storage, and I/O across multiple processors. As Figure 4.18 shows, blade servers consist of a standardized chassis in which we can insert server blades. Each server blade is a separate system that runs its own operating system and application software independently of the rest of the system, relying on its local processor(s), memory, and I/O resources to handle its applications. The chassis contains shared resources (power, cooling, storage, I/O ports, network connections, etc.) that all server blades in the chassis share. A server blade slides into the chassis and connects to the shared resources through a backplane or midplane connection. It is hot swappable, allowing live upgrades to the server resource pool. Hence, we can add processing resources to a data centre by sliding in another server blade in the chassis without interrupting the functioning of other server blades. A typical blade server chassis can hold 8 to16 physical server blades, each with 2 to 8 processor cores. With virtualization, we can create several virtual machines on each server blade, yielding a compact system with hundreds of virtual servers for a data centre. Hence, the key hardware and software components of a blade server are: (a) (b) (c) (d) (e)

Standardized chassis Server blades containing multi-core processors, memory, local storage, and chassis interface Shared storage, I/O ports, network connections, etc. Shared power and cooling Virtualization software

142

Chapter 4 ■ Computer Architecture

(f) Software for management of resources of individual server blades (g) Software for power and cooling monitoring and management As compared to multiple rack-mounted servers, blade servers offer the following advantages to data centers: (a) They provide dramatic reduction in floor space, power consumption, and cooling requirement because of integration of servers, storage, networking, I/O devices, and other components in a single, modular chassis. Due to this, we often refer to a blade server as a “data centre in a box”. (b) They help eliminate complex cabling, thereby improving overall data centre reliability. (c) They provide simplified management while retaining enterprise class performance, reliability, and availability. (d) They handle scalability with greater ease. We can add new functionality by sliding another server blade in the chassis. (e) They reduce total cost of ownership (TCO) of a data centre by enabling sharing of expensive resources, dramatically improving resource utilization, and reducing management and operation cost.

Shared I/O ports, network connections, power, and cooling units are at the back of the chassis Blade server chassis

Shared storage

Handle for lifting the chassis

. . .

Disk and controller bays ... A server blade slides into the chassis

Server blades

Light indicators for power and cooling monitoring

Figure 4.18. A blade server.

In-spite-of all its advantages, users still have the following concerns with blade servers: (a) Blade servers do not perform well in case of large-scale transaction processing applications. (b) Chassis systems are proprietary, leading to vendor lock-in problem. We need to purchase all server blades from the same vendor, which supplied the chassis. (c) Blade servers are not economical for applications requiring less than 5 to 10 servers.

PARALLEL PROCESSING SYSTEMS A parallel processing system is a multiprocessor system, which treats a large number of processors as a pool and shares them among users as needed. A special server (called run server) manages and allocates processors in the pool to different users on demand basis. When a user submits a job for computation, the run server temporarily assigns an appropriate number of processors to his/her job. For example, if the user's computation job is compilation of a

■ Points to Remember

143

program having n independently compilable segments, to produce separate relocatable object files, the system can allocate n processors from the pool to this job to compile all the n segments in parallel. When the system completes the job, it returns the allocated processors to the pool for use by other users. Parallel processing systems process a job much faster by making multiple processors process different parts of the job in parallel. For this, the job has to be programmed using parallel programming libraries such as MPI (Message Passing Interface) or PVM (Parallel Virtual Machine). Multiprocessor systems (both shared memory and distributed memory systems) are often used as parallel processing systems.

Points to Remember 1.

All computer systems perform the following five basic functions for converting raw input data into useful information – inputting, storing, processing, outputting, and controlling.

2.

Figure 4.1 shows the main components of a computer system.

3.

Input unit enables feeding of data and instructions to a computer system from outside world in computer acceptable form.

4.

Input interfaces transform input data and instructions (fed to a computer through its input devices) into binary codes that are acceptable to the computer.

5.

Output unit enables a computer system to supply information (obtained from data processing) to outside world in human acceptable (readable) form.

6.

Output interfaces transform information (obtained from data processing) from binary form to human acceptable (readable) form.

7.

Storage unit of a computer system holds data and instructions to be processed and intermediate and output results of processing. Two types of storage are – primary and secondary storage. As compared to primary storage, secondary storage is slower in operation, larger in capacity, cheaper in price, and can retain information even when computer system switches off or resets.

8.

During data processing, execution of instructions takes place in Arithmetic Logic Unit (ALU) of a computer system.

9.

Control Unit (CU) of a computer system manages and coordinates the operations of all other components of the computer system.

10. Control unit and arithmetic logic unit of a computer system together form the Central Processing Unit (CPU), which serves as the brain of the computer system and is responsible for controlling the operations of all other units of the system. 11. We often refer to a computer as a computer system because it consists of integrated components (input unit, output unit, storage unit, and CPU) that work together to perform the steps called for in a program. 12. CPU is the brain of a computer system. A computer performs all major calculations and comparisons inside its CPU. CPU is also responsible for activating and controlling the operations of other units of the computer system. Hence, no other single component of a computer determines its overall performance as much as its CPU. 13. The two basic components of a CPU are control unit and arithmetic logic unit. 14. Control Unit (CU) of a computer’s CPU acts as the central nervous system for all other components of the computer. It manages and coordinates the entire computer system including the input and output units. It obtains instructions from the program stored in main memory, interprets the instructions, and issues signals that cause other units of the system to execute them. 15. Arithmetic Logic Unit (ALU) of a computer’s CPU is the place where execution of instructions takes place during data processing. 16. Every CPU has built-in ability to execute a set of machine instructions, called its instruction set. 17. As a computer’s CPU interprets and executes instructions, there is movement of information between various units of the computer. To handle this process and to speed up the rate of information transfer, the CPU uses a number of special memory units called registers. These registers hold information on a temporary basis and are part of the CPU (not main memory).

144

Chapter 4 ■ Computer Architecture

18. The speed of a processor depends on a computer’s clock speed, which is the number of pulses produced per second by the built-in electronic clock. We measure clock speed in megahertz (MHz) or gigahertz (GHz). 19. Normally, we measure the processing speed of personal computers in MHz or GHz; that of workstations, mini computers, and mainframe systems in MIPS (Millions of Instructions Per Second) or BIPS (Billions of Instructions Per Second); and that of supercomputers in MFLOPS (Millions of Floating Point Operations Per Second), GFLOPS (gigaflops, which refers to a billion FLOPS), TFLOPS (teraflops, which refers to 10 12 FLOPS), or PFLOPS (petaflops, which refers to 1015 FLOPS). 20. Three commonly known processor architectures are CISC (Complex Instruction Set Computer), RISC (Reduced Instruction Set Computer), and EPIC (Explicitly Parallel Instruction Computing). 21. CPUs with large instruction set, variable-length instructions, and a variety of addressing modes are called CPUs based on CISC (Complex Instruction Set Computer) architecture. 22. CPUs with a small instruction set, fixed-length instructions, and reduced references to memory to retrieve operands are called CPUs based on RISC (Reduced Instruction Set Computer) architecture. 23. Explicitly Parallel Instruction Computing (EPIC) architecture uses three key techniques for improved performance. They are explicit parallelism, predication, and speculation. 24. Multicore processor technology enables building of computers with better overall system performance by handling more work in parallel. In this technology, a processor chip has multiple cooler-running, more energy-efficient processing cores instead of one increasingly powerful core. A multicore chip can run multiple programs/threads at the same time with each core handling a separate program/thread. To take advantage of multicore chips, we must redesign applications so that the processor can run them as multiple threads. 25. Considering total cost of ownership (TCO), a new measure that has become popular for measuring the performance of computing systems is power consumption to processing power ratio. Processors that reduce power consumption right at processor level are known as power-efficient processors. 26. Demand Based Switching (DBS) is a technology used in power-efficient processors for reduced power consumption. 27. Instructions and data of a program reside in a temporary storage area mainly when the CPU is executing the program. This storage space is known as primary storage, main memory, or simply memory. 28. A storage unit of a computer system is characterized and evaluated based on following properties – storage capacity, access time, cost per bit of storage, volatile, and random access. 29. Main memory of a computer system consists of several small storage areas called locations or cells. Each location can store a fixed number of bits, called word length of the memory. Each location has a unique address, which remains the same regardless of its contents. The first address starts at 0 and the highest address equals the number of words that can be stored in the memory minus 1. 30. Data and instructions move to and from memory as one or more words at a time. Therefore, even if the electronic circuits used are comparable in speed, computers having smaller word length will be slower in operation than computers having larger word length. 31. In a word-addressable computer, each numbered address location can store a fixed number of characters (equal to its wordlength in bytes). These computers allocate storage space in multiples of word-length. On the other hand, in a characteraddressable computer, each numbered address can store only a single character (A, B, 1, 2, +, -, etc.). 32. Main memory capacity of a computer is the number of bytes that its main memory can store. Normally, we measure main memory capacity in terms of kilobytes (KB), which is equal to 1024 (2 10) bytes of storage, megabytes (MB), which is equal to 1,048,576 (220) bytes of storage, or gigabytes (GB), which is equal to 1,073,741,824 (2 30) bytes of storage. 33. A computer’s main memory uses volatile RAM chips. RAM chips are of two types – dynamic and static. Dynamic RAM (DRAM), uses an external circuitry to periodically “regenerate” or refresh storage charge to retain the stored data, while static RAM (SRAM), does not need any special regenerator circuit to retain the stored data. 34. A special type of RAM, called read-only memory (ROM), is a non-volatile memory chip in which data is stored permanently. Usual programs cannot alter this data. There are two types of read-only memory (ROM) – manufacturer-programmed and user-programmed. The latter is known as Programmable Read-Only Memory (PROM) because a user can program it. 35. Once information is stored in a ROM or PROM chip, a user cannot alter it. Erasable Programmable Read-Only Memory (EPROM) chip overcomes this problem by allowing users to reprogram it to store new information. EPROM chips are

■ Questions

145

of two types – Ultra Violet EPROM (UVEPROM) and Electrically EPROM (EEPROM). EEPROM is also known as flash memory. 36. We can improve overall system performance by minimizing memory-processor speed mismatch. Two approaches used commonly for doing this are use of cache memory and memory interleaving. 37. Cache memory is an extremely fast, small memory between the CPU and main memory whose access time is closer to the processing speed of CPU. It acts as a high-speed buffer between CPU and main memory and computer systems use it to temporarily store active data and instructions during processing. 38. The connectivity channel used for interaction between the CPU and memory is known as a bus. Physically, a bus is a set of wires, which carries a group of bits in parallel and has an associated control scheme. Width of a bus is the number of parallel lines (wires) in the bus. Every computer system has following three types of buses – data bus, address bus, and control bus. 39. Every computer system also uses buses for interconnecting the CPU with I/O devices. Computer systems use the same three types of buses (data bus, address bus, and control bus) for interconnecting the CPU with I/O devices. 40. Interconnection architecture of a computer system defines the manner in which its CPU, memory, and I/O devices are connected to each other. Accessing mechanism and flow of data from one unit to another depends on interconnection architecture. The three commonly used interconnection architectures are unibus architecture, dual bus architecture, and DMA (Direct Memory Access) architecture. 41. Multiprocessor systems consist of multiple processors (CPUs). They are broadly classified as shared memory systems (also called tightly-coupled systems) and distributed memory systems (also called loosely-coupled systems). 42. A shared memory system uses a single system-wide primary memory, which all its processors share. 43. A distributed memory system consists of multiple computers interconnected together by a communication network. Hence, they are also known as multicomputer systems. Each individual computer can itself be a multiprocessor system (a shared memory system). As interconnected computers do not share a common memory (each one has its own local memory), all physical communication between them takes place by passing messages across the communication network that interconnects them. Hence, these systems are also known as message-passing systems. 44. A parallel processing system is a multiprocessor system, which treats a large number of processors as a pool and shares them among users as needed. It processes a job much faster by making multiple processors process different parts of the job in parallel.

Questions 1.

What are the five basic functions performed by a computer system?

2.

Draw a block diagram to illustrate basic organization of a computer system and explain the functions of various units.

3.

What is an input interface? How it differs from an output interface?

4.

How many types of storage a computer system normally uses? Justify the need for each storage type.

5.

Differentiate between the characteristics of primary and secondary storage of a computer system.

6.

Write the logical steps taken by a computer system along with the roles of its main units in each step while transforming input data to useful information for presentation to a user.

7.

What is a system? Why do we often refer to a computer as a computer system?

8.

No other single component of a computer determines its overall performance as much as the CPU. Discuss.

9.

Write the main functions of CPU in a computer system.

10.

What are the two main components of CPU of a computer system? Write the main functions of each component.

11.

Describe the role of decoder of a CPU.

12.

The control unit acts as a central nervous system for other components of a computer system. Discuss.

13.

What is a microprocessor?

146 14.

Chapter 4 ■ Computer Architecture What is an instruction set of a computer system? Do computers made by different manufacturers have the same or different instruction sets?

15.

Machine language programs written for one computer will not run on another computer with a different CPU. Explain why.

16.

What is a family of CPUs? When do two CPUs belong to the same family?

17.

When do we say that a computer is backward compatible with another computer? How this feature is useful for users of these computers?

18.

What are registers? Name some commonly used registers and briefly describe the function of each.

19.

What does length of a register mean? What are the commonly used register-lengths in modern computer systems? Why is a larger register length desirable?

20.

Write the main steps involved in execution of an instruction by a computer’s CPU.

21.

What is clock speed of a computer system? How does it influence the overall speed of a computer system?

22.

How is the clock speed of a computer system determined?

23.

Differentiate between the terms “clock cycle” and “clock speed”.

24.

What is a superscalar CPU architecture? How does it lead to better performance of a computer system?

25.

Generally, we measure the processing speed of personal computers in MHz (Mega Hertz), but that of workstations, mini computers, and mainframe systems in MIPS (Millions of Instructions per Second). Explain why.

26.

Why do we measure the speed of supercomputers in FLOPS?

27.

Name two important design parameters that influence the performance of a CPU. Explain how each parameter influences the speed with which a CPU can execute instructions.

28.

Write features of CISC processors.

29.

Write features of RISC processors.

30.

Differentiate between CISC and RISC processors.

31.

Write relative advantages and disadvantages of CISC and RISC processors.

32.

Explain how RISC architecture leads to the design of faster and less expensive processors as compared to CISC architecture.

33.

What is EPIC technology? What are its key features?

34.

How do EPIC processors achieve better performance than CISC or RISC processors?

35.

What is explicit parallelism? How does it help in improved processor performance?

36.

What is predication? How does it help in improved processor performance?

37.

Explain the difference between "branch prediction" and "branch predication" techniques.

38.

What is load speculation? How does it help in improved processor performance?

39.

The performance of EPIC processors comes from both hardware and software. Discuss.

40.

Imagine a computer system, which has no primary memory. Explain how this system would carry out computations. What would be the major drawback of such a system? Based on this, explain the need for primary memory in a computer system.

41.

A fast processor alone is not sufficient for good performance of a computer system. Discuss.

42.

What is a multicore processor? How does it differ from a single-core processor?

43.

Explain the limitations of current transistor technology that has forced processor manufacturers to shift from making more powerful single-core processors to multicore processors.

44.

Explain how a multicore processor can handle execution of multiple simultaneous tasks more efficiently than a single-core processor.

45.

Multicore processor technology adds to extra work for programmers. Explain why.

■ Questions 46.

147

Write advantages and current limitations of multicore processor technology as compared to single-core processor technology.

47.

Why do we refer to multicore processor technology as energy-efficient or power-aware processor technology?

48.

Why software licensing is a key issue with multicore chips?

49.

What is a power-efficient processor? Explain the use of Demand Based Switching (DBS) technology in such a processor.

50.

Write key properties used to characterize and evaluate storage units of computer systems.

51.

Explain the difference between volatile and non-volatile memory. Write an example of each type of memory.

52.

Explain the difference among random access, pseudo-random access, and sequential access storage units. Write an example of each type of storage unit.

53.

Differentiate among a bit, a byte, and a word.

54.

What is a memory address? Describe with an example.

55.

Explain the difference between an address and the content of an address.

56.

Explain the key difference between read and write operations on memory.

57.

Explain why it is advantageous to have more number of bits per word instead of having more words of shorter length in the memory architecture of a computer system.

58.

Distinguish between word-addressable and character-addressable computers. Write their relative advantages and disadvantages.

59.

How many bytes will be required to store the word ‘MEMORY’ in (a) a character-addressable computer, (b) a wordaddressable computer having word-length of 64 bits?

60.

Name some commonly used units for stating memory capacity. Roughly, how many characters does each unit represent?

61.

A computer has 512 MB of memory. How many characters can be stored in its memory at a time?

62.

Is it possible to enhance the existing memory capacity of a computer system? If no, explain why. If yes, explain how.

63.

Differentiate between static and dynamic RAMs. Which one does main memory of most computers commonly use?

64.

What is a ROM? Why it is so called? Write few typical uses of ROM.

65.

What is a micro-program? Write an example of a micro-program that is a good candidate for storage in the ROM of a computer system.

66.

Differentiate between PROM and EPROM.

67.

Differentiate between UVEPROM and EEPROM.

68.

What is a flash memory? Why it is so called?

69.

Differentiate among RAM, ROM, PROM, and EPROM.

70.

The rate at which a CPU can fetch data from memory is about ten times slower than the rate at which it can process data. Name two methods that computer systems use to minimize this speed mismatch. Write details of one of the two methods and explain how it helps in minimizing the speed mismatch.

71.

What is a cache memory? How it is different from a primary memory?

72.

Explain how cache memory helps in improving overall performance of a computer system.

73.

Effective use of cache memory requires that data and instructions needed for processing by the CPU is available beforehand in the cache. Explain how a system ensures this.

74.

What is the principle of locality of reference? How speed of execution of a program depends on it? In what manner do branch statements affect the locality of reference?

75.

Many computer systems use separate data and instruction caches. Explain why.

76.

Explain the concept of multi-level cache design in a computer system. What are its advantages and disadvantages as compared to a single-level cache design?

148

Chapter 4 ■ Computer Architecture

77.

What are the key design issues involved in the use of cache memory in a computer system? Describe the mechanisms used commonly to handle each of these issues.

78.

What is cache size? How it is normally decided?

79.

What is block size in the context of cache design? How it is normally decided?

80.

What is hit ratio? How a programmer can help in improving the hit ratio of a computer system?

81.

What is replacement policy in the context of cache design? Name a commonly used cache replacement policy.

82.

Explain how the least recently used (LRU) replacement policy leads to effective cache usage.

83.

What is write policy in the context of cache design? Describe two write policies and list their relative advantages and disadvantages.

84.

What is memory interleaving? Explain how it helps in improving the overall performance of a computer system.

85.

Explain how an interleaved memory system distributes instructions in different memory modules.

86.

Explain how cache memory and interleaved memory mechanisms can be used together to improve overall performance of a computer system.

87.

What is a bus? Why it is required in a computer system?

88.

What is bus width? How does it affect the overall performance of a computer system?

89.

What are memory buses? How many types of memory buses are there? Describe the role of each type.

90.

A wider bus enables faster exchange of data. Discuss.

91.

Why the width of memory address bus is an important parameter for a computer system?

92.

How the width of memory address bus and the number of memory locations of a computer system are co-related?

93.

What are I/O buses? How many types of I/O buses are there? Describe the role of each type.

94.

Write the similarities and differences among PCI, PIC-X, and PCIe.

95.

What is the basic architecture difference between PCI and PCIe?

96.

What is an I/O device controller? Explain its role in I/O data transfer.

97.

What is interconnection architecture of a computer system? Write three commonly used interconnection architectures.

98.

Describe how data transfer takes place in case of unibus interconnection architecture. Write the advantages and limitations of this architecture.

99.

Describe the busy wait mechanism of data transfer between the CPU and an I/O device in case of dual bus architecture. Write the advantages and limitations of this mechanism.

100. Describe the interrupt mechanism of data transfer between the CPU and an I/O device in case of dual bus architecture. Write the advantages and limitations of this mechanism. 101. Draw schematic diagram of DMA interconnection architecture. Describe how data transfer takes place in this case. Explain how this architecture minimizes CPU’s participation in I/O data transfer. 102. Write the advantages and limitations of DMA data transfer mechanism. 103. What is cycle stealing in the context of DMA architecture? 104. Differentiate between loosely-coupled and tightly-coupled multiprocessor systems. 105. Differentiate between shared memory and distributed memory multiprocessor systems. Which has better scalability and why? 106. Write about three commonly known architectures of shared memory systems. 107. What are blade servers? What advantages do they have as compared to multiple rack-mounted servers in building a data centre? 108. What is a parallel processing system? How does it run a job faster?

Secondary Storage

Primary storage of computer systems has the following limitations: 1. Limited capacity. Its storage capacity is not sufficient to store large volumes of data. 2. Volatile. It loses data stored in it in case of power off or interruption of power. To overcome these limitations, computers use additional memory called auxiliary memory or secondary storage. Secondary storage is non-volatile and has lower cost per bit stored, but operates at speeds far slower than that of primary storage. Computer systems use it to store large volumes of data on permanent basis, which they transfer partially to primary storage, whenever required for processing. This chapter deals with terminologies, principles of operation, uses, and trade-offs of different types of secondary storage devices.

CLASSIFICATION OF SECONDARY STORAGE Over the years, computer systems have used several devices and media as secondary storage. Many of them such as punched paper tape, punched cards, and floppy disks have become obsolete now. Figure 5.1 shows the popular ones used in today’s computer systems. They are broadly classified as: 1. Sequential-access devices. A sequential-access storage device is one in which arrival at a desired storage location is preceded by sequencing through other locations so that access time varies according to location. That is, we can retrieve information stored on a sequential-access device only in the same sequence in which it is stored. In case of a sequential-access device, if we need to access an address that is out of order, we can reach at it only by traversing through all the addresses stored before it. For instance, to access the 28 th data record stored on a sequential-access device, a computer must first access (although not process) the first 27 data records.

150 Chapter 5 ■ Secondary Storage

Secondary storage devices

Sequential access devices

Direct access devices

Magnetic tape

Magnetic disks

Zip disk Disk Winchester CD-ROM pack disk

Memory storage devices

Optical disks

WORM (CD-R)

CD-RW

DVD

Flash Memory RAM disk drive card

Figure 5.1. Commonly used secondary storage devices and their classification.

Sequential access devices are suitable for storing data of such applications, which need to process most (if not all) data records one after another. Preparations of monthly pay slips, monthly electricity bills, etc., are examples of such applications. These applications process data records of every employee or customer at scheduled intervals (in this case monthly). Magnetic tape is an example of a sequential-access storage device. 2. Direct/Random-access devices. A direct-access or random-access storage device is one in which we can reach and access any storage location at random, and approximately equal access time is required for accessing each location. Direct-access devices are useful for such applications, which need to access information in a more direct manner than sequential-access devices allow. For example, in a computerized bank, at any instance, we may require to determine the exact balance in a customer’s savings account. Similarly, in a computerized airline ticket booking system, we may require immediate access to reservation system records to find out, if seats are available on a particular flight. In such applications, if we use a sequential-access device for data storage, accessing desired information may take a long time, causing frustration to the customer. Magnetic disks, optical disks, solid state drive and memory storage devices are examples of direct-access storage devices.

MAGNETIC TAPES Magnetic tape is the most popular storage medium for large data sets accessed and processed sequentially. Computer systems also use it as a backup storage for data stored on on-line storage devices such as a hard disk. Magnetic tape medium is a plastic ribbon usually ½-inch or ¼-inch wide and 50 to 2400 feet long. Its surface has a coating (such as iron oxide or chromium dioxide) that can record data by magnetization. Data is recorded on the coated surface as tiny, invisible magnetized and non-magnetized spots (representing 1s and 0s). Tape ribbon itself is stored in reels, or a small cartridge, or cassette. We can erase old data and record new data on magnetic tapes. As we record new data on it, it erases old data in the same area. However, we can read stored data many times without affecting it.

■ Magnetic Tapes

151

Basic Principles of Operation Storage Organization A tape consists of vertical columns called frames, and horizontal rows called channels or tracks. Most modern magnetic tapes have 9 tracks, and use 8-bit EBCDIC code format for data recording (see Figure 5.2). The fourth track records parity bit. A parity bit or check bit enables detection of errors that may occur due to loss of a bit from a string of 8 bits during data input or output operations. In odd-parity, the check bit is 0, if the total number of 1 bits for representing a character is odd and it is 1, otherwise. On the other hand, in even parity, the check bit is 0 if the total number of 1 bits for representing a character is even and it is 0, otherwise. The tape in Figure 5.2 uses the parity bit for an odd parity. Notice that, it represents letter A by its 8-bit EBCDIC code 11000001. Track/channel numbers

A frame for each character

0 1 2 3 4 5 6 7 8 9

8’s digit

Track representation

Characters for corresponding codes

A B C

9

8 2’s digit Added zone 7

Added zone 6 Zone

5

Parity bit

4

Zone

3

Unit’s digit 4’s digit

2

Each vertical line represents a binary 1 bit

1

Figure 5.2. Data recording on a 9 track magnetic tape using 8-bit EBCDIC code format. Here the 4th track is used for an odd-parity. Hence, all frames contain an odd number of 1 bits.

A magnetic tape is a continuous medium, which records data serially. There is no addressing. In this situation, how different pieces of data (known as records) are identified on a tape? For this, it separates records by blank spaces called inter-record gaps (IRG). A tape drive creates IRGs automatically as it writes data on tape. Each IRG is about 0.5 inches. While reading data from a moving tape, a tape drive stops tape movement when it encounters an IRG. The tape remains stationary until the record processing is over, and then moves again to read the next record. This process repeats for all records in a file. Records are of varying lengths. When a tape contains a large number of short records with an IRG after each record, more than half of the tape is unused (occupied with IRGs). Moreover, tape I/O operation also becomes slow due to frequent interruption in tape movement during I/O operations. To overcome these problems, it groups records in blocks, and separates blocks by blank spaces called inter-block gaps (IBG). The process of grouping two or more records together to form a block of data is known as blocking, and the number of records grouped together in each block is called blocking factor. Blocking factor depends on record length. To reduce wastage of tape storage space, the general rule followed for deciding blocking factor is – a block should be at least ten times as long as the IBG. In addition to better utilization of tape storage space, blocking also helps in faster tape I/O operations. It permits transmission of multiple records with each “read” or “write” operation. Each tape “read” operation transmits all records of the next block from the tape to memory. Similarly, a tape “write” operation transmits an entire block of records from memory to tape drive, which then writes a block of data and an IBG on the tape.

152 Chapter 5 ■ Secondary Storage Figure 5.3 illustrates the concept of blocking. Figure 5.3(a) shows an unblocked tape (one that does not use blocking), Figure 5.3(b) shows a tape that uses a blocking factor of two, and Figure 5.3(c) shows a tape that uses a blocking factor of three. Notice how tape usage increases as blocking factor increases. However, blocking factor should not be too large because in case of data loss due to some parts of the tape becoming bad, all records in a block become irretrievable. Tape motion R1

IBG

IBG

R2

IBG

R3

IBG

R4

IBG

R5

IBG

R6

(a) An unblocked tape. There is an IBG after each record.

Tape motion IBG

R1

R2

IBG

R3

R4

IBG

R5

R6

IBG

R7

R8

IBG

(b) A tape that uses a blocking factor of two. There is an IBG after every two records.

Tape motion IBG

R1

R2

R3

IBG

R4

R5

R6

IBG

R7

R8

R9

IBG

(c) A tape that uses a blocking factor of three. There is an IBG after every three records. Figure 5.3. Concept of blocking. Tape usage increases as blocking factor increases.

A block is a group of records, and a file is a set of blocks. A single tape normally stores several files. To separate one file from another when they are stored sequentially one after another on a tape, the system adds a file header label and a file trailer label respectively at the beginning and at the end of each file. File header label identifies the beginning of a file and contains the file’s attributes such as its name (file identifier), date of creation, etc. File trailer label signifies the end of a file and contains total number of records in the file. Figure 5.4 shows data organization on a magnetic tape with file header and file trailer labels. File header label

File trailer File header label label of next file Tape motion IBG

Block of records

IBG

Block of records

IBG

IBG

a file Figure 5.4. Data organization on a magnetic tape with file header and file trailer labels.

A tape drive wounds a tape on a spool and moves it during tape I/O operations from a supply spool to a take-up spool. To allow for threading on the take-up and supply spools, the first and the last several feet of a tape are unused (not used for any type of information recording). After the unused length towards the beginning of tape, there is a reflective metal foil known as beginning of tape (BOT) marker to indicate to the tape drive the beginning of usable tape. Similarly, before the unused length towards the end of tape, there is another reflective metal foil known as end of tape (EOT) marker to indicate the end of usable tape. These two markers are on opposite edges of the tape for machine identification purposes. Between BOT marker and the first file header label is a tape header label, which contains the tape’s attributes such as its identifier, number of files it contains, date of its last use, and other control information, which help to prevent an important tape from accidental eraser. Figure 5.5 shows data organization on a magnetic tape with BOT and EOT markers, and tape header label.

■ Magnetic Tapes

153

Tape header label BOT marker

unused tape

File trailer label

File header label I B G

I B G

Blocks of records of the file separated by IBGs

I B G

Tape motion

I B G

File trailer label of last file I B G

unused tape

EOT marker

Figure 5.5. Data organization on a magnetic tape with BOT and EOT markers and tape header label.

Storage Capacity Storage capacity of a tape = Data recording density × Length Data recording density is the amount of data that can be stored on a given length of tape. We measure it in bytes per inch (bpi), or number of bytes (characters) that can be stored per linear inch of tape. Tape density varies from 800 bpi in older systems to 77,000 bpi in modern systems. Hence, if a 2400 feet tape has a data recording density of 800 bpi, its storage capacity will be 2400 × 12 inches × 800 bpi = 23 × 10 6 bytes = 23 Mega bytes. This is the total (raw) storage capacity of the tape. Its actual storage capacity (storage available for storing user data) is much less due to use of IBGs. In fact, actual storage capacity of a tape may be anywhere from 35% to 70% of its raw storage capacity depending on storage organization.

Data Transfer Rate Data transfer rate of a tape is the number of characters transmitted per second from the tape to primary storage. We measure it in bytes per second (bps). Its value depends on data recording density and speed of tape movement under read/write head. Tape speed is typically of the order of 100 inches per second. Hence, for a tape having data recording density of 77,000 bpi and its drive having tape speed of 100 inches per second, data transfer rate is 77,000 × 100 = 77,00,000 bytes or roughly 7.7 MB per second.

Tape Drive A magnetic tape drive enables storage/retrieval of data on/from tape. It has read/write heads. As tape ribbon passes under the read/write heads, it can read/write data from/to the tape by giving suitable commands (read or write) to the tape drive. We have to first load a magnetic tape reel, cartridge, or cassette on to a tape drive attached to a computer for processing. The magnetic tape is on-line once we load it on a magnetic tape drive. The computer can now use it for storage or retrieval of data. When processing is complete, we remove the tape from the tape drive for off-line storage (away from the computer system), and data on it becomes inaccessible until we load it again on the tape drive.

Tape Controller We must mount a magnetic tape on a tape drive, before we can use it for reading/writing of information. A tape controller controls a tape drive connected to it. It interprets the commands for operating the tape drive. Figure 5.6 shows a set of commands, which a tape controller typically supports.

154 Chapter 5 ■ Secondary Storage Command

Meaning

Read Write Write tape header label Erase tape Back space one block

Reads one block of data Writes one block of data Updates contents of tape header label Erases data recorded on a tape Rewinds tape to the beginning of previous block

Forward space one block Back space one file Forward space one file Rewind

Forwards tape to the beginning of next block Rewinds tape to the beginning of previous file Forwards tape to the beginning of next file Fully rewinds the tape

Unload

Releases tape drive’s grip so that tape spool can be unmounted from tape drive Figure 5.6. Set of commands typically supported by a tape controller.

Types of Magnetic Tapes Commonly used types of magnetic tapes are described here.

Half-inch Tape Reel A half-inch tape reel uses ½-inch tape ribbon stored on a tape reel (see Figure 5.7). Figure 5.8 shows its tape drive on which we have to mount the tape reel for data processing. During processing, the tape moves from a supply reel to a take-up reel via two vacuum columns and through a read/write head assembly. The read/write head assembly reads/writes data from/to the tape. It is a single unit having one read/write head for each tape track. Therefore, the read/write head assembly of a 9-track tape drive will have a set of nine heads. Each head operates independently and stores information on nine tracks parallel to the edge of the tape. This method of storing data in adjacent bit configurations is known as parallel representation. In parallel representation, a tape drive reads/writes data a byte at a time. Different tape drives use different mechanisms to prevent tape damage from sudden bursts of speed. For example, the tape drive of Figure 5.8 uses two vacuum columns to take up slack tape, acting as buffers, to prevent the tapes from snapping or stretching when starting from a stationary position or slowing down from full speed. Users commonly use magnetic tape reels as archival storage for off-line storage of data and for exchange of data and programs between organizations. Mainly organizations having large computing systems (such as mainframe systems) use them because the tape controller and tape drives of magnetic tape reels are bulky and expensive. Many mediumsized business organizations have vaults containing several thousands of tape reels. For example, a large insurance company may have a storage area containing over 50,000 magnetic tape reels. However, tape cartridge, streamer tape, and digital audio tape are fast replacing magnetic tape reels because these new magnetic tape storage devices are more compact, cheaper, and easier to handle and use.

■ Magnetic Tapes Supply reel

155

Magnetic tape Take-up reel Read/write head assembly

Figure 5.7. Magnetic tape in reel form.

Vacuum columns Tape loops varying in length Figure 5.8. Tape drive of a magnetic tape reel.

Half-inch Tape Cartridge Tape cartridges look similar to audio or video cassettes used few years ago in home music or video systems (see Figure 5.9). Their tape drives are also similar in look and mechanical operation to the audio or video players used earlier in our homes. We push/eject a tape cartridge inside/from a tape drive just as we used to push/eject a videotape cassette inside/from a video player.

Figure 5.9. Magnetic tape cartridge.

Tape cartridges provide a more convenient way to package tape. They also simplify mounting of tape on tape drive as compared to magnetic tape reels. Moreover, tape cartridges provide protection against dirt and contamination because of its sealing inside the cartridge. In addition to the differences in shape and size of tapes and mechanical operation of their tape drives, the two main differences in data organization and data recording/reading of half-inch tape reels and half-inch tape cartridges are: 1.

Half-inch tape cartridge has 36 tracks, as opposed to 9 tracks for most half-inch tape reels. Like tape reels, tape cartridges also store data using parallel representation. Hence, 4 bytes of data is stacked across the width of the tape in case of tape cartridges, as opposed to a single byte of data in case of tape reels. This enables more bytes of data to be stored on the same length of tape.

2.

Tape cartridges record/read on the top half of the tape in one direction and on the bottom half in the other direction. That is, out of 4 bytes (36 tracks) of data stacked across the width of the tape, it reads 2 bytes (18 tracks) of data in each direction. Recall that tape reels record/read data in one direction only.

Quarter-inch Streamer Tape In addition to storage of data for sequential data processing applications, one of the primary uses of magnetic tapes is to serve as backup storage medium for data stored on on-line devices such as a disk. During backup or recovery process, backup mechanisms process backup tapes continuously from beginning to end because there is no need for selective access of records. Hence, there is no need to start and stop a backup tape after every few records. Based on this idea, researchers came out with a special type of quarter-inch streamer tape, eliminating the need for start/stop operation of traditional tape drives for half-inch tape reels or tape cartridges. As there is no start/stop mechanism, streamer tape drives can read/write data more efficiently than traditional tape drives, which stop and restart tape movement at each IBG. Moreover, streamer tape drives also utilize tape storage area more efficiently. Typically,

156 Chapter 5 ■ Secondary Storage streamer tapes use 97% of tape for data storage, whereas traditional start/stop tapes use only 35% to 70%, depending on blocking factor. These tapes are ¼-inch wide and sealed in a cartridge. Their tape drives are similar in look and mechanical operation to the tape drives of half-inch tape cartridges. Unlike half-inch tapes, which use parallel representation for data recording, these tapes use serial representation for data recording. That is, they align data bits in a row, one after another in tracks. A streamer tape can have from 4 to 30 tracks, depending on tape drive. Depending on tape drive, read/write head reads/writes data from/to one, two, or four tracks at a time. Figure 5.10 shows a streamer tape having 8 tracks. It records data on two tracks at a time. That is, it first writes data on the top two tracks for entire length of the tape or until the data is exhausted. If it reaches end of the tape while recording the data, it rewinds the tape, positions the read/write head on the next two tracks, and continues recording the data in a similar manner. Streamer tapes are so called because they read/write data serially as streams of bits. They use a data format known as the QIC (Quarter Inch Cartridge) standard. Standard data format helps in easy use of these tapes for exchanging data between different computers. Recording area ends here

Recording area begins here Tracks 1

1

0

1

1

0

0

1

1 1

0

1

0...

2

0

0

1

0

1

0

0

1 1

1

0

1...

3 4 5 6

Unused portion of the tape

Unused portion of the tape

7 8 Figure 5.10. Serial representation of data on a streamer tape having 8 tracks. In this example, data is recorded two tracks at a time in a serpentine manner.

4mm Digital Audio Tape (DAT) DAT provides very high data density per inch of tape. It uses a tape ribbon of 4mm width enclosed in a cartridge. Tape length is either 60 meters or 90 meters. For very high data recording density, its tape drive uses helical scan technique for data recording. As Figure 5.11 shows, helical scan has two read heads and two write heads built into a small wheel (or cylinder) that spins near the tape at about 2000 rpm. The tape also moves at a relatively slow speed of about ⅓-inch per second. The two write heads write data with opposite magnetic polarities on overlapping areas of the tape. Each read head reads only one polarity or the other. The result is high data density per inch of tape. The helical scan records data on the tape at an angle to the tape. DAT drives use a data-recording format called Digital Data Storage (DDS), which provides three levels of error correcting code to ensure excellent data integrity. Storage capacity of DAT cartridges varies from 4 GB to 14 GB, and data transfer speed of DAT drives is about 366 KB/sec.

■ Magnetic Tapes

157

Write head B Read head B

Read head A

Spinning helical

scan Write head A Moving tape Shaft Figure 5.11. Helical scan technique used for data recording by a DAT drive.

Advantages and Limitations of Magnetic Tapes Advantages 1.

Storage capacity of a magnetic tape storage is virtually unlimited because as many tapes as required can be used for storing large data sets.

2.

With low cost of tape reels and cartridges and high data recording densities, cost per bit of storage is low for magnetic tapes. An additional cost benefit comes from the fact that we can erase data on a tape and reuse it many times. In-spite-of recent advancements in many other storage technologies, tapes remain an unrivalled storage because no other technology offers high capacity advantage at such low cost.

3.

Tape reels and cartridges are easy to handle and store because they are compact and light in weight. They enable storage of huge amount of data in a small storage space.

4.

Magnetic tape reels and cartridges are easily portable because of their compact size and lightweight.

Limitations 1.

Magnetic tapes are not suitable for storage of those data that we need to access randomly because of their sequential access nature.

2.

We must store them in dust-free environment because specks of dust can cause tape-reading errors. The environment must also have controlled temperature and humidity levels to prevent the tape ribbon from twisting due to warping.

3.

We must label magnetic tapes properly and logically to remember what data is on which tape, and to prevent erasure of useful data by mistake.

Uses of Magnetic Tapes We use magnetic tapes for the following purposes: 1.

For sequential data processing applications. For example, we often use magnetic tapes for applications in which contents of an inventory master file (permanent source of inventory data) is updated periodically (weekly, monthly, etc.) using a transaction file (containing data reflecting inventory activities during the period) to create a new inventory master file, which is used in the next processing cycle (see Figure 5.12). Backing up of data stored on an on-line storage device such as a disk, for its off-line storage. However, over time, tape will become more of an archive medium because users are increasingly using disk-based solutions to meet backup requirements.

2.

Archiving of data used occasionally. Tape continues to be the preferred medium for data archival.

158 Chapter 5 ■ Secondary Storage 3.

Transferring of data and programs between two computers not linked together.

4.

Distribution of software. Vendors often distribute software products or their updates on magnetic tapes. Inventory master file

New inventory master file Next processing

Processing

Transaction file

New inventory master file

New transaction file

Figure 5.12. Illustrating the use of tapes in a sequential application.

MAGNETIC DISKS Magnetic disks are the most popular direct-access secondary storage device. They are also the most popular on-line secondary storage device. A magnetic disk is a thin, circular plate/platter of metal or plastic. Its surfaces on both sides have a coating (such as iron oxide) that can record data by magnetization. Data is recorded on its coated surfaces as tiny, invisible magnetized and non-magnetized spots (representing 1s and 0s). It uses a standard binary code, usually 8-bit EBCDIC, for recording data. The disk itself is stored in a specially designed protective envelope, or cartridge, or several of them are stacked together in a sealed, contamination-free container. Like in the case of magnetic tapes, we can erase old data and record new data on magnetic disks as well. As we record new data on it, it erases old data in the same area. However, we can read stored data many times without affecting it.

Basic Principles of Operation Storage Organization A magnetic disk’s surface has a number of invisible, concentric circles called tracks. Tracks have numbers consecutively from outermost to innermost starting from zero (see Figure 5.13). Number of tracks varies greatly, with low-capacity disks having as few as 40 tracks and high-capacity disks having several thousands tracks. A magnetic disk’s surface also has invisible, pie-shaped segments (see Figure 5.14). Hence, if there are eight such segments, each track has eight parts. Each such part of a track is called a sector. Typically, a sector contains 512 bytes. It is the smallest unit of data access by a disk drive. That is, disk drives can access (read/write) a complete sector at a time. Even if a computer needs to change just one byte out of 512 bytes stored on a sector, it rewrites the entire sector. Notice from Figure 5.14 that the sectors on the outer tracks are longer than sectors on the inner tracks. Since each sector records the same number of characters (usually 512 characters), length of the sectors on the innermost track determines the storage capacity of the sectors on all other tracks of a disk. This means that storage space remains underutilized on the sectors on the outer tracks of the disk. This is a disadvantage of dividing a disk’s surface into pieshaped segments. To avoid this problem, some systems partition a disk’s surface in such a manner that all sectors occupy approximately the same amount of space. Figure 5.15 shows one such type of partitioning. This method first partitions tracks into groups, with tracks in different groups having different number of sectors per track. For

■ Magnetic Disks

159

example, the disk in Figure 5.15, partitions tracks into three groups. Tracks in the innermost group have 8 sectors per track, tracks in the next group have 9 sectors per track, and tracks in the outermost group have 10 sectors per track. Using this new method of disk partitioning, Apple was able to increase the storage capacity of its 3½-inch floppy disk by about 40%. 200 Tracks

Track 000 A sector



Track 199



Figure 5.13. Tracks on a disk. The outermost track is numbered 000, and the innermost track is numbered one less than the total number of tracks (199 in this example).

Figure 5.14. Sectors of a disk. The number varies, but there are often 8 or more sectors per track.

If a disk has 200 tracks and 8 sectors per track, it has 1600 (200  8) sectors with each sector having a unique number. To access a piece of data (a record) from a disk, we need to specify its disk address, which represents the physical location of the record on the disk. It is comprised of sector number, track number, and surface number (when double-sided disks are used).

Figure 5.15. A disk partitioning method in which all sectors occupy approximately the same amount of space.

Note that sector size (usually 512 bytes) is the smallest unit of data access by disk drives, and a file size (number of bytes in a file) is usually not a multiple of sector size. Hence, some part of the last sector allocated to a file is unused normally, resulting in on an average wastage of half sector for each file stored on disk. Hence, sector size for a disk should not be too large. It should not even be too small, otherwise the size of mapping table used to map disk addresses to data records will become too large. Some operating systems combine two or more sectors to form a cluster. In this case, the smallest unit of data access from a disk is a cluster, instead of a sector. That is, read/write operations read/write a whole cluster at a time. Cluster sizes vary depending on the size and type of disk, but they range from 2 to 64 sectors per cluster. Notice that a cluster-based organization may lead to more wastage of disk space as compared to sector-based organization, because on an average, it wastes half of cluster size for each file stored on disk. However, cluster-based organization leads to less management overhead for mapping of data records to physical disk locations, and faster read/write operations. Often, multiple disks are stacked together as a disk pack to create large capacity disk-storage systems (see Figure 5.16). The disk pack is sealed and mounted on a disk drive consisting of a motor to rotate the disk pack about its axis. The disk drive also has an access arms assembly having separate read/write heads for each recordable surface of the

160 Chapter 5 ■ Secondary Storage disk pack. Normally, a disk pack does not use the upper surface of the topmost disk and the lower surface of the bottommost disk because these surfaces get scratched easily. However, modern disk drives use miniaturization and precision components to eliminate this drawback. Upper surface not used Surface - 0 Surface - 1 Cylinder

Surface - 2

Read/Write head Direction of movement of access arms assembly

Surface - 3 Surface - 4 Surface - 5 Lower surface not used

Access arms assembly

Central shaft

Figure 5.16. A disk pack having 4 disk platters. The upper surface of the top plate, and the lower surface of the bottom plate are not used. Hence, altogether there are 6 usable surfaces numbered 0, 1, 2, 3, 4 and 5. As shown, a set of corresponding tracks on all 6 surfaces is called a cylinder.

All access arms (on which read/write heads are fixed) of an access arm assembly for all disk surfaces move together. Hence, if the read/write head serving the 0 th recording surface is positioned over the 5th track, each of the heads on the arms serving other recording surfaces is also positioned over the 5 th track of respective surfaces. For faster access of data, disk packs use a concept called cylinder for data organization. A set of corresponding tracks on all recording surfaces of a disk pack together form a cylinder (see Figure 5.16). For example, the 5 th track of all recording surfaces together forms the 5th cylinder of the disk pack. Hence, if there are 200 tracks on each disk surface, there are 200 cylinders in the disk pack. Obviously, disk address of a data record on a disk pack consists of sector number, cylinder number, and surface number (track number is not required because track number and cylinder number are same). This addressing scheme is called CHS (Cylinder-Head-Sector) addressing. It is also known as disk geometry. Cylinderbased organization achieves faster access of data by avoiding movement of access arms when an application has to process large number of records in sequence. It stores related records of a file on the same cylinder of a disk pack so that in one revolution of the disk pack, the disk drive can read/write all records stored on, say cylinder 5 of all surfaces.

Storage Capacity Storage capacity of a disk system = Number of recording surfaces  Number of tracks per surface  Number of sectors per track  Number of bytes per sector Let us assume that a disk pack has 10 disk plates, 2655 tracks per plate, 125 sectors per track, and 512 bytes per sector. Since the disk pack has 10 disk plates, there are 18 recording surfaces (excluding the upper surface of the topmost disk and the lower surface of the bottommost disk). Hence, its capacity = 18  2655  125  512 = 3,05,85,60,000 bytes = 3  109 bytes (approximately) = 3 GB (3 Giga Bytes). As one character is stored per byte (using 8-bit EBCDIC encoding), the disk pack can store over 3 billion characters. Designers prefer to increase the storage capacity of a disk by increasing the number of tracks per inch of surface and bits per inch of track, rather than increasing the disk size. Hence, a constant goal of designers of disk systems is to increase the data density of each square inch of disk surface.

■ Magnetic Disks

161

Access Mechanism A disk drive records data on the tracks of a spinning disk surface and reads data from the surface by using one or more read/write heads on its access arms assembly (see Figure 5.17). Most disk drives use a single read/write head for each disk surface. However, some faster disk systems use multiple heads on each access arm to service a number of adjacent tracks simultaneously. As the access arms assembly moves in and out in the direction shown in the figure, read/write heads move horizontally across the surfaces of the disks. The disk drive positions the read/write heads on any track on/from, which it wants to write/read data. In case of a disk pack, each usable surface has its own read/write head and all heads move together. Hence, the disk drive can simultaneously access information stored on the tracks constituting a cylinder through the disk pack. Recall the cylindrical storage arrangement of information in a disk pack. Read/write heads are of flying type. They do not have direct contact with disk surfaces. There is a separation of about 0.00002 inch between a read/write head and its corresponding disk surface. This prevents wear of a disk surface. However, read/write heads fly so close to the disk surface that if a dust particle (typically of 0.0015 inch size), smoke particle (typically of 0.00025 inch size), finger print (typically of 0.00062 inch size), or a human hair (typically of 0.003 inch size) is placed on the disk surface, it would bridge the gap between read/write head and disk surface, causing the head to crash. A head crash, in which the head touches the disk, destroys the data stored in the area of the crash and can destroy a read/write head as well. One read/write head per surface

Central shaft

Direction of movement of access arms assembly

. . Disk platters .

Access arms assembly Figure 5.17. Vertical cross section of a disk system. There is one read/write head per recording surface.

Access Time Disk access time is the interval between the time a computer makes a request for transfer of data from a disk system to primary storage and the time this operation completes. To access data stored on a disk, we need to specify the disk address of the desired data in terms of surface/head number, track/cylinder number, and sector number. A disk stores information always from the beginning of a sector and reads information always from the beginning of a track. Hence, disk access time depends on the following three parameters: 1. Seek time. When a disk unit receives a read/write command, it first positions the read/write heads on the specified track (cylinder) number by moving the access arms assembly in proper direction. The time required to position the read/write heads on the specified track/cylinder is called seek time. Seek time varies depending on the position of access arms assembly when a read/write command is received. If access arms assembly is on the outermost track and the specified track is the innermost one, seek time will be maximum. It will be zero, if the access arms assembly already happens to be on the specified track. Most systems specify average seek time, which is of the order of 10 to 100 milliseconds. To reduce seek time, some disk systems use multiple read/write heads on each access arm. For example, a disk system having two sets of read/write heads for each surface (one for inner tracks, and another for outer

162 Chapter 5 ■ Secondary Storage tracks), will reduce average seek time by half. This is because each read/write head needs to cover and move across only half of the total number of tracks. 2. Latency. Once the disk drive positions the read/write heads on the specified track, it activates the head on the specified surface. Since the disk is continuously rotating, this head should wait for the specified sector to come under it. This rotational waiting time, i.e., the time required to spin the specified sector under the head is called latency. Latency, also known as rotational delay time, is a variable that depends on the distance of the specified sector from the initial position of the head on the specified track. It also depends on rotational speed of the disk that is anywhere from 300 rpm (rotations per minute) to 7200 rpm. Modern ultra fast disks can reach 10,000 to 15,000 rpm or more. Thus, disk systems specify average latency, which is of the order of 5 to 80 milliseconds. Note that average latency of a disk system is equal to half the time taken by the disk to rotate once. Hence, average latency of a disk system with rotational speed of 3600 rpm will be 0.5/3600 minutes = 8.3 milliseconds. 3. Transfer rate. Transfer rate is the rate at which a computer reads/writes data from/to a disk into memory. Once the disk drive positions the read/write head on the specified sector, it reads/writes data at a speed determined by the rotational speed of the disk. If rotational speed of a disk is 3600 rpm and the disk has 125 sectors/track with 512 bytes/sector, the amount of data transferred in one full revolution of the disk is 125  512 = 64,000 bytes = 64K bytes (approximately). Hence, transfer rate of the disk system is 64,000  3600/60 bytes/second = 38,40,000 bytes/second = 3.8 Megabytes/second (approximately). Notice that transfer rate of a disk system depends on the density of stored data and rotational speed of the disk. Since data transfer time is negligible (due to high transfer rate) as compared to seek time and latency, average access time for a disk system is its average seek time plus its average latency. Average access time varies from one type of disk system to another and is anywhere from 10 to 600 milliseconds. Since access time for a piece of data stored on a disk depends on its physical location, it is more appropriate to refer to a disk system as direct access storage device instead of random access storage device. Random access refers to a storage device in which access time of any data is independent of its physical location. For example, primary storage is random access storage. However, we do not follow this distinction strictly and refer to disk systems as random access storage devices.

Disk Formatting Magnetic disks come in different sizes. Typical disk sizes include those with 14-inch, 9-inch, 8-inch, 5¼-inch, 3½inch, and 3¼-inch diameter. Obviously, for proper match of dimensions, different size disks require different disk drives. Even for disks of same size, all disk drives are not the same because disk drives of different computers often have their own way of defining tracks, sectors, and sector size (number of bytes/sector) to match their own way of organizing data. This implies that computer manufacturers should also manufacture the disks used in their computer systems. This limitation prevents use of disks manufactured by third party vendors into one’s own computer system. To overcome this problem, earlier computer systems provided low-level disk formatting utility. It enabled a user to prepare (format) a new disk before using it with the computer system. For this, the user had to insert the raw (unformatted) disk in the disk drive of the computer system and initiate disk-formatting command. The read/write head of the disk drive then laid down a magnetic pattern on the disk’s surface, making it compatible for use with it. Modern disk drives do not require low-level formatting because modern disk controllers present a consistent view of disk geometry to the computer while hiding the internal hardware arrangement. They accept and can work with disks that are factory formatted by their manufacturers. In fact, running a generic low-level format on these disks can cause irreparable damage to drive hardware. For this reason, modern computer systems do not provide low-level disk formatting utility. To store files and data on a disk, the operating system (OS) creates a file-system on the disk. It maintains a table with the sector and track locations of data on the disk. This table, known as File Allocation Table (FAT), enables the

■ Magnetic Disks

163

computer to locate data easily. The operating system’s disk formatting command takes care of scanning and marking bad sectors, creating the FAT, and setting aside sufficient disk space for it.

Disk Drive We have to mount a magnetic disk on a disk drive for reading/writing of data from/to it. A disk drive, also known as Hard Disk Drive (HDD), contains all mechanical, electrical, and electronic components for holding one or more disks and for reading/writing of data from/to it. It contains a central shaft on which the disks are mounted, an access arms assembly, a set of read/write heads, and motors to rotate the disks and move the access arms assembly. Although, disk drives vary in their shape, size, and disk-formatting pattern, we classify them broadly into two types: 1.

Disk drives with interchangeable disks. These disk drives allow loading and use of different disks in the same disk drive at different instances, enabling off-line storage of data on disks. They provide virtually unlimited capacity to a disk system because as many disks as required can be used one after another to store large data sets.

2.

Disk drives with fixed disks. These disk drives come along with a set of permanently fixed disks. The disks, read/write heads, and access mechanisms of the disk drive are housed permanently in a sealed, contaminationfree container. Sealed packaging allows the disks to operate in a dust-free environment. This enables designers to provide increased data density (by using smaller magnetized spots) on each square inch of disk surface by reducing the distance between a read/write head and its corresponding disk surface. Hence, as compared to disk drives with interchangeable disks, these disk drives provide larger storage capacity with same size disks and same number of disk surfaces. However, the disks are not removable from their disk drives because of sealed packaging. Thus, storage capacity of these disk systems is limited.

Disk Controller A disk controller controls a disk drive connected to it. It interprets the commands for operating the disk drive. Since disk is a direct access storage device, typically, a disk controller supports only Read and Write commands. A user has to specify disk address (consisting of surface number, cylinder/track number, and sector number) as a parameter to Read and Write commands. Often, a disk controller controls more than one disk drive connected to it. In this case, the user also has to specify disk drive number as a parameter to Read and Write commands.

Types of Magnetic Disks All magnetic disks are round platters. They come in different sizes, use different types of packaging, and are made of rigid metal or flexible plastic. Their size ranges from 1 to 14-inch diameter. Commonly used sizes are 1.0 inch, 2.5 inch and 3.5 inch. The disks are packaged individually or in multiples in cartridges or contamination-free containers. Depending on the type of packaging, magnetic disks are classified into Zip/Bernoulli disks, Disk packs, and Winchester disks (see Figure 5.18). They are described here. Magnetic disks

Zip/Bernoulli disks

Disk packs

Winchester disks

Figure 5.18. Broad classification of magnetic disks.

164 Chapter 5 ■ Secondary Storage 1.

Zip/Bernoulli disk. It consists of a single hard disk platter encased in a plastic cartridge. Depending on the disk drive and size of disk, storage capacity varies from a few GB to few tens of TB. Its disk drive, called zip drive, may be of portable or fixed type. The fixed type is part of a computer system, connected to it permanently. A user can bring and connect the portable type to a computer system for the duration of use, and can then disconnect and take it away. We can load/unload a zip disk into a zip drive, just as we insert/remove a video cassette in a video cassette player.

2.

Disk pack. It consists of multiple (two or more) hard disk platters mounted on a single central shaft. All disks revolve together at the same speed. Its disk drive has a separate read/write head for each usable disk surface (recall that when a disk device uses multiple disks, the upper surface of the topmost disk and the lower surface of the bottommost disk are sometimes not used). The disk drive is of interchangeable type and allows users to load/unload different disk packs whenever required. When not in use, a user stores a disk pack offline in a plastic case (see Figure 5.19). This gives virtually unlimited storage capacity to disk packs. Depending on the disk drive, size of disk, and number of disks in a pack, storage capacity of a single disk pack varies from a few TB to few hundred TB. Lid of plastic container Plastic container

Hard disk platters Figure 5.19. A disk pack.

3.

Winchester disk. A Winchester disk consists of multiple (two or more) hard disk platters mounted on a single central shaft. However, unlike a disk pack drive, a Winchester disk drive is of fixed type. That is, its hard disk platters and disk drive are sealed together in a contamination-free container and cannot be separated from each other. Hence, Winchester disks have limited capacity. However, for the same number of disk platters of the same size, Winchester disks have larger storage capacity than disk packs due to the following reasons: (a) As the disk platters and disk drive are sealed together permanently, all surfaces of all disk platters (including the upper surface of the topmost platter and the lower surface of the bottommost platter) are used for data recording. That is, for a Winchester disk with four platters, there are eight usable surfaces as opposed to six surfaces in case of a disk pack with four platters. (b) Contamination-free environment allows Winchester disks to employ greater precision of data recording and accessing, resulting in greater data storage density than interchangeable disk packs.

Advantages and Limitations of Magnetic Disks Advantages 1.

Magnetic disks support direct access of data making them more suitable for a wider range of applications as compared to magnetic tapes, which support only sequential access of data.

2.

Due to random access property, computers often use magnetic disks as a shared device, which is shared simultaneously by multiple users. For example, computers often use Winchester disks and disk packs as online secondary storage devices storing data of multiple users of a computer system. A tape is not suitable for such type of usage due to its sequential-access property.

3.

Magnetic disks are suitable for both on-line and off-line storage of data.

■ Optical Disks

165

4.

Except for fixed type Winchester disks, storage capacity of other magnetic disks is virtually unlimited because as many disks as required can be used for storing very large data sets.

5.

Due to their low cost and high data recording densities, cost per bit of storage is low for magnetic disks. An additional cost benefit comes from the fact that we can erase data on a magnetic disk and reuse it many times.

6.

Due to their compact size and high data recording densities, they enable storage of large amount of data in a small storage space.

7.

Zip disks are portable, and users often use them to transfer data and programs between two unlinked computers.

8.

Data access rate for a magnetic disk system is much superior to a tape system.

9.

Magnetic disks are less vulnerable to data corruption due to careless handling or unfavorable temperature and humidity conditions than magnetic tapes.

Limitations 1.

Although magnetic disks are usable for both random and sequential data processing applications, their usage for sequential applications is less efficient than magnetic tapes.

2.

It is more difficult to maintain security of information stored on magnetic disks used as shared, on-line secondary storage devices as compared to information stored on magnetic tapes or on other types of magnetic disks.

3.

For Winchester disks, a disk crash or drive failure often results in loss of entire data stored on it. It is not easy to recover the lost data. Hence, data stored on Winchester disks requires suitable backup procedures.

4.

Some types of magnetic disks, such as disk packs and Winchester disks, are not portable as easily as magnetic tapes.

5.

On cost-per-bit basis, cost of magnetic disks is low, but the cost of magnetic tapes is even lower.

6.

Magnetic disks must be stored in a dust-free environment.

7.

We must label zip disks and disk packs properly and logically to remember what data is on which disk/disk pack, and to prevent erasure of useful data by mistake.

Uses of Magnetic Disks We use magnetic disks for the following purposes: 1.

For random data processing applications.

2.

As a shared, on-line secondary storage device. We often use Winchester disks and disk packs for this purpose.

3.

As a backup device for off-line data storage. We often use zip disks and disk packs for this purpose.

4.

Archiving of occasionally used data. We often use zip disks and disk packs for this purpose.

5.

Transferring of data and programs between two unlinked computers. We often use zip disks for this purpose.

OPTICAL DISKS An optical-disk storage system consists of a metallic or plastic disk coated with a reflective material. It uses laser beam technology for reading/writing of data from/to disk surface. Optical disks are also known as laser disks or optical laser disks because they use laser beam technology for data read/write. Computer systems use optical disks as

166 Chapter 5 ■ Secondary Storage a random access medium for high capacity secondary storage because of their capability to store large amount of data in a limited space.

Basic Principles of Operation Storage Organization Unlike magnetic disks having several concentric tracks [see Figure 5.20(b)], an optical disk has one long track starting at the outer edge and spiraling inward to the center [see Figure 5.20(a)]. Spiral track is ideal for reading large blocks of sequential data, such as audio or video. It, however, causes slower random access of data than in case of concentric tracks used by magnetic disks. This is because in case of concentric tracks organization, disk mechanism can locate sectors faster, as they are always located on a given track at a fixed distance from the center.

(a) Track pattern on an optical disk

(b) Track pattern on a magnetic disk

Figure 5.20. Difference in track patterns on optical and magnetic disks.

Spiral track organization divides the spiral track of an optical disk into equal-length sectors regardless of the position of a sector from the center. Recall from Figure 5.14 that the sectors on a magnetic disk are of varying length with the ones near the centre being smaller than the ones away from the center. All sectors being of equal length enables data packing at maximum density over the entire disk. However, it also requires a more complicated drive mechanism because the rotational speed of the disk must vary inversely with the radius. That is, the drive must slow down the disk’s rotation speed to read/write data from/to sectors towards the periphery of the disk, and speed it up to read/write data from/to sectors towards the center of the disk.

Storage Capacity Cost-per-bit of storage is low for optical disks because of their low cost and high storage density. They come in various sizes ranging from 12.0-inch to 3.0-inch diameter. The most popular one is of 5.25-inch diameter with capacity of about 650 Megabytes, which is equivalent to about 2,50,000 pages of printed text. Optical disks are the most suitable storage media for multimedia applications because of their large storage capacity. As optical disks have a single track, Storage capacity of an optical disk = Number of sectors  Number of bytes per sector The 5.25-inch optical disk typically has 3,30,000 sectors each of 2352 bytes, making its storage capacity equal to 3,30,000  2352 = 776  106 bytes = 776 Megabytes. This is unformatted capacity. Formatted capacity is about 650 Megabytes.

Access Mechanism An optical disk drive uses laser beam technology for reading/writing of data from/to an optical disk surface. It has two laser beam sources. It uses one laser beam (of greater intensity) to write data by etching microscopic pits on the disk surface and another laser beam (of lesser intensity) to read data from the light-sensitive disk surface. To write data, it turns the laser beam ON and OFF at a varying rate due to which tiny pits (visible only through a powerful microscope) are burnt into the metal coating of disk surface along its tracks. To read data, it focuses the less-powerful laser beam on the disk surface. This beam is strongly reflected by the coated surface (known as a land) and weakly

■ Optical Disks

167

reflected by the burnt surface (known as a pit), producing patterns of ON and OFF reflections, which are converted into electronic signals of binary 1s and 0s by a sensor (see Figure 5.21). It uses a mechanical forward-backward moving read/write access arm with laser source and detection lens (called eye) assembly to place the unit at the desired place on the optical disk. This assembly and the disk do not come in contact. The disk itself is on a spindle attached to a motor that rotates the disk during access. Laser beam source

Laser beam source Prism

Prism

Sensor

Laser beam is scattered by a pit

Sensor

Laser beam is reflected by a land

Pit

Land

Pit

Land

Pit

Land

Figure 5.21. Surface of an optical disk consists of tiny lands and pits. The laser beam is strongly reflected by lands and weakly reflected (scattered) by pits, producing patterns of ON and OFF reflections, which are converted into electronic signals of binary 1s and 0s by a sensor.

Optical Disk Drive A user mounts an optical disk on an optical disk drive for reading/writing of information from/to it. An optical disk drive contains all the mechanical, electrical, and electronic components for holding an optical disk and for reading/writing of data from/to it. It contains a tray on which the disk is kept, read/write laser beams assembly, and motor to rotate the disk. Figure 5.22 shows an optical disk drive. An optical disk drive differs from a magnetic disk drive in the following manner: 1. As Figure 5.22 shows, it uses laser beam technology for data reading/writing and has no mechanical read/write access arm. 2. Magnetic disk drives use a constant angular velocity (CAV) encoding scheme, whereas optical disk drives use a constant linear velocity (CLV) encoding scheme. That is, in case of magnetic disk drives, the disk spins at a constant rate of speed and each sector occupies the area subtended by a fixed angle. On the other hand, in case of optical disk drives, the rotational speed of the disk varies inversely with the radius; the motor slows down the disk to read sectors towards the periphery of the disk and speeds it up to read sectors towards the center of the disk. Doing this requires a more complicated drive mechanism that can overcome the inertia of the disk when accelerating and the momentum when decelerating, which slows the drive’s random access time. However, this encoding scheme enables data packing at maximum density over the entire disk. Light indicator

Volume control button used when the drive is used to play an audio CD Optical disk

Headphone socket enables a user to plug-in headphones and listen to recorded sound when the drive is used to play audio CDs.

Is placed on top of this groove Direction Tray of movement eject button of the tray

Optical disk tray

Figure 5.22. An optical disk drive and disk.

168 Chapter 5 ■ Secondary Storage

Access Time Optical disk drives are slower (have larger access time) than magnetic disk drives due to the following reasons: 1.

Sectors of an optical disk are on a continuous spiral track. This data organization results in slower random access of a sector than in case of concentric tracks organization (used by magnetic disks) because in case of concentric tracks, data access mechanism always finds sectors on a given track at a fixed distance from the center.

2.

In case of optical disks, each sector has the same length regardless of its position from the center. This data organization requires a more complicated drive mechanism because disk’s rotation speed must vary inversely with the radius. That is, the drive must slow down disk’s rotation speed to read/write sectors towards the periphery of the disk and speed it up to read/write sectors towards the center of the disk. This access mechanism leads to slower data access (larger access time) as compared to magnetic disks in which case the disks rotate at a constant speed irrespective of the location of accessed data.

3.

Since optical disk is a removable media, it is prone to scratches, dust, sticky prints (including fingerprints), etc. while handling. This causes the read mechanism to employ error correction mechanisms, like re-read, varying angular velocity, data reconstruction using parity, etc.

4.

The entire read/write and disk assembly is not a sealed unit. Hence, the disk drive cannot spin the disk at fast speed as it may damage the disk and other parts.

Access time of optical disks varies in the range of 100 to 300 milliseconds. Compare this with the access time of hard disks, which varies in the range of 10 to 30 milliseconds.

Types of Optical Disks All optical disks are round platters. They come in different sizes and capacities. Commonly used types of optical disks are CD-ROM, WORM (CD-R), CD-RW, and DVD. They are described here.

CD-ROM CD-ROM stands for Compact Disk-Read-Only Memory. It is a spin-off of audio CD technology and works much like audio CDs used in music systems. In fact, if your computer has sound card and speakers, you can play audio CDs in your computer. CD-ROM disk is a shiny, silver color metal disk usually of 5¼-inch (12 cm) diameter. It is made of polycarbonate plastic having thin layer of pure aluminum coating to make its surface reflective. For some good quality disks, gold layer is used. A thin layer of lacquer on top of the reflective surface protects it. It has storage capacity of about 650 Megabytes or 700 Megabytes in newer ones. It is so called because of its large storage capacity on a compact-size disk and because it is a read-only storage medium. That is, these disks come pre-recorded and a user cannot alter the information stored on them. Since an optical disk mechanism reads a disk from the center to outer edge, several sizes are possible. Apart from the most common 120mm 74/80 minute disk having storage capacity of 650MB to 700MB, 80mm 21 minute disk (called Mini-CD) having 184MB storage is also available. They are usable with the disk drive of a 120 mm disk. Mini-CDs are available in various fancy shapes like round, oval, triangle, etc., while ensuring that the storage area is not affected. The fact that a normal user cannot write data to a CD-ROM disk does not mean that this storage medium is not useful. In fact, many applications deal with huge volumes of data that rarely change. Hence, CD-ROM is preferable for such applications. For example, infopedia is a single CD-ROM disk that holds a complete encyclopedia, or a dictionary, or a world atlas, or a dictionary of quotations, or biographies of great people, or information about all educational institutions of a particular type in a country, etc. CD-ROM disk is often used for distribution of

■ Optical Disks

169

1.

Electronic version of conference proceedings, journals, magazines, books, etc.

2.

New software products

3.

Software upgrades

4.

Multimedia applications such as video games, which involve integration of text, sound, graphics, motion video, and animation.

For wide distribution and use of CD-ROM disks on different computers, the International Standards Organization (ISO) has evolved a standard for recording information on CD-ROM disks, called ISO 9660. This standard requires creation of a Volume Table of Contents (VTOC) on a disk, which allows storage and direct access of 1,40,000 files on the disk. This enables opening of any one of the 1,40,000 files with a single seek. Microsoft Corporation has developed MSCDEX (Microsoft CD Extension) software, which records data in ISO 9660 format on CD-ROM disks. All CD-ROM vendors have accepted the ISO 9660 format.

WORM Disk/CD-Recordable (CD-R) Disks WORM stands for write-once, read-many. WORM disks allow users to create their own CD-ROM disks by using a CD-recordable (CD-R) drive attached to a computer as a regular peripheral device. WORM disks look like standard CD-ROM disks, are available blank in market, and a user can encode on it using a CD-R drive. We can use any ordinary CD-ROM drive to read information recorded on a WORM disk by a CD-R drive. As the name implies, we can write data only once on a WORM disk, but can read it many times. However, we can write all desired data on a WORM disk in multiple recording sessions. The sessions after the first one are always additive and cannot alter the etched/burned information of earlier sessions. WORM-disk-storage mechanism enables hiding of information added in a session in a subsequent session by creating File Allocation Table (FAT) at a new location, but the etchings on the surface are permanent (not removable). Such disk is called Multi-Session Disk. It uses laser beam technology (discussed earlier) for data recording/reading. Because of its permanent recording nature and large storage capacity, WORM disk is the preferred storage medium for archival applications, which now depend on microfilm, magnetic, or paper file media. Data archiving enables recording of old data on a secondary storage medium (such as a WORM disk) so that they can be deleted from the online storage device (such as a hard disk), thus freeing space for new data. WORM disk is also an ideal medium for making a permanent record of data. For example, many banks use them for storing their daily transactions. They write the transactions to a WORM disk, which becomes a permanent record for them (they can only read it whenever required, but can never alter).

CD Read/Write (CD-RW) Disk A CD Read/Write (CD-RW) disk is similar to a WORM disk with the exception that we can erase its previous content and write on it multiple times. Such disks use metallic alloy layer. Laser beam changes the chemical property during writing (or burn process), changing reflectivity at desired places. The land-pit difference on CD-RW is not significant and hence CD drives have to be compatible to read such disks. A CD-RW disk usually has a lifetime of 100 or more erase-write cycle. CD-RW drives have the capability to change the chemical property again of the metallic alloy layer when we erase old data and write new data on a CD-RW disk. CD-RW disks are little expensive than CD-R disks, but offer great cost saving because of their erase and rewrite capability.

Digital Video (or Versatile) Disk (DVD) DVD is a standard format for distribution and interchange of digital content in both computer-based and consumer electronic products. The format enables storage of various types of large multimedia data on a new and improved version of CD (Compact Disk), which works on optical disk technology. That is, both DVD and CD store data by using pits embossed on a disk surface. However, these pits are about 4½ times as dense on a DVD as on a CD, and can store about seven times more data per side. The greater density is due to a more efficient data modulation scheme

170 Chapter 5 ■ Secondary Storage and error correction method that packs more data bits into every inch. DVD follows Eight-to-Fourteen Modulation Plus (EFMPlus) encoding as compared to Eight-to-Fourteen Modulation (EFM) encoding used by CD. Physically, both DVD and CD are identical in both diameter and total thickness. There are two variants of DVD – single-layer disk and double-layer disk. Single-layer disk has storage capacity of 4.7GB, whereas double-layer disk has storage capacity of 8.5GB. A single-layer disk provides about 135 minutes of video playback at an average data rate of little less than 5 Megabits/second. DVD standard has two layers of specifications known as physical layer and logical layer. Physical layer specifications apply to the physical media itself, whereas logical layer specifications are for supporting all types of applications. The physical layer specification defines the following types of physical media: 1.

DVD-ROM. Users use it for mass distribution of pre-recorded software programs and multimedia.

2.

DVD-RAM. Users use it for general read-and-write applications in PC or consumer electronics domains.

3.

DVD-R. Users use it for low-cost, write-once recordable media.

4.

DVD-RW. It is a rewritable version of DVD-R.

On the other hand, the logical layer specification defines recording formats for video and audio data for mass distribution of pre-recorded motion pictures and music. Key features of DVD-video and DVD-audio specifications are as follows: 1.

DVD-video. DVD-video is now the most dominant movie storage format used. It allows storage of video in 4:3 or 16:9 aspect ratios in MPEG-2 video format using NTSC or PAL resolution. NTSC has resolution of 720x480 and PAL has resolution of 720x576. The audio is usually Dolby Digital (AC-3) or Digital Theater System (DTS), and can be either monaural or 5.1 Surround Sound. In addition, it has multiple selectable language soundtracks and subtitles, voice-over commentaries by the movie’s cast or director, and convenient random access to special features.

2.

DVD-audio. It offers multiple choices of sampling rate and number of bits per sample. For super-high fidelity, the music producer might opt for two channels with 24-bit sampling at a rate of 192 KHz. Contrast the basic CD standard with its two channels and 16-bit sampling at 44 KHz. The specification also supports up to six channels of multichannel surround sound with 24-bit sampling at a 48 KHz rate. Besides the improved audio features, DVD-audio specification goes beyond CD by making provision for visual menus, still images, and video to accompany the audio program.

DVD has enough space to store movie and support multi-lingual subtitles, multi-lingual audio, multiple camera angles, etc. It supports region marking to protect against piracy and use of DVD from one region to another. It also supports Content Protection for Pre-recorded Media (CPPM) security technique to safe guard against copying, etc.

Advantages and Limitations of Optical Disks Advantages 1.

Cost-per-bit of storage for optical disks is low because of their low cost and high storage density. Additional cost benefit comes from the fact that we can erase data on some optical disks and reuse them many times.

2.

Use of a single spiral track makes optical disks an ideal storage medium for reading large blocks of sequential data such as audio or video.

3.

Optical disk drives do not have any mechanical read/write heads to rub against or crash into the disk surface. This makes optical disks more reliable storage medium than magnetic tapes or magnetic disks.

4.

Optical disks have data storage life in excess of 30 years, making them better storage medium for data archiving as compared to magnetic tapes or magnetic disks.

■ Memory Storage Devices

171

5.

Since data once stored on CD-ROM/WROM disks becomes permanent, there is no danger of losing stored data by erasing it or overwriting on it by mistake.

6.

Due to their compact size and lightweight, optical disks are easy to handle, store, and port from one place to another.

7.

We can use a computer having a CD-ROM drive, a sound card, and speakers as a music system, whenever desired, for playing audio CDs.

8.

We can use a computer having a DVD drive to watch videos (such as movies) by playing DVDs.

Limitations 1.

Data access speed of optical disks is slower than that of magnetic disks.

2.

Optical disks require more complicated drive mechanism than magnetic disks due to the need to have laser generating source and detection lens, which require precision engineering and careful handling.

3.

Since optical disk is a removable media, it is prone to scratches, dust, sticky prints (including fingerprints), etc. while handling. Hence, they need careful handling.

4.

When used for off-line storage, we must label optical disks properly for easy identification.

Uses of Optical Disks We use optical disks for the following purposes: 1.

For distributing large amounts of data at low cost. For example, companies/ organizations often distribute an encyclopedia, dictionary, world atlas, dictionary of quotations, biographies of great people, information about all educational institutions of a particular type in a country, etc. on CD-ROM disks.

2.

For distribution of electronic version of conference proceedings, journals, magazines, books, product catalogs, etc.

3.

For distribution of audio such as songs.

4.

For distribution of new or upgraded versions of software products by software vendors.

5.

For storage and distribution of wide variety of multimedia applications such as video games.

6.

For archiving of data used occasionally.

7.

End-user companies often use WORM disks to make permanent storage of their own proprietary information. For example, many banks use them for making permanent record of their daily transactions.

8.

DVDs have become a popular medium for distribution of movies.

MEMORY STORAGE DEVICES With the advent of efficient manufacturing technologies, price of memory chips has fallen considerably. As a result, storage manufacturers have introduced a new breed of electronic secondary storage devices (which do not use any mechanical component for operation). They often provide applications (like music player, etc.) on top of these storage devices for better marketability. Some of the popular ones are described here.

Solid State Drive (SSD) Until recently, the secondary storage (used as non-volatile storage device for permanent storage of data) provided in laptops, personal computers, desktops, workstations and other types of computers by their manufacturers was usually

172 Chapter 5 ■ Secondary Storage a magnetic disk, also popularly known as Hard Disk Drive (HDD). The buyers of these systems only had the option to choose the capacity of secondary storage, but had no option to choose the type of secondary storage device. Today, manufacturers and buyers of these systems have the option to choose between HDD and Solid State Drive (SSD), or a combination of both in the same system. Obviously, to make this choice, we need to know the difference between the two (HDD and SSD) and their relative advantages and disadvantages.

Difference between HDD and SSD As explained earlier, an HDD consists of one or more metal platters with read/write heads mounted on access arms in an enclosure (see Figure 5.23 (a)). The access arms assembly moves the read/write heads to the desired location on the spinning metal platter(s) to read/write data on the disk(s). The disk(s) and the access arm assembly are either permanently fixed inside the system unit (in case of fixed type secondary storage device) or are packaged in a small box enclosure, which can be connected with a short cable to one of the system’s I/O port (in case of portable type secondary storage device). An SSD is a relatively new type of non-volatile storage device used as secondary storage in computer systems. It consists of interconnected flash memory chips, which are installed either on the system’s motherboard (in case of fixed type secondary storage device) or on a separate electronic card (printed circuit board) that is packaged in a small box enclosure, which can be connected with a short cable to one of the system’s I/O port (in case of portable type secondary storage device) (see Figure 5.23 (b)). The flash memory chips of an SSD are typically faster and more reliable than the flash memory chips used in USB pen drives. Hence, SSD storage is more expensive than USB pen drive storage of same capacity.

(a) Hard Disk Drive (HDD)

(b) Solid State Drive (SSD)

Figure 5.23. Inside view of HDD and SSD. When packaged in an enclosure, both may look similar from outside, but internally their design is different.

Notice that an SSD is built entirely out of semiconductors (hence the name solid state) and does not have any moving parts. On the other hand, an HDD has mechanical components like motors to spin the disk(s) and move the access arms. Due to this, as compared to HDDs, SSDs are more compact in size, quieter in operation, consume less power, have faster data access time and have higher reliability. However, currently SSDs are four to five times costlier than HDDs of same capacity. Hence, SSDs usually have much smaller storage capacity as compared to HDDs. Figure 5.24 provides a detailed comparison of HDD and SSD, with their relative advantages and disadvantages, to enable users to determine which is better for their requirement. Notice from the figure that SSD scores over HDD for most of the attributes except price and storage capacity. Over the last few years, SSD prices have dropped considerably making SSDs as viable alternative to HDDs in many systems. Today, desktop-class and laptop-class HDDs are available in 3.5-inch and 2.5-inch form factor respectively. Currently, a 3.5-inch HDD can have storage capacity as high as 10TB. On the other hand, most SSDs of today are available in 2.5-inch form factor having maximum storage capacity of 4TB. Since both HDD and SSD are available in 2.5-inch form factor, a laptop user can replace an existing HDD with an SSD to fit it into the same slot.

■ Memory Storage Devices

Sr. No.

HDD (Hard Disk Drive)

Attribute

Large. Varies from 500GB to 10TB or more Cheap. Cost per gigabyte of storage is five to six times less for HDD than SSD. Relatively slow

SSD (Solid State Drive)

Which scores more? HDD

1.

Storage capacity

2.

Price

3.

Data access speed

4.

Operating system boot time

Relatively more

5.

Power consumption

Relatively more

6.

Less

Relatively more because SSD consumes less power than HDD.

SSD

7.

Battery life (is important for battery-charged devices like laptop) Heat generation

Less

SSD

8.

Cooling requirement

Less

SSD

9.

Noise generation

Relatively more because of moving parts and more power consumption. Relatively more because of more heat generated. Mechanical movement of spinning disk(s) and access arm assembly generates noise.

No noise as there is no moving part.

SSD

10.

Vibration

No vibration as there is no moving part.

SSD

11.

Reliability

Moving parts result in some vibration. Less reliable. Mean Time Between Failure (MTBF) is about 1.5 million hours.

More reliable. MTBF is about 2.0 million hours.

SSD

12.

Safety magnetism

Required because magnets can erase data stored in HDD.

Not required because data stored in SSD is safe against magnetic effects.

SSD

13.

Ruggedness

Less safe against rough handling because of moving parts.

SSD

14.

Compact factor)

More safe against rough handling, like dropping or hitting your laptop against a hard surface, or moving your system from one place to another, while it is operating. Size can reduce substantially, making future laptops and other devices slimmer and smaller.

against

size

(Form

Size cannot reduce beyond a limit because of spinning platters and access arms assembly. Current smallest form factor is 1.8-inch.

Relatively small. Varies from 250GB to 4TB. Relatively costly

Fast. Data access speed is three to four times faster for SSD than HDD. Less. Operating system boot time is three to four times less for SSD than HDD. Less. Power consumed by SSD is two to three times less than that consumed by HDD.

173

HDD

SSD SSD

SSD

SSD

Figure 5.24. Comparison between HDD and SSD with their relative advantages and disadvantages. SSD scores over HDD for most of the attributes except storage capacity and price.

Flash Drive (Pen Drive) Flash drive is a compact device of the size of a pen. It comes in various shapes and stylish designs (such as pen shape, wallet shape, etc.), and may have different added features (such as with a camera, with a built-in MP3/WMA/FM Radio play back for music on the go, etc.). It enables easy transport of data from one computer to another.

174 Chapter 5 ■ Secondary Storage A user simply plugs it into a USB (Universal Serial Bus) port of a computer. The computer detects it automatically as a removable drive. Now the user can read, write, copy, delete, and move data from the computer’s hard disk drive to the flash drive or from the flash drive to the hard disk drive. The user can even run applications, view videos, or play MP3 files from it directly. Once done, the user simply plugs it out of the USB port of the computer. The user can carry it in pocket anywhere. A flash drive does not require any battery, cable, or software, and is compatible with most PCs, desktop, and laptop computers with USB 2.0 port. Today, it is the most preferred external data storage for mobile people to carry or transfer data from one computer to another. As the name implies, it uses flash memory storage technology discussed in earlier chapter. Recall that flash memory is non-volatile, Electrically Erasable Programmable Read Only Memory (EEPROM) chip. It is a highly durable solidstate (electronic) storage having data retention capability of more than 10 years. Available storage capacities are 1GB, 2GB, 4GB, 8GB, 16GB, 32GB, 64GB, 128GB and 256GB. Figure 5.25 shows a flash drive. It has a main body and usually a port connector cover. To plug the drive into a USB port of a computer, a user has to remove the cover or push out the port connector. Usually, the main body has a write protect tab, a read/write LED (Light Emitting Diode) indicator, and a strap hole. Some manufacturers also provide software for use with the drive. Part that plugs into a Read/write light computer’s USB port indicator Main body

Cover

Strap hole (can be used to hang it with a string)

Write protect tab Figure 5.25. A flash drive (pen drive).

Memory Card (SD/MMC) Similar to flash drive, flash memory based cards (see Figure 5.26) are available as removable storage device in different types of electronic equipment. Some of the most popular ones are Secure Digital (SD) and Multimedia Card (MMC). Some other manufacturers have their own proprietary cards based on flash memory. Storage capacity of these cards range from 8MB to 128GB. In addition to computers, various types of digital devices (such as digital camera and cell phone) use these cards. This also facilitates easy transfer of data from these devices to a computer for storage in the computer’s hard disk or for further processing by the computer. For example, a user can transfer photographs taken by a digital camera to a computer for storage or editing. Each of these cards has its own interface and specific design features for use with certain types of devices.

Write-protect lock (slides down/up to lock/ unlock write operation)

Direction notch (guides which side of the card should be inserted first in the electronic equipment)

Vendor name Storage capacity

Figure 5.26. A flash memory based card (SD/MMC). The label on it contains vendor identification, storage capacity, etc.

■ Hybrid Secondary Storage Drives

175

RAM Disk We saw that most modern computer systems use hard disks as on-line secondary storage device. However, the data access speed of a hard disk is much slower than that of a semiconductor RAM (recall that main memory uses RAM chips). This is because hard disks involve mechanical movements, whereas semiconductor RAMs are pure electronic devices. To make applications execute faster, some computer systems use a block of semiconductor RAM chips (other than the RAM chips used for main memory) as a simulated disk. That is, to execute an application, they first load it from hard disk into the simulated disk and then only they start its execution. The application executes faster than normal in this case because the method avoids most of the delay caused otherwise by frequent calls to the hard disk for data loading during execution. RAM chips used as a simulated disk are known as RAM disk, silicon disk, or pseudo disk. They either are placed on an add-on circuit board that fits inside the main computer box, or are housed in a separate cabinet. In either case, these extra RAM chips look just like a disk drive to the control programs used in the computer’s operating system. Note that RAM disk is not really a disk at all. A RAM disk helps in enhancing the speed of a computer system because its CPU can now access the desired data instantly from RAM disk instead of waiting for few milliseconds to obtain the same data from hard disk. However, RAM chips are volatile and lose data stored in them in case of power off or interruption of power. Thus, a computer system using RAM disk must store programs and data files produced during a processing session on a permanent storage device, such as a hard disk, before power off.

HYBRID SECONDARY STORAGE DRIVES Manufacturers are now providing hybrid secondary storage drives in modern computer systems to combine the advantages of both HDD and SSD. Both SSD and HDD coexist in such systems. The following two configurations are commonly used (other types of configurations may also be used): 1. Dual-drive system: In this configuration, SSD and HDD are configured as separate drives (say, C: and D: drives respectively). Drive C: is used for storage of system files such as the operating system and system applications, whereas drive D: is used for storing user files. With this configuration, users get large storage space, whereas system performance gets better because booting of the system, performing system tasks, and launching of important applications becomes faster. 2. SSD as cache and HDD as normal secondary storage: In this configuration, SSD is invisible to users and is configured as a cache to store frequently used files. All files are stored on the HDD and cache replacement policy is used to transfer any required file from HDD to SSD, if it is not found in the cache (SSD) at the time of accessing it. The SSD also stores the boot program. Hence, this configuration helps to boot the system faster as well as to quickly access most of the needed files, as they are likely to be available in the cache. In this manner, it helps to speed up the overall system performance. Several users are now also augmenting their system’s secondary storage by buying portable SSD and storing their frequently used files on it. They purchase a system with cheaper HDD having large storage capacity and then purchase a smaller capacity portable SSD and use it by plugging it to I/O port of their computer as and when required.

MASS STORAGE DEVICES Mass storage devices are storage systems having storage capacity of several trillions of bytes of data. They use multiple units of a storage media (such as multiple disks, multiple tapes, multiple CD-ROMs, etc.) as a single secondary storage device. Commonly used types of mass storage devices are disk array, automated tape library, and CD-ROM jukebox. They are described here.

176 Chapter 5 ■ Secondary Storage

Disk Array It uses a set of magnetic disks. A disk array is a set of hard disks, hard disk drives, and a controller mounted in a single unit. The unit has one or more disk drives to read/write data from/to the disks in the disk array. A large disk array has several high capacity disks; making the storage capacity of the storage unit to several terabytes or several petabytes (1 Terabyte = 1012 bytes and 1 Petabyte = 1015 bytes). A disk array is commonly known as a RAID (Redundant Array of Inexpensive Disks). The term “inexpensive” comes from the fact that each of the medium-sized hard disks in the disk array is much less expensive than a single large hard disk. Computer systems often use RAID as on-line secondary storage devices. Although, RAID systems were originally popular for providing large secondary storage capacity with enhanced performance, today they are more popular due to enhanced reliability. This chapter later explains how RAID systems provide enhanced storage capacity, performance, and reliability.

Automated Tape Library It uses a set of magnetic tapes. An automated tape library is a set of magnetic tapes, magnetic tape drives, and a controller mounted in a single unit. The unit has one or more tape drives to read/write data from/to the tapes in the tape library. In case of units having multiple tape drives, it is possible to read/write data from/to multiple magnetic tapes simultaneously, resulting in faster data transfer rates. Multiple drives also lead to improved reliability of storage unit because if one of the drives fails, the unit can continue to function with other drives at a slower speed. The unit has robotic arms to retrieve the appropriate tape from the tape library and mount it on one of the tape drives for processing. The robot returns the tape to the library automatically after processing. A large tape library can accommodate up to several hundred high capacity magnetic tapes, making the storage capacity of the storage unit to several terabytes or several petabytes. Large computer centers use automated tape libraries for data archiving and as on-line backup devices for automated data backup.

CD-ROM Jukebox It uses a set of CD-ROMs. A CD-ROM jukebox is a set of CD-ROM disks, CD-ROM drives, and a controller mounted in a single unit. The unit has one or more CD-ROM drives to read data from CD-ROM disks in the jukebox. In case of units having multiple CD-ROM drives, it is possible to read data from multiple CD-ROM disks simultaneously, resulting in faster data transfer rates. Multiple drives also lead to improved reliability of storage unit because if one of the drives fails, the unit can continue to function with other drives at a slower speed. The unit has robotic arms to retrieve the appropriate CD-ROM and mount it on one of the CD-ROM drives for processing. The robot returns the CD-ROM to the appropriate slot automatically after processing. A large CD-ROM jukebox can accommodate up to several hundred CD-ROM disks, making the storage capacity of the storage unit to several terabytes or several petabytes. Computer systems use CD-ROM jukeboxes for archiving read-only data that needs on-line access, but where access time is not critical. For example, on-line museums, on-line digital libraries, and on-line encyclopedia are a few systems that often make use of this mass storage device in an effective manner. __________________________________________________________________ We measure average access time of mass storage devices in seconds, instead of milliseconds, because a transport mechanism must first move to retrieve the storage media (such as disk, tape, or CD-ROM) on which the accessed data is stored. It requires several seconds to locate the storage media specified, and then few milliseconds to transfer the data from it to memory. However, a mass storage device has huge storage capacity and a small cost per bit stored.

■ RAID Storage

177

Relatively slow access time limits the use of mass storage devices in many applications. However, they are costeffective alternative to on-line magnetic disk storage in applications requiring huge storage capacity and in which rapid access to data is not essential.

RAID STORAGE RAID stands for Redundant Array of Inexpensive Disks. It is a disk array with special features to improve fault tolerance, offer better performance, and allow easier storage management. It presents multiple disks of a disk array as a single storage volume, which simplifies storage management. How RAID storage offers enhanced storage capacity, performance, and fault tolerance is explained here. Suppose we have a 4 Gigabyte disk, whose each track contains 128 sectors, each of 512 bytes. The system uses 4 sectors per cluster (also known as a block), so that every read/write access to the disk transfers 2 Kilobytes (512 bytes  4) of data. The disk makes one revolution in 10 ms and can transfer a block in 0.15 ms. Now, suppose a RAID system uses 4 of these disks and puts them in the same enclosure. This 4-disk RAID unit will have total storage capacity of 4  4 = 16 Gigabytes. This results in a four-fold increase in storage capacity as compared to a single disk’s storage capacity. Furthermore, this RAID unit will have blocks of 4  2 = 8 Kilobytes, which will consist of the matching blocks (the ones with the same block number) on the four disks (recall the cylinder concept of data organization when multiple disks are used in a disk pack). The access time of a block on this RAID unit will be the same as that of the individual disks, but the transfer rate will be four times since we can now deliver an 8 Kilobyte block in 0.15 ms. The transfer rate has increased from 2K/0.00015 = 13.33 Megabytes/second to 8K/0.00015 = 53.33 Megabytes/second. We can further enhance storage capacity and performance by using more number of disks in the RAID with parallel data transfer.

RAID Techniques Various RAID types use one or more of the following three fundamental RAID techniques: 1.

Mirroring. In mirroring, the system stores the same data on two disks. Mirroring improves fault tolerance capability because if one copy of the data is corrupted, the other copy is available for accessing. It also improves “read” performance because the system can process two independent read requests simultaneously. Notice that it does not improve “write” performance because the system has to write data to both disks simultaneously. Hence, it cannot process independent write requests simultaneously. The disadvantage of mirroring is that it reduces effective storage capacity of a disk array to half its total capacity, so it is expensive.

2.

Striping. In striping, the system partitions a piece of data into smaller pieces and distributes the pieces across multiple disks. Striping improves both “read” and “write” performance of single tasks, but improvement in “read” performance is less than mirroring when processing multiple tasks. Striping also enables effective storage capacity of a disk array to be equal to its total storage capacity. The disadvantage of striping is that it provides zero fault tolerance. In fact, striping leads to worse availability than just using disks without RAID because a single disk failure causes the entire RAID system to fail. Hence, systems never use striping alone. They use it together with mirroring or parity.

3.

Striping with parity. In striping with parity, the system partitions a piece of data into smaller pieces, distributes the pieces across multiple disks, generates a parity for the data, and stores the parity on one or more disks. With parity data, a system can reconstruct a RAID volume if one disk (sometimes two disks) fails. Parity generation is done either by the RAID controller hardware or by special software at driver level, OS level, or volume manager level. Although parity data uses up some storage space, it uses far less storage than mirroring for supporting fault tolerance. Hence, striping with parity is a cost-effective technique of converting a disk array into reliable large-capacity storage.

178 Chapter 5 ■ Secondary Storage

RAID Levels RAID levels define RAID types. Different RAID levels use one or more of the RAID techniques described above. Following are the commonly accepted RAID levels: 1.

RAID level 0. It uses cluster-level striping. Clusters can vary in size and are user-definable, but they are typically blocks of 64,000 bytes. The system partitions data into clusters and distributes the clusters evenly across multiple disks. Obviously, this RAID type does not provide any fault tolerance. Video editing professional sometimes use it as a temporary storage space.

2.

RAID level 1. It uses mirroring. The system copies all data on one disk to another disk. Both disks are peers (not primary and secondary). This RAID type provides fault tolerance at the cost of reducing effective storage space to half of total storage space. However, it is easy to manage and does not require significant processing time for normal operations or for recovery. Server computers often use it for storing system partition for enhanced reliability.

3.

RAID level 2. It uses bit-level data striping with parity. The system distributes the bits evenly across multiple disks and uses one of the disks to store parity. Hence, it reduces the effective storage capacity of a disk array by one disk. That is, if a system configures a disk array having “N” disks with RAID Level 2, its effective storage capacity is equal to the sum of storage capacity of “N-1” disks. This RAID type is rarely used.

4.

RAID level 3. It uses byte-level data striping with parity. The system partitions data into bytes, distributes them evenly across multiple disks, and uses one of the disks to store parity. It reduces the effective storage capacity of a disk array by one disk. This RAID type is rarely used.

5.

RAID level 4. It uses cluster-level data striping with parity. Clusters can vary in size and are user-definable, but they are typically blocks of 64,000 bytes. The system partitions data into clusters, distributes the clusters evenly across multiple disks, and uses one of the disks to store parity. It reduces the effective storage capacity of a disk array by one disk. This RAID type is rarely used.

6.

RAID level 5. It uses cluster-level data striping with distributed parity for enhanced performance. The system partitions data into clusters and distributes the clusters and parity evenly across multiple disks. This provides better performance than using a single disk for parity. It reduces the effective storage capacity of a disk array by one disk. This RAID type is the most common implementation of data striping with parity.

7.

RAID level 6. It uses cluster-level data striping with dual distributed parity for enhanced fault tolerance. It is similar to RAID Level 5, except that it uses the equivalent of two disks to store two sets of parities for all data. Hence, it reduces the effective storage capacity of a disk array by two disks. It also degrades performance as compared to RAID Level 5 because it calculates each set of parities separately. Computer systems use this RAID type for building highly reliable storage systems. Dual parity allows any two disks to fail without data loss. Notice that if a disk fails in a disk array configured as RAID Level 5, we can restore the disk array to a healthy state in a few hours, provided a second failure does not occur during recovery time. RAID Level 6 can restore the disk array to healthy state even if a second failure occurs during recovery time. Hence, storage industry considers it the ultimate RAID level for fault tolerance.

8.

RAID level 10 (composite of 1 and 0). It is also called RAID Level 1 + 0. It uses mirroring and striping, with mirroring done before striping. This provides better fault tolerance because it can survive multiple disk failures, and performance does not degrade as much when a single disk fails. RAID Level 0 + 1, which does striping before mirroring, is an inferior RAID type. RAID Level 10 is the most common composite RAID type. Database applications commonly use it because it provides good I/O performance when the application cannot distribute its own data across multiple storage volumes.

■ Storage Interfaces

179

With such a wide range of reliability features inbuilt in them, modern RAID systems have mean time between data loss (MTBL) of well over a million hours. Hence, system designers often consider them as a basic unit for building reliable computer systems. For organizations relying on information technology to run their business, unscheduled interruptions have serious consequences. As a result, today many organizations are turning to RAID as a safer way to store large amounts of data.

STORAGE INTERFACES A secondary storage device needs a controller, which acts as an intermediary between the device and a computer system. In some computers, the controller is an integral part of the computer’s main motherboard. In others, it is an expansion board, which connects to the system bus by plugging into one of the expansion slots of the computer. To enable use of devices manufactured by independent vendors with computers manufactured by different vendors, controllers follow some drive interfacing standards. Storage devices use industry standard storage interfaces to connect to a system’s motherboard. Some industry standard storage interfaces that were used in older computer systems and that have now become obsolete are IDE (Integrated Drive Electronics), ESDI (Enhanced Small Device Interface), IPI-3 (Intelligent Peripheral Interface-level 3), and ATA (Advanced Technology Attachment). Industry standard storage interfaces used currently in computer systems are SCSI, SAS, SATA, FC, FireWire, and iSCSI. They are described here.

SCSI (Small Computer System Interface) In earlier storage interfaces, each type of device required a separate device controller for connecting devices of that type to a computer system. Researchers introduced SCSI (pronounced “scuzzy”) interface as an interesting variation of the separate device controller for each device type idea. It uses a generic device controller (called SCSI controller) on a computer system and allows any device having SCSI interface to connect directly to the SCSI bus of the SCSI controller. SCSI interface of a device contains all circuitry that the device needs to operate with the computer system. As Figure 5.27 shows, a SCSI controller connects to a computer bus on one side and controls another bus (called SCSI bus) on the other side. Either the controller is a card that we can plug into an available slot, or it is inbuilt into the computer’s motherboard. The SCSI bus is a bus designed for connecting devices to a computer in a uniform way. In effect, the SCSI controller extends the computer’s bus outside the main system box and enables connection of other devices to the computer with the help of this extended bus. There is a standard protocol for sending device control messages and data on the SCSI bus. Each device connected to the SCSI bus has a standard SCSI interface (a single chip) that knows about the bus protocol. Since SCSI extends a computer’s bus outside the main computer box, it enables connection of any SCSI device to the computer without the need to open the computer box and install a device controller on its internal bus. A SCSI being an extension of a computer’s bus, it can accommodate multiple devices simultaneously. Most current implementations of SCSI limit the number of devices to sixteen on a given chain due to bus capacity limitation. Moreover, SCSI being an extension of the bus, any type of device (hard-disk drive, optical-disk drive, tape drive, printer, plotter, scanner, etc.) can be linked (or daisy-chained) on a single SCSI port (see Figure 5.27). Each SCSI device on a SCSI bus must have a unique identifier (ID) so that the controller can send an I/O request to the appropriate device. If a SCSI bus supports sixteen devices, their IDs range from zero to 15. The SCSI controller itself uses one of the IDs, typically the highest one, leaving room for 15 other devices on the bus. Introduced in 1981, there have been eight generations of SCSI namely, SCSI-1, SCSI-2, SCSI-3, Ultra SCSI, Ultra2 SCSI, Ultra160 SCSI, Ultra320 SCSI, and Ultra640 SCSI. All these SCSI standards are backward compatible. This has provided SCSI users the utmost in flexibility and has helped to maintain SCSI’s affordability. Ultra640 SCSI, the current SCSI, is the most robust and powerful I/O enterprise solution available today. It allows data to transfer safely and reliably at 640 Mbytes/second.

180 Chapter 5 ■ Secondary Storage

Processor

Memory Main computer system

Computer bus SCSI controller

SCSI buses

SCSI interface

SCSI interface

SCSI interface

Disk drive

Disk drive

CD-ROM drive



SCSI devices connected to the computer Figure 5.27. SCSI drive interface standard.

As the name implies, SCSI started out as a standard interface for connecting devices to small computer systems. However, the advantages of a common interface soon became apparent in all sizes of systems. Today, SCSI commands a substantial presence in both the desktop and server systems.

SAS (Serial Attached SCSI) All SCSI types mentioned above are Parallel SCSI in the sense that bits of data move through the bus simultaneously rather than one bit at a time. Hence, a Parallel SCSI using a bus of 16 bits width moves 16 bits simultaneously through the bus. The newest type of SCSI, called Serial Attached SCSI (in short, SAS), uses SCSI commands, but transmits data serially (one bit at a time). SAS uses a point-to-point serial connection to transfer data at 3.0 Gigabits/sec. Each SAS port can support up to 128 devices or expanders. With expanders, SAS allows maximum possible connectivity of up to 16,384 devices. SAS is therefore the logical choice, if scalability is a key requirement. With SAS expanders (which are like high-speed switches) within the enclosures, each device has a dedicated connection to the computer making arbitration unnecessary and resulting in improved performance. SAS dual porting capability and the ability to support I/O requests from more than one controller at a time (multi-initiator) also enables the design of dynamic load balancing systems and redundant path configurations to further increase performance and reliability. In addition to being software compatible with Parallel SCSI (using same command set), SAS is interoperable with Serial ATA (SATA – described later in this section) as well. As a result, an organization can choose a mix of both SAS and SATA hard disk drives for an optimal mix of high-performance (SCSI-based) and low cost (SATA-based) per GB storage required to meet its unique storage requirements. Compatibility with Parallel SCSI is valuable because it protects an organization’s investments in SCSI. Recall that SCSI technology is more than 30 years old and most servers and many storage applications across the industry use it. Due to its small form factor (compactness), SAS also addresses the issues of space, heat, and power consumption, which are important in today’s data centers. Its backplane, enclosures, and cabling are less cumbersome, connectors are smaller, and cables are thinner and easier to route. Hence, enterprise users who need more power, easier connectivity, greater scalability, and greater flexibility in building storage solutions also prefer to use SAS.

■ Storage Interfaces

181

SATA (Serial Advanced Technology Attachment) Serial Advanced Technology Attachment (SATA) interface is the latest technology of Advanced Technology Attachment (ATA) interface standard. It is fast replacing the older Parallel ATA (PATA) interface, which has been the most popular disk drive interface for PC platforms. PATA’s popularity was due to its relatively low cost and simplicity. However, it was a storage-centric bus with limited scope. It allowed only two storage devices inside the box on an 18-inch cable, with a simple protocol and a single host. Researchers introduced SATA to take care of these limitations of PATA. It is primarily for desktop and mobile computing systems. Key features of SATA are: 1.

It is fully compatible with PATA.

2.

It supports data transfer rates of 150 Mbps, 300 Mbps, and 600 Mbps.

3.

It provides hot-pluggable support.

4.

It can support cable lengths up to 1 meter.

5.

It provides improved reliability with 32-bit cyclic redundancy checking for all transfers and improved signalintegrity.

6.

It is a point-to-point interconnection architecture, which provides a direct path and dedicated bandwidth between the disk drive and the host system.

7.

It uses Advanced Host Controller Interface (AHCI) and Native Command Queuing (NCQ) to achieve a much higher throughput than older PATA devices.

8.

It uses differential signaling, making it easy to filter out noise from data signal at receiving end.

Due to its features listed above, SATA is fast replacing PATA disk drives not only in desktop systems, but also in other types of systems such as personal video recorders, electronic gaming, and some network storage applications. It is also finding acceptance in enterprise datacenters.

Fiber Channel (FC) The conventional method of connecting a storage device to a computer system is to attach the storage device directly to the computer using a storage interface. This methodology is known as Direct Attached Storage (DAS) (more details of DAS are given in the next section). Although, the method is simple, easy, and cost-effective, its main limitations are that it enables attachment of only a few devices and the distance between the controller and storage cannot exceed a few meters. Few years ago, researchers introduced a new paradigm in storage, called Storage Area Network (SAN) to overcome these limitations (more details of SAN are in the next section). Fiber Channel (FC) is an enabling technology for SAN. It has become the de-facto standard interconnect for SAN environment. Existing FC topologies describe port interconnect. A port is usually an active communication entity, such as a disk, a communication switch, or a server. Popular FC interconnection techniques are: 1.

Point-to-Point (FC-P2P). It provides direct connection between two ports. It is the simplest topology, but is limited in scope of use.

2.

Arbitrated Loop (FC-AL). It enables connection of multiple ports in a loop or ring topology. It functions in a way similar to that of a Token-ring topology, and has similar benefits and drawbacks.

3.

Switched Fabric (FC-SW). In this topology, all devices or loops of devices are connected to Fibre Channel switches. Conceptually, this is similar to Ethernet. The switches manage the state of the fabric, providing optimized interconnections on fixed or dynamic possibilities/links.

FC has several features for addressing enterprise storage requirements. These include:

182 Chapter 5 ■ Secondary Storage

1.

It operates as a SCSI protocol superset, but also lets other higher-level protocols access the underlying transport layer, including TCP/IP over FC.

2.

It allows connection of 126 devices per controller, and can address more than 16 million devices in a FC SAN.

3.

It works with both copper twisted-pair cables and optical fiber cables. This dual capability allows use of inexpensive copper connections for intra-cabinet, intra-chassis, and short distances, and use of expensive optical connections for longer distances.

4.

Depending on the medium (copper or optical fiber cables) and interconnection topology used, speed of FC varies from 1 Gigabits/sec to 128 Gigabits/sec.

5.

It allows copper connections to several meters, basic optical connections to 500 meters, and long-wave connections to 10 kilometers. Some implementations allow direct connections to distances of 80 kilometers. The distances allow direct data center connections via native fiber channels. With TCP/IP protocol, FC allows long distance connections worldwide, enabling interconnection of islands of SANs anywhere across the globe.

6.

It allows hot plugging of devices, enabling expansion of a storage solution without any disruption to an operational system.

FireWire FireWire, also called IEEE 1394 standard, is primarily a mass-storage interface. Today, several other products use FireWire interface, including consumer products such as cameras, scanners, printers, televisions, game consoles, and many kinds of storage devices. Apple’s iPod MP3 player uses FireWire as its only data and power connection. FireWire is a high performance serial bus that can support packet transfer at 100, 200, 400, and 800 Megabits/sec simultaneously. A single bus can freely mix up to 63 devices supporting any or all of these speeds. The bus transports each packet at the best possible speed depending on the source and destination nodes. Hence, adding a digital video camera capable of only a 100 Megabits/sec rate need not force computers and storage devices to slow down from a 800 Megabits/sec rate they commonly support. Like a bus, it makes all packets visible to all nodes, with the exception that it cannot send higher-speed packets to or through lower-speed devices. FireWire uses isochronous transport to provide real-time data delivery, reserving up to 80% of the bus bandwidth for one or more isochronous channels. The hardware then provides guaranteed transmit opportunities at defined intervals to ensure timely data transfer. FireWire uses Open Host Controller Interface (OHCI) specification, which can service read and write requests by Direct Memory Access (DMA) to the specified memory address, without assistance from the local CPU or any interrupts. With this architecture, each storage device added to a FireWire bus acts as an additional DMA controller and can move data to or from host memory at its own pace. FireWire devices can be connected or disconnected from the bus at any time. Self-describing and self-configuring, these devices free users from having to adjust ID selectors or assign drivers to devices individually. FireWire provides an easy and quick way to add, upgrade, and share computer storage devices. High-performance RAID applications have also adopted FireWire. FireWire is particularly useful for connecting multiple devices. Using peer-to-peer access, the devices can interoperate as peers to deliver greater capability as a system than each device can offer alone.

■ Storage Interfaces

183

iSCSI (Internet SCSI) Internet SCSI (iSCSI, for short) is an enhancement of SCSI technology for use in Storage Area Network (SAN) environment. iSCSI is a device control and communication protocol, which uses SCSI commands over commonly available network fabric like Ethernet or Internet. This approach has several advantages: 1.

It uses SCSI commands set, enabling all existing SCSI devices to work in an iSCSI environment.

2.

Use of SCSI devices and protocol allows high data throughput with direct device control.

3.

It allows use of SCSI commands over a common TCP/IP network, enabling device connectivity over long distances.

4.

It allows a datacenter to consolidate its storage at identified locations while the devices that use them can be at other locations, enabling better and efficient planning and resource utilization.

5.

It allows easy handling of failures by simply changing network address of the failed device in user systems to point to another device.

iSCSI defines the following active components that together form an iSCSI environment: 1.

Initiator. It is an iSCSI client. It may be either a hardware, software, or hardware/software combination connected with or stored on a computer system. It communicates with a remote iSCSI device over the network by generating, encrypting, and transmitting iSCSI packets to the remote device. It also receives, decodes, and acts upon the responses sent from the remote iSCSI device. It also synchronizes multiple requests made to the remote iSCSI device.

2.

Target. It is an iSCSI enabled storage array or iSCSI service on a storage server. It services the requests made by the initiators over the network.

3.

Network. It forms communication channels between initiators and targets. It can be any high-speed network such as TCP/IP Gigabit Ethernet. Initiators and targets are addressed using iSCSI Qualified Name (IQN).

FC versus iSCSI Both FC and iSCSI technologies are targeted towards SAN environments. They have many features in common. Both use an underlying high-speed serial transport to carry SCSI read and write commands to storage devices. They both have a variable network address identity and a fixed unique World Wide Name (WWN) address. They both also rely on flow-control mechanisms to maintain stable conversations between pairs of communicating devices across the network. However, the two differ in the following manner: 1.

While FC uses a dedicated gigabit network infrastructure separated from the corporate LAN, iSCSI uses mainstream Gigabit Ethernet switching, enabling tight integration with corporate LAN. By integrating storage data into mainstream data communications infrastructures, iSCSI makes shared storage access ubiquitous.

2.

An iSCSI SAN differs from a FC SAN primarily in plumbing that supports SCSI exchanges. FC provides Layer 2 architecture, analogous to bridged LANs before the introduction of TCP/IP. On the other hand, iSCSI relies on Layer 3 architecture that includes network routing. Once the system puts SCSI commands, status, and data in an IP format, storage data can use conventional equipment to traverse any common IP network

184 Chapter 5 ■ Secondary Storage infrastructure, including Gigabit Ethernet, ATM (Asynchronous Transfer Mode), SONET (Synchronous Optical NETwork), or Frame Relay.

DAS, SAN, AND NAS In earlier computer systems, the only way to connect a storage device to a computer’s processor was to attach it directly to its system board by a cable. However, with advancements in networking and storage technologies, today there are multiple options available for processor-to-storage connectivity. Newer options offer significant capabilities and flexibilities that were not available earlier. As, different options have their own tradeoffs in cost, ease-ofmanagement, performance, and distance, understanding these technologies is important for making right choices while planning a storage solution. Three commonly used processor-to-storage connectivity technologies are DAS, SAN, and NAS. They are described here.

DAS (Direct Attached Storage) This is the conventional method of processor-to-storage connectivity. In this method, a connector cable directly attaches a storage system board/card to the processor system board/card (see Figure 5.28). The simplest example of DAS is a disk drive inside a PC, or a tape drive attached to a single server. Some disk systems allow partitioning of total capacity of disk storage into multiple logical disks and assignment of different partitions to different processors. Further, the sub-system may allow mutual reassignment of partitions from one processor to another. This is essentially still a DAS. …

Personal Computer (PC)

Client systems LAN – Local Area Network S1, S2 – File servers D1, D2 – Storages

LAN

S1

S2

File server S1 can access data only on storage D1 File server S2 can access data only on storage D2

D1 (a) A storage attached to a PC directly.

D1

D2

Clients can access data on storage D1 or D2 through their respective file servers

(b) Storages attached to file servers. Clients access them over the LAN through their respective file servers. Figure 5.28. Direct Attached Storage (DAS).

DAS is the best choice for connecting a storage device to an individual, isolated processor such as a laptop, desktop PC, or a single small server. These systems connect disk storage (usually residing inside the processor enclosure) to the processor using DAS technology. DAS has low initial cost and is simple to implement. It however, does not allow sharing of storage with processors (see Figure 5.28). Hence, when an organization has multiple computers, DAS may initially appear to be low cost from the point of view of each user or department. However, from the point of view of the entire organization, the total cost of ownership (TCO) of DAS may turn out to be higher than other processor-to-storage connectivity approaches because DAS does not allow sharing of unused capacity of storages with other processors and it also lacks a central point of management for multiple storages.

■ DAS, SAN and NAS

185

SAN (Storage Area Network) In this method, one or more processors and one or more storage devices are interconnected, forming a dedicated network called SAN. SAN technology provides any-to-any connection for processors and storage devices on the same SAN (see Figure 5.29). As compared to DAS, SAN has the following advantages: 1.

It provides scalability, enabling dynamic configuration of a large number of processors and storage devices in any-to-any connection model.

2.

It enables storage sharing among multiple processors. Essentially, it makes multiple storage devices on the same SAN to appear as a single pool of storage devices accessible to all processors on the SAN.

3.

It enables easy-manageability by allowing management of all storage devices on a SAN from a single point of control.

4.

It enables building of reliable storage solutions, which can tolerate failures of both processors and storage devices.

However, as compared to DAS, SAN has the following limitations: 1.

Initial cost of implementation is higher for SAN than DAS.

2.

A SAN requires specialized hardware and software to manage the SAN and provide many of its potential benefits.

3.

Processors cannot access storage devices on another SAN, which is part of the same system (see Figure 5.29). …



LAN

LAN

S1

S1

S2 SAN

D1

D2

(a) A storage solution with one SAN.

LAN – Local Area Network SAN – Storage Area Network

S2 SAN-1

D1

D2

S3

S4 SAN-2

D3

D4

(b) A storage solution with two SANs.

Si – File servers Di – Storages

File server S1 can access data on storage D1 or D2, but not on D3 and D4 File server S2 can access data on storage D1 or D2, but not on D3 and D4 File server S3 can access data on storage D3 or D4, but not on D1 and D2 File server S4 can access data on storage D3 or D4, but not on D1 and D2 Figure 5.29. Storage Area Network (SAN).

186 Chapter 5 ■ Secondary Storage

NAS (Network Attached Storage) A NAS is a storage device (also called NAS appliance) consisting of its own processor and disk storage. It can be attached to a TCP/IP-based network (LAN or WAN), and accessed using specialized file access or file sharing protocols. When a NAS appliance receives a file access request over the network, its processor translates the request to device access request for accessing the appropriate device. In this manner, a NAS system enables any file server to access data on any NAS appliance on the same network (see Figure 5.30). It, therefore, allows file sharing using lowcost, Ethernet-based networks. While NAS and SAN seem similar because they both deal with storage networking, they differ as follows: 1.

SAN is a dedicated storage network, whereas NAS is a device on a conventional LAN/WAN network.

2.

SAN uses block-level I/O, whereas NAS does file-level I/O.

3.

Initial cost to implement a SAN is higher than that for NAS.

4.

NAS is easier to install and manage than a SAN.

5.

SAN has better scalability than NAS. This is because NAS allows storage capacity pooling within a NAS appliance only, and there is little if any sharing of resources across multiple appliances. In contrast, SAN allows pooling of all devices on a SAN (multiple disk and tape devices) as a large shared resource with a single point of control and specialized backup facilities. Hence, as total storage capacity grows, a SAN-based storage solution becomes easier to manage and most cost effective at some point.

6.

In a SAN-based storage solution, SAN and LAN are independent networks and file servers can share storage only on the same SAN (see Figure 5.29), whereas in a NAS-based storage solution, there is only one network and file servers can share all NAS appliances on the network (see Figure 5.30).

… LAN – Local Area Network Si – File servers Ni – NAS devices N4

N1

LAN

N2

N3

File server S1 can access data from any of the NAS devices N1, N2, N3, or N4 File server S2 can access data from any of the NAS devices N1, N2, N3, or N4

S1

S2 Figure 5.30. Network Attached Storage (NAS).

As there are tradeoffs, choice of DAS, SAN, or NAS for building an organization’s storage solution depends on the environment. No solution is best for all types of environments. In fact, for large organizations, a mix of DAS, SAN, and NAS may be used.

■ Data Backup

187

DATA BACKUP What is Data Backup? Data backup is the process of creating a copy of some data from an on-line storage device to a secondary storage backup device such as, magnetic tape, zip disk, disk pack, or WORM disk. Usually, the copy serves the purpose of off-line storage of the data so that if the system somehow loses original data from on-line storage device, it can retrieve it from the backup device and restore it on on-line storage device.

Why Backup Data? Taking periodic backup of on-line data and keeping them on off-line secondary storage devices is important because a system can lose data from its on-line storage device (such as a hard disk) in any one or more of the following ways: 1.

A disk crash.

2.

A virus attack.

3.

A hardware malfunction.

4.

An unintended accidental deletion of useful files.

5.

A natural disaster like fire or earthquake damaging the computer system.

The amount of time it would take us to re-create all our files, if we lost them, is far greater than the few minutes it takes to back them up. Hence, protecting valuable data with regular backups is necessary for all computer users.

Types of Backup Two basic types of backup are: 1. Full backup. This method copies all data from an on-line secondary storage device to a backup device at the time of backup. The backup procedure creates a copy of every file from the on-line secondary storage device on to the backup device, irrespective of whether the file was changed or not. Depending on the volume of data being backed up and backup device used, full backups can take anywhere from a few minutes to a few hours to complete. 2. Incremental backup. Backup is an expensive process both in terms of time taken to complete and storage space occupied on backup device. To save on backup time and storage space, one can often go for incremental backup instead of full backup. This method copies only newly created files or files changed since the last backup from on-line secondary storage device to the backup device at the time of backup. As every file stored in a system contains the date and time of its creation and last update, incremental backup utility software compares these dates to those in its log for deciding which are the newly created and modified files since the last backup. Incremental backup is faster than full backup because it creates a copy of only the new and modified files since the last backup. This may result in copying of only a few files out of hundreds of files stored on the on-line secondary storage device. However, full backup is simpler and a little safer for restoring data back from the backup device on to the on-line secondary storage device. If we want to restore a particular file that was lost, we need to search for it at only one place in case of full backup, whereas in case of incremental backup, we need to search for it on several backups tracing back from the most recent backup until we find the file. Similarly, in the

188 Chapter 5 ■ Secondary Storage event of a disk crash, when all the files are lost, it is easy to restore the files back on to a new disk with full backup as compared to incremental backup because the full backup is a mirror image of the entire disk and the system can restore it as it is.

Backup Policy Every computer system needs to have a well-defined backup policy. Backup policy for a computer system depends on its nature of usage, types of users, its operating environment, etc. A backup policy defines the following: 1.

What is the periodicity of backup? Is the backup procedure executed hourly, daily, weekly, fortnightly, or monthly? Normally, periodicity depends on the nature of usage and criticality of stored data of a system.

2.

Whether to take full or incremental backup? This again depends on the nature of usage of the system. For example, if a user creates only a few files (say letters) a day, an incremental backup performed at the end of each day or even once a week may be sufficient. On the other hand, if a user frequently creates many files, weekly full backups are safer. A compromise that works well for many systems is performing incremental backup daily and full backup weekly.

3.

What storage media to use for backup? Average volume of backup data in each backup cycle normally decides this. We normally take small backup on CD/pen drive, whereas we take larger backup on magnetic tapes, and very large backup on disk packs.

4.

Who takes backup? This normally depends on the usage environment of computer systems. For example, a PC user normally takes the backup of his/her PC. In case of large computer centers, where many users share a system, a system administrator normally takes backup of the system. Often backup is an automated procedure in large computer centers. In this case, the system automatically executes backup procedure at defined periodicity for backup of data on hard disk to an on-line backup device such as a tape library. Hence, the system itself takes backup in such systems.

5.

Where to store the backup media with the backed up data? We just now saw that the backup device along with the media might be an on-line device such as a tape library. In this case, the backup media is stored near to the computer system. This is not acceptable if we need to protect the data against natural calamities. Hence, off-line storage of backup data is always preferred to its on-line storage. Moreover, to protect the data of a computer system against natural calamities, users should store the backup media with the backed up data in a building that is away from the building where the computer system is located.

Backup versus Archiving Backup is often confused with archiving probably because they both deal with copying/moving of data from secondary storage to another secondary or tertiary storage. However, backup and archiving are two different processes, involving different capabilities. Having an understanding of both these processes and associated challenges helps an organization to develop the foundation for an intelligent and robust storage solution. The two concepts have the following basic differences: 1.

Backup deals with active data, whereas archiving deals with inactive data. A system accesses active data frequently, whereas it accesses inactive data occasionally. Hence, it is less likely for a system to access inactive data. Reasons for maintaining inactive data might be to comply with corporate and government regulations on data authenticity, to perform trend analysis in future, or to maintain a history of customers or transactions.

2.

The goal of backup is active data security through redundancy on backup storage, whereas the goal of archiving is inactive data retention through its movement to archival storage.

■ Hierarchical Storage System

189

3.

Backup creates secondary copy of active primary information on backup storage, whereas archiving moves inactive primary information to archival storage.

4.

Backup provides short-term protection of active data to ensure business continuity in case of failures, whereas archiving provides long-term retention of inactive data for future reference.

5.

In most cases, a system retains backup data only for a few days or weeks, as new backup data supersedes previous versions. On the other hand, a system retains archived data for several years and data archived periodically does not supersede previously archived data.

6.

A system generates backup data in a periodic automated fashion, and systematically overwrites it. On the other hand, archived data is in its final form, and does not undergo any modification.

7.

Normally, a system architect chooses backup storage media to enable modification by overwriting on previous version, whereas he/she chooses archiving storage media to prevent modification (WORM) of archived data because data authenticity is the key to archiving.

8.

Backup requires ease of restoring lost data from backup storage in case of failures. Hence, easy access to all data is crucial. On the other hand, archiving requires access and retrieval of a specific piece of information rather than access to all data. Hence, organization of backup and archival data is done differently.

HIERARCHICAL STORAGE SYSTEM (HSS) We saw that different types of storages have different capacity, speed of access, and cost per bit stored. Since a single type of storage is not superior in all aspect, most computer systems build their storage solutions by making use of a hierarchy of storage technologies. Such a storage solution, called Hierarchical Storage System (HSS), is a costeffective way of designing computer systems with very large storage capacities.

Cache memory Less storage capacity, faster access time, and higher cost per bit stored

Main memory On-line, SSD-based secondary storage

More storage capacity, slower access time, and lower cost per bit stored

On-line, HDD-based secondary storage devices such as hard disk or disk array Near-line, tertiary mass storage devices such as tape library, CD jukebox, etc. Off-line, direct-access, and sequential-access storage devices such as magnetic tape, magnetic disk, optical disk, memory storage devices, etc.

Figure 5.31. A typical storage hierarchy pyramid.

Figure 5.31 shows a typical storage hierarchy pyramid of six layers. It includes cache memory, main memory, SSDbased secondary storage, HDD-based secondary storage, near-line mass storage devices, and off-line direct/sequential

190 Chapter 5 ■ Secondary Storage access storage devices. As we move up the pyramid, we encounter storage elements having less storage capacity, faster access time, and higher cost per bit stored. More storage capacity, slower access time, and lower cost per bit stored are the results of moving down the pyramid. Hence, cache memory has the fastest access time, the least storage capacity, and the highest cost per bit stored. Primary storage (main memory) falls next in the storage hierarchy list. On-line, SSD-based secondary storage forms the next layer of the storage hierarchy pyramid, whereas HDD-based secondary storage devices such as magnetic hard disks make up the layer of hierarchy just below that. Near-line, tertiary mass storage devices such as tape library, CD jukebox, etc. fall next in the storage hierarchy. Off-line, directaccess, and sequential-access storage devices such as magnetic tape, magnetic disk, optical disk, memory storage devices, etc. are at the bottom of the storage hierarchy. They are cost-effective for storage of large quantities of data when fast access time is not an important parameter. As we move down the storage hierarchy pyramid, the increasing width of the layers in the figure represents the increasing size of their storage space.

On-line, Near-line, and Off-line Storage Yet another classification of secondary storage devices is on-line, near-line, and off-line. The differences among the three are as follows: 1.

On-line storage. An on-line storage device is under direct control of the processing unit of the computer to which it belongs. It provides rapid access to data on a constant basis. It stores all frequently used data. Computer systems often use SSD, hard disk or disk array as an on-line storage device.

2.

Near-line storage. A near-line storage device is an intermediate storage between on-line storage and off-line storage. It means nearly on-line. It is so called because it is slower than on-line storage, but data can still be accessed from it without any human intervention (off-line storage requires human intervention). Computer systems use near-line storage to store infrequently used data. They often use mass storage devices such as tape library, CD jukebox, etc. as a near-line storage device.

3.

Off-line storage. An off-line storage is not under direct control of any computer. A user records data on it using a computer and then physically removes or disconnects it for storing away from the computer. Hence, it is also known as disconnected storage. To reuse data stored on it, a human operator has to insert it or connect it to a computer system. Hence, it requires human intervention for storage/retrieval of data on/from it. Computer systems often use magnetic tape, magnetic disk, optical disk, and memory storage devices as an off-line storage device. Users often use off-line storage to transfer data between two computers, which are not physically connected. They also use it for off-line data backup to prevent loss of data in case of a disaster at computer’s site, for example a fire, flood, or earthquake. Off-line storage (with backup data) kept at a remote location remains unaffected, enabling disaster recovery. Off-line storage also provides information security against computerbased attack because data on off-line storage is physically inaccessible from a computer.

Hierarchical Storage Management (HSM) Hierarchical Storage System (HSS) is also known as tiered storage. An important issue in HSS is how to decide which data should reside on which storage tier at what point of time, and when and how to move data from one storage tier to another. With the huge volume of data handled by today’s storage solutions, it would be a nightmare if this required human intervention. Fortunately, Hierarchical Storage Management (HSM) software automatically handles this. Hence, all HSSs have HSM software, which monitors the way data is used, and makes decisions as to which data can be moved safely to slower devices (near-line storage) and which data should stay on fast devices (online storage). In a typical scenario, HSM stores frequently used data on on-line storage, but eventually moves them to near-line storage, if the system does not access them for a certain period, typically a few months. If the system accesses a data on near-line storage, HSM moves it back automatically from near-line storage to on-line storage. The advantage is that since only rarely used data is on near-line storage, most users do not notice any slowdown in data access. Moreover, users do not need to know or keep track of where the accessed data is stored and how to get it back.

■ Points to Remember

191

The computer retrieves the data automatically. Notice that movement of data to/from off-line storage still requires human intervention because a human operator has to insert or connect an off-line media or device to the computer system for initiating data transfer.

Points to Remember 1.

Primary storage of a computer system has limited capacity and is volatile. Hence, most computer systems use additional memory, called auxiliary memory or secondary storage.

2.

Secondary storage of a computer system is non-volatile and has low cost per bit stored, but operates at speeds far slower than that of primary storage.

3.

A sequential-access storage device is one in which the arrival at a desired location is preceded by sequencing through other locations so that access time varies according to location. On the other hand, a random-access storage device is one in which we can reach and access any storage location at random, and approximately equal access time is required for accessing each location.

4.

Magnetic tape is the most popular storage medium for large data sets, which applications need to access and process sequentially. Magnetic tape medium is a plastic ribbon usually ½-inch or ¼-inch wide. Its surface has a coating (such as iron oxide or chromium dioxide) that can record data by magnetization. Tape ribbon itself is stored in reels, or a small cartridge, or cassette.

5.

The tape of magnetic tape storage has vertical columns, called frames, and horizontal rows called channels or tracks. Each frame records a character.

6.

Storage capacity of a magnetic tape is a multiple of its data recording density and length.

7.

A magnetic tape drive enables storage/retrieval of data on/from magnetic tape.

8.

A tape controller controls a tape drive connected to it. It interprets the commands for operating the tape drive.

9.

The four commonly used types of magnetic tapes are ½-inch tape reel, ½-inch tape cartridge, ¼-inch streamer tape, and 4-mm digital audio tape.

10. Magnetic disk is the most popular direct-access secondary storage device. A magnetic disk is a thin, circular plate/platter made of metal or plastic and coated on both sides with a recording material (such as iron oxide), which can be magnetized. The disk itself is stored in a specially designed protective envelope, or cartridge, or several of them are stacked together in a sealed, contamination-free container. 11. A magnetic disk’s surface has a number of invisible, concentric circles called tracks. Each track has multiple sectors. A sector is the smallest unit of data access by a disk drive. In case of disk units having multiple disk plates, a set of corresponding tracks on all recording surfaces together form a cylinder. 12. Storage capacity of a disk system is a multiple of its number of recording surfaces, number of tracks per surface, number of sectors per track, and number of bytes per sector. 13. A disk’s data access time depends on seek time, latency, and transfer rate. The time required to position the read/write heads on the specified track/cylinder is called seek time. The time required to spin the specified sector under the head is called latency. Transfer rate is the rate at which a system reads/writes data from/to the disk into main memory. 14. A magnetic disk drive contains all mechanical, electrical, and electronic components for holding one or more disks and for reading/writing of data from/to it. 15. A disk controller controls a disk drive connected to it. It interprets the commands for operating the disk drive. 16. Depending on the type of packaging, magnetic disks are classified into Zip/Bernoulli disks, disk packs, and Winchester disks. 17. An optical-disk storage system consists of a metallic or plastic disk coated with a reflective material. It uses laser beam technology for reading/writing of data from/to disk surface.

192 Chapter 5 ■ Secondary Storage 18. Storage capacity of an optical disk is a multiple of its number of sectors and number of bytes per sector. 19. An optical disk drive contains all the mechanical, electrical, and electronic components for holding an optical disk and for reading/writing of data from/to it. 20. Commonly used types of optical disks are CD-ROM, WORM (CD-R), CD-RW, and DVD. CD-ROM disk is a read-only storage medium. WORM (CD-R) disk is a write-once, read-many storage medium. CD-RW disk allows erasing of previous content and writing on it multiple times. DVD is a standard format for distribution and interchange of digital content in both computer-based and consumer electronics products. The format enables storage of various types of large multimedia data on a new and improved version of CD, which works on optical disk technology. 21. Memory storage devices use flash memory technology for secondary storage devices. Three popular memory storage devices are Solid State Drive (SSD), flash drive (pen drive) and memory card (SD/MMC). 22. Hybrid Secondary Storage Drives use both SSD and HDD. 23. Mass storage devices use multiple units of a storage media to create a single secondary storage device. Commonly used types of mass storage devices are disk array (also known as RAID), automated tape library, and CD-ROM jukebox. 24. A disk array (also known as a RAID) is a mass storage device that uses a set of hard disks, hard disk drives, and a controller mounted in a single unit. 25. An automated tape library is a mass storage device that uses a set of magnetic tapes, magnetic tape drives, and a controller mounted in a single unit. 26. A CD-ROM jukebox is a mass storage device that uses a set of CD-ROM disks, CD-ROM drives, and a controller mounted in a single unit. 27. RAID (Redundant Array of Inexpensive Disks) is a disk array with special features to improve fault tolerance, offer better performance, and allow easier storage management. It uses mirroring, striping, and striping with parity techniques for improved fault tolerance and better performance. 28. To enable devices manufactured by independent vendors to be used with computers manufactured by different vendors, controllers follow some drive interfacing standards. Commonly used drive interface standards are  Small Computer System Interface (SCSI), Serial Attached SCSI (SAS), Serial Advanced Technology Attachment (SATA), Fiber Channel (FC), FireWire, and Internet SCSI (iSCSI). 29. Three commonly used processor-to-storage connectivity technologies are Direct Attached Storage (DAS), Storage Area Network (SAN), and Network Attached Storage (NAS). 30. Data backup is the process of creating a copy of some data from an on-line storage device to a secondary storage backup device so that if the original data on the on-line storage device is corrupted or lost by accident, it can be retrieved from the backup device and stored back on the on-line storage device. 31. Two basic types of backup are  full backup an incremental backup. Full backup method copies all data from an on-line secondary storage device to a backup device at the time of backup, whereas incremental backup method copies only newly created files or files changed since the last backup. 32. As a single type of storage is not superior in all aspect (speed of access, capacity, and cost), most computer systems build their storage solutions by making use of a hierarchy of storage technologies. Such a storage solution, called Hierarchical Storage System (HSS), is a cost effective way of designing computer systems with large storage capacities. A typical storage hierarchy pyramid includes cache memory, main memory, on-line secondary storage devices, near-line mass storage devices, and off-line storage devices. All HSSs have Hierarchical Storage Management (HSM) software, which monitors the way data is used, and makes decisions as to which data can be moved safely to slower devices (near-line storage) and which data should stay on fast devices (on-line storage).

■ Questions

193

Questions 1.

What is a secondary storage? How it differs from a primary storage?

2.

What are the main limitations of primary storage of a computer system?

3.

Why do most computer systems use secondary storage?

4.

Name some popular secondary storage devices used in today’s computer systems.

5.

Draw the broad classification diagram of popular secondary storage devices used in today’s computer systems.

6.

What is a sequential-access storage device? Write examples of a few applications for which such a storage device is suitable.

7.

What is a random-access storage device? Write examples of a few applications for which such a storage device is suitable.

8.

“The storage approach selected for a particular application is determined by the way data is organized and processed.” Discuss.

9.

Differentiate between on-line and off-line storage of data. Name a storage device suitable for each type of data storage.

10.

Explain how a system records information on a magnetic tape.

11.

What is a parity bit? Explain how a system uses it for detecting errors.

12.

What is a magnetic tape drive? Describe the main components and basic operation mechanism of a half-inch magnetic tape reel drive.

13.

Define “data recording density” and “data transfer rate” for a magnetic tape drive. What is the data transfer rate of a magnetic tape system of 800 BPI tape density and 200 inches per second tape speed?

14.

A magnetic tape is a continuous medium which records data serially and there is no addressing mechanism. In this situation, explain how a system accesses a desired data record stored on a magnetic tape efficiently.

15.

In context of magnetic tape storage, define the following terms and explain their role: (a) Inter-record gap (c) Blocking (b) Inter-block gap (d) Blocking factor

16.

Tape usage increases as blocking factor increases. Write an example to illustrate this. How does a system generally decide blocking factor?

17.

Tape usage increases as blocking factor increases. This means that blocking factor should be as large as possible. What is the problem in making blocking factor too large?

18.

In context of magnetic tape storage, explain the role of the following: (a) File header label

(c) Tape header label

(b) File trailer label

(d) End of tape marker

Beginning of tape marker 19.

What is a magnetic tape controller? Write some commands that a magnetic tape controller typically supports.

20.

Write advantages of half-inch tape cartridges over half-inch tape reels.

21.

Write differences in the way data is organized and accessed in case of half-inch tape reels and half-inch tape cartridges.

22.

Differentiate between half-inch tape and quarter-inch streamer tape. Which one better utilizes tape storage and why?

23.

Differentiate between serial and parallel representation of data recording on magnetic tapes. Write one example of each to illustrate the two types of data recording.

24.

Explain how digital audio tape obtains high data recording density.

25.

Write advantages and limitations of magnetic tapes as a secondary storage device.

194 Chapter 5 ■ Secondary Storage 26.

Write typical uses of magnetic tapes.

27.

What is a magnetic disk? Explain how data is stored and organized on a magnetic disk.

28.

In context of magnetic disk storage, define the following terms and write the relationship among them (if any): (a) Track (b) Sector (c) Cluster

(d) Cylinder (e) Disk address

29.

Describe the two commonly used methods of partitioning a disk surface into sectors and write their relative advantages and disadvantages.

30.

What will be the storage capacity of a double-sided disk that has 400 tracks, 16 sectors per track, and 512 bytes per sector?

31.

Write relative advantages and disadvantages of sector-based and cluster-based disk organizations.

32.

Sector size of a disk should not be too large or too small. Explain why.

33.

What is a disk pack? Explain how data is organized and accessed from a disk pack.

34.

What is a cylinder? A disk pack has 16 surfaces and 200 tracks on each surface. How many cylinders are there in this disk pack?

35.

Explain how cylinder-based organization leads to faster access of data in a disk pack.

36.

What factors determine storage capacity of disks?

37.

A disk pack consists of 6 disk plates. Each plate has 400 tracks and there are 50 sectors per track. If 512 bytes can be stored per sector, calculate its total storage capacity.

38.

Describe the structure of the two commonly used types of access arms assembly in disk systems. Also, write their relative advantages and disadvantages.

39.

What is a head crash in case of a disk system? How does it affect a computer system?

40.

Define the following terms in context of a disk storage: (a) Access time (b) Latency

(c) Seek time (d) Transfer rate

41.

For every read/write access to a disk, is seek time constant or variable? If it is constant, what is its value? If it is variable, what are its minimum and maximum values?

42.

For every read/write access to a disk, is the value of latency constant or variable? If it is constant, what is its value? If it is variable, what are its maximum and minimum values?

43.

Explain how disk systems with multiple read/write heads per surface help in reducing seek time as compared to those with single read/write head per surface.

44.

What is transfer rate of a disk system? What are the two main parameters on which it depends?

45.

Rotational speed of a disk system having a single recording surface is 300 rpm. It has 80 sectors/track and 512 bytes/sector. What is the transfer rate of this disk system?

46.

Explain access time, seek time, and latency for disk storage. What is the access time of a disk system with average seek time of 20 milliseconds and average latency of 7 milliseconds?

47.

What is “flying-head?” How it helps in increasing the life of disk storage?

48.

Differentiate between direct and random access storage devices. In which category does a magnetic disk fall? Write reasons for your answer.

49.

What is a File Allocation Table (FAT) in context of disk storage? Why disk storage systems need FAT? How do they create it?

50.

What is a magnetic disk drive? Differentiate between disk drives with interchangeable magnetic disks and disk drives with fixed magnetic disks. Write their relative advantages and limitations.

■ Questions

195

51.

What is a disk controller? Write the typical commands supported by a disk controller along with the parameters required for each command.

52.

List various types of magnetic disks commonly used in today’s computer systems. Write some typical uses of each type.

53.

What is a disk pack? Write similarities and differences between a disk pack and a Winchester disk.

54.

For the same number of disk platters of same size, Winchester disks can manage to have larger storage capacity than disk packs. Explain why.

55.

Write advantages and limitations of magnetic disks as a secondary storage device.

56.

Write advantages of magnetic disks as compared to magnetic tapes as a secondary storage device.

57.

Write typical uses of magnetic disks.

58.

What is an optical disk? How a system records/reads data on/from an optical disk?

59.

Differentiate between data organization on a magnetic disk and an optical disk. Which data organization leads to faster random access time and why?

60.

Why optical disk drives require a more complicated drive mechanism than magnetic disk drives?

61.

What are the main parameters on which storage capacity of an optical disk depends?

62.

A 5¼-inch optical disk has 3,00,000 sectors each of 2352 bytes. What is its total storage capacity?

63.

Why optical disk drives are slower (have larger access time) than magnetic disk drives?

64.

What are the commonly used types of optical disks? Write typical uses of each type.

65.

What is an “infopedia”? Write some typical examples of infopedia.

66.

What is a DVD? Write down its features and uses.

67.

What is data archiving? Why do systems archive data? Name some secondary storage media used for data archiving.

68.

Write advantages and limitations of optical disks as a secondary storage device.

69.

Write reasons why optical disks are a better storage medium for data archiving as compared to magnetic tapes and magnetic disks.

70.

Write typical uses of optical disks.

71.

What is a Solid State Drive (SSD)? Why is the speed of data access and reliability better for SSD than HDD?

72.

Write the relative advantages and disadvantages of SSD and HDD.

73.

What is a flash drive (pen drive)? How does a user connect it to a computer? Write its features and typical uses.

74.

What is a memory card? Write its features and typical uses.

75.

What is a RAM disk? How does it help in faster execution of an application?

76.

What is a pseudo disk? How does it help in enhancing the speed of a computer system?

77.

Write relative advantages and disadvantages of a RAM disk and a magnetic disk.

78.

What is a hybrid secondary storage drive? Describe its two commonly used configurations.

79.

What is the basic principle of having larger capacity in mass storage devices?

80.

What are the three commonly used types of mass storage devices? What are the basic storage media components used in each type?

81.

What is a disk array? How does it provide enhanced storage capacity and enhanced performance?

82.

What is a RAID? Why it is so called? Explain how it provides enhanced reliability.

83.

Describe the three fundamental RAID techniques with their relative advantages and disadvantages.

196 Chapter 5 ■ Secondary Storage 84.

What is mirroring? Explain how mirroring leads to enhanced reliability and faster read operations in case of a RAID. What is the disadvantage of mirroring?

85.

What is striping? Explain how striping leads to enhanced performance of read and write operations. What is the disadvantage of striping?

86.

Explain why striping leads to worse availability than using multiple disks without RAID configuration.

87.

What is a RAID level? Name some commonly used RAID levels and the techniques used by each for enhanced reliability.

88.

Differentiate between RAID Level 5 and RAID Level 6.

89.

What is an automated tape library? What are its main components? How are these components used together to provide a mass storage device? Write some uses of an automated tape library.

90.

What is a CD-ROM jukebox? What are its main components? How are these components used together to provide a mass storage device? Write some uses of a CD-ROM jukebox.

91.

What is a drive interface standard? How it is useful? Name commonly used industry standard storage interfaces.

92.

What are (a) SCSI controller, (b) SCSI bus, and (c) SCSI device?

93.

Draw a diagram to illustrate how SCSI devices connect to and communicate with a computer system.

94.

Both FC and iSCSI are for SAN environments. Differentiate between the two.

95.

Differentiate among DAS, SAN, and NAS as processor-to-storage connectivity technologies. Write their relative advantages and limitations.

96.

What is data backup? Why do systems need to backup data?

97.

Name some secondary storage devices that are used commonly for data backup.

98.

Write four different ways in which a system may lose data on an on-line storage device.

99.

Name the two basic types of backup. Which one normally takes more time and storage? Write reasons for your answer.

100. Differentiate between full backup and incremental backup. Write their relative advantages and disadvantages. 101. What is a backup policy? Why do systems need it? What types of issues it deals with? 102. What is periodicity of backup? How it is normally decided? 103. What is automatic backup? How it is different from manual backup? 104. How can we protect critical data against natural calamities? 105. Differentiate between backup and archiving of data. 106. What is a hierarchical storage system? Draw a typical storage hierarchy pyramid. 107. Explain how computer systems build large storage capacity in a cost effective way. 108. Differentiate among on-line, near-line, and off-line storage. Write names of storage devices typically used for each type of storage. 109. What is Hierarchical Storage Management (HSM)? Where does a computer system need it and why?

Input-Output Devices

To be useful, a computer needs to communicate with its external environment (its users). Input-output devices (abbreviated I/O devices) provide this capability to a computer. They are also known as peripheral devices. Input devices enter data from outside world into primary storage, and output devices supply the results of processing from primary storage to users. Today, many types of I/O devices are available. For an application, one type may be more suitable than another type. Some I/O devices perform both input and output functions. This chapter describes the commonly used I/O devices. I/O devices are much slower in operation than primary storage and CPU. This is because they have mechanical parts, and the potential for improvement in speed of such parts is limited.

INPUT DEVICES An input device is an electromechanical device that accepts data from outside world and translates them into a form that a computer can interpret. Commonly used input devices are broadly classified into the following categories: 1. Keyboard devices

5. Electronic cards based devices

2. Point-and-draw devices

6. Speech recognition devices

3. Data scanning devices

7. Vision based devices

4. Digitizer

These types of input devices and their applications are described here.

Keyboard Devices Keyboard devices allow data entry into a computer by pressing a set of keys (labeled buttons) mounted on a keyboard. They are broadly classified into two types: general-purpose keyboards and special-purpose keyboards. These two types and some other related concepts are described here.

198 Chapter 6 ■ Input-Output Devices

General-purpose Keyboards General-purpose keyboards are standard keyboards that have enough keys to meet the data entry requirements of a wide range of computer users and applications.

Figure 6.1. Layout of keys on a QWERTY keyboard.

The most popular general-purpose keyboard used today is the 101-keys QWERTY keyboard (see Figure 6.1). It has 101 keys out of which the keys for alphanumeric characters follow the commonly used QWERTY layout. QWERTY layout adopts the standard typewriter keyboard layout, in which the positioning of character keys ensures faster typing speed. This layout organizes alphabetic keys so that the upper-left row of letters begins with the six letters Q, W, E, R, T, and Y (see Figure 6.1). A QWERTY keyboard groups the keys into the following functional groups: 1.

Alphanumeric keys. This group has the keys for the letters of English alphabet, the numbers 0 to 9, and several special characters such as /, ?, $, &, @, whose arrangement follows QWERTY layout.

2.

Numeric keypad. Numeric keypad, located on the right side of the keyboard, has the keys for the ten digits and mathematical operators (+, , * and /). Notice from Figure 6.1 that these keys are also present in the set of alphanumeric keys, making the numeric keypad redundant. Although redundant, the numeric keypad permits rapid entry of numeric data. Keyboards of portable PCs (laptops) do not have numeric keypad due to space limitation.

3.

Arrow keys. These are a set of four keys  up (), down (), left () and right (), which allow us to move the cursor up and down (usually a line at a time), and left and right (usually a character at a time). A cursor, which usually appears as an underscore (_), a vertical line (), or a rectangle ( ) on the terminal screen, always indicates the location of the next keyed-in character on the screen. These keys are also used for vertical scrolling (using up and down keys) and horizontal scrolling (using left and right keys) of the contents displayed on the terminal screen, when a displayed document or worksheet extends beyond the size of the terminal screen.

4.

Special function keys. Figure 6.2 lists some of the important keys that belong to this set.

5.

Other function keys. These are user-programmable keys labeled as F1, F2, F3, and so on. The function assigned to each of these keys is different for different software packages. For example, a word processing program can use F1, F2 and F3 keys to make the selected text underlined, italic, and bold, respectively. These keys are also known as soft keys because their functionalities are software definable.

■ Input Devices Special function keys Enter Shift Ctrl Alt Backspace

Function performed Sends keyed-in data or a selected command to the memory. Enters a capital letter or one of the special characters above the numbers when pressed with the corresponding character key simultaneously. Used in conjunction with other keys to expand the functionality of the keyboard. The exact functionality depends on the software used. Used in conjunction with other keys to expand the functionality of the keyboard. Moves the cursor one position to the left and deletes the character in that position.

Tab

Advances the cursor to the next user-defined tab position.

Caps Lock

Toggles (alternate/switch) the capital letter lock feature on and off.

Num Lock

Toggles the number lock feature on and off. Moves the cursor to the beginning of a work area (line/screen/document depending on the software used). Moves the cursor to the end of a work area.

Home End Delete

Spacebar

Deletes the character at the cursor position. Displays the previous page of the current document or the previous record of a database. Displays the next page of the current document or the next record of a database. Toggles between insert mode (adds entered character at cursor position) and typeover mode (replaces character at cursor position with entered character) of data entry. Negates the current command or menu and returns to the work screen. Sometimes performs other functions depending on the software used. Enters a space at cursor position.

Print Screen

Prints what is displayed currently on the screen.

Page Up Page Down Insert Escape

199

Figure 6.2. Some special function keys on a QWERTY keyboard and their functions.

Special-purpose Keyboards Computer systems used for special-purpose applications often use special-purpose keyboards to enable faster data entry and rapid interaction with the system because their data entry requirements may not be as versatile as generalpurpose computer systems. For example, a bank ATM (Automatic Teller Machine) uses a simple keyboard with only a few keys, which are sufficient for financial transactions by customers.

Foreign Language Keyboards Several countries have designed special keyboards for data entry in their local languages. Some of these keyboards have a large number of keys and use a coding scheme with more bits to accommodate the large number of characters used in the language. For example, QWERTY keyboards work with an 8-bit coding scheme, which can accommodate 28 = 256 different characters. However, Japanese language keyboards work with a 16-bit coding scheme to accommodate all characters used in Japanese language.

200 Chapter 6 ■ Input-Output Devices

Keyboard Templates We saw that the function assigned to the function keys F1 to F12 and to some of the special function keys depends on the software used. When different software packages program the same keys to perform different functions, it becomes difficult for a user using multiple software to remember the functions assigned to different keys by different software. Hence, several software vendors distribute their software packages with keyboard templates that designate assignment of various commands to function keys. These templates, made of plastic, nicely fit over the keyboard. The functionality of various function keys is written on top of the plastic at the positions of those function keys. With this, a user need not remember the functions assigned to different keys by different software packages.

Software Simulated Keys We often come across the situation of entering a non-standard character such as “” or “”, or a phrase or name such as “Prentice-Hall of India” repeatedly while preparing a document. For faster data entry, a user may reassign a keyboard key to produce them. For example, a user may write software to reassign the character “#” to the name “Prentice-Hall of India” so that the system automatically enters “Prentice-Hall of India” in place of the character # whenever this key is pressed. Such arrangements of making a key produce something different from what it is supposed to produce is known as software simulation of the key.

Autorepeat Feature If a user keeps a key pressed for an auto-repeat initial delay period (usually of the order of 300 milliseconds), its corresponding character, or functionality starts auto-repeating. For example, if the user keeps the key with character “a” pressed, the characters “aaaaa…..” start appearing on the terminal screen till he/she stops pressing it. This feature enables faster data entry when the user wants to enter the same character multiple times, or when he/she wants to skip multiple lines or pages.

Keyboard Buffer A keyboard buffer is a small memory inside either the terminal or the keyboard. It temporarily stores keyboard input data before transferring it to the computer’s main memory for processing. It has the capacity to store a few tens to a few hundreds of keystrokes. Storing of keystrokes in keyboard buffer instead of sending them directly to main memory makes user interaction with the system more efficient and smooth. This is because when a user presses a key, the processor may be busy doing something else and may not be in a position to transfer the keyboard input to main memory immediately. In this case, in a system without keyboard buffer, the system locks the keyboard after every keystroke, not allowing the user to enter anything until the system completes transferring the keyboard input to main memory, and releases the lock. This causes inconvenience and delay in data entry, especially for operators with fast typing speeds. Keyboard buffer helps users to enter keyboard inputs at their own convenient speeds because the input data is temporarily stored in the keyboard buffer and the processor keeps transferring them to the main memory whenever it finds time to attend to the keyboard device.

Point-and-Draw Devices Initially, interaction with computers was restricted mainly to text mode. Text-mode interaction being cumbersome, time-consuming, and limited in scope of operation, computer designers came up with a new type of user interface, called graphical user interface (GUI). A GUI provides a screen with graphic icons (small images on the screen) or menus and allows a user to make rapid selections from them to give instructions to a computer (see Figure 6.3). GUI requires an input device with which a user can rapidly point to and select a graphic icon or menu item from multiple options displayed on the screen. The keyboard, though usable, is inconvenient and unsuitable for this requirement. Hence, research efforts to find a suitable input device to meet this requirement gave birth to several input devices like mouse, track ball, joystick, light pen, and touch screen. Many of these devices, like mouse and light pen, are also useful for creating graphic elements on the screen such as lines, curves, and freehand shapes. With this new ability,

■ Input Devices

201

manufacturers and users of these devices started calling them point-and-draw devices. These devices enable computers to be used by a wide range of users including children, illiterate citizens, and graphic designers. Some commonly used point-and-draw devices are described here. Menus File

Edit

View

Image

Options

Help

Graphic icons

Figure 6.3. A graphical user interface (GUI) of Microsoft® Windows desktop.

Mouse A mouse is a small hand-held device that fits comfortably in a user’s palm (see Figure 6.4). It rolls on a small bearing and has one or more buttons on the top. When a user rolls a mouse (connected to a user terminal) on a flat surface, a graphics cursor moves on the terminal screen in the direction of the mouse’s movement. Since movements of the graphics cursor on the screen reproduce all movements of the mouse, we can easily position the graphics cursor at a menu item or an icon by using the mouse.

Click buttons

Figure 6.4. A mouse.

    Different applications display the graphics cursor as different symbols such as an arrow  (    ) , a wrist with a pointing finger (), etc. An application may also display the text and graphics cursor on the screen simultaneously. The graphics cursor, irrespective of its size and shape, has a pixel-size point that is the point of reference to decide the position of the cursor on the screen. This point is called hot spot of the graphics cursor. The graphics cursor points to a menu item or icon, when a user positions the hot spot on it. With a click of the mouse’s button, a user can notify the system of this choice. This is much easier than notifying a choice by pressing various key combinations. With proper software, we can also use a mouse to draw pictures on the screen and edit text.

Mouse Operations Figure 6.5 lists simple operations to carry out various functions with a mouse. A mouse reports movement and button click events in a sequential stream as they happen. The system codes them as multi-byte records. The first byte is event type, and the following bytes are particulars of the event (the change in vertical and horizontal position of the mouse for mouse movement events; which button and the type of click for mouse click events). A mouse uses an interrupt mechanism to report mouse operations to a computer system. It does not send a message directly to the program that is currently executing, but stores the sequential stream of events in a

202 Chapter 6 ■ Input-Output Devices

Sr. No. 1

2 3 4

Operation Point

Click (Left button) Click (Right button) Double-click (Left button)

5

Double-click (Right button)

6

Simultaneousclick

7

Drag

Meaning Move the mouse so that hot spot is positioned at a menu item or an icon. Press and release left mouse button once. Press and release right mouse button once. Press and release left mouse button twice in rapid succession. Press and release right mouse button twice in rapid succession. Press and release both left and right mouse buttons simultaneously. Move the mouse from one hot spot position to another hot spot position with the left mouse button pressed.

Function Graphics cursor points to the menu item or icon at the hot spot position. Selects the menu item or icon at the hot spot position. Function varies with software used, but it is used often to call up a menu of options. Initiates execution of the program represented by the icon at the hot spot position. Function varies with software used.

Provides added functionality to the mouse. Actual functionality varies with software used. Use to (a) Change the location of an icon on the screen; (b) Draw graphics objects (lines, circles, curves, freehand, drawings, etc.); (c) Select a block of text for performing some operation on the entire block.

Figure 6.5. Simple operations to carry out various functions with a mouse.

memory buffer and sends an interrupt request to the CPU. The currently executing program checks periodically to see whether a mouse event has occurred. On sensing an interrupt signal, the program reads the sequential stream of events from the buffer and acts accordingly. Types of Mouse Mouse devices are usually categorized as: 1.

Mechanical and optical mouse. A mechanical mouse has a ball that partially projects out through an opening in its base. The ball rolls due to surface friction when a user moves the mouse on a flat surface. On two sides of the ball (at 900 angles from each other) are two small wheels that spin to match the speed of the ball. Each wheel of the mouse connects to a sensor. As the mouse ball rolls, the sensors detect how much each wheel spins and send this information to the computer in the form of changes to the current position of the graphics cursor on the screen. An optical mouse has no mechanical parts like the ball and wheels. Instead, it has a built-in photo-detector. It comes with a special pad with gridlines printed on it. When a user moves the mouse on the pad, the photodetector senses each horizontal and vertical line on the pad, and sends this information to the computer in the form of changes to the current position of the graphics cursor on the screen.

2.

One, two, and three buttons mouse. A mouse can have one, two, or three buttons. A one-button mouse is good enough for programs designed to use only a single button. Some programs operate with a two-button or three-button mouse, but can still run on a system having fewer buttons by providing an alternative way to indicate a click of these buttons – such as by pressing shift key on keyboard while the mouse button is clicked. The leftmost button of a multi-button mouse is the main button that allows for most mouse operations because most people are right-handed and use their right index finger to click the main button. However, a user can configure another button as main button. For example, a left-handed user can configure the rightmost button as main button.

■ Input Devices

203

3.

Serial and bus mouse. A serial mouse plugs into a normal serial port (a built-in socket in a computer’s back panel to which we can connect external devices) of a computer, while a bus mouse requires a special electronic card, which provides a special port for connecting the mouse to a computer. The special electronic card fits into one of the expansion slots of the computer. Thus, a bus mouse occupies one of the expansion slots, whereas a serial mouse does not need any expansion slot.

4.

Wired and cordless mouse. A wired mouse connects to a computer with a small cord (wire), while a cordless mouse has no wired connection to a computer. It has a controller that communicates with the computer by transmitting a low-intensity radio or infrared signal. Although more expensive than a wired mouse, a cordless mouse allows easier movement of the mouse.

Trackball A trackball is a pointing device similar to a mechanical mouse. Its roller ball is on the top (instead of the base) along with the buttons (see Figure 6.6). To move the graphics cursor on the screen, the user simply rolls the ball with hand (instead of moving the whole device). Hence, a trackball requires less space than a mouse for operation, and is often attached to or built into the keyboard. Trackballs are usually built into the keyboard of laptops, because laptop users do not always have a flat surface for moving the mouse. Three shapes in which trackballs are commonly found in laptops are ball, button, and square. To move the graphics cursor at a desired position on the terminal screen, the user rolls the ball with fingers, or pushes the button with a finger, or moves a finger on the square platform. Trackball is preferred for CAD/CAM (Computer Aided Design/Computer Aided Manufacturing) applications, because a designer can move the graphics cursor with hand movements only without moving the device, which suits the working style of designers working on large drawings. Several equipment having embedded computers also use a trackball. For example, an Ultrasound machine usually has a trackball that a sinologist (medical expert in sonography) uses to move the cursor (usually in cross-hair shape) to mark the points of references on the image on the screen.

Joystick A joystick is a pointing device that works on the same principle as a trackball. To make the movements of the spherical ball easier, it is placed in a socket with a stick mounted on it (see Figure 6.7). A user moves the stick forward or backward, left or right, to move and position the graphics cursor at a desired position. Most joysticks use potentiometers to sense stick and ball movements, and a click button on top of the stick to select the option pointed to by the cursor. Click button

Light indicator

Click buttons

Stick

Ball Ball is rolled with fingers Figure 6.6. A trackball.

Socket

Figure 6.7. A joystick.

Typical uses of a joystick include video games, flight simulators, training simulators, and remote control of industrial robots.

204 Chapter 6 ■ Input-Output Devices

Electronic Pen An electronic pen is a pen-based point-and-draw device. Its two commonly used types are: 1.

Light pen. It uses a photoelectric (light sensitive) cell and an optical lens assembled in a pen-shaped case. When a user moves the tip of the pen over the screen surface, the photoelectric cell and lens assembly detects the light emitted from a limited field of view of the screen’s display. The system transmits this electric response to a processor, which identifies the menu item or icon that is triggering the photocell. In this manner, the graphics cursor locks on to the position of the pen and tracks its movement over the screen. The pen has a finger-operated button, which the user clicks to select an option from the screen. A user can also draw on the screen with a light pen. For example, CAD applications allow users to use it with a keyboard to select different colors and line thickness, reduce/enlarge drawings, and add/erase graphics objects such as lines, circles, rectangles, etc.

2.

Writing pen with pad. This type comes with a special writing pad. A user writes on the pad with the electronic pen the data to be input to the computer. With handwriting recognition software, this device enables input of text and freehand drawings into computer for word processing. Modern PDAs (Personal Digital Assistants) provide this feature. Moreover, signatures and messages stored and transferred as graphic images are input with the use of this device. For example, delivery persons of goods delivery organizations often use pocket computers with this device to accept recipients’ signatures against their names. The device captures the image of a signature and stores it in the computer for future references.

Touch Screen Touch screen enables a user to choose from available options by touching with a finger the desired icon or menu item displayed on a computer’s screen, which has optical sensors to detect the touch of a finger. When a user touches the screen with a finger, the sensors communicate the position of touch to the computer, which interprets the input made by the user. Another type of touch screen uses a flat pad located beneath the screen, which has sensitive sensors to measure the pressure at many points. When a user touches the screen, the changing pressure allows the device to detect the location of touch, which it transmits to the computer as user’s desired input. Information kiosks often use touch screens. An information kiosk is an unattended system located at a public place that stores information of public interest and allows common people to access stored information as per their requirement. For example, information kiosks are often located at: 1. An airport or a railway station to provide information to arriving passengers about hotels, restaurants, tourist

spots, etc. in a city. 2. In large museums or zoos to guide the visitors to locations of various attractions and facilities, and to caution

them against things they are not supposed to do while inside. 3. In a large bank, post office, or insurance company to introduce various types of services to customers, and to

guide them to appropriate counters for their specific jobs. Bank ATMs also use them to enable customers to carry out their transactions easily. 4. In environments having dirt or weather conditions, which prohibit use of keyboards and/or pointing devices.

Data Scanning Devices To reduce human error in data entry, the trend in data entry to computers has always been to decrease the number of steps involved in transcription (copying data by typing, keying, or writing). One way to accomplish this is by enabling data entry directly from the source documents by using data scanning devices. These devices have the following characteristics: 1.

They eliminate the need for manual entry of data by human beings, thus, improving data accuracy and timeliness of the data processed.

■ Input Devices

205

2.

They demand high quality of source documents and often reject documents typed poorly, having strikeovers, or having erasures.

3.

Form design and ink specification requirements become more critical with the use of these devices than with the use of keyboard devices for data entry.

4.

Some of these devices are also capable of recognizing marks or characters.

Some commonly used types of data scanning devices are described here.

Image Scanner An image scanner is an input device that translates paper documents into an electronic format for input to a computer. The input documents may be typed text, pictures, graphics, or even handwritten material. A copy of a document stored in a computer in this manner does not deteriorate in quality with age, and can be displayed or printed, whenever desired. We can alter and manipulate the stored images in interesting ways, if the computer has imageprocessing software. Image scanners use optical technology to convert an image into electronic form. They shine light on a document and sense the intensity of the reflection at every point of the image. For example, suppose a document has the word “BIT” written on it. The scanner treats the document as if it is on a graph sheet (see Figure 6.8(a)). An intersection of a horizontal and vertical line of the graph is a grid point. If there is a dark spot at a grid point, it is represented by a 1, otherwise it is represented by a 0. Figure 6.8(b) shows the representation of the image of Figure 6.8(a). This representation is called bit map representation of an image. Each bit in the representation is called a pixel (a picture element). 0 0 0 0 0 0 0 0 0 0 0 (a) A scanned document

1 1 1 1 1 1 1 1 1 1 1

1 0 0 0 0 1 0 0 0 0 1

1 0 0 0 0 1 0 0 0 0 1

1 0 0 0 0 1 0 0 0 0 1

0 1 1 1 1 0 1 1 1 1 0

1 0 0 0 0 0 0 0 0 0 1

1 0 0 0 0 0 0 0 0 0 1

1 1 1 1 1 1 1 1 1 1 1

1 0 0 0 0 0 0 0 0 0 1

1 0 0 0 0 0 0 0 0 0 1

1 1 0 0 0 0 0 0 0 0 0

1 0 0 0 0 0 0 0 0 0 0

1 1 1 1 1 1 1 1 1 1 1

1 0 0 0 0 0 0 0 0 0 0

1 1 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0

(b) Bitmap representation of the scanned document

Figure 6.8. A scanned document and its bitmap representation.

The finer is the granularity of grid points, the better the scanner is because it can convert an image with greater accuracy. Scanners having 300 to 600 grid points per inch are common. Moreover, Figure 6.8 shows the use of just 1 bit for encoding of each grid point. High quality black-and-white scanners and color scanners use more bits to represent each grid point. For example, a good quality black-and-white scanner might use 4 bits per grid point to encode different shades from black to gray to white. Similarly, a color scanner might use 24 bits per grid point to represent a maximum of 256 different shades of color. The two commonly used types of image scanners are: 1.

Flatbed scanner. A flatbed scanner is like a document copy machine. It has a box with a glass plate on its top and a lid that covers the glass plate (see Figure 6.9). To scan a document, a user places it upside down on the glass plate. A light beam below the glass plate moves horizontally from one end to another when activated. After scanning one line, the light beam moves up a little and scans the next line. The process repeats until the beam finishes scanning the entire document. It takes about 20 seconds to scan a document of 21 cm  28 cm size.

206 Chapter 6 ■ Input-Output Devices 2. Hand-held scanner. A hand-held scanner (see Figure 6.10) has a set of light emitting diodes encased in a

small case that conveniently fits in hand. To scan a document, a user drags it steadily over the document from one end to another with its light on. Hand-held scanners are used to scan low volume documents. They are much cheaper than flatbed scanners.

Figure 6.9. A flatbed scanner.

Figure 6.10. A hand-held scanner.

Optical Character Recognition (OCR) Device We can use image scanners to input a variety of documents including pictures, graphics, typed text, and handwritten text. When we use them for inputting text documents (typed or handwritten), we face the following limitations: 1.

Since a scanned input document is stored as an image, instead of text, it is not possible to do any word processing of the document (the computer cannot interpret the stored document as letters, numbers, and special characters).

2.

Storage space required for storing the document as an image is much more than that required for storing the same document as a text. For example, a page of printed text having 2000 characters can be stored as 2000 bytes by using the ASCII representation. A bitmap-image representation of the same document requires 10 to 15 times more storage depending on the resolution (granularity) of grid points.

An OCR device overcomes these limitations. It has a scanner equipped with character recognition software (called OCR software), which converts bitmap images of characters to equivalent ASCII codes. The scanner first creates the bitmap image of the document and then the OCR software translates the array of grid points into ASCII text that the computer can interpret as letters, numbers, and special characters. To translate bitmaps of characters into equivalent text, OCR software examines the bitmap of each character and compares with the pre-programmed set of characters, which the machine can recognize. Whichever character pattern it matches, or nearly matches, the machine considers it as the input character. If a scanned character does not match satisfactorily with any of the stored character patterns, the OCR software rejects it. OCR software is designed to recognize texts written using standard type fonts (called OCR fonts) only. Two such standard fonts are OCR-A (American standard) and OCR-B (European standard) (see Figure 6.11). If a document contains italics or bold face letters, or text written using fonts which the OCR software cannot recognize, then the OCR software will not be able to translate it correctly. Modern OCR devices can also recognize handwritten characters. In this case, users have to take special care to ensure that in the handwritten document, characters are of standard size, lines making up the characters are connected, and no stylish loops etc. are used. OCR devices for converting handwritten text into ASCII are more complex and difficult to design than those for printed text. This is because handwritings of different users are different, making the parameters for how individual characters are formed very broad.

■ Input Devices

(a) OCR-A fonts (American standard)

207

(b) OCR-B fonts (European standard)

Figure 6.11. Two standard OCR fonts.

Optical Mark Reader (OMR) OMR is a scanner that can recognize a pre-specified type of mark made by pencil or pen. For example, in objective type tests, applicants mark their choices of correct answers on a special pre-printed test scoring sheet by darkening a small square, circular, or oval shaped box by a pencil (see Figure 6.12). These answer sheets are fed to an OMR device for automatic grading by a computer. For each question, four options are given out of which only one is correct. Choose the correct option and mark your choice against the corresponding question number in the given answer sheet by darkening the corresponding circle with a lead pencil. 1.

Binary equivalent of decimal 4 is: (a) 101 (c) 001 (b) 111 (d) 100

2.

Full form of CPU is: (a) Cursor Positioning Unit (b) Central Power Unit (c) Central Processing Unit (d) Control Power Unit

3.

Which is the largest unit of storage among following: (a) Terabyte (c) Megabyte (b) Kilobyte (d) Gigabyte (a) Question sheet

Indicates direction in which the sheet should be fed to OMR device 1. a

b

c

d

a

b

c

d

a

b

c

d

2.

3. (b) Pre-printed answer sheet

Figure 6.12. A sample question sheet of an objective type test and its pre-printed answer sheet, which is read by an OMR device to grade the test.

An OMR device focusses a light beam on the document and detects the reflected light pattern from the marks. Pencil marks made with a soft lead pencil (high graphite content) reflect the light strongly, enabling the OMR device to determine which responses are marked. OMR devices require that the pre-printed forms use good quality paper without any foldings. They also require accurate alignment of markings in the boxes for correct interpretation of input data. We can use OMR devices for any input data that is of a choice or selection nature. Thus, in addition to their use for grading tests with objective type questions, they are often used to tabulate responses to large surveys where responses are restricted to one or more out of a few possibilities.

208 Chapter 6 ■ Input-Output Devices

Bar-Code Reader Data coded in the form of small lines (known as bars) are known as bar codes. Bar codes represent alphanumeric data by a combination of adjacent vertical lines (bars) by varying their width and the spacing between them. All types of goods, books, postal packages, badges, tags, etc. use bar codes for unique identification purpose. A bar-code reader is a device for reading (decoding) bar-coded data. It is either a hand-held or a stationary scanner having bar-code reader embedded in it. It scans a bar-code image and converts it into an alphanumeric value for input to a computer connected to it. A bar-code reader uses laser-beam scanning technology. It focuses a laser beam across the pattern of bars of a bar code. Different bar codes having different patterns of bars reflect the beam in different ways. A light-sensitive detector senses the reflected light patterns and converts them into electrical pulses, which the reader then transmits to recognition logic circuits. Finally, the logic circuits convert the electrical pulses into an alphanumeric value. There are many types of bar-coding systems. The most widely known one is the Universal Product Code (UPC). It appears on almost all retail packages in USA and now in India as well on many products. The UPC bar-code patterns decode as 10 digits. The first five digits identify the manufacturer or supplier of the product, and the next five digits identify a specific product of the manufacturer (see Figure 6.13). We often find bar code readers in supermarkets and department stores. When a customer picks up a product for purchasing and brings it to the cash counter for payment, the sales person at the counter uses a bar-code reader to scan the bar code printed on the product. The bar-code reader converts the bar code into an alphanumeric value and feeds it to a computer that looks up the price of the product, possibly updates inventory and sales records, and uses the price and description information to prepare a purchase bill for the customer. Postal and goods delivery services also use bar codes to identify and track each packet. Product category character 0 – grocery products 3 – drugs and health related products, etc.

0

21000 Manufacturer/supplier identification number

67520 Specific product code number

Figure 6.13. An example of UPC bar code.

Magnetic-Ink Character Recognition (MICR) MICR is similar to OCR. Banking industry uses it for faster processing of large volume of cheques handled every day by this industry. A bank cheque has bank’s identification code (name, branch, etc.), account number, and cheque number pre-printed (encoded) on it by using characters from a special character set. The characters on the cheque are pre-printed using a special ink containing particles of iron oxide (having magnetic property). Figure 6.14 shows a sample cheque that employs MICR technology.

■ Input Devices

209

Pre-printed MICR characters Figure 6.14. A bank cheque that employs MICR technology.

When a customer presents a filled-in cheque at a bank, a bank employee enters manually (keys in) the customersupplied information, including the amount written on the cheque. The bank then processes this cheque by using an MICR reader-sorter, which reads the pre-printed data on the cheques, and sorts the cheques into different pockets according to their identification code numbers for distribution to other banks, or for further processing. E13B font is the most commonly used character set by MICR devices. It consists of numerals 0 to 9 and four special characters (see Figure 6.15). Besides enabling faster processing of cheques, MICR technology also ensures greater accuracy of data entry because of mostly pre-printed information on the cheque and direct feeding of the cheques to the computer. However, other industries have not adopted MICR because it has only 14 symbols (10 digits and 4 special characters). No alphabetic characters are available.

Figure 6.15. E13B font (character set) used by MICR devices.

Digitizer A digitizer is an input device used for converting (digitizing) pictures, maps, and drawings into digital form for input to computers. For example, x and y coordinates of points in a line drawing may be stored in digital form. This enables re-creation of the drawing from the stored information and easy incorporation of changes in the drawing, whenever required. A digitizer consists of a digitizing tablet (also known as graphics tablet) and a stylus (see Figure 6.16). The digitizing tablet is a flat surface that contains hundreds of fine copper wires forming a grid. Each copper wire receives electric pulses. The digitizing tablet spreads over a working table and connects to a computer. The stylus is like a pen or a lens-like cursor with a cross hair and button. It

Digitizing tablet Stylus (cursor with a cross hair and button) Tabletop

Figure 6.16. A digitizer.

210 Chapter 6 ■ Input-Output Devices connects to the tablet and a user can press it down at a point on the tablet to input the (x, y) coordinates of the point. As a user moves the stylus on the tablet, a cursor on computer’s screen moves simultaneously to a corresponding position on the screen to provide visual feedback to the user. This enables the user to draw sketches or to input sketched drawings. Inputting drawings or developing sketches by using a digitizer is simpler because it inputs poorly sketched lines, arcs, and other graphical objects as mathematically precise objects (like straight lines and smooth curves). Architects and engineers use digitizers in the area of Computer Aided Design (CAD) for designing cars, buildings, medical devices, robots, mechanical parts, etc. Designers of Geographical Information System (GIS) applications also use them for digitization of maps available in paper form.

Electronic-card Reader Electronic cards are small plastic cards having encoded data appropriate for the application for which they are used. An electronic-card reader, normally connected to a computer, reads the data encoded on an electronic card and transfers it to the computer for further processing. Banks issue electronic cards to their customers for use with automatic teller machines (ATMs). An ATM is an unattended machine connected to a bank’s computer, which allows a customer to perform certain bank transactions 24 hours a day, without the need to interact with a bank employee. An electronic card for use in an ATM has its customer’s account number and credit limit (maximum amount that he/she can withdraw in a day) encoded on the card. When a customer inserts his/her card into the ATM (actually the electronic-card reader of the ATM), the reader reads the data encoded on the card and transmits it to the bank’s computer activating the customer’s account. The customer then carries out the desired transaction by following the instructions displayed on the screen of the ATM and by pressing a few keys on its customized keyboard or touch screen. Many organizations also use electronic cards for controlling access to physically secured areas. In this case, an organization issues an electronic card to each employee with his/her authorization data encoded on it. Authorization data specifies which employee has access to which areas. All physically secured areas of the organization have an electronic-card reader installed at its entrance. When an employee wants to enter into a physically secured area, he/she inserts his/her electronic card into the reader installed at the entrance of that area. If the electronic card and its reader use RFID technology, a user simply needs to flash his/her electronic card near the reader instead of inserting it into the reader. The reader reads and checks the authorization data encoded on the card before permitting the individual to enter the area (the door has electronic connection with the reader and opens only if the reader finds that the individual has authorization to access the area). In such applications, a central computer having link to the electronic-card reader maintains a record of the identity and time of people entering/leaving a secured area. In case of security breaches, an organization uses this record to trace the problem. Depending on the manner in which data is encoded, electronic cards are of the following types: 1.

Magnetic strip cards. These cards have a magnetic strip on which encoded data is stored. It can contain much more data per unit of space than do printed characters or bar codes. Moreover, we cannot read data stored in it visually. Many organizations issue magnetic strip cards to their employees or customers with their confidential data stored on it.

2.

Smart cards. Smart cards have a built-in microprocessor chip in whose memory the encoded data is stored. It can store much more data than the magnetic strip of a magnetic strip card. A smart card also has some processing capability because its microprocessor has its own processor and memory. This feature attributes intelligence to smart cards and makes them more suitable for a wider variety of applications than magnetic strip cards. For example, a smart card can be used as an electronic wallet by storing a specific amount of cash in the microprocessor chip before the card is issued to a customer. Whenever the customer uses the card to make purchases, the amount of purchase made at every instance is deducted from the balance amount stored in the card by inserting the card in a card read/write machine (also called electronic registers), which is available with shops that allow use of smart cards for making purchases. At any time, the customer can pay additional money to the card company and get the balance amount stored in the card increased. Because smart

■ Input Devices

211

cards can hold more information, have some processing capability, and is almost impossible to duplicate, they are fast replacing magnetic strip cards.

Speech Recognition Devices Speech recognition devices are input devices that allow a user to input data to a computer system by speaking to it. As users speak with different accents (pronounce differently) and intonations (with different tone or pitch of the voice), and the fact that the meaning of a word varies depending on the context in which it is used, speech recognition systems are limited to accepting few words or sentences within a relatively small domain. A computer with a speech recognition device consists of a microphone and follows the following steps to recognize and act upon a spoken input data (see Figure 6.17):

STOP

3 Convert analog signals to digital form Word STOP in digital form

1 User speaks the word STOP to a computer

2 Convert spoken word into electrical signals (analog form)

5 Display the recognized word and/or perform command

4 Match with MOVE NO PUT STOP TEN WAIT YES ZERO

  

pre-stored words in computer’s electronic dictionary

Figure 6.17. Steps followed in speech recognition by a speech recognition system.

1.

Speak. A user speaks into the microphone attached to it.

2.

Convert into electrical signals. The device converts the spoken word(s) into its analog form by converting the word(s) into electrical signals by breaking down each sound into its various frequencies.

3.

Digitize. A digital-to-analog converter in the device then converts the analog form of the spoken word(s) into its digital form (in 1s and 0s) so that the computer can store and interpret it.

4.

Match with pre-stored words. The device next matches the digitized version of each spoken word against similarly formed pre-stored words in the computer’s electronic dictionary. A user creates the electronic dictionary (a database of pre-stored words) during a training session, when he/she speaks several times the words and phrases to be stored in its electronic dictionary to train the system to recognize them. When operated in training mode, the device creates and stores the patterns for all spoken words and phrases for future matching.

5.

Perform corresponding action. When the device finds a match for the spoken word(s), it displays the word(s) on computer’s screen and/or initiates appropriate action corresponding to the input (for example, stops doing whatever it was performing). In some case, the system displays the word(s) and waits for the user’s confirmation to prevent doing something different from what the user intended (in case of wrong interpretation of the spoken word(s) by the device). If it does not find a match for the spoken word(s), the system informs the user by displaying a message on computer’s screen.

212 Chapter 6 ■ Input-Output Devices Speech recognition systems are of two types: 1.

Speaker-dependent. Due to vast variation in the accent of different speakers, speech recognition systems are usually speaker-dependent. They recognize the speech of only a single individual or a few individuals. In case of multiple individuals, each one of them participates separately in a training session to train the system to recognize his/her accent of pre-stored words in computer’s dictionary. The system usually maintains a separate database of pre-stored words for each individual because the digital form of the same word may be different for different individuals.

2.

Speaker-independent. Speaker-independent speech recognition systems can recognize words spoken by anyone. Since such a system requires a large database of pre-stored words to accommodate anyone’s voice pattern, speaker-independent systems usually have a limited vocabulary. For example, the vocabulary of such a system may have the words YES, NO, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, and TEN.

According to another classification mechanism, two types of speech recognition systems are: 1.

Single word recognition systems. These systems can recognize only a single spoken word, such as YES, NO, MOVE, STOP, at a time. Speaker-independent systems are mostly of this type.

2.

Continuous speech recognition systems. These systems can recognize spoken sentences such as MOVE TO THE NEXT BLOCK. Since recognizing continuously spoken sentences is more difficult than recognizing words, continuous speech recognition systems are usually speaker-dependent.

A wide range of applications use speech recognition systems. A few examples are: 1.

For data input to a computer system by a person in situations where his/her hands are busy or he/she must continuously look at a measuring instrument or some other object. For example, doctors in an operation room can request certain information about a patient while operating.

2.

For data input by dictation of long text or passage for later editing and review.

3.

For authentication of a user by a computer system based on speech input.

4.

For limited use of computers by individuals with physical disabilities.

In addition to making input of data easier, speech recognition systems also provide freedom of movement because the user is free to stand up, move around, or do some other work by hand while inputting voice data to the system.

Vision-Input Systems A vision-input system consists of a digital camera to accept input by seeing an object. Input data in this case is normally an object’s shape and features in the form of an image. A computer with a vision-input device follows the following steps to recognize a given object: 1.

It focuses the camera on the given object to take its picture.

2.

The camera creates a digital image of the object and feeds it to the computer.

3.

The computer matches the image with similarly formed pre-stored images in its image database.

4.

The computer takes appropriate action depending on whether it finds a match or not.

Vision-input systems are often part of industrial robots that are used for quality control and assembly processes. For example, the robot of Figure 6.18 inspects the objects passing on a conveyor belt and separates those not meeting certain quality-control specifications. It also inspects the shapes of objects and separates objects of different shapes in different bins.

■ Output Devices

Computer

213

Contains a database of images of correct samples

Camera

The computer activates one of the robotic arms at the right time to separate the objects in appropriate bins

Conveyor belt movement Reject Bin for Bin for circular square bin objects objects Figure 6.18. An application of a vision-input system.

OUTPUT DEVICES An output device is an electromechanical device that accepts data from a computer and translates them into a form that is suitable for use by outside world (users). Commonly used output devices are broadly classified into the following categories: 1. Monitors 4. Computer output microfilm 2.

Printers

5.

Screen image protector

3.

Plotters

6.

Voice response system

These types of output devices and their applications are described here. Output devices generate computer outputs that are broadly of the following two types: 1.

Soft-copy output. A soft-copy output is temporary in nature because it does not appear on a paper or some material that a user can carry for showing to others, or for filing and use later when he/she is not using a computer. For example, contents displayed on a terminal screen, or words spoken out by a voice response system are soft-copy output.

2.

Hard-copy output. A hard-copy output is permanent in nature because it appears on a paper or some material that a user can carry for showing to others, or for filing and use later when he/she is not using a computer. For example, output produced on paper by printers or plotters are hard-copy output.

Monitors Monitor

Monitors generate soft-copy output by displaying an output on a screen (see Figure 6.19). A monitor and a keyboard together form a video display terminal (VDT). A VDT (often referred to as just terminal) is both an input and output device. A user uses the keyboard to input data to a computer and the monitor to view the output from the computer. The name “terminal” comes from the fact that a terminal is at the terminus or end of a communication path. It is the most popular I/O device used today.

Keyboard Figure 6.19. A video display terminal consists of a monitor and a keyboard.

214 Chapter 6 ■ Input-Output Devices Two basic types of monitors are cathode-ray-tube (CRT) and LCD (Liquid Crystal Display) flat-panel. As compared to CRT monitors, LCD flat-panel monitors are thinner, lighter, and are suitable for use with both portable and nonportable computer systems. Users prefer them because they occupy less table space and consume less power.

How a CRT Monitor Displays an Output? A CRT monitor is a glass tube with a screen at one end and an electron gun at the other end. Figure 6.20 shows its major components. The electron beam generator has an oxide-coated metal (called cathode) and a heating filament. The cathode emits a large number of electrons when heated by the filament. In front of the electron beam generator is a control grid applied with an appropriate positive voltage. It allows the exact number of electrons, out of the generated ones, to pass through it for striking at the monitor’s screen. Larger is the positive voltage applied to the control grid, larger is the number of electrons that pass the control grid and strike the screen, and larger is the beam’s intensity. If the grid voltage is negative, no electrons pass the control grid and the beam is “blanked”. An assembly unit consisting of accelerating electrodes and a focusing electron lens accelerates and focuses the electrons, which pass through the control grid. The unit applies a positive voltage to accelerating electrodes to accelerate the electrons. The focusing electron lens consists of a cylindrical metal enclosure with a hole through which the electrons pass in the form of an electron beam. The electron gun of the CRT monitor includes the electron beam generator, control grid, accelerating electrodes, and focusing electron lens. Consists of a cathode and a heating filament

Accelerating electrodes with focusing electron lens

Horizontal deflection plates

Electron beam generator

Electron beam

Screen Phosphor Control grid

Vertical deflection plates

Figure 6.20. Major components of a CRT monitor.

The electron beam generated by the electron gun passes through a pair of vertical deflection plates and a pair of horizontal deflection plates. It applies appropriate positive voltages to one of the vertical plates and one of the horizontal plates to focus the beam at a desired point on the screen. For example, the display mechanism applies a suitable positive voltage to the top/bottom vertical plate to move the beam up/down, and to the left/right horizontal plate to move the beam left/right. Thus, the electron beam hits at the desired point on the screen. The backside of the screen has phosphor coating, a chemical that glows for a short time when hit by the electron beam. The screen’s phosphor coating is in the form of a grid of dots called pixels (a contraction of picture elements). Since phosphor glows only for a short time (few microseconds), an image drawn on the screen would be visible only for a few microseconds and then would fade away, unless the display mechanism draws the image repeatedly. This may appear to be an inconvenience, but it is also an advantage since there is no need to erase anything. The display mechanism just draws new images and the old ones fade away automatically. The electron gun does not draw an image directly by focusing and shooting on the pixels forming the image. Instead, it traverses the screen in a fixed pattern (see Figure 6.21). That is, it aims at every pixel on the screen systematically, starting at the top-left corner and scanning to the right horizontally, then dropping down a small distance and scanning another line. Each horizontal line of pixels is called a scan line. Each scan line has a fixed number of pixels, and the electron gun can write or not write a pixel in each position by turning the beam on or off. When the beam reaches the right end of a scan line, the device turns it off and moves it to the starting point of the next scan line. This is called

■ Output Devices

215

horizontal trace. After scanning all scan lines, when the beam reaches the right end of the bottom-most scan line, the device turns it off and moves it to the starting point of the top-most scan line. This is called vertical trace. Scan lines

Vertical retraces

(a) Progressive scan

Horizontal retraces

(b) Interlaced scan

Figure 6.21. Scanning of a monitor’s screen by its electron beam.

In one pass of scanning the entire screen, if the electron beam travels all scan lines from top to bottom sequentially, it is called a progressive scan (see Figure 6.21 (a)). On the other hand, if the electron beam travels only odd numbered scan lines in one pass and even numbered scan lines in the next pass, it is called an interlaced scan (see Figure 6.21 (b)). In case of interlaced scan, since the monitor scans every other line instead of each line in order, it has to transmit only half as much data in a single pass, but takes two passes to draw the entire screen. Interlaced scan may cause flicker of images drawn on the screen. Hence, low quality monitors use interlaced scan and high quality monitors use progressive scan.

How to Compare CRT Monitors We often use the following attributes to compare CRT monitors: 1.

Screen size. Display screens of monitors vary in size from 5 to 25 inches (diagonal dimension). Monitors with 17-inch to 21-inch screen size are common with personal and desktop computers. Although, monitors with larger screen are costlier, users prefer them because they enable viewing of multiple windows, video clips, animated objects, and complex graphics.

2.

Resolution. Resolution refers to the number of points to which the electron beam can be directed (pixels) on the screen. As the pixels are arranged in scan lines, resolution of a monitor depends on its total number of scan lines and total number of pixels per scan line (each scan line has same number of pixels). Total number of scan lines is called a monitor’s vertical resolution and total number of pixels per scan line is called its horizontal resolution. Overall resolution of a monitor is a multiple of its horizontal and vertical resolutions. A low-resolution monitor has a resolution of about 320 × 200, while high-end monitors have resolutions of 1024 × 768, 1280 × 1024, or more. The higher the resolution of a monitor, the sharper is its displayed images.

3.

Refresh rate. Since a pixel on phosphor-coated screen glows for a short time only (few microseconds) and then fades away, the display mechanism redraws an image 30 to 60 times a second to make it appear flickerfree. Hence, the electron beam should scan the entire screen 30 to 60 times a second. The actual number of times that the electron beam scans the entire screen per second is called refresh rate of the monitor. The higher the refresh rate, the better is the display quality. Today, most monitors operate at 60 Hz, refreshing the screen 60 times per second. Better quality monitors operate at 70 to 90 Hz.

4.

Color. Monitors are either monochrome or color. A color monitor displays multi-colored images, while a monochrome monitor displays images only in a single color, usually white, red, green, blue, or amber. Although a monochrome monitor displays only a single color, it is usually capable of displaying multiple shades (increased and reduced color intensities) of the same color. The term gray scales is used to refer to the number of shades of a color that a monitor can display. Monochrome monitors have become obsolete, as most applications today require color monitors.

216 Chapter 6 ■ Input-Output Devices To add color, a color monitor uses three electron beams instead of one, and each pixel on screen consists of three tiny red, green, and blue phosphors arranged in the shape of a triangle. When the device combines three electron beams and focuses the combined beam on a pixel, phosphors of that pixel light up to form a tiny spot of white light. The device displays different colors by combining various intensities of the three beams. Color monitors are also called RGB monitors because they use red, green, and blue as primary additive colors for generating multiple colors. Color monitors use multiple bits to represent each pixel. For example, if display mechanism represents each pixel by one byte (8 bits), it can indicate one of 2 8 = 256 different colors to draw the pixels. That is, the monitor supports 256 different colors. There are millions of colors when we consider all shades and mixtures of color possible, for which 256 is far too few colors. High-end monitors use 24 bits to represent each pixel. Such monitors can support 224 or about 16 million different colors. Based on the resolution and number of colors supported, several standards for color monitors have evolved. We can implement a standard by installing an add-on board (commonly known as a graphics adapter board or a video card) in the main computer box and connecting it to the monitor. The four popular standards are: (a) (b) (c) (d)

CGA (Color Graphics Adapter). It has a low resolution of 320 × 200 and supports up to 16 colors. EGA (Extended Graphics Adapter). It has a resolution of 640 × 350 and supports up to 16 colors. VGA (Video Graphics Array). It has a resolution of 640 × 480 and supports up to 256 colors. Super VGA. It provides resolution from 800 × 600 to 1280 × 1024 and supports 256 or more colors.

All modern personal computers come with at least VGA output. A video card (graphics adaptor card) has its own memory called video RAM. The higher the resolution and the more colors a monitor supports, the larger is the video RAM required. Figure 6.22 summarizes the video RAM capacity required for different types of monitors. Memory required for number of colors supported (in bytes)

Resolution (Total number of pixels)

2 colors (Requires 1 bit per pixel)

4 colors (Requires 2 bits per pixel)

8 colors (Requires 3 bits per pixel)

16 colors (Requires 4 bits per pixel)

256 colors (Requires 8 bits per pixel)

640 × 480 (3,07,200)

(307200 × 1)/8 = 38,400 bytes

(307200 × 2)/8 = 76,800 bytes

(307200 × 3)/8 = 1,15,200 bytes

(307200 × 4)/8 = 1,53,600 bytes

(307200 × 8)/8 = 3,07,200 bytes

800 × 600 (4,80,000)

(480000 × 1)/8 = 60,000 bytes

(480000 × 2)/8 = 1,20,000 bytes

(480000 × 3)/8 = 1,80,000 bytes

(480000 × 4)/8 = 2,40,000 bytes

(480000 × 8)/8 = 4,80,000 bytes

1024 × 768 (7,86,432)

(786432 × 1)/8 = 98,304 bytes

(786432 × 2)/8 = 1,96,608 bytes

(786432 × 3)/8 = 2,94,912 bytes

(786432 × 4)/8 = 3,93,216 bytes

(786432 × 8)/8 = 7,86,432 bytes

1280 × 1024 (13,10,720)

(1310720 × 1)/8 = 1,63,840 bytes

(1310720 × 2)/8 = 3,27,680 bytes

(1310720 × 3)/8 = 4,91,520 bytes

(1310720 × 4)/8 = 6,55,360 bytes

(1310720 × 8)/8 = 13,10,720 bytes

Figure 6.22. Video RAM capacity required for different types of monitors.

Flat Panel Monitors A flat panel monitor (see Figure 6.23) is only about one inch thick, is light in weight, and consumes less electricity as compared to a CRT monitor. It is most suitable for use with portable computer systems, such as a laptop, because such systems must be compact in size, light in weight, and should consume less power.

.

■ Output Devices

The display technologies used by flat panel monitors include liquid-crystal display (LCD), electro-luminescent display (ELD), and gas-plasma display (GPD). Out of these, LCD monitors are in most common use. As the name implies, LCD monitors use a special kind of liquid crystals to display images on the screen. The liquid crystals used in these monitors are normally transparent, but become opaque when charged with electricity.

217

Foldable flat screen

Keyboard, trackball, hard disk, USB port, etc. are in this unit

Figure 6.23. A notebook computer with a flat panel monitor.

Liquid crystals do not glow when charged, so there is not enough contrast between the images displayed and their background to make them clearly legible under all lighting conditions. Hence, LCD monitors use a light source behind the screen to make the screen easier to read.

Dumb, Smart, and Intelligent Terminals Depending on their local processing capability, we classify terminals (monitors along with keyboards) as dumb, smart, and intelligent. A dumb terminal is a low-cost terminal, without any local processing capability. It transmits all input data as received to the computer. This type of data is called “dirty” data because it contains errors along with good data. The computer identifies errors and informs the terminal operator. In this process, processing based on input data is delayed until “clean” data is obtained from the operator. This delay, accompanied by the need to process the data again, can be expensive. A smart terminal has a microprocessor (a CPU) and some internal storage in addition to I/O capabilities. It has local data editing capability and the ability to consolidate input data prior to sending it to the computer. Preliminary processing of input data takes place locally, and the terminal cleans up the data before transmitting it to the main computer for processing. This saves clean data preparation time as compared to dumb terminals. However, users cannot program smart terminals. An intelligent terminal is a small computer by itself. It consists of a built-in microcomputer and users can program it. These programmable terminals have extensive local data processing capability. They can maintain large working files locally and can handle small data processing jobs, without the need to interact with the main computer. They have their own secondary storage devices like disk, which they use during processing of these small jobs. Programmed error-detection tests can also be stored in the terminal for validation of input data, which can ensure transmission of clean data to the main computer system for further processing. Most terminals used today are intelligent or at least smart.

Terminal Emulators Computers are often connected to networks and communicate with other computers on the network. In this case, computers interact with each other in client-server mode and may keep changing their roles of client and server at different occasions. In such a situation, a full-fledged computer like a PC or a workstation is required to serve as a terminal for communicating with a remote computer. However, a PC or a workstation is not a terminal, and does not act like a terminal. A simple way to solve this problem is to write a software program that runs on the PC or workstation, communicates with the network interface over a serial port on the PC or workstation, and pretends that it is a terminal. Such a program is called terminal emulator.

218 Chapter 6 ■ Input-Output Devices

Privacy Filters Often users work in an open area with sensitive information displayed on their monitors, and have the fear of their coworkers around them viewing the displayed information. A privacy filter, which fits over a monitor’s screen, hides the displayed contents from prying eyes. It is made of a plastic film that is inlaid with microscopic black strips. A user sitting in front of the screen can see through the filter clearly, but the screen looks black to others standing/sitting nearby on either side.

Printers Printers are the most popular hard-copy output devices used today.

Parameters for Classifying Printers We classify modern printers based on: 1.

Printing technology. According to this classification, common types of printers are dot-matrix printers, inkjet printers, drum printers, chain/band printers, and laser printers.

2.

Printing approach. According to this classification, printers are of impact and non-impact types. Impact printers use the approach of hammering a typeface against paper and inked ribbon to produce printed output. Nonimpact printers do not hit (impact) a ribbon to print. They use thermal, electrostatic, chemical, or inkjet technology to produce printed output. Impact printers can produce multiple copies by using carbon in a single print cycle, which is not possible with a non-impact printer. However, impact printers are noisy in operation and normally use a cover to reduce noise level. Non-impact printers are quiet in operation.

3.

Printing speed. According to this classification, printers are classified as character, line, and page printers. As the names imply, a character printer prints one character at a time, a line printer prints one line at a time, and a page printer prints an entire page at a time. Accordingly, we measure printer speeds in characters-persecond (cps) for character printers, lines-per-minute (lpm) for line printers, and pages-per-minute (ppm) for page printers. Print-speed ranges for the three types of printers are 40 to 450 cps, 1000 to 5000 lpm, and 4 to 800 ppm.

4.

Printing quality. Quality of printed output is directly proportional to resolution of printing, measured in dots per inch (dpi). The dpi qualifier refers to the capability of a printer to print number of dots per linear inch, horizontally or vertically. That is, a 300-dpi printer is capable of printing 90,000 (300 × 300) dots per square inch. According to this classification, we classify printers as near-letter-quality (NLQ), letter-quality (LQ), near-typeset-quality (NTQ), and typeset-quality (TQ). The resolution of near-letter-quality printers is about 300 dpi, letter-quality printers is about 600 dpi, near-typeset-quality printers is about 1200 dpi, and typesetquality printers is about 2000 dpi. Users use NLQ and LQ printers for ordinary day-to-day printing jobs, and NTQ and TQ printers for top-quality professional printing, such as in publishing industries.

5.

Language scripts. Printers are available in almost all scripts, such as, English, Devnagari, Japanese, Arabic, etc. According to this classification, printers are classified based on the scripts (also called fonts) supported. A printer may support multiple scripts simultaneously to print in multiple languages. For example, a printer may be capable of printing in both English and Devanagari.

6.

Color. Printers can print either in a single color (such as black, red, blue), or in two to three colors (such as a document printed in black and white with keywords printed in red), or in multiple colors. Although printers that print in a single or two to three colors are suitable for printing textual documents, multi-color printers are desirable for printing other types of documents, such as those containing graphs and images.

Different types of printers available today are dot-matrix, inkjet, drum, chain/band, laser, and hydra printers. They are described here.

■ Output Devices

219

Dot-Matrix Printers Dot-matrix printers are character printers that print one character at a time. They form characters and all kinds of images as patterns of dots (see Figure 6.24). Figure 6.25 shows the printing mechanism of a dotmatrix printer. It has a print head that moves horizontally (left to right and right to left) across the paper. The print head contains an array of pins. The printer can activate each pin independent of others to extend and strike against an inked ribbon to form a dot on the paper. To print a character, the printer activates the appropriate set of pins as the print head moves horizontally. For faster printing, many dot-matrix printers print both ways – while the print head moves from left to right and while it moves from right to left, on return. Such method is called bi-directional printing. Figure 6.26 shows a dot-matrix printer. Paper below the ribbon

Inked ribbon

Printed characters formed of dots in a 5 x 7 matrix

ABCDEFGHIJKLMN OPQRSTUVWXYZ 0123456789-., &/$*#%@=(+) Figure 6.24. Formation of characters as patterns of dots.

Print head pins

Direction of movement of print head pins

Direction of movement of print head Print head

Figure 6.25. Printing mechanism of a dot-matrix printer.

Print head Pins

Figure 6.26. A dot-matrix printer.

Figure 6.27. Arrangement of pins in an 18-pin print head of a dot-matrix printer. It permits dots to overlap to increase the density of dots and, therefore, quality of printed output.

220 Chapter 6 ■ Input-Output Devices In Figure 6.24 all characters are formed by 5 horizontal and 7 vertical dots. Such a pattern is called a 5 × 7 matrix. It can be generated by a print head having 7 pins. However, notice that the print head in Figure 6.25 has 9 pins. The printer uses the bottom 2 pins for printing lower-case letters that extend below the line (for example, p, g, q, and y). Quality of printed output is directly proportional to the density of dots in the matrix. Dot matrix printers with 9, 18, or 24 pins are available. Printers with 24 pins can print near-letter-quality characters that appear solid. Figure 6.27 shows the arrangement of pins in an 18-pin print head of a dot-matrix printer. Dot matrix printers can print any shape of character that a program can describe as patterns of dots. Hence, they can print special characters, different sizes of print, and graphics such as charts and graphs. Dot-matrix printers are impact printers because they print by hammering pins on an inked ribbon to leave ink impressions on a paper. Hence, we can use them for producing multiple copies by using carbon paper or its equivalent. Due to impact printing, dot-matrix printers are noisy as compared to non-impact printers. Dot-matrix printers are usually monochrome. However, some dot-matrix printers use a ribbon having rows of two to three colors to produce printed output in few colors. Dot-matrix printers are slow, having printing speeds in the range of 30 to 600 characters per second. However, they are cheap in terms of both initial cost and cost of operation. Hence, individuals and organizations prefer them for generating hard-copy outputs, if the speed and quality of printing are not important factors. They also use them for applications requiring multi-copy output such as shipping forms and invoices that rely on impact printing for generating multiple copies.

Inkjet Printers Inkjet printers are character printers that form characters and images by spraying small drops of ink on a paper. The print head of an inkjet printer contains up to 64 tiny nozzles. The printer can heat up the nozzles selectively in a few microseconds by an integrated circuit resistor. When the resistor heats up, the ink near it vaporizes and ejects through the nozzle making a dot on the paper placed in front of the print head. To print a character, the printer selectively heats the appropriate set of nozzles as the print head moves horizontally. Figure 6.28 shows an inkjet printer. Inkjet printers produce higher quality output than dot-matrix printers do, because they form characters by very tiny ink dots. A highresolution inkjet printer has as many as 64 nozzles within a height of 7mm, providing print resolution of around 360 dots per inch. Figure 6.28. An inkjet printer.

Inkjet printers can print any shape or characters that a program can describe as patterns of tiny dots. Hence, they can print special characters, different sizes of print, and graphics such as charts and graphs. Inkjet printers are non-impact printers because they print by spraying ink on paper. Hence, they are quieter in operation, but we cannot use them for producing multiple copies of a document in a single printing. Inkjet printers are both monochrome and color. A monochrome inkjet printer uses a single cartridge with black ink, whereas a color inkjet printer uses two ink cartridges – black and tri-color. The tri-color cartridge contains red, blue, and green colors in a package that can mix appropriate amount of these colors with black from the other cartridge to get any desired color. Hence, inkjet printers can produce multi-colored and photo-quality output.

■ Output Devices

221

Inkjet printers are slower than dot-matrix printers, with printing speeds ranging from 40 to 300 characters per second. They are costlier than dot-matrix printers. Users prefer them for better quality output, if speed of printing is not an important factor.

Drum Printers Drum printers are line printers that print one line at a time. Figure 6.29 shows the print mechanism of a drum printer. It consists of a solid cylindrical drum with characters embossed (raised characters) on its surface in the form of circular bands. Each band consists of all printing characters supported by the printer in its character set. Total number of bands is equal to the maximum number of characters (print positions) that the printer can print on a line. Hence, a drum printer with 132 characters per line and supporting a character set of 96 characters will have altogether 12,672 (132×96) characters embossed on its surface. In addition to the drum, the printer has a set of hammers (one opposite each band) mounted in front of the drum in a manner that an inked ribbon and paper can be placed between the hammers and the drum. The total number of hammers is equal to the total number of bands on the drum, which is also equal to the total print positions per line. The drum rotates at a high speed. To print a character at a desired print position, the printer activates the appropriate hammer when the character embossed on the band at the print position passes below it. Hence, the drum would have to complete one full revolution to print each line of output. This means that the printer does not print all characters on a line at exactly the same time, but the time required to print an entire line is so fast that it appears as if it prints one line at a time. Figure 6.30 shows a drum printer. The drum of a drum printer is expensive and we cannot change it often. Hence, drum printers can print a pre-defined set of characters only in a pre-defined style embossed on the drum. Drum printers, therefore, do not have the ability to print any shape of characters, different sizes of print, and graphics such as charts and graphs. Hammers (one for each band) Paper Ribbon WW W WWWWWWWWWWW V V V V V V V V V V VV V V U U U U U U U U U U U U U U T T T T T T T T T T T T T T S S S S S S S S S S S S S S

Solid cylindrical drum with embossed characters

R R R R R R R R R R R R R R Q Q Q Q Q Q Q Q Q Q Q Q Q Q P P P P P P P P P P P P P P O O O O O O O O O O O O O O N N N N N N N N N N NN N N

Total number of bands is equal to the maximum number of characters (print positions) on a line. Each band has all characters supported by the printer. Figure 6.29. Printing mechanism of a drum printer.

222 Chapter 6 ■ Input-Output Devices Drum printers are impact printers because they print by hammering on a paper and inked ribbon against characters embossed on the drum. Hence, we can use them for producing multiple copies by using carbon paper or its equivalent. Due to impact printing, drum printers are noisy in operation and often use a cover to reduce noise level. Printing speeds of drum printers are in the range of 300 to 2000 lines per minute. Figure 6.30. A drum printer.

Chain/Band Printers Chain/band printers are line printers that print one line at a time. Figure 6.31 shows the print mechanism of a chain/band printer. It consists of a metallic chain/band on which all characters of the character set supported by the printer are embossed. A standard character set may have 48, 64, or 96 characters. To enhance printing speed, these printers have several sets of embossed characters in the character set on the chain/band. For example, the chain/band of a 64 character set printer may have four sets of 64 characters each embossed on it. In this case, the chain/band will have altogether 256 (64×4) characters embossed on it.

Complete chain is composed of five sections of 48 characters each

One section of 48 characters

Direction of movement of the chain

Paper Ribbon Hammers 132 print positions Figure 6.31. Printing mechanism of a chain/band printer.

The printer has a set of hammers mounted in front of the chain/band in a manner that we can place an inked ribbon and paper between the hammers and chain/band. The total number of hammers is equal to the total number of print positions. Therefore, a printer supporting 132 print positions will have 132 hammers. The chain/band rotates at a high speed. To print a character at a desired print position, the printer activates the appropriate hammer when the character embossed on the chain/band passes below it. Since the character set appears several times on the chain/band, it is not necessary to wait for the chain/band to make a complete revolution to position the desired character in the correct print position. Unlike the drum of a drum printer, we can change the chain/band of a chain/band printer. This allows use of different fonts (styles of characters) and different scripts (languages) with the same printer. Like drum printers, chain/band printers can print only pre-defined sets of characters embossed on the chain/band used with the printer. Chain/band printers, therefore, do not have the ability to print any shape of characters, different sizes of print, and graphics such as charts and graphs. Chain/band printers are impact printers because they print by hammering on a paper and inked ribbon against characters embossed on the chain/band. Hence, they enable production of multiple copies by using carbon paper or its equivalent. Due to impact printing, chain/band printers are noisy in operation and often use a cover to reduce noise level. Printing speeds of chain/band printers are in the range of 400 to 3000 lines per minute. Figure 6.32 shows a chain/band printer.

■ Output Devices

223

Laser Printers Laser printers are page printers that print one page at a time. Main components of a laser printer are a laser beam source, a multi-sided mirror, a photoconductive drum, and toner (tiny particles of oppositely charged ink). To print a page of output, the printer focuses the laser beam on the electro statically charged drum by the spinning multi-sided mirror. The mirror focuses the laser beam on the surface of the drum in a manner to create the patterns of characters/images that the printer has to print on the page. Since the drum is photoconductive, print mechanism creates a difference in electric charge on those parts of the drum surface, which are exposed to the laser beam. As a result, the toner, composed of oppositely charged ink particles, sticks to the drum in the places where the laser beam has charged the drum’s surface. The printer then applies heat and pressure to fuse the toner permanently on the paper to generate the printed output. It then rotates the drum and cleans it with a rubber blade to remove the toner sticking to its surface to prepare the drum for next page printing. Figure 6.33 shows a laser printer.

Figure 6.32. A chain/band printer.

Figure 6.33. A laser printer.

Laser printers produce high quality output because they form characters by tiny ink particles. The most common laser printers have resolution of 600 dpi (dots per inch), whereas some high-end laser printers have resolution of 1200 dpi. Due to their high resolution, these printers give excellent graphics art quality. Laser printers can print any shape of characters that a program can describe as patterns generated by the laser beam. Hence, they can print special characters, different sizes of print, and graphics such as charts and graphs. Laser printers are non-impact printers. Hence, they are quiet in operation, but we cannot use them for producing multiple copies of a document in a single printing. Although, earlier laser printers could print only in black color, because they had a single toner-drum arrangement, now color laser printers are also available at affordable price. A color laser printer has four-color toners, each with a drum of its own. It uses the drums and toners in the same manner as described above, but charges each drum in such a way that together they produce the desired color output. Laser printers are faster in printing speed than other printers discussed earlier. Low-speed laser printers can print 4 to 12 pages per minute. High-speed laser printers are also available. Owing to their better print quality and printing speed, laser printers are more expensive than other types of printers.

Hydra Printers Today, modern offices need the following office equipment – a printer, a copy machine, and a scanner. The need for these machines at one place and considerable overlap in the technologies used in them has triggered their manufacturers to create an all-in-one multifunctional device, which can perform all these functions. Such a device is called a hydra printer. Organizations prefer them because they occupy less table space and consume less power as compared to multiple devices.

224 Chapter 6 ■ Input-Output Devices

Plotters Many engineering design applications like architectural plan of a building, design of mechanical components of an aircraft or a car, etc., often require high-quality, perfectly-proportioned graphic output on large sheets. Various types of printers described earlier are not suitable for meeting this output requirement of such applications. Hence, such applications use plotters. A plotter is an ideal output device for architects, engineers, city planners, and others who need to generate high precision, hard-copy, graphic output of varying sizes. The two types of plotters in common use are: 1. Drum plotter. It consists of a drum, one or more penholders mounted perpendicular to the drum’s surface,

and a graph-plotting software. The drum rotates in both clockwise and anti-clockwise directions to produce vertical motion. The pen(s) clamped in the holder(s) moves left to right or right to left to produce horizontal motion. The graph-plotting software controls movements of the drum and pen(s). Hence, under software control, the drum and pen(s) move simultaneously to draw designs and graphs on a sheet placed over the drum. The plotter can also annotate a design or graph so drawn by drawing characters of various sizes with the pen. Since each pen is program selectable, a user can use the plotter to produce multi-colored designs by mounting pens having ink of different colors in different holders. Figure 6.34 shows a drum plotter. 2. Flatbed plotter. It consists of a rectangular flatbed table, one or more penholders mounted perpendicular to

the table’s surface, and a graph-plotting software. It plots a design or graph on a sheet of paper spread and fixed over the table. Normally, the paper does not move and the pen holding mechanism provides all types of motions necessary to draw complex designs and graphs. Hence, under software control, the pen(s) move in the required manner to draw designs and graphs on the sheet placed on the flatbed table. The plotter can also annotate a design or graph so drawn by drawing characters of various sizes with the pen. Provision is also there to mount more than one pen in the pen(s) holding mechanism. Since each pen is program selectable, a user can use the plotter to produce multi-colored designs by mounting pens having ink of different colors in different holders. The plot size is restricted by the area of the bed. Some are as small as A4 size (8"×11" page), while some large beds used in the design of cars, ships, aircrafts, buildings, highways, etc. are up to 20 ft. by 50 ft. Some plotters also etch on plastic or metal plates. In this case, the plastic or metal sheet spreads on the bed and the drawing pen has a sharp-edged needle. Figure 6.35 shows a flatbed plotter.

Paper Design drawn on the paper

Design drawn on the paper Paper

Figure 6.34. A drum plotter.

Figure 6.35. A flatbed plotter.

Plotters are slow in operation because of excessive mechanical movement required during plotting. Hence, mismatch between CPU speed and plotter speed is large. Hence, in most cases of plotting an output, the CPU first transfers the output onto a tape or disk, and then activates the plotter to plot the output from the tape or disk.

3D Printers As the name signifies, a 3D printer prints (creates) three-dimensional objects. Figure 6.36 shows an example of an object printed by a 3D printer. This is contrary to the types of printers that we discussed earlier, which print on 2D surface (on paper or on sheet of plastic/metal).

■ Output Devices

3D printers use Additive Manufacturing (AM) techniques to create 3D objects. In an AM technique, manufacturing material is combined/joined/added/glued together to create a 3D object. For example, a potter makes a pitcher using AM technique. To create a pitcher, he/she adds layers of mud, giving proper shape to each layer, while moving from bottom to top. This is contrary to Subtractive Manufacturing (SM) technique, in which material is carefully removed/cut out/hollowed from a piece. For example, a sculptor often uses SM technique to carve out a statue from a single piece of stone/wood. As compared to SM techniques, AM techniques are generally cheaper because they enable manufacturing of objects having complex shapes with less material waste. 3D printers are gaining popularity because they automate the AM techniques of creating 3D objects, thus enabling creation of 3D objects in less time and at lower cost than manual AM techniques.

225

Figure 6.36. An example of an object printed by a 3D printer.

How 3D Printers Print 3D Objects? A 3D printer requires the following three steps to print a 3D object: 1. First create a 3D digital file (3D model) of the object. The first step is to create a 3D digital file of the object to be printed. For this, the user either uses a 3D modeling software to create a CAD (Computer Aided Design) file for the object, or uses a 3D scanner to create a 3D digital file of the object. 2. Then slice the 3D model into horizontal layers. As the next step, the user uses a slicing software to slice the 3D model of the object into hundreds/thousands of thin horizontal layers (16 to 180 microns). Note that the 3D printer forms the 3D object by placing and gluing these layers one-by-one on top of each other in the right sequence. Slicing software often comes with a 3D printer, and the user should use the slicing software of the same 3D printer on which he/she is going to print the object. 3. Then upload the sliced file and print. Finally, the user uploads the sliced file to the 3D printer by giving a print command to it. The 3D printer prints the object layer-by-layer by depositing and solidifying the manufacturing material used by the printer on top of an already printed layer. As soon as the printer completes depositing and solidifying the last layer of material, the printed 3D object is ready.

Types of 3D Printers All 3D printers use additive manufacturing technology. However, they mainly differ in the way they build an object layer-by-layer and the material they use for manufacturing objects. We describe here some commonly used 3D printing technologies. 1. Fused Deposition Modeling (FDM). The method uses plastic/metal filament (wire) as the build material that melts when heated and quickly solidifies after extrusion (release) from a nozzle. The printer consists of a supply reel, which supplies material filament to an extrusion nozzle. The extrusion nozzle has a heating mechanism to melt the filament. It can move horizontally in both left and right directions under direct control of computer-aided manufacturing (CAM) software. To print an object, the printer releases the molten material from the nozzle on a specific path determined by the software, to create the first horizontal layer of the object on a build platform/tray located below the nozzle. The molten material instantly cools down and solidifies. The printer then lowers the build platform by a distance equal to the thickness of a layer, and again releases the molten material from the nozzle to form the next layer on top of the already built layer. The printer repeats this process until all layers are completed. In this manner, the printer creates the entire 3D object

226 Chapter 6 ■ Input-Output Devices layer-by-layer. Color printers based on this technology use multiple supply reels (each having filament of different color) and multiple nozzles. The software takes care of releasing the right color of molten material from the appropriate nozzle to create a multi-color object. 2. STereoLithography (STL) and Digital Light Processing (DLP). Both the methods use photopolymerization technique, which involves solidification of photosensitive resin (sticky substance) by means of a light source. 3D printers based on this technique use a vat (tub/tank) containing liquid (photosensitive polymer) resin as the build material. The printer sprays the liquid resin through a nozzle onto a build platform/tray in ultra-thin layers and uses a light source to solidify the liquid resin. SLA uses laser, while DLP uses traditional arc lamp as the source of light. The printer lowers the build platform by distance equal to the thickness of a layer, again sprays the liquid resin from the nozzle, and solidifies it using the light source, to form the next layer on top of the already built layer. The printer repeats this process until all layers are completed. In this manner, the printer creates the entire 3D object layer-by-layer. Color printers based on this technology use multiple vats (each having liquid resin of different color) and multiple nozzles. The software takes care of releasing the right color of liquid resin from the appropriate nozzle to create a multi-color object. 3. Selective Laser Sintering (SLS). The method uses small particles of plastic, ceramic or glass in powder form as the build material. The printer uses high power laser to melt and fuse (sinter) these particles to create the desired 3D object. The printer spreads a thin layer of plastic/ceramic/glass powder onto a build platform/tray and selectively sinters the powder particles using a high power laser source, mapping the shape of the desired 3D object. The printer lowers the build platform by distance equal to the thickness of a layer, again spreads the powder particles, and selectively sinters the powder particles using the laser source, to form the next layer on top of the already built layer. The printer repeats this process until all layers are completed. In this manner, the printer creates the entire 3D object layer-by-layer. As the printer creates the 3D object layer-by-layer, excess un-melted powder acts as support for the 3D object and the printer finally removes it from the object and reuses it during the next printing cycle. 3D printers that use this method of printing, but use metal powder as the build material, instead of plastic/ceramic/glass powder, are called Direct Metal Laser Sintering (DMLS) printers. 4. A much faster, experimental 3D printing technique. A team of scientists at the University of Michigan, USA is currently experimenting with a new STL-based 3D printing technique, which promises to print 3D objects at about 100 times the speed of other 3D printers based on current technologies. The technique uses a vat of specially engineered chemical resin along with Ultra Violet (UV) and blue LED lights, instead of laser beam. It prints a 3D object by sending UV light through a glass-bottomed vat of specially designed resin. Then, at the same time, through that same glass window, it sends patterns of bright and dim blue light. The specially engineered resin has the property that it hardens (polymerizes) when exposed to a particular shade of blue light, but does not harden in the presence of a certain wavelength of UV light. Hence, the technique uses UV light inhibitor in conjunction with blue light to sculpt 3D surfaces and contours of hardened resin. It also uses it to prevent the hardened resin from sticking to the window. The team of scientists working on this technique claim that this is the first truly 3D printing technique in that it prints not just a series of single 2D layers, but rather entire 3D wedges of material in one pass. 3D printing technologies are still evolving with gradual addition of many new technologies to the list above. To choose a 3D printer based on a particular technology, a user needs to make his/her judgement based on function, material, budget and design parameters.

Applications of 3D Printers It is faster and cheaper to manufacture many types of 3D objects by 3D printing method than by other manufacturing methods. By using 3D printing, it is also possible to create complex and customized designs with greater ease and cheaper cost as compared to other manufacturing methods, because no expensive tooling is required to create a new type of object through 3D printing method. Hence, many types of industries are now using 3D printing technologies as their preferred manufacturing method. We provide here a few such examples.

■ Output Devices

227

1. Rapid prototyping. Manufacturers extensively use 3D printers in their design process to create prototype designs, before finalizing a design for mass production. They quickly print an object from its paper design, and if they do not like the design, they make instant changes to the design on the computer and re-print the revised prototype, saving enormous time and effort as compared to conventional methods of creating prototype designs. 2. Rapid manufacturing of customized designs. With 3D printing, manufacturers are allowing customers to place orders for products with customized designs. For example, customers can now order for decoration pieces of fancy designs and matching sizes, lighting fixtures and lamp shades of unique shapes/sizes/colors, chocolates/candies/cakes of fancy shapes and colors, ornaments/jewelry of fancy designs and colors, etc.; and suppliers can rapidly manufacture and deliver these products to customers by using 3D printers. This was not possible so easily with conventional methods of manufacturing.

Filament Gears pull & feed the filament to extrusion nozzle

Supply reel

Heating mechanism to heat & melt the filament

X

Y

- - - - - - - - - - - - - -- - - - - - - - - - - - - - Nozzle extruding molten material Melted material is deposited in layers to create the 3D object

Build platform is lowered one layer thickness at a time

Z Figure 6.37. Schematic of FDM (Fused Deposition Modeling) technology.

228 Chapter 6 ■ Input-Output Devices 3. Manufacturing body/engine parts. Several types of industries use 3D printing for manufacturing body/engine parts. For example, car manufacturers manufacture parts of car body/engine, aircraft manufacturers manufacture parts of airplane body/engine; furniture manufacturers manufacture parts of assembled furniture; construction companies manufacture parts of assembled buildings; etc., by using 3D printers. 4. Manufacturing implants and prosthetics. In the medical world, implants and prosthetics (an artificial device that replaces a missing body part, which might have been lost through accident, disease, or congenital conditions) need to be custom designed for each patient. Manufacturers of such implants and prosthetics are quickly manufacturing such designs by using 3D printers. Although, grown up people may use their prosthetic devices for long time, but children need to change their prosthetic devices periodically, as they grow. It is possible now to manufacture such prosthetic devices at affordable costs with 3D printing. Due to this, such patients around the world are experiencing improved quality of medical care, which was not available earlier. 5. Manufacturing hearing aid and dental appliances. Just as implants and prosthetics, hearing aid and dental appliances (such as, braces, dentures, crowns, night guards, retainers, etc.) also need to be custom designed for each patient. Many dentists are now using 3D printers to manufacture such dental appliances in the exact shape and size that their clients need at a fraction of the cost and time required earlier for making such appliances. 6. Manufacturing museum souvenirs. Museums across the world are using 3D printers to manufacture miniature versions of objects kept in the museum for sale as museum souvenirs. Figure 6.37. shows the schematic diagram of FDM technology. The figure shows a flower vase printed by the author using a 3D printer based on FDM technology. The author had used orange color plastic filament to print an orange color flower vase made of plastic.

Computer Output Microfilm (COM) COM is an output device that records computer output as microscopic filmed images on a sheet of microfilm usually measuring 4"×6". This sheet of film is called a microfiche (“fiche” is pronounced as “fish”. It is a French word that means card). COM recording process produces page images that are 48 or more times smaller than those produced by conventional printers. Hence, a single microfiche can hold about 300 times as much information as a standard computer printed page. A microfiche roll consists of several microfiche sheets. COM uses a microfilm recorder for recording output on a microfiche, and a microfilm reader to view recorded information. The microfilm recorder receives output from a computer system, which it displays page-by-page on to a screen. A high-speed camera (in-built into the system) then takes picture of the displayed information. In some systems, the recorder processes the film from the camera, while other systems use a separate automated film developer to produce filmed images of the output. A user uses a microfilm reader (see Figure 6.38) to view the output recorded on a microfiche. It operates on a “back projection” principle and displays a frame (a single page of information) at a time on a translucent screen, whose size is about 8"×11". A user reads the displayed information on the screen. Most microfilm readers also have a printer in-built into it (or attached to it) to allow a user to print selected pages for hard-copy output.

Figure 6.38. A microfilm reader.

■ Output Devices

229

Most COM systems come with computer-assisted-retrieval software, which allows a user to search a document quickly from thousands of pages of recorded information on the film by specifying pre-assigned index terms. As compared to a printer, a COM system has the following advantages and limitations: 1. Information recording speed is many times faster for a COM system as compared to a printer. A COM system

is 20 to 25 times faster than an average line printer. 2. Microfilm output is many times more compact than a printed page output. A single microfiche can hold about

300 times as much information as a standard computer printed page. Thus, the mailing and storage costs of filmed documents are much less than paper documents. 3. Microfilm output is less costly than printed output. The cost of paper needed for printing a 1000 page

document is about 20 to 30 times more than the cost of the film needed to record the same information. 4. The initial investment required for installing a COM system is much more than that required for buying an

ordinary printer. Hence, use of a COM system is justified only in case of high volume workload. 5. Many people feel uncomfortable using a COM system because of retrieval delays and lack of facility to write

notes on margins of the reports. A COM system provides an easy and compact way of recording and storing information, and retrieving a piece of information in a matter of seconds. It is ideal for use in applications that need to record and store large volume of information, and selectively retrieve them off-line. Organizations often need to maintain records of their various types of documents, such as catalogues, bills, invoices, etc., for a number of years before destroying them. A COM system is most suitable for this purpose. Insurance companies, banks, libraries, public utilities departments, government agencies, and many other types of organizations are regular users of COM systems.

Screen Image Projector Screen image projector is an output device, which is used to project information from a computer on a large screen (such as a cloth screen or wall) so that a group of people can view it simultaneously. It is useful for making presentations to a group of people with direct use of a computer. We can plug a screen image projector to a computer system directly, and a presenter makes a presentation to a group of people by projecting the presentation material page-by-page on a large screen with the help of computer’s keyboard or mouse. With this facility, the presenter can also directly point to, mark, or edit certain portions of the contents of the displayed material during the presentation to make the presentation more understandable. Additionally, a presenter can prepare a full-fledged multimedia presentation with audio, video, image, and animation, and can make a lively and interesting presentation by using this device. Screen image projectors have become common presentation equipment today. Users often use them with portable notebook computers to setup a modern presentation facility quickly at any place with great ease. Like monitors, screen image projectors provide a temporary, soft-copy output. Figure 6.39 shows a screen image projector.

Operations buttons On/Off light indicator Projection lens Figure 6.39. A screen image projector.

Voice Response Systems Just as a speech recognition system allows a user to talk to a computer, a voice response system enables a computer to talk to a user. A voice response system has an audio-response device that produces audio output. Obviously, the

230 Chapter 6 ■ Input-Output Devices output is temporary, soft-copy output. Voice response systems are of two types – voice reproduction system and speech synthesizer. They are described here.

Voice Reproduction System A voice reproduction system produces audio output by selecting an audio output from a set of pre-recorded audio responses. The set of pre-recorded audio responses may include words, phrases, or sentences spoken by human beings, music or alarms generated by musical instruments, or any other type of sound. The system first converts the analog recordings of the pre-recorded sounds into digital data and stores them on a disk or in its memory chip permanently. To produce an audio output, the system selects the corresponding sound from the set of pre-recorded sounds. It then converts the selected sound back into analog form and routes it to a speaker. Several applications use voice reproduction systems, including the following: 1.

Audio help for guiding how to operate a system. For example, banking industry uses voice reproduction systems in automatic teller machines to provide systematic guidance to customers on how to transact with the bank by using an ATM.

2.

Automatic answering machines. For example, automatic answering machines often take care of telephone enquiries for new telephone numbers in place of old numbers, or vacancy status of a flight/train.

3.

Manufactures of video games make them exciting and interesting by playing an event-based sound from a set of pre-recorded sounds.

4.

Talking alarm clocks. For example, every hour the clock speaks out what is the time by selecting the voice message corresponding to that hour from the set of pre-recorded voice messages. In addition, the clock may speak “its time to wake up” at the time set for alarm.

5.

Talking toys and home appliances also use a voice reproduction system.

Speech Synthesizer A speech synthesizer converts text information into spoken sentences. To produce speech, it combines basic sound units called phonemes. From a given text information, it combines the sequence of words into phonemes, amplifies it, and produces the output through a speaker. Several applications use speech synthesizers, including the following: 1.

For reading out text information to blind persons. For example, we can scan a recently published book using a scanner, convert it into text using OCR software, and then a speech synthesizer can read it out to blind persons. This allows blind persons to know the latest information published in a book as soon as it is printed, rather than wait for the book to appear in Braille.

2.

For allowing those persons who cannot speak, to communicate effectively. For example, a person with this type of disability types the information he/she wants to communicate to another person, and the speech synthesizer converts it into spoken words.

3.

For translation systems that convert an entered text into spoken words in a selected language. For example, a foreign tourist in India may enter a text he/she wants to communicate to an Indian, and the speech synthesizer converts it into spoken words of the selected Indian language.

■ I/O Interfaces

231

Ergonomically Designed Devices Ergonomics is the science that deals with designing and arranging machines and other things in such a way that their users can use them with maximum comfort. This helps in achieving maximum efficiency of the people working on these machines and protecting them from accidents or medical problems caused due to continuous usage of a machine for long hours. For example, prolonged usage of a badly designed keyboard can cause wrist problems, and that of a badly designed monitor can cause eyesight problems. Hence, manufactures of I/O devices try making ergonomically better devices. A few examples are (there are hundreds of such examples): 1. Originally, the keyboard of a computer was attached to its monitor. However, now keyboards are attached to

the monitor with a reasonably long cable, which enables a user to move the keyboard to a comfortable position on the table, or to place it on his/her lap during operation. 2. Many new keyboards have tilt adjustments and hand-rest pads to make their use more comfortable for the

operators. 3. A cordless mouse is more comfortable to use than a wired mouse. 4. A monitor mounted on a ball bearing enables a user to tilt and rotate it to suit his/her comfortable height and

angle of operation. Hence, it is more comfortable to use than a monitor fixed at one angle. 5. Flat-screen monitors have replaced curved-screen monitors because they improve readability and reduce

reflections. 6. Color monitors have replaced monochrome monitors because they improve readability and are more

comfortable to view. 7. Higher resolution monitors are preferred because they prevent flicker of displayed objects, which may lead to

eye problems. 8. Monitors also use special screen coatings for reducing glare on eyes.

I/O INTERFACES I/O interfaces deal with how I/O devices connect to and communicate with a computer system. The commonly used I/O interfaces are described here.

Device Controllers We saw in Chapter 4 that all components of a computer communicate with its CPU through the system bus. Hence, I/O devices need to be connected to the system bus. However, they are not directly connected to a computer’s system bus, but via an intermediate electronic device called device controller. Hence, a device controller is an interface unit between an I/O device and a computer’s system bus. On one side, it communicates with the I/O device connected to it, and on the other side, it communicates with the computer’s CPU and memory through the system bus. A single device controller usually controls multiple I/O devices. It comes in the form of an electronic circuit board (also known as an electronic card) that plugs into the system bus. There are cables from the controller to each device it controls. The cables coming out of the controller terminate usually at the back panel of the main computer box in the form of connectors called I/O ports. Figure 6.38 illustrates how device controllers connect I/O devices to a computer system. Using device controllers for connecting I/O devices to a computer system, instead of connecting them directly to the system bus has the following advantages: 1. Multiple I/O devices can share a controller, thus, allowing us to connect many I/O devices to a system.

232 Chapter 6 ■ Input-Output Devices 2. We can easily upgrade or change I/O devices without any change in the computer system. 3. We can easily plug-in to a computer system those I/O devices that are manufactured by manufacturers other

than the computer manufacturer. This provides greater flexibility of buying I/O devices of ones own choice. Device controllers may or may not have DMA (Direct Memory Access) capability. As Figure 6.40 shows, a device controller without DMA capability transfers data between a computer’s memory and an I/O device connected to it via the CPU of the computer. On the other hand, a device controller with DMA capability transfers data directly between the memory and an I/O device without the help of CPU. Obviously, a device controller with DMA capability can transfer data much faster than a device controller without DMA capability. Hence, almost all modern device controllers have DMA capability.

Memory

CPU

non-DMA path

System bus Multi-port device controller

DMA path

Single-port device controller

I/O port

I/O port

I/O port

I/O port

I/O device

I/O device

I/O device

I/O device

Figure 6.40. Connecting I/O devices to a computer system through device controllers.

Serial and Parallel Ports We connect I/O devices to I/O ports of a device controller, which in turn connects to a computer’s system bus. We plug in I/O devices into I/O ports of a computer system in the same manner as we plug in electrical appliances into electric sockets in a house. I/O ports are broadly of two types: serial ports and parallel ports. They are described here.

Serial Ports A serial port sends data bits one at a time (that is, serially). It has only two wires – one for sending data and another for receiving data. Hence, it sends eight bits of a byte one at a time. Usually, it sends two extra bits with a byte of data to help in the control and timing of communication. A chip called UART on the device controller’s card converts parallel data from the system bus into serial data that can flow through a serial cable or telephone wire. Figure 6.41 illustrates the process. Similarly, the UART converts serial data received by the device controller from the I/O device into parallel data before the device controller sends it to the system bus.

■ I/O Interfaces

233

Bit 0 Stop bit

Bit 1 S Y S T E M

Bit 2

Bit 5 B U S

Data bits of 2nd byte

Bit 3 Bit 4

Start bit

UART of device controller card

Stop bit

Start bit

Data bits of 1st byte

11100111001010110010

Bit 6

Direction of flow of data in this example

I/O P O R T

Serial I/O device

Bit 7 Parity bit

Figure 6.41. Process of data transfer in case of a serial I/O port.

Users use serial ports for connecting slow I/O devices, such as terminal, keyboard, mouse, modem, etc., that send/receive a stream of bytes serially (one bit at a time). RS-232C interface is a popular serial port standard for transmission of data over telephone lines. Figure 6.42 shows the physical appearance of a serial port.

Figure 6.42. Physical appearance of a serial port.

Parallel Ports Parallel ports transfer 8 or 16 bits of data at a time. Hence, a parallel port has 8 or 16 parallel wires for sending and receiving data. Obviously, a parallel port with 8 wires transfers one byte (8 bits) at a time, and one with 16 wires transfers two bytes (16 bits) at a time. Figure 6.43 illustrates the process. Notice that unlike in the case of serial I/O port, conversion of bytes into bit streams and vice-versa is not required in this case. This further leads to faster data transfer rate than in case of serial I/O ports. Users use parallel ports for connecting faster I/O devices such as high-speed printers and plotters, analog-to-digital and digital-to-analog converters, magnetic tape backup units, external hard disk units, etc. Figure 6.44 shows the physical appearance of a parallel port.

234 Chapter 6 ■ Input-Output Devices

Byte 2

Byte 2 Byte 1

Byte 3

S Y S T E M B U S

Byte 1

Byte 3

Bit 0

010

Bit 0

010

Bit 1

111

Bit 1

111

Bit 2

110

Bit 2

110

Bit 3

101

Bit 3

101

Bit 4

000

Bit 4

000

Bit 5

110

Bit 5

110

Bit 6

001

Bit 6

001

Bit 7

010

Bit 7

010

Parity bit 0 1 1

Device controller card

Parity bit

I/O P O R T

Parallel I/O device

011

Figure 6.43. Process of data transfer in case of a parallel I/O port.

Figure 6.44. Physical appearance of a parallel port.

SCSI Interface A computer’s system bus has finite number of slots (called expansion slots) to which we connect device controllers. If every I/O device comes with its own device controller card, we can connect only a limited number of I/O devices to a computer because it will soon run out of available expansion slots. Use of SCSI interface overcomes this problem, As described Figure 6.45. SCSI interface. in Chapter 5, a SCSI interface uses a generic device controller (called SCSI controller) and allows any device having SCSI interface to connect to the SCSI bus of the SCSI controller. That is, instead of connecting device controller cards into the computer’s system bus via the expansion slots, SCSI extends the computer’s system bus outside the computer by way of a cable, and just as we plug one extension cord into another to lengthen circuits; we can plug one SCSI device into another to form a daisy chain.

■ I/O Interfaces

235

Most current implementations of SCSI limit the number of devices to sixteen on a given daisy chain due to bus capacity limitation. This saves expansion slots in a computer for connecting other devices. If none of a computer’s device controller cards has a SCSI interface, we can purchase a separate SCSI interface (as the one shown in Figure 6.45) to plug into an existing parallel port to which we can connect additional SCSI devices.

USB (Universal Serial Bus) Standard We often use USB standard to connect I/O devices to a computer. It is a serial bus, which supports four speeds – a super-speed mode of 5 Gbits/sec, a high-speed mode of 480 Mbits/sec, a full-speed mode of 12 Mbits/sec, and a lowspeed mode of 1.5 Mbits/sec. USB version 3.0 supports super-speed mode, version 2.0 supports high-speed mode, while the earlier version 1.1 supported full-speed and low-speed modes. The latest USB version 4.0 promises to support 40 Gbits/sec. USB is host controlled in the sense that there can be only one host per bus. USB standard aims at and is limited to single point-to-point connections such as a mobile phone and personal organizer, and not multiple hub, multiple device desktop configurations. The USB host is responsible for undertaking all transactions and scheduling bandwidth. USB uses a tiered star topology, similar to that of 10BaseT Ethernet. This imposes the use of a hub somewhere for connecting devices to USB. Many devices have USB hubs integrated into them. For example, keyboard and monitor contain a hub connected to a computer’s USB port. We can connect other I/O devices to the keyboard or monitor using the hub they have. For example, we often plug a mouse into the back of a keyboard, and a digital camera into the front/back/side of a monitor. USB’s tiered star topology, rather than daisy chaining devices together, has the following benefits: 1.

We can monitor power to each device and even switch off a device, if an over current condition occurs without disrupting other USB devices.

2.

It can support all four types (super-speed, high-speed, full-speed, and low-speed) of devices, with the hub filtering out transactions of different speed, so that low-speed devices do not receive high speed transactions.

At any given time, we can connect up to 127 devices to a single USB. If we need to connect more devices, we can add another port/host. While earlier USB hosts had two ports, the latest ones support 4 and 5 port host cards with an internal port for hard disks. The early hosts had one USB controller, and thus, both ports shared the same available USB bandwidth. As bandwidth requirements grew, manufacturers are now making multi-port cards with two or more controllers, allowing individual channels for each port. USB supports plug-and-play facility with dynamically loadable and unloadable drivers. When a user plugs in a device into the bus, the host detects this addition, interrogates the newly inserted device, and loads the appropriate driver. Once the user finishes using the device, he/she pulls the cable out and the host detects its absence and automatically unloads the driver. A pen drive plugs into a USB port of a computer. Another important feature of USB is its support for bus-powered devices – devices that obtain its power from the bus and require no batteries, or external plugs, or additional cables. Additionally, a USB device enters suspend mode automatically when there is no activity on the bus for more than 3.0 ms. It then has a further 7.0 ms to shutdown the device and draw no more than the designated suspend power. Hence, it draws only the rated suspend power from the bus 10.0 ms (3 ms + 7 ms) after bus activity stops. This feature makes USB devices power-efficient.

236 Chapter 6 ■ Input-Output Devices

Points to Remember 1.

Input-output devices (abbreviated I/O devices) provide the capability to a computer to communicate with its external environment (its users). They are also known as peripheral devices.

2.

An input device is an electromechanical device that accepts data from outside world and translates them into a form that a computer can interpret.

3.

Keyboard devices are the most commonly used input devices today. They allow data entry into a computer by pressing a set of keys (labeled buttons) mounted on a keyboard.

4.

A graphical user interface (GUI) provides a screen with graphic icons (small images on the screen) or menus and allows a user to make rapid selections from them to give instructions to a computer.

5.

Point-and-draw devices are input devices used to rapidly point to and select a graphic icon or menu item from multiple options displayed on a screen. Many of these devices are also useful for effectively creating graphic elements on the screen such as lines, curves, and freehand shapes. Some commonly used point-and-draw devices are mouse, trackball, joystick, electronic pen, and touch screen.

6.

Data scanning devices are input devices that allow data entry directly from the source documents. Some of these devices are also capable of recognizing marks or characters.

7.

An image scanner is an input device that translates paper documents into an electronic format for input to a computer. Input documents may be typed text, pictures, graphics, or even handwritten material. Image scanners use optical technology to convert an image into electronic form.

8.

An optical character recognition (OCR) device is a scanner equipped with character recognition software. Users use it for scanning text documents and converting the scanned bitmap images of characters into equivalent ASCII text, which a computer can interpret as letters, numbers, and special characters for word processing.

9.

An optical mark reader (OMR) is a scanner that can recognize a pre-specified type of mark made by pencil or pen. We can use OMR device for any input data that is of a choice or selection nature.

10. Bar codes represent alphanumeric data by a combination of adjacent vertical lines (bars) by varying their width and spacing between them. A bar-code reader is a device for reading (decoding) bar-coded data. 11. Banking industry uses Magnetic-ink character recognition (MICR) technology for faster processing of large volume of cheques. Besides enabling faster processing of cheques, this technology also ensures greater accuracy of data entry because of mostly pre-printed information on the cheque and direct feeding of the cheques to the computer. 12. A digitizer is an input device used for converting (digitizing) pictures, maps, and drawings into digital form for input to computers. This enables re-creation of the drawing from the stored information and easy incorporation of changes in the drawing, whenever required. 13. Electronic cards are small plastic cards having encoded data appropriate for the application for which they are used. An electronic-card reader, normally connected to a computer, reads the data encoded on an electronic card and transfers it to the computer for further processing. 14. Depending on the manner in which they encode data, electronic cards are of two types: magnetic strip cards and smart cards. Magnetic strip cards store encoded data on a magnetic strip attached to the card, while smart cards have a built-in microprocessor chip in whose memory the encoded data is stored. 15. Speech recognition devices are input devices that allow a user to input data to a computer system by speaking to it. They are of two types: speaker-dependent and speaker-independent. Speaker-dependent systems recognize the speech of only a single individual or a few individuals, while speaker-independent systems can recognize words spoken by anyone. 16. A vision-input system consists of a digital camera to accept input by seeing an object. Input data in this case is normally an object’s shape and features in the form of an image. 17. An output device is an electromechanical device that accepts data from a computer and translates them into a form that is suitable for use by outside world (users). 18. Computer output generated by output devices are of two types – soft-copy output and hard-copy output. Soft-copy output is temporary in nature because it does not appear on a paper or some material that a user can carry for showing to others, or for filing and use later when he/she is not using a computer. Hard-copy output is permanent in nature because it appears on a

■ Points to Remember

237

paper or some material that a user can carry for showing to others, or for filing and use later when he/she is not using a computer. 19. Monitors generate soft-copy output by displaying an output on a screen. 20. A monitor and a keyboard together form a video display terminal (VDT) often referred to as just terminal. A terminal serves as both an input and output device. It is the most popular input/output (I/O) device used today. 21. Depending on their local processing capability, we classify terminals as dumb, smart, and intelligent. A dumb terminal is a low-cost terminal, without any local processing capability. A smart terminal has local data editing capability and the ability to consolidate input data prior to sending it to the computer. It has a microprocessor and some internal storage in addition to I/O capabilities. An intelligent terminal is a small computer by itself that has extensive local data processing capability. It consists of a built-in microcomputer and users can program it. 22. A terminal emulator is a software program that runs on a PC or workstation, communicates with the network interface over a serial port on the PC or workstation, and pretends that it is a terminal. 23. Monitors often use privacy filters to prevent others sitting/standing nearby from viewing the contents displayed on it. 24. Printers are the most popular hard-copy output devices used today. Based on the printing technology used, we classify printers as dot-matrix printers, inkjet printers, drum printers, chain/band printers, and laser printers. According to printing approach that a printer uses, we classify printers as impact printers and non-impact printers. 25. Dot-matrix printers are character printers that form characters and images as patterns of dots. 26. Inkjet printers are character printers that form characters and images by spraying small drops of ink on paper. 27. Drum printers are line printers that print characters by striking a set of hammers on an inked ribbon and paper placed against a solid cylindrical drum with characters embossed on its surface in the form of circular bands. 28. Chain/band printers are line printers that print characters by striking a set of hammers on an inked ribbon and paper placed against a metallic chain/band on which all characters of the character set supported by the printer are embossed. 29. Laser printers are page printers that produce high quality output by forming characters and images with tiny ink particles. 30. Hydra printers are multifunctional devices that perform the functions of two or more of the following office equipment – printer, copy machine, and scanner. 31. A plotter is an ideal output device for architects, engineers, city planners, and others who need to generate high precision, hard-copy graphic output of varying sizes. Two types of plotters in common use are drum plotter and flatbed plotter. 32. 3D printers print (create) 3D objects by using additive manufacturing techniques. 33. Some commonly used 3D printing technologies include Fused Deposition Modeling (FDM), STereoLithography (STL), Digital Light Processing (DLP), and Selective Laser Sintering (SLS). 34. Computer Output Microfilm (COM) is an output device that records computer output as microscopic filmed images on a sheet of microfilm. It uses a microfilm recorder for recording output on a microfiche, and a microfilm reader to view recorded information. 35. Screen image projector is an output device, which is used to project information from a computer on a large screen (such as a cloth screen or wall) so that a group of people can view it simultaneously. 36. A voice response system enables a computer to talk to a user. Two types of voice response systems are – voice reproduction system and speech synthesizer. A voice reproduction system produces audio output by selecting an audio output from a set of pre-recorded audio responses, while a speech synthesizer converts text information into spoken sentences. 37. Ergonomically designed I/O devices aim at achieving maximum efficiency of the people working on them and protecting them from accidents or medical problems caused due to continuous usage of a device for long hours. 38. I/O interfaces deal with how I/O devices connect to and communicate with a computer system. 39. A device controller is an interface unit between an I/O device and a computer’s system bus. On one side, it communicates with the I/O device connected to it, and on the other side, it communicates with the computer’s CPU and memory through the system bus. 40. I/O devices connect to I/O ports of a device controller, which in turn connects to a computer’s system bus. I/O devices plug into I/O ports of a computer system. I/O ports are of two types – serial ports and parallel ports.

238 Chapter 6 ■ Input-Output Devices 41. A user can use a serial port of a computer to connect any device that sends or receives a stream of bytes serially, one bit at a time. Users normally use it for connecting slow I/O devices such as terminal, keyboard, mouse, modem, etc. 42. A parallel port can handle higher volume of data than a serial port because it transfers 8 or 16 bits of data at a time. Users normally use it for connecting faster I/O devices such as printer, analog-to-digital and digital-to-analog converters, etc. 43. SCSI interface uses a generic device controller (called SCSI controller) and enables connection of any device (having SCSI interface) with the SCSI bus of the SCSI controller. This helps save expansion slots in a computer for connecting other devices. 44. We often use USB (Universal Serial Bus) standard to connect I/O devices to a computer. It is a serial bus, which supports four speeds – a super-speed mode of 5 Gbits/sec, a high-speed mode of 480 Mbits/sec, a full-speed mode of 12 Mbits/sec, and a low-speed mode of 1.5 Mbits/sec.

Questions 1.

Why are I/O devices necessary for a computer system?

2.

What are peripheral devices? Why are they so called?

3.

Differentiate between an input and an output device. Can a device be used as both an input and an output device? If no, explain why. If yes, give an example of such a device.

4.

Why are I/O devices slow as compared to the speed of primary storage and CPU?

5.

What is an input device? Name some commonly used input devices.

6.

What are keyboard devices? Differentiate between general-purpose and special-purpose keyboards.

7.

Describe the organization of the keys on a QWERTY keyboard.

8.

Explain the use of the following types of keys found on a keyboard: (a) Arrow keys (c) Alphanumeric keys (b) Soft keys (d) Special function keys

9.

What are soft keys on a keyboard? Why are they so called? How are they used?

10.

Name some special function keys along with their use.

11.

Write examples of two special-purpose keyboards.

12.

What is a keyboard buffer? How does it help in the operation of a keyboard?

13.

What are software-simulated keys? How do they help in faster data entry?

14.

What are point-and-draw devices? Name some commonly used point-and-draw devices.

15.

What is a mouse? Explain how a user uses it to notify the system of a particular user choice out of a given set of choices on a monitor’s screen.

16.

What is a graphics cursor? What is its relationship with a mouse?

17.

List and describe the basic operations used to carry out various functions possible with a mouse.

18.

Differentiate between a mechanical and an optical mouse.

19.

Differentiate between a serial and a bus mouse.

20.

Differentiate between a wired and a cordless mouse.

21.

What is the minimum number of buttons required in a mouse? How does it help having more number of buttons than the minimum requirement?

22.

What is a trackball? How is it different from a mouse?

23.

Explain how a user uses a trackball to notify the system of a particular user choice out of a given set of choices on a monitor’s screen.

24.

What is a joystick? How is it different from a trackball? Write some uses of a joystick.

■ Questions 25.

Explain how a user uses an electronic pen as an input device.

26.

Describe the working mechanism of a light pen input device.

27.

Describe some applications for which writing pen with pad are suitable as an input device.

28.

What is a touch screen device? Explain the technology used in making touch screen devices.

29.

Write three applications for which touch screen is the most suitable input device.

239

30.

What is an information kiosk? Write three uses of an information kiosk.

31.

What are data scanning devices? How do they help in improving input data accuracy as compared to keyboard devices?

32.

What is an image scanner? Explain how it inputs an image document.

33.

What is bit map representation of an image? Draw bit map representation of the letter ‘A’. Use any suitable grid size for your representation.

34.

What is the minimum number of bits required to encode each grid point (pixel) in bit map representation of an image? How does it help having more number of bits than the minimum requirement?

35.

Differentiate between a flatbed and a hand-held image scanner.

36.

What are the limitations of an image scanner when we use it for inputting text documents? How an OCR device overcomes these limitations?

37.

What is an OCR device? Write its advantages and limitations for inputting text documents.

38.

Explain how OCR devices convert bit map images of characters to equivalent ASCII codes.

39.

Explain why OCR devices for handwriting recognition are more complex and difficult to design than those for printed text.

40.

What is an OMR device? Explain the technique used by it for recognition of marks. Write some applications that make use of it.

41.

Differentiate between an OMR device and an OCR device.

42.

What are bar codes? How does a bar-code reader read bar-coded data? Write a use of a bar-code reader.

43.

What is the Universal Product Code (UPC)? Which input device is suitable for inputting data based on UPC?

44.

What is an MICR device? Which industry is the primary user of MICR?

45.

Explain how an MICR device helps in faster processing of bank cheques with greater accuracy.

46.

What is the main limitation of MICR technology?

47.

Write the similarities and differences between an OCR device and an MICR device.

48.

What is a digitizer? What are its two main components? What are its main areas of application?

49.

Explain how we can use a digitizer to convert a drawing into digital form for storage in computers.

50.

What is an electronic card? Write two applications that can make use of electronic cards effectively.

51.

What is an automatic teller machine (ATM)? Explain how a customer transacts with a bank using an ATM.

52.

Explain how an organization can use electronic cards to control access of various categories of people to physically secured areas.

53.

What is a smart card? How is it different from a magnetic strip card?

54.

Explain how we can use smart cards as electronic money.

55.

What is a speech recognition device? Write three applications of speech recognition systems.

56.

Explain how a speech recognition device recognizes and acts upon a spoken input data.

57.

What is a vision-input system? Write three applications of vision-input systems.

58.

Explain how a vision-input device recognizes a given object and takes appropriate action.

59.

Differentiate between speaker-dependent and speaker-independent speech recognition systems. Which one is more difficult to design? Write reasons for your answer.

240 Chapter 6 ■ Input-Output Devices 60.

How are graphs and pictures fed to a computer?

61.

What is an output device? Name some commonly used output devices.

62.

Differentiate between soft-copy output and hard-copy output.

63.

Name two output devices used for producing soft-copy output and two output devices used for producing hard-copy output.

64.

What is a computer terminal? Why is it so called?

65.

What is a monitor device? Name the two basic types of monitors along with their relative advantages and disadvantages.

66.

Explain how a CRT monitor displays an output.

67.

Why does the display mechanism of a CRT monitor needs to refresh CRT screen?

68.

Why does the display mechanism of a CRT monitor turns off the electron beam during horizontal and vertical traces?

69.

Why does the display mechanism of a CRT monitor represents displayed characters and images as a pattern of dots?

70.

71.

Explain the meaning of the following terms with respect to a CRT monitor: (a) Scan line (e) Interlaced scan (b) Horizontal trace (f) Resolution (c) Vertical trace (g) Refresh rate (d) Progressive scan Differentiate between progressive scan and interlaced scan monitors. Which type of monitor has better quality and why?

72.

Explain how a color monitor displays color images.

73.

Differentiate among CGA, EGA, VGA, and super VGA standards for color monitors.

74.

What is a video RAM? What factors normally decide its capacity?

75.

A monitor has a resolution of 800x600. It supports 256 different colors. Calculate the video RAM capacity (in bytes) required by this monitor.

76.

What is a flat panel monitor? Where is it commonly used?

77.

Explain how LCD monitors display images.

78.

Write relative advantages and limitations of a CRT monitor and a flat-panel monitor.

79.

Differentiate among dumb, smart, and intelligent terminals.

80.

What is a terminal emulator? What type of scenario requires it?

81.

What is a privacy filter? How does it work?

82.

What is a printer? What are the commonly used types of printers?

83.

Differentiate between impact and non-impact printers. Write their relative advantages and disadvantages. Write names of two printers of both types.

84.

What are the units used for measuring printer speed. Also, specify which unit is suitable for measuring the speed of what type of printer.

85.

What is the unit for measuring printer output quality? According to this feature, what are the common classifications of printers?

86.

Can a printer support multiple scripts simultaneously? If no, explain why. If yes, name two types of printers with this capability.

87.

Explain the printing mechanism of dot-matrix printers.

88.

Write features and limitations of dot-matrix printers.

89.

Explain the printing mechanism of inkjet printers.

90.

Write features and limitations of inkjet printers.

91.

Write relative advantages and limitations of an inkjet printer and a dot-matrix printer.

92.

Explain the printing mechanism of drum printers.

■ Questions 93.

Write features and limitations of drum printers.

94.

Explain the printing mechanism of chain/band printers.

95.

Write features and limitations of chain/band printers.

96.

Differentiate between a drum printer and a chain/band printer. Write their relative advantages and limitations.

97.

Explain the printing mechanism of laser printers.

98.

Write features and limitations of laser printers.

99.

What is a hydra printer? How is it more useful than a normal printer?

241

100. Name four types of printers that modern computer systems use. Describe the print mechanism of any one of them. 101. What is a 3D printer? Explain the basic technique used by 3D printers. 102. Explain the three steps that 3D printers require to print a 3D object. 103. Name three commonly used 3D printing technologies. Describe any one of them. 104. What is a plotter? What types of users need it? 105. Explain the working mechanism of a drum plotter. 106. Explain the working mechanism of a flatbed plotter. 107. What is a COM device? Explain how it records information and how a user retrieves information using a COM device. 108. Write advantages and limitations of a COM system as compared to a printer. 109. For what type of applications is a COM system most suitable? Write its typical users. 110. What is a screen image projector? Write its uses. 111. What is a voice response system? Write its applications. 112. What is a voice reproduction system? How does it function? Write its applications. 113. What is a speech synthesizer? How does it function? Write its applications. 114. What are ergonomically designed devices? Write five examples of such devices. 115. Write five features of keyboards and monitors that make computer terminals easier to use. 116. What is a device controller? Explain with a diagram its role in connecting I/O devices to a computer. 117. Why do computers use device controllers for connecting I/O devices, instead of connecting them to the system bus directly? 118. Differentiate between device controllers with DMA capability and without DMA capability. Which one can transfer data faster from an I/O device to a computer’s memory and why? 119. What is an I/O port? Differentiate between serial and parallel ports. 120. What is a serial port? Why is it so called? Explain how an I/O device connected to a serial port of a computer system transfers data to the computer’s system bus. 121. What is a parallel port? Why it so called? Explain how an I/O device connected to a parallel port of a computer system transfers data to the computer’s system bus. 122. What is a SCSI interface? Explain how it helps in expanding the capability of a computer system in having more I/O devices connected to it. 123. Define the following terms: (a) SCSI controller (b) SCSI bus (c) SCSI device 124. What is an expansion slot? Explain how a SCSI interface helps in saving expansion slots in a computer system for connecting other devices. 125. What are the advantages of a SCSI controller over a conventional device controller? 126. Write key features of USB as a standard interface for connecting I/O devices to a computer.

Software

We often use the terms “hardware” and “software” in connection with computers. Hardware refers to the physical devices of a computer system. Thus, input, storage, processing, control, and output devices are hardware. In fact, the earlier few chapters covered the hardware of computer systems. In this chapter, we will learn about software, software development, and examples of some popular software.

BASIC CONCEPTS AND TERMINOLOGIES What is Software? A computer cannot do anything on its own. We need to give instructions to it to make it do a job desired by us. Hence, it is necessary to specify a sequence of instructions a computer must perform to solve a problem. Such a sequence of instructions written in a language understood by a computer is called a computer program. A program controls a computer’s processing activity, and the computer performs precisely what the program wants it to do. When a computer is using a program to perform a task, we say, it is running or executing that program. The term software refers to a set of computer programs, procedures, and associated documents (flowcharts, manuals, etc.) describing the programs, and how they are to be used. A software package is a group of programs that solve a specific problem or perform a specific type of job. For example, a word-processing package may contain programs for text editing, text formatting, drawing graphics, spelling checking, etc. Hence, a multipurpose computer system, like a personal computer, has several software packages, one each for each type of job it can perform.

Relationship between Hardware and Software The following points explain the relationship between hardware and software:

■ Basic Concepts and Terminologies

243

1.

Both hardware and software are necessary for a computer to do useful job. Both are complementary to each other.

2.

We can load different software on the same hardware to make a computer perform different types of jobs.

3.

Except for upgrades (like increasing main memory and hard disk capacities, or adding speakers, modems, etc.), hardware is normally a one-time expense, whereas software is a continuing expense. We buy new software for running on the same hardware as and when need arises, or funds become available.

Types of Software Although, the range of software available today is vast and varied, we classify most software into two categories: 1.

System software. System software is a set of one or more programs, which controls the operation and/or extends the processing capability of a computer system. It makes the operation of a computer system more effective and efficient. It helps hardware components work together, and provides support for the development and execution of application software (programs). Good system software enables development and execution of application packages on a computer system with less time and effort. A computer without some kind of system software would be ineffective and most likely impossible to operate. Programs included in a system software package are called system programs, and programmers who prepare system software are referred to as system programmers. Some commonly known types of system software are operating systems, programming language translators, utility programs, performance monitoring software, and communications software. They are described in subsequent chapters.

2.

Application software. Application software is a set of one or more programs, which solves a specific problem, or does a specific task. For example, payroll processing software, examination results processing software, railway/airline reservation software, and computer games software are application software. Similarly, a program written by a scientist to solve a research problem is also application software. Programs included in an application software package are called application programs, and programmers who prepare application software are referred to as application programmers. Today, millions of application software packages are available for a wide range of applications. They range from simple applications such as word processing, inventory management, preparation of tax returns, banking, hospital administration, insurance, publishing, to complex scientific and engineering applications such as weather forecasting, space shuttle launching, oil and natural gas exploration, design of complex structures like aircrafts, ships, bridges, sky-rise buildings, etc. With so many applications available, it is not possible to categorize them all and to cover them here. Later in the chapter, we describe some commonly known application software.

Logical System Architecture Figure 7.1 shows the logical architecture of a computer system. It depicts the relationship among hardware, system software, application software, and users of a computer system. At the centre is hardware comprising of physical devices/components of the computer system. System software layer surrounds the hardware, hiding hardware details of the system from application programmers. It defines the operating and programming environment of the computer system and coordinates operations of various hardware devices for optimizing the performance of all devices. Application software layer then surrounds the system software. It consists of a wide range of application software. Finally, the users’ layer consists of the user interfaces provided by the application software. Different application software usually provides different user interfaces. Hence, how a user interacts with the computer system depends on which application he/she is using.

Chapter 7 ■ Software

244

Firmware Firmware refers to a sequence of instructions (software) substituted for hardware. For example, when cost is more important than performance, a computer system architect might decide not to use special electronic circuits (hardware) to multiply two numbers, but instead write instructions (software) to cause the machine to accomplish the same function by repeated use of circuits designed already to perform addition. This software (known as firmware) is stored in a read-only memory (ROM) chip of the computer, and is executed (used) whenever the computer has to multiply two numbers. Hence, firmware is software substituted for hardware and stored in read-only memory. USERS APPLICATION SOFTWARE SYSTEM SOFTWARE HARDWARE Physical devices/components of the computer system Software that constitute the operating and programming environment of the computer system Software that do a specific task or solve a specific problem Users normally interact with the system via the user interfaces provided by the application software Figure 7.1. Relationship among hardware, system software, application software, and users of a computer system.

Initially, vendors supplied only system software in the form of firmware. However, many vendors now supply even application programs as firmware. Vendors also program dedicated applications in this fashion and make them available as firmware. Because of rapid improvement in memory technology, firmware is frequently a cost-effective alternative to wired electronic circuits, and its use in computer design has been increasing gradually. In fact, increased use of firmware has today made it possible to produce smart machines of all types. These machines have microprocessor chips with embedded software.

Middleware In early days of computer networks, the two-tier, client-server system architecture [shown in Figure 7.2(a)] was used to implement distributed applications (computer networks and distributed applications are described later in the book). In this two-tier system architecture, one or more server computers served several client computers connected to them. This architecture was inflexible and had its own limitations due to the following reasons: 1.

Programmers had to include the code for management and support services (such as directories for locating resources, authentication for handling security, exception management for handling failures, and coscheduling of networked resources for better performance) within the client and server parts of the application software.

2.

Programmers had to synchronize client and server processes for exchange of messages between them (they used synchronous mode of communication rather than asynchronous mode, which is more flexible).

3.

Programmers had to include the code for business application logic inside the user interface on the client, or within the application software on the server, or both.

■ Basic Concepts and Terminologies

Client computer

Server computer

Client part of application software – Includes user interface, application logic, messaging services, and management and support services

Server part of application software – Includes applicationspecific services, application logic, messaging services, and management and support services

Operating system and network interfaces

Operating system and network interfaces

245

Network connection (a) Two-tier, client-server architecture

Client computer

Server computer

Client part of application software – Includes user interface and business and application logic

Server part of application software – Includes application specific services

Middleware services – Includes APIs and client part of messaging, management, and support services

Middleware services – Includes APIs and server part of messaging, management, and support services

Operating system and network interfaces

Operating system and network interfaces

Network connection (b) Three-tier, client-server architecture Fig. 7.2. Illustrating the use and location of middleware.

As a result, there was close knitting between client and server systems, making independent development of interoperable client and server software difficult. Hence, rapid development and deployment, ease of management, and portability of distributed applications were difficult. Distributed application developers invented the three-tier system architecture [shown in Figure 7.2(b)] to overcome these problems. The basic idea here was to have a separate software layer, which acts as “glue” between the client and server parts of an application. It provides a programming abstraction that masks the heterogeneity of underlying network, hardware, and operating systems from application programmers. This software layer is known as middleware because it sits in the middle, between the operating system and applications. In general, middleware is a set of tools and data that help applications use networked resources and services.

Chapter 7 ■ Software

246

ACQUIRING SOFTWARE Earlier, application and system software were included in the purchase price of a computer. Today, software is usually not included in the purchase price of a computer. For most computer manufacturers, the purchase price of a computer includes only its hardware and a minimum of system software. A customer has to pay extra charges for additional system software and application software that he/she wants to purchase. We can obtain the desired software in one or more ways described here. The description also provides the relative advantages and limitations of each way of obtaining software.

Buying Pre-written Software Thousands of pre-written software packages are available today. If we can find a software package that meets our requirements, purchasing it is the best option. We follow the following steps in selecting and buying a pre-written software package: 1.

Prepare a list of all available software packages that can perform the desired task(s).

2.

From this list, select those software packages only that meet the system specifications. For example, we should check for compatibility with user’s available/planned hardware, I/O devices, Operating System, etc.

3.

Now choose the best one (based on factors such as supported features, duration of warranty support, cost, etc.) from the list of those selected in Step 2.

4.

Now find out the source from where you can purchase the chosen software at the cheapest price. Different vendors offer different discount rates on the list price, and selecting the best vendor in terms of price and after-sale support is important.

Following are the advantages and limitations of buying a pre-written software package: 1.

Pre-written software packages usually cost less because many customers share their development and maintenance cost.

2.

With a pre-written software package, a user can start the planned activity almost immediately. The user need not wait for the software to be developed and tested. This may be important, if the development and testing efforts involve several months.

3.

Pre-written software packages are usually general purpose, so that they can meet the requirements of as many potential users as possible. Due to this, many times, the operating efficiency and capability to meet the specific needs of a user more effectively is not as good for pre-written software packages as for in-house developed software packages.

Ordering Customized Software If none of the available pre-written software packages meet the specific requirements of a user (an organization or an individual), it becomes necessary for the user to create a customized software package. If the user has an in-house software development team, the user can create the software package in-house. However, if such a team does not exist in-house, the user must get it created by another organization by placing an order for it. We follow the following steps for this:

■ Acquiring Software

247

1.

The user prepares a list of all user requirements carefully.

2.

The user then floats a tender for inviting quotations for creation of the requisite software. Sometimes, the user contacts few software houses instead of floating a tender for quotations.

3.

After receiving the quotations, the user selects a few of them for further interaction based on the cost quoted by them, their reputation in the market, their submitted proposal, etc.

4.

The user then interacts with the representative(s) of each of the selected vendors. Based on this interaction, the user chooses a vendor to offer the contract for creation of the requisite software.

5.

The chosen vendor then creates the software package and delivers it to the user. Often, the vendor has to closely interact with the user during the software development process.

The vendor need not develop everything from scratch to meet the user’s requirements. If one or more pre-written software packages meet the user’s requirements partially, the vendor may use them along with its own developed software in such a manner that the overall software package so created meets the user’s requirements fully. This helps in reducing the development cost and time needed for creation of the required software package. If a user has to order for both hardware and software for his/her requirement, the user may choose to place the order for both to a single vendor. The vendor develops the software on the chosen hardware, and delivers the software along with the hardware to the user. We refer to this as end-to-end solution or turnkey solution. Following are the advantages and limitations of ordering a customized software package rather than developing it inhouse: 1.

The user need not maintain its own software development team. Maintaining and managing such a team is expensive, and may not be justified for an organization not needing to develop software on a regular basis.

2.

It is easier to carry out changes in the software, if an in-house team develops it. For ordered customized software, the user needs to always depend on the vendor for carrying out the changes, and the vendor often charges separately for each request for change.

Developing Customized Software If none of the available pre-written software packages meet the specific requirements of an organization, and if the organization has an in-house software development team, the organization may choose to develop a customized software package in-house for its requirements. We follow the following steps for this: 1.

The organization first constitutes a project team to develop the software.

2.

The team studies the requirements and plans functional modules for the software.

3.

It then identifies the functional modules, which the team has to develop. It also identifies existing pre-written software, which can meet the requirements of other functional modules.

4.

For the functional modules that the team needs to develop, the team next plans their programs and does coding, testing, debugging, and documentation for the planned programs.

5.

The team then tests all the modules in an integrated manner.

6.

The team then deploys the software for use by users.

7.

The users then use the software and the project team members responsible for maintenance activities maintain it.

Following are the advantages and limitations of developing a customized software package in-house by an organization rather than getting it developed by an outside party:

Chapter 7 ■ Software

248 1.

It is easier to carry out changes in the software, if the organization develops it in-house.

2.

Developing software in-house means a major commitment of time, money, and resources for the organization because the organization needs to maintain and manage an in-house software development team.

Downloading Public-domain Software Public-domain software is software available free or for a nominal charge from the bulletin boards or user-group libraries on the Internet. Basic objective of the creators of such software is to popularize their software to as many users as possible. Users are encouraged to copy such software and try them out. Usually, the creators share the software freely with other users. Hence, we also refer to public-domain software as shareware/freeware. They are also known as community-supported software as mostly the authors do not support the product directly and users of the software support and help each other. While some shareware software remain full-featured and free perpetually, some other have to be bought to use all features (such partial packages are referred to as Lite/Free/Personal edition) or after some use (referred to as trial period). Another type of public-domain software becoming popular among users, and fellow programmers equally, are those that come with their source code. We refer to such software as Open Source Software (OSS). Usually, open source software allows a user to download, view, modify, and distribute modified source code to others. There are special licensing systems for open source software and their source code. They promote open source movement and protect the copyright of original and subsequent authors of open source software. General Public License (GPL) of GNU organization and BSD License from Berkeley Software Division of University of California are some of the most popular licensing systems in place and used world over. Not all open source software is necessarily free, and not all free software is necessarily open source. If a user finds a public-domain software suitable for his/her requirements, he/she can obtain it by downloading it from the Internet. Following are the advantages and limitations of downloading and using public-domain software packages: 1.

Usually, they are free and accompanied with their source code.

2.

A user can download and use them immediately. The user need not wait to start the planned activity until a team develops the required software.

3.

Normally, the creators of OSS do not test the software properly before release, and their support is poor as compared to commercial software. Hence, OSS may fail during operation, and even if a user reports a bug, the creators may not fix it soon.

SOFTWARE DEVELOPMENT LIFE CYCLE (SDLC) Someone must develop all software, no matter by which source we acquire software. Developing software, putting it to use, and maintaining it is a complex process involving the following phases: 1.

Requirement Specification

2.

System Analysis and Design

3.

Implementation (also known as Construction or Code Generation)

4.

Testing and Debugging

■ Software Development Life Cycle (SDLC) 5.

Deployment (also known as Installation)

6.

Maintenance

249

Evolving software products through these phases is known as Software Development Life Cycle (SDLC) model. In this model, we go through the above listed phases sequentially, with each phase feeding in inputs to the next phase [Figure 7.3]. Development process proceeds from one phase to the next in a purely sequential manner. Hence, the next phase in the life cycle starts only after the defined set of goals are achieved for its previous phase and it is completed fully, perfected, and frozen. This model is also known as waterfall model because it is a sequential development process, which flows steadily downwards (like a waterfall) through the various phases of the process.

Requirement specification System analysis and design

Implementation

Testing and debugging

Deployment

Maintenance

Figure 7.3. Phases of Software Development Life Cycle (SDLC) model. It is also known as Waterfall model.

A software development team performs the various activities involved in SDLC model. For small software this may be a one-person team (who alone carries out all the activities of all phases), whereas for large software the team may consist of several tens or even hundreds of people with different types of skills. The main activities performed in the various phases of SDLC model are: 1.

Requirement specification. The team defines all possible requirements of the software in this phase. These include functionality, capability, performance, user interface, inputs, and outputs requirements. The team records the defined requirements in a requirement specification document, which serves as input to the next phase of the model.

2.

System analysis and design. The team studies the requirements specified in the first phase with respect to available hardware and software technologies and prepares a system design document. The system design document defines the overall system architecture. It specifies the various hardware and software components of the system and the interfaces between the components. It includes the hierarchy of software components, rules for component selection, and interfaces between components. The design document serves as input to the next phase of the model.

Chapter 7 ■ Software

250 3.

Implementation. This phase is also known as construction or code generation because in this phase, the team constructs (codes in selected programming languages) the various software components specified in the system design document. While constructing the software components, the team keeps track of the hardware components specified in the system design document so that the constructed software components are compatible with the specified hardware components. To construct a software component, the team first divides it into modules, and then codes each module separately. The team does this, especially for large software, to enable multiple programmers to work parallely on different modules so that they can carry out the implementation phase faster. While dividing software components into modules, the team also defines module interfaces to enable interaction between the modules. The team codes and tests each module independently. This type of testing of a module done by the programmer who developed the module is referred to as unit testing. Unit testing mainly verifies if a module meets its specifications.

4.

Testing and debugging. In this phase, the team integrates the independently developed and tested modules into a complete system. The team then tests the integrated system to check if all modules coordinate properly with each other and the system as a whole behaves as per the specifications. They debug (correct) any bug (error) that they find during integrated system testing, and repeat testing of that functionality of the system. After the team completes this phase, the software is ready for release and deployment.

5.

Deployment. Once the team tests the software and removes all known errors, the team deploys the software at user(s) site on (or along with) associated hardware for use by the intended user(s). At this stage, the team phases out old system (if any in operation) and phases in the new system and puts it into operation. The team also evaluates the system against the specified requirements in this phase.

6.

Maintenance. Some problems with the system, which the team is unable to find during various phases of the development life cycle of the system, surface only after the team deploys the system and puts it in operation. The team fixes these problems in the system in its maintenance phase. Additionally, the team needs to make changes in the system from time-to-time to take care of new user requirements, changes in technology, changes in organizational policies, etc. The team incorporates all these changes in the system in its maintenance phase. Hence, maintenance phase virtually lasts for the entire life of the software after its deployment.

Advantages of SDLC Model Many software engineering texts and courses use the waterfall model as a beginning example of software development model. It has the following advantages: 1.

It is simple to understand and easy to follow because the development process progresses sequentially through a well defined set of discrete, easily understandable, and easily explainable phases.

2.

It provides a disciplined and structured approach to software development.

3.

It also enables easy demarcation of milestones in the development process.

4.

It is now a well-established fact that time spent early on in planning and design of software before coding it makes better economic sense in software lifecycle. For example, a bug found in early stages (such as during requirement specification phase or system analysis and design phase) is easier and cheaper to fix than the same bug found in a later phase. The waterfall model supports this central idea of economy of software development.

5.

The model places emphasis on documentation (such as need for requirement specification document, system design document, implementation document, testing document, etc.). Documentation helps new team members or even entirely new teams to familiarize themselves and carry on the development activity from any intermediate stage in the development process.

■ Software Development Life Cycle (SDLC)

251

Limitations of SDLC Model Many have criticized the waterfall model because of its following drawbacks: 1.

In a project of reasonable size and complexity, it is impossible to perfect one phase of software development before moving on to the next phase.

2.

Often, clients are not clear about their requirements in the beginning. They are able to articulate and define their requirements only when they see a working prototype of the system they desire. Hence, following the phases sequentially (as required in the waterfall model) may not be possible in such cases.

3.

Often, clients keep changing their requirements constantly, and software development team has to accommodate several (if not all) of these proposed changes. If clients propose such changes during the implementation phase (after completion of system design), the team must revisit the requirement specification as well as system analysis and design phases to accommodate the new requirements, invalidating some of the original specifications and system design. Hence, following the phases sequentially (as required in the waterfall model) may not be possible in such cases.

4.

Often, designers are not aware of future implementation problems when designing and preparing the architecture of unimplemented software. The team may realize only during the implementation phase that certain aspect of the design is difficult to implement, and hence, it should modify the design. A purely sequential approach (like the waterfall model) is not suitable for taking care of such requirements.

5.

Often, developers discover many of the system’s details/problems as they progress from one phase to another. Some of the details/problems that they discover at certain points require the developers to backtrack into earlier phases to accommodate the discovered details or to correct the discovered problems. A purely sequential approach (like the waterfall model) is not suitable for taking care of such requirements.

Lightweight SDLC Models Many software developers have found the traditional SDLC model to be unsuitable in today’s fast-paced world because it is not possible to remain competitive, if they follow the procedures strictly as required by the SDLC model. Hence, they have introduced several modified SDLC models, which are popularly known as lightweight SDLC models. These models address some or all of the drawbacks of the pure waterfall model. They are a compromise between no process and too much process. Some popular lightweight SDLC models are: 1.

Extreme Programming (XP)

2.

Agile Software Process (ASP)

3.

Adaptive Software Development (ASD)

4.

Feature Driven Development (FDD)

5.

Rational Unified Process (RUP)

All lightweight SDLC models follow iterative approach of software development with overlapping phases. For example, code generation phase runs together with testing and debugging phase. Lightweight SDLC models are also known as agile development methods because they are quite flexible in iterative refinement of the requirements, design, and generated code (unlike the rigid approach taken in the traditional SDLC model for freezing the requirements and design). For example, in agile development methods:

Chapter 7 ■ Software

252 1.

Requirements can change any time during the project. The client is part of the project team and keeps giving feedback on requirements as things become clearer in various phases of development.

2.

Code generation may start even before program specifications are fully ready and frozen. Team members start coding based on their understanding of the project from its requirement specification.

3.

Team members might like to create test cases for unit testing or integrated testing from requirement specification even before actual coding starts. This provides quick way to test the software.

4.

Team members might also like to create test cases for unit testing during code generation and run the test cases iteratively to refine the code.

5.

Team members might like to evaluate the system several times before deployment of the system.

6.

Team members might like to review and refine the design and code repeatedly as they (team members including the client) meet periodically.

In short, the focus in agile development methods is more on deliverables than strict procedures.

SOFTWARE DESIGN APPROACHES The three software design approaches used commonly are top-down, bottom-up, and out-of-the-middle. They are described here. 1.

Top-down approach. The top-down approach starts with system architecture definition in which the designer defines the overall system architecture in terms of its major components. The architecture includes a set of relationships among components (for example, hierarchical structure, interfaces, communications, and process dependencies). In the next step, the designer defines the architecture of each major component in terms of its sub-components and a set of relationships among the sub-components. He/she then defines the architecture of each sub-component in terms of its sub-sub-components and a set of relationships among the sub-sub-components. This process of decomposing components and sub-components continues until the designer reduces all components and sub-components to base elements, further decomposition of which is not possible. All components, sub-components, sub-sub-components, and so on defined in the process along with their specifications and relationships among them form the complete system architecture. The components, sub-components, sub-sub-components, and so on are implemented (coded in a programming language) and linked properly to build the system in the implementation phase. Figure 7.4 illustrates this approach. It is also known as decomposition approach because it arrives at the complete system architecture by decomposing components and sub-components into additional subcomponents, until the entire system specification is reduced to base elements. This approach was popular until the late 1980s. The other two approaches have now replaced it. However, designers still use this approach in those situations where gap analysis between the requirements of the target system and the available software components indicates low functional fit.

2.

Bottom-up approach. The bottom-up approach starts with base elements selection and specification in which the designer first does a survey of available software libraries and/or existing applications and selects those base elements that can serve as useful building blocks for the target software system. He/she also lists the current specifications of the selected base elements. In the next step, the designer lists modifications required (if any) in the base elements to change their current specifications to match the specifications/requirements of the target software system. For example, modifications may be required to make them suitable for the hardware, operating system, etc. of the target system. He/she then defines linkages among the base elements to create sub-components, which form sub-systems of the target system. In the next step, he/she defines linkages among the sub-systems to create larger sub-systems of the target system. The designer continues with this process of defining linkages among the sub-systems of the previous step to create larger sub-systems until he/she forms a complete top-level system. The selected base elements along with their current specifications and customization requirements (if any), and the linkages defined at various levels to create

■ Software Design Approaches

253

sub-components, larger sub-systems, and the complete top-level system together form the complete system architecture. The base elements are customized and linked properly (as defined in the system architecture) to build the system in the implementation phase.

System architecture definition Step 1

Defines overall system architecture in terms of its major components and a set of relationships among the components

Components definition Step 2

Defines architecture of each major component defined in Step 1 in terms of its sub-components and a set of relationships among the sub-components

Step 3

Defines architecture of each sub-component defined in Step 2 (if it has to be further decomposed) in terms of its sub-sub-components and a set of relationships among the sub-sub-components

Sub-components definition

Subsequent steps

This process of decomposing components and subcomponents continues until all components and subcomponents are reduced to base elements, which cannot be further decomposed Figure 7.4. The top-down approach of software design.

Figure 7.5 illustrates this approach. It is also known as synthesis approach because it arrives at the complete system architecture by synthesizing base elements into sub-systems, and sub-systems into larger sub-systems, and so on until a complete top-level system is formed. Re-usability of code is one of the main benefits of this approach. Object-oriented paradigm, which promotes re-usability of code in the form of re-usable objects, popularized this approach. This approach is suitable for use in those situations where gap analysis between the requirements of the target system and the available software components indicates high functional fit. 3.

Out-of-the-middle approach. This approach combines both top-down and bottom-up approaches. It is the most popular approach for designing modern software systems because software industry has matured over the years and re-usable software components for almost all domains are available today. Hence, most modern software projects make use of a mix of existing software components and newly developed components to build the complete target software system. In this approach, the designer first uses the top-down approach to define a high-level architecture of the target system. He/she then uses the bottom-up approach to fill in the detailed architectural levels. Thereafter, he/she identifies additional components and their relationship with other components to fill the gaps remaining to complete the architecture. In the implementation phase, the team customizes (if required) the components that have been identified by the bottom-up approach and implements the new components. The team then links all the components (as defined in the system architecture) to build the target system.

Chapter 7 ■ Software

254

Subsequent steps

This process of defining linkages among the subsystems of the previous step to create larger subsystems continues until a complete top-level system is formed

Larger sub-systems creation Step 4

Define linkages among the sub-systems to create larger sub-systems of the target system

Sub-components creation Step 3

Define linkages among the base elements to create sub-components, which form sub-systems of the target system

Base elements customization Step 2

List modifications required (if any) in the base elements to change their current specifications to match the specifications/requirements of the target software system

Base elements selection and specification Step 1

From available software-libraries and/or existing applications select base elements that can serve as useful building blocks for the target software system and list their current specifications Figure 7.5. The bottom-up approach of software design.

SOFTWARE IMPLEMENTATION Software implementation deals with code generation of various software components specified in system design document and linking them to build the target software system. Code generation of software components and linking them involves: 1.

Planning of computer programs

2.

Selecting a programming language for coding a component

3.

Coding the component in the selected programming language

4.

Using linking tools to link the codes of different components

Chapters 8 and 9 deal with these and other associated activities involved in software implementation.

■ Software Testing and Debugging

255

SOFTWARE TESTING AND DEBUGGING What are Testing and Debugging? As long as human beings program computers, computer programs will have errors. Program errors are known as bugs, and the process of detecting and correcting these errors is called debugging. In general, testing is the process of making sure that the program performs the intended task, and debugging is the process of locating and correcting program errors. Testing and debugging are important steps in program development. They are also time-consuming steps. In fact, for large programs, the time spent in testing and debugging often exceeds the time spent in coding the program.

Types of Program Errors Generally, the following two types of errors occur in a computer program: 1.

Syntax errors. Syntax errors occur when the rules or syntax of a programming language are not followed. Such program errors typically involve incorrect punctuation, incorrect word sequence, undefined terms, or misuse of terms. For example, the FORTRAN statement C = (A + B/2 has a syntax error; the missing closing parenthesis that should be placed in the appropriate place depending on the logic of the program. A compiler will not compile a program successfully until its programmer corrects all its syntax errors.

2.

Logic errors. Logic errors occur when we make errors in planning the program’s logic or while converting the logic into program code. They cause the program to produce incorrect result or behave unexpectedly. A compiler will compile a program successfully, if it is free of syntax errors, even if it has one or more logic errors. Although we can execute such a program, but it will not produce correct result or will not behave as expected. For example, if a FORTRAN instruction should be “A = B + C” but the programmer has coded it wrongly as “A = B – C”, it is an example of a logic error because the program will not produce correct result. Similarly, if one has wrongly entered 999999 (only six 9s) instead of 9999999 (seven 9s) as the sentinel value for Rollno in the instruction for detecting the end of last record, the program will expect more records even after the last record (sentinel values are introduced in a later chapter). In case of a logic error, since a programmer does not violate any rule of the programming language, the computer cannot identify the error. Hence, it does not produce any error message for a logic error. Therefore, identifying logic errors in a program is the responsibility of the program development and testing team. The testing procedure involves running the program to process input test data, and comparing the obtained results with the known correct results. If the results obtained for the test data do not match with the known correct results, most likely the program contains one or more logic errors. Logic errors are typically due to either missing logic or incorrect logic. If the logic is incorrect, the results obtained for the test data will be wrong. These errors are the easiest of the logic errors to find. Errors caused by missing logic result from logical situations that the programmer did not think of while planning/writing the program. For example, let us assume that an arithmetic process uses a numeric field and the data entry operator has entered a non-numeric value in it. The program logic should determine that the data is not numeric before attempting the arithmetic process. If this logic is missing, the program will fail when the arithmetic process encounters non-numeric data. This type of logic error can be difficult to find. This error will occur only when a user enters nonnumeric data in a numeric field. Users may use the program for weeks, months, or years before this happens and the error in program logic shows up.

Debugging a Program for Syntax Errors Both syntax and logic errors are known as bugs and the process of locating and correcting these errors is known as debugging. As compared to logic errors, syntax errors are easier to locate and correct because almost all language

Chapter 7 ■ Software

256

processors detect syntax errors automatically. When a language processor processes the source code of a program, it indicates on the source listing of the program each program statement having one or more syntax errors, and gives hints regarding the nature of the error. Programmers use these error messages to rectify all syntax errors in their programs. Hence, it is relatively easier to detect and correct syntax errors. Note that in high-level languages such as FORTRAN and COBOL, a single error in a program often causes generation of multiple error messages by the compiler/interpreter. There are two reasons for this. One is that highlevel language instructions often convert to multiple machine instructions. The other one is that symbolic instructions are often dependent upon other instructions. Hence, if a program instruction contains an error that defines a field name, all program instructions that use that field name will have an error message. The error message will indicate that a field used is not a defined name. In such cases, removal of the single error will result in the removal of all associated error messages.

Debugging a Program for Logic Errors Unlike syntax errors, a computer does not produce any error message for logic errors in a program. Hence, logic errors are more difficult to locate and correct than syntax errors. However, once the testing of a program indicates the presence of a logic error in it, a programmer uses one or more of the following methods to locate and correct the error: 1.

Doing hand simulation of the program code. One approach is to take a printout of the source code of the program and go through its execution manually with the test data input that produced incorrect results. During manual execution, the programmer follows the same sequence of paths that a computer would follow for the test data, while keeping track of changes in values of various variables that come across during the execution. Before he/she completes manual execution of the program, he/she will most likely detect the cause of the problem. This method is suitable only for simple and small programs because manual execution of a program is a tedious process.

2.

Putting print statements in the program code. In this approach, the programmer puts several print/write statements at appropriate locations in the program so that during execution of the program, the computer prints/displays values of different variables to indicate intermediate computations results. The programmer recompiles the program with these statements and executes it. These statements print/display the values of intermediate computations, telling what is happening during the execution of the program. By doing a proper analysis of the printed/displayed intermediate results, the programmer can detect the cause of the problem. The programmer removes the print/write statements from the program after correcting the detected errors, and re-compiles the program for future executions.

3.

Using a debugger. This is the most commonly used approach. Debugger is a software tool that assists a programmer in following a program’s execution step-by-step by allowing him/her to display intermediate calculation results and field values whenever desired. In effect, a debugger helps a programmer in debugging a program’s logic more easily than having to put (and later remove) print/write statements into the program’s source code. Almost all modern programming language processors support some kind of debugger. When using a debugger for debugging program logic, the programmer can move either from statement to statement or from one checkpoint to another, pausing the execution of the program as needed to examine the values of key variables or machine registers. Most debuggers support two kinds of checkpoints called breakpoints and watchpoints as explained here: (a) Breakpoint. A breakpoint is a point at which the debugger stops during program execution and awaits further command from the user. When it stops, the user may instruct it to display the current values of key variables or machine registers. A debugger provides the flexibility of setting or removing breakpoints after any program statement. The user may even set multiple breakpoints, and set or remove breakpoints when the program execution stops at a breakpoint and awaits further command.

■ Software Testing and Debugging

257

(b) Watchpoint. Suppose a program contains a variable named “radius” whose initial value of 5 is not supposed to change during execution of the program or after some point in the program. However, during debugging of the program, a programmer discovers that its value is changing. To know the exact point in the program where its value is changed, the programmer can declare “radius” as a watch variable. Then the debugger keeps track of the variable “radius” and the moment its value changes, it stops after the statement that causes the value of the variable “radius” to change and awaits further command from the programmer. Both kinds of checkpoints are helpful in detecting logic errors in programs. 4.

Using memory dump. Generally, programmers use this approach when the program “hangs up” during a test run. In this approach, a programmer prints/displays the contents of main memory and CPU registers at the time when the program hangs up. This information, called memory dump or storage dump, lists the instructions and data held in the computer’s main memory and CPU registers in their raw form, that is, their binary or equivalent hexadecimal or octal form. By doing a proper analysis of this listing, the programmer can detect the cause of the problem.

Software Testing Concepts Testing is the process of ensuring that the software performs its intended functions. It also ensures that the software behaves properly in case of abnormal or unusual input data. Testing and debugging are two separate tasks, but people often confuse between the two because they both deal with program errors. Figure 7.6 clarifies the difference between the two. Software developers assign increased weightage to testing activities in software lifecycle because software bugs often lead to high cost of system downtime. Hence, software testing has today evolved into a multi-stage process with its own methodology, structure, organization, and documentation. In modern software development projects, testing takes place in parallel with other activities, starting as soon as the project begins. Test planning can start immediately after the team has defined software requirements. Based on software requirements, test planners can build a master test plan, which includes testing strategies, priorities, and objectives. Based on the master test plan, testers can define test requirements (what all to test), or specific testing goals (such as performance goals). Once the testers have defined the requirements, they can start developing testing procedures designed to meet/validate those requirements and run the tests. The advantage of doing testing activities in parallel with other activities is that the team can make use of the knowledge that it had put into designing of the software for designing testing strategy. Sr. No.

Testing

Debugging

1

Testing is the process of validating the correctness of a program. Its objective is to demonstrate that the program meets its design specifications.

Debugging is the process of eliminating errors in a program. Its objective is to detect the cause of error, and remove known errors in the program.

2

Testing is complete when all desired verifications against specifications are completed.

Debugging is complete when all known errors in the program are fixed. Note that, debugging process ends only temporarily because it restarts whenever new errors are detected in the program.

3

Testing is a definable process that can and should be planned and scheduled properly.

Debugging, being a reactive process, cannot be planned ahead of time. It is carried out whenever errors are detected in a program.

4

Testing can begin in the early stages of software development. Although the test runs of a program are carried out only after the program is coded, but the decision of what to test, how to test, and with what kind of data to test can and should be done before the coding is started.

Debugging can begin only after the program is ready. The approach used for debugging depends largely on the personal choice of a programmer and the type of error in the program.

Figure 7.6. Difference between testing and debugging.

Chapter 7 ■ Software

258

Testing Methodologies Methodologies used commonly for testing software systems are described here.

Unit and Integrated Testing In unit testing, the programmer who develops a module of software tests the module independently for its functionality. Unit testing verifies if a module meets its specifications. When the team integrates the independently developed and tested modules into a complete system, the team then tests the integrated system to check, if all modules coordinate properly with each other and the system as a whole behaves as per the specifications. This is known as integrated testing. The software is ready for release after completion of integrated testing.

Alpha and Beta Testing After completion of integrated testing, the team releases the software for further testing to a select user group within or outside the organization. This group tests the software by using it as if they are its users. This release version of the software is known as alpha version and the test conducted on it is called alpha testing. If the software is to be sold commercially, instead of releasing it directly in the commercial market after alpha testing, the team sometimes releases it for additional testing to a selected set of users such as long time customers, partner agencies, and at times put for download and trial by anyone. This release version of the software is known as beta version. The selected set of users use the beta version of the software for an identified period and report any bug found in the software to the company developing the software. The use of beta version of the software by the selected set of users for additional testing is known as beta testing. After beta testing, the team fixes the reported bugs (if any), and then the company releases the software to the commercial market. Even at this stage the software may contain certain errors.

Functional and Non-Functional Testing Functional testing verifies whether the software functions as expected with all types of possible valid input data and meets all the design requirements. This ensures that the software operates correctly for all types of input data falling within its design requirements and scope. Functional testing is necessary, but insufficient to guard against certain risks. It does not test the error handling capability of software (how the software behaves in case of abnormal or unusual input data). Good software must produce appropriate error messages for invalid data instead of hanging (not continuing with its execution), or generating meaningless output. Non-functional testing verifies whether the software behaves properly even when it receives invalid or unexpected inputs (such as incorrect, incomplete, or inappropriate data). Non-functional testing tests non-functional aspects of software such as: 1.

Scalability testing, which tests if the software can handle large quantities of data or large number of users.

2.

Usability testing, which tests if the software is easy to learn and use.

3.

Security testing, which tests if the software can protect use of confidential data by unauthorized users.

4.

Internationalization testing, which tests if users from other countries can use the software.

5.

Localization testing, which tests if the software takes care of country-specific parameters (currency, formats, look-and-feel, etc.).

■ Software Testing and Debugging

259

Black-box, White-box, and Grey-box Testing In black-box testing, the tester treats the software as a black box because he/she has no knowledge of its internal data structures, algorithms, or the code of the software. The tester designs test cases based on the system specifications and planned usage to test the functionality according to the requirements. The tester inputs data for a test case and verifies if the output is the same as the expected value specified in the test case (the system behaves as expected). Black-box testing has the advantage of an unbiased opinion because the tester is not part of the design or implementation team. Hence, the tester can find those bugs, which the design or implementation team cannot think of. On the other hand, black-box testing has the disadvantage of blind exploration because the tester has no idea of the internal construction details of the system. Due to this, it is possible that the tester writes many test cases to test something, which a white-box tester can test by only one or two test cases. It is also possible that the test cases written by a black-box tester do not test some parts of the system at all. Hence, testing teams use black-box testing primarily for specification-based testing and usage-based testing. These two types of testing are described later. In white-box testing, the tester has good knowledge of the internal data structures, algorithms, and the code of the software. He/she designs test cases based on the knowledge of internal construction details of the system. This allows the testing team to ensure that all parts (function points) of the system are tested. For example, testing team can generate test cases to cause all statements in a program to be executed at least once (this is known as code-coverage testing). Testing teams use white-box testing primarily for code-based testing and fault-based testing. These two types of testing are described later. In grey-box testing, the testing team designs test cases based on requirement specification as well as internal data structures, algorithms, and code of the software. Hence, grey-box testing ensures that the testing team generates test cases to test the system in optimal time. It also includes testing of non-functional aspects of the system. Once the members responsible for generation of test cases have completed their job, they hand over the test cases to a different set of members, who carry out black-box type testing of the system with the received test cases. They generate a set of input data for each test case and compare the system’s output for each input with the expected output.

Test-set-generation Techniques Test cases form an important component of software testing. Efficiency and effectiveness of software testing depends largely on the choice and generation of right test cases. Hence, researchers have proposed several test-set-generation techniques, which testers use today for software testing. Figure 7.7 summarizes the popular ones. They are also described here.

Technique

Description Specification-based techniques

Equivalence partitioning

A test case is generated for each equivalence class found. The test case is selected at random within the class.

Boundary-value analysis

Several test cases are generated for each equivalence class: one that belongs to the inside of the class and as many as necessary to cover its limits (boundaries).

Decision tables/ cause-effect graphing

Test cases are derived considering every possible combination of inputs and outputs.

Finite-state-machinebased

Test cases are selected to cover states and transitions of a state machine that models the program.

Derived from formal specifications

Test cases are generated from formal specification languages.

Random testing

Test cases are generated at random according to the input domain defined in the specification. Figure 7.7. Test-set-generation techniques.

(Continued on next page…)

260

Chapter 7 ■ Software

Technique

Description Code-based techniques based on control-flow criteria

Sentence coverage

Test cases are generated to ensure that all program sentences are executed at least once.

Decision (branch) coverage (all edges)

Test cases are generated to ensure that all program decisions take the value true and false.

Condition (predicate) coverage

Test cases are generated to ensure that all conditions (predicates) forming logical expression of the decisions take the value true and false.

Decision/ condition coverage

Test cases with condition coverage are supplemented to achieve decision coverage.

Modified condition/ decision coverage

Test cases are generated to ensure that independent influence of every condition on the decision is tested (every condition is varied while holding fixed all other possible conditions).

Reinforced condition/ decision coverage

The modified condition/decision rule is required, and every condition must independently keep the decision value to true and false.

Path coverage

Test cases are generated to ensure that all program paths are executed. This criterion isn’t workable in practice.

Code-based techniques based on data-flow criteria All-definitions

Test cases are generated to ensure that each definition of each variable is covered for at least one use of the variable.

All-c-uses, some-puses

Test cases are generated to ensure that there is at least one path of each variable definition to each use of the variable in a computation. If some variable definitions aren’t covered, use puses.

All-p-uses, some-cuses

Test cases are generated to ensure that there is at least one path of each variable definition to each use of the variable in a predicate. If some variable definitions aren’t covered, use c-uses.

All-c-uses

Test cases are generated to ensure that there is at least one path of each variable definition to each use of the variable in a computation.

All-p-uses

Test cases are generated to ensure that there is at least one path of each variable definition to each use of the variable in a predicate.

All-uses

Test cases are generated so that there is at least one path of each variable definition to each use of the definition.

All-du-paths

Test cases are generated to ensure that all possible paths of each definition of each variable to each use of the definition are executed.

All-dus

Test cases are generated to ensure that all possible executable paths of each definition of each variable to each use of the definition are executed.

Strong (standard) mutation

Test cases are generated to ensure that all mutants generated by applying all mutation operators are covered.

Selective (constrained) mutation

Test cases are generated to ensure that all mutants generated by applying some mutation operators are covered.

Weak mutation

Test cases are generated to ensure that a given percentage of mutants generated by applying all mutation operators are covered.

Schema-based mutation

All mutants for a program are encoded into one metaprogram to improve test-execution performance.

Fault-based techniques based on mutation testing

Figure 7.7. Test-set-generation techniques.

(Continued on next page…)

■ Software Testing and Debugging

261

Usage-based techniques Operational profile

Test cases are generated according to their probability of occurring in actual operation.

Software reliabilityengineered testing

Tests are designed according to reliability objectives, expected use, and criticality of different functions. Figure 7.7. Test-set-generation techniques.

1.

Specification-based techniques. Testers use specification-based techniques to generate test cases based on requirement specification of the system. They use this technique primarily for black-box testing of software. Figure 7.7 lists popular techniques used for specification-based test-set generation.

2.

Code-based techniques. Testers use code-based techniques to generate test cases based on the knowledge of the code of the programs of the system. Two popular categories of code-based techniques are control-flowbased criteria and data-flow-based criteria. Testers use control-flow-based criteria to generate test cases to cover a program’s control flow, whereas they use data-flow-based criteria to generate test cases to cover the execution space between where variables are defined and where they are used. Figure 7.7 lists popular techniques used for control-flow-based criteria and data-flow-based criteria. Studies indicate that the effectiveness of testing is greater if testers apply both criteria together. Specification-based and code-based techniques complement each other in the kind of faults they detect.

3.

Fault-based techniques. Testers use fault-based techniques to generate test cases based on tester’s knowledge of what are the typical faults that the system can have. They also use it for mutation testing of programs. Mutation operators represent the faults a program will likely contain. Testers use them to generate program variants containing source code errors, called mutants. Testers use mutants to generate a set of test cases. Figure 7.7 lists popular techniques used for mutation testing.

4.

Usage-based techniques. Testers use usage-based techniques to generate test cases based on the idea of usage pattern of various functionalities of software. Figure 7.7 lists popular techniques used for usage-based test-set generation.

Test-case-selection Techniques Testing teams use test-set-generation techniques to generate test cases. Out of the test cases generated, it is important to select the test cases that the testers should use for testing. Testing teams use test-case-selection techniques primarily for three purposes: 1.

Filtering. Testing team must remove redundant test cases from the generated test cases to optimize testing time. Filtering techniques help in this process.

2.

Prioritization. Time and resource constraints make it difficult to conduct comprehensive testing of all requirements of a software system. Hence, testing team must prioritize the requirements so that they pay more time and attention to testing of high priority requirements. Ideally, the testing team should test each requirement at least once, and should test higher priority requirements several times. Prioritization techniques help in this process.

3.

Regression. When maintenance team modifies software during its maintenance phase, the testing team must re-test it. However, instead of running all the test cases in the existing test suite, it is more logical to run only selected test cases depending on the modifications made. Regression techniques help in selecting such test cases.

Figure 7.8 lists the commonly used test-case-selection techniques for these purposes.

Chapter 7 ■ Software

262

Technique

Description Filtering techniques

Cluster filtering

Generated test cases are filtered on the basis of cluster analysis of execution profiles.

Failure pursuit

Generated test cases are filtered on the basis of failure pursuit of execution profiles.

Prioritization techniques Branch coverage

Generated test cases are ordered according to their achieved branch coverage.

Statement coverage

Generated test cases are ordered according to their achieved statement coverage.

Function coverage

Generated test cases are ordered according to their achieved function coverage.

FEP (Fault Exposing Potential)

Generated test cases are ordered according to the probability a modified statement will cause a failure for a given test case.

Optimum

Generated test cases are ordered to optimize fault detection.

Regression techniques DejaVu

Test cases are selected by detecting modified code entities such as functions, variables, types, and preprocessor macros.

Test Tube

Test cases are selected according to a variant of DejaVu that is less precise but more robust in analyzing large software systems.

Textual differencing

Test cases are selected by comparing source files from the old and the new version of the program.

Modifications based

Test cases are selected to cover modified program components and those that the modifications might affect.

Data-flow-coverage based

Test cases are selected to exercise data interactions that the modifications have affected. Figure 7.8. Test-case-selection techniques.

SOFTWARE DEPLOYMENT Once the team has tested the software, and has removed all known errors in it, the team deploys the software at site, along with associated hardware for use by intended users. At this stage, the deployment team, and the users phase out the old system (manual system in most cases) and phase in the new system.

Changeover Operations Usually, the changeover process involves the following operations: 1.

Imparting system and user training to the members of the user organization of the system. The team imparts system training to the members responsible for managing and maintaining the system, whereas it imparts user training to the members responsible for operating the system and/or using the results produced by the system. The team also imparts some training to all those who will be affected by the new system to make them familiar with the changes.

2.

Replacing old operation procedures by new ones. This involves things such as discarding of old forms, manual registers, etc.

■ Software Deployment

263

3.

Replacing the old input and output devices by those of the new system.

4.

Defining the roles of different members, and assigning responsibilities to them as per the requirements of the new system.

5.

Converting the data in currently existing files into a form acceptable to the new system. This involves inputting of data stored in manual registers and hard-copy files through the input devices of the new system. While converting existing files, the team consolidates their records and eliminates duplicate records in them. The team also detects and removes inconsistencies or any errors in existing files.

Changeover Methods The three methods normally followed to carry out the changeover process are immediate changeover, parallel run, and phased conversion. Each one has its own advantages and disadvantages. No single method is suitable for converting all types of systems, and the choice of a particular method depends on the prevailing conversion circumstances. These methods are described here.

Immediate Changeover In this method, the deployment team and user organization decide a suitable cut-off date jointly, and make the new system operational from that day onwards [Figure 7.9(a)]. Operation of the old system stops from that day. This method is risky because any failure in the new system during the changeover process may cause total breakdown of those operations of the organization that are dependent on the new and old systems. The work cannot progress because the old system is not operational. Organizations prefer this method in those situations where available manpower and changeover time is less, and the system is not so critical in the sense that some problem during the changeover process would not lead to a disaster or great loss to the organization.

Parallel Run In this method, the organization operates both the old and new systems parallely with the same data for the initial three to four cycles [Figure 7.9(b)]. During this overlapping period of complete operation of the two systems, end users compare the results produced by the new system with those produced by the old system to develop confidence in the new system. They may discover some discrepancies. Often, these are due to inaccurate design of the old system, or due to missing program logic, or due to mistakes in the program itself. Programmers correct them by further debugging before the conversion is complete. This is the safest method because of the availability of the old system as a backup. If there are problems in the new system, there is no interruption of work because the old system is still in operation. The team can correct the problems found while the old system is still in use. This method, however, is expensive because the organization needs additional manpower during the overlapping period for operation of the two systems. Due to the requirement of additional manpower, the organization is under considerable strain during the period of parallel operation, and organizational breakdown may occur, if the period of parallel operation is long. Hence, the deployment team must ensure that they do not carry on parallel operation any longer than needed to establish confidence in the new system. Continuing it too long is a sign of weakness in the new system. Organizations do not prefer to use this method in situations where manpower resource is scarce. It is also not suitable for use in situations where the new system greatly differs from the old system in its functions, input, and output.

264

Chapter 7 ■ Software

Phased Conversion In this method, the complete changeover to the new system takes place incrementally over a period [Figure 7.9(c)]. The deployment team and user organization implement the new system gradually in parts. The end users compare the results produced by each part of the new system with the results of the old system. The team corrects any discrepancies or errors found. As soon as the organization develops confidence in a particular part, the team phases in that part of the new system, and phases out the corresponding part (operations) of the old system. This approach continues for each part of the new system. Hence, over a period, the team phases in the new system gradually, and phases out the old system gradually. Old system in operation

New system in operation

Old system

New system

Cut-off date Time (a) Immediate changeover

Old system in operation

New system in operation Overlapping period of complete operation of both the old and new systems.

Old system

New system Time (b) Parallel run

Old system completely operational

Old and new systems in operation in parts

New system completely operational

Old system

New system Time (c) Phased conversion Figure 7.9. Methods of system changeover to the new system.

■ Software Maintenance

265

This method is not as expensive as the parallel run method because changeover process being gradual, the organization can handle the changeover with existing manpower. Moreover, there is no danger of interruption of work, if there are problems with the new system because the corresponding part of the old system is still in operation. Users also get sufficient time to become familiar with the new system. Hence, they can handle the new system confidently when the deployment team hands over the complete system to them. Organizations, however, cannot use this method in situations where the time supplied for conversion process is short, or when the new system significantly differs from the old system.

System Evaluation Once the new system becomes operational after deployment, an evaluation team evaluates it to verify whether it meets its objectives. Requirement specification document states these objectives. The evaluation team normally consists of those people who have independent viewpoint (are not part of the development team). While evaluating a system, the evaluation team considers the following points: 1.

Performance evaluation. The evaluation team evaluates the performance of the new system by comparing it with that of the old system. Generally, the new system should be at least as efficient as the old one. If the evaluation team reports any slack, the development team analyzes the reason, and if possible, incorporates necessary changes in the new system to rectify it.

2.

Cost analysis. The evaluation team does cost analysis to verify whether cost estimates done for various phases of the project during the planning phase match with the actual cost incurred in each phase. In case of discrepancies, cost analysis helps in finding out the reasons. This knowledge is useful in making correct cost estimates for future systems.

3.

Time analysis. The evaluation team does time analysis to verify whether time estimates done for various phases of project during the planning phase match with the actual time taken in each phase. In case of discrepancies, time analysis helps in finding out the reasons. This knowledge is useful in making correct time estimates for future systems.

4.

User satisfaction. The evaluation team does user satisfaction analysis to verify things such as – How useful is the system for users? How enthusiastic they are about the service they receive? Do they receive outputs in time to take necessary action? The morale of people using or affected by the new system is a good measure of the success of the system.

5.

Ease of modification. All systems need modification due to one or more of the reasons mentioned in the next section. Hence, the ease with which a programmer can modify a system to incorporate the suggested changes is also an important parameter to judge the quality of the system.

6.

Failure rate. The quality of a system also depends on its failure rate. A system that fails frequently cannot meet its objectives successfully. Hence, it is of poor quality.

SOFTWARE MAINTENANCE

Definition Software maintenance is the process of modifying software system or component after deployment to correct faults, add functionality, improve performance or other attributes, or adapt to a change in environment.

Chapter 7 ■ Software

266

Need for Software Maintenance Law of software evolution states that any software used in real world environment must change with time or become less useful progressively. Hence, no matter how good a new software system is, and how well it is operating currently, it needs modification from time-to-time due to one or more of the following reasons: 1.

Changes in business conditions or operations of the organization using the software.

2.

Changes in organizational policies or enforcement of new laws.

3.

Changes in user needs, such as demand for additional features or output reports.

4.

Changes in technology, such as availability of new and more powerful processors, more efficient storage, more convenient input/output devices, new version of operating system used, new operating system, new version of database system used, new database system, etc.

Types of Software Maintenance Software products undergo one or more of the following types of maintenance: 1.

Perfective maintenance. It deals with making changes in software products to accommodate changes in requirements suggested by the user(s). For example, user(s) may ask for additional functionality, different user interface, better performance, etc.

2.

Adaptive maintenance. It deals with making changes in software products to make them suitable for use in new environments, such as a new hardware platform, a new operating system, a new version of an existing operating system, a new database system, or a new version of an existing database system.

3.

Corrective maintenance. It deals with making changes in software products to remove faults, which user(s) or internal testing team(s) report.

4.

Preventive maintenance. It deals with making changes in software products to make them more maintainable. For example, software organizations update their products and/or apply software patches in advance, so that issues/problems do not occur in the products supplied to the user(s).

Importance of Software Maintenance Maintenance is an important phase in SDLC. Studies have shown that, on an average, maintenance cost of software systems is two to four times the development cost. This means that more than half of the programming tasks in this world involve program maintenance. Hence, some software organizations have a group of programmers whose only job is to maintain production programs.

Controlling Modifications Frequent change is disrupting and disturbing. Therefore, some control over changes is required. One method of achieving this is to have a change control board, which evaluates all requests for change. Usually, this board is comprised of the principal users of the system, a system analyst, and data processing personnel who are familiar with the system. The change control board need not approve normal maintenance operations. Maintenance staff should record and summarize these operations for periodic reporting to the board. Examples of maintenance activities are modifying the format of a report, or rewriting a part of software to improve performance. Major changes are those that alter the system significantly, or require extensive personnel, hardware, or software. For example, conversion of software from Unix to Windows environment is a major change.

■ Software Documentation

267

Whenever a programmer modifies a program, the concerned members must also modify the associated documents. Without proper documentation that is consistent with the programs, carrying out future changes would be difficult and expensive.

Tools for Effective Software Maintenance Software maintenance is a major activity in SDLC that consumes large resources. Hence, over the years, software industry has developed and used several tools that simplify the maintenance processes and increase the productivity of members involved in maintenance activities. Out of several tools that software maintenance personnel use, two of the most important ones are: 1.

Configuration management/version control tool. Software developers use this tool to make changes to the correct files and to keep track of who is changing what parts of the source code. When multiple members of a development team work on the same software, it becomes a challenge to keep track of who is changing what parts of the source code. When the members of the development team are located in different locations (cities, countries, or even continents), the problem becomes compounded due to limited communication among the remotely located developers. The version control or configuration management tool proves to be useful for development teams in such situations. It allows developers to check out code, make changes, and save both the old and new versions of the changed file(s). Visual Source Safe (VSS) from Microsoft, ClearCase by IBM Rational and monotone an Open Source tool are three examples of version control tool.

2.

Bug reporting/tracking tool. Software developers, testers, maintenance team members, and even the users (customers) use this tool to report bugs/problems in software along with information associated with a bug/problem. The development team also uses the tool to record the solution provided and associated information when they fix a reported bug/problem. In this manner, the tool helps in creating a knowledge repository of all known bugs/problems in software and the solutions provided for them. This knowledge repository is useful for support/maintenance team members in finding solutions to newly reported bugs/problems. BugZilla from the open source community is an example of bug reporting/tracking tool. JIRA is a commercial bug-tracking tool. Several major software vendors use their own in-house tool for this purpose.

SOFTWARE DOCUMENTATION What is Documentation? Documentation is the process of collecting, organizing, storing, and maintaining a complete historical record of programs and other documents used or prepared during the different phases of the life cycle of software. Without proper documentation of software, the software industry does not consider it complete. In fact, documentation is an on-going process that starts as early as in the study phase of the software and continues until its implementation and operation phase. Moreover, documentation is a never-ending process throughout the life of the software. The maintenance team has to carry out documentation from time-to-time, whenever it modifies the software.

Need for Documentation Proper documentation of software is necessary due to the following reasons: 1.

It solves the problem of indispensability of an individual for an organization. Even if the designer or programmer of the software leaves the organization, the documented knowledge remains with the organization that is useful for the continuity of the software.

2.

It makes software easier to modify and maintain in future. The key to maintenance is proper and dynamic documentation. It is easier to understand the logic of a program from documented records rather than its code.

Chapter 7 ■ Software

268

System flowcharts, program flowcharts, or comments written within the programs are quite helpful in this regard. 3.

It helps in restarting a software project postponed earlier due to some reason. The job need not start from scratch. The new team can recapitulate the old ideas from the available documents, avoiding duplication of work, and saving lot of time and effort.

Forms of Documentation The six commonly used forms of documentation for software are requirement specification document, design document, comments, system manual, user manual, and marketing document. They are described here. All these forms of documentation are necessary to document any software completely.

Requirement Specification Document Before developing some software, the development team must analyze its requirements and document them. Requirement specification document is an outcome of this exercise. It specifies the objectives of developing the software and its usefulness to various categories of users. It also specifies the functionalities, capabilities, performance, inputs, and outputs requirements of the software. It specifies what all the software will do when developed. We can specify the requirements in requirement specification document in a variety of styles, notations, and formats. For example, we may use textual statements in a natural language like English, or diagrams, or mathematical formulae, or a combination of all of these. The requirement specification document is useful for a variety of purposes such as: 1.

It serves as an agreement between the customer requesting development of the software and the developer on what is the scope of the software.

2.

Software developers use it to define the modules, user interfaces, performance parameters, etc. during the design phase to meet the specified requirements.

3.

Testing team uses it to test whether the software performs its stated objectives as per the specified requirements.

4.

Deployment team uses it to evaluate the deployed system against the specified requirements. Maintenance team finds it useful when maintaining changes in software. When they modify the software, they find requirement specification document useful for verifying, if the modifications affect any of the software’s original requirement.

Design Document Design document defines the overall architecture of the software. It specifies the various hardware and software components of the software and interfaces between the components. It includes a hierarchy of software components, rules for component selection, and interfaces between the components. A good design document provides an overview of the total system architecture and does not get into implementation details of the various components.

Comments Comments are natural language statements put within a program to assist anyone reading the source program listing in understanding the logic of the program. They do not contain any program logic, and are ignored (not translated) by a language processor. From maintenance point of view, comments are necessary. All high-level languages provide the

■ Software Documentation

269

facility to write comments in the source code of a program. Liberal use of this facility by programmers for documentation of their programs is highly recommended. Comments should not be redundant, incorrect, incomplete, or written in a manner that others find difficult to understand. For example, a redundant comment for the statement N = N + 1 would be “INCREMENT N BY 1”. Useful comments describe the meaning of a group of statements such as, “READ AND ECHO PRINT THE INPUT DATA”. Good comments are those that mediate between a program and its problem domain.

System Manual Good software must have a standard system manual containing the following information: 1.

Specific module names along with their description and purpose.

2.

Detailed system flowcharts and program flowcharts for each module cross-referenced to program listing.

3.

Description of program listings and control procedures.

4.

Source listing of all programs with full details of all modifications made from time-to-time.

5.

Specifications of all input and output media required for operation of various programs.

6.

Specimen of all types of inputs/outputs to/from software.

7.

File layout, that is, detailed layout of input and output records.

8.

Structure and description of all test data, test results, storage dumps, trace program printouts, etc., for testing and debugging of programs.

User Manual User manual describes how to use the software. Good software must have a good user manual to ensure its easy and smooth usage. It is the users, not the developers, who use the software regularly. Hence, the user manual must contain the following information: 1.

Installation and operational details of software.

2.

Loading and unloading procedures.

3.

Starting, running, and terminating procedures.

4.

Description and example of any control statements used.

5.

All console commands with errors and console messages, their meaning, reply, and/or operation action.

6.

List of error conditions with explanation for their re-entry into the system.

7.

List of programs, which users must execute before and after execution of each program.

8.

Special checks (if any) and security measures, etc.

User manual describes each feature of software in a manner that users can easily make use of these features. The three commonly used ways to do this are (many software use all the three): 1.

Commands/functions list. In this method, the user manual lists the commands or functions of the software alphabetically or grouped logically, often with cross-referenced indexes. Each item in the list describes a command or function in detail with examples.

2.

Tutorial. In this method, the user manual contains tutorials for various functionalities or tasks of software, which provide step-by-step guidance to users on how to accomplish a task by using the software.

Chapter 7 ■ Software

270 3.

Online help. In this method, the user manual contains online information, which users can use whenever needed while using the software, without the need to refer to any other document associated with the software. This saves time and effort of users, which they would require otherwise to trace and refer to a hardcopy user manual for solving problems while using the software.

Marketing Document Marketing document serves as promotional material for software products. Marketing personnel use it to promote the product. Typically, a marketing document consists of the following: 1.

Usefulness of the software product

2.

Its salient features

3.

Its comparison with other competing products

4.

Its system requirements (hardware, operating system, etc.)

Documentation Standard There have been many problems in the past with poorly documented software. Elimination of errors and incorporation of modifications are usually difficult in such software, making them expensive to maintain. Realizing the importance of software documentation, several software organizations have developed strict documentation standards. These standards describe how to do documentation, how to choose meaningful program variable names, how to design the GUI for any software, how and up to what detail to include comments in program code, and what diagrams, charts, reports, outputs, etc. are necessary for completing documentation. Software developers and programmers working in such an organization are required to adhere to its documentation standards.

SOFTWARE ENGINEERING What is Software Engineering? “Software” is a set of computer programs, procedures, and associated documents. On the other hand, “engineering” is systematic application of scientific knowledge in creation and building of cost-effective solutions to practical problems. Hence, “software engineering” is systematic application of principles of computer science and mathematics in creation and building of cost-effective software solutions.

Need for Software Engineering With software products growing in scale and complexity, number of software developers involved in a software development project has been increasing proportionately. Software industry soon realized that managing the development of large software products and maintaining them is a difficult task. Software development projects frequently faced the problems of missed schedules, cost overruns, and low quality software products. Moreover, use of progressively larger software products in sensitive applications, where errors in software products could have severe and even life-threatening consequences, required correctness and reliability of software products to be of high degree. These quality and productivity demands for software products led to the introduction of systematic practices (later on known as software engineering practices) in software industry.

■ Software Engineering

271

Goals of Software Engineering Software engineering aims at producing software products having the following properties: 1.

Their correctness should be of high degree. Correctness refers to the degree to which a software product performs its intended functions properly, consistently, and predictably.

2.

Their usability should be of high degree. Usability refers to the ease with which a software product and its associated documentation are usable by the intended audience.

3.

They should be cost-effective. Cost-effectiveness means that the total development and operational costs of a software product should be as low as possible without compromising on the quality of the product in any way. Overall cost-effectiveness also requires that the maintenance team can modify and enhance a software product easily.

Software products that meet these goals do not cause unusual stress during their various phases of development and are adaptable to unanticipated needs.

Principles of Software Engineering Principles of software engineering are the generally accepted guidelines that software designers and developers should follow to produce a software product for meeting the goals of software engineering. These guidelines are described here.

Precise Requirements Definition The designer of a software product must define its requirements precisely to ensure that the resulting product meets users’ needs. Ill-defined software requirements lead to problems in the later phases of software life cycle.

Modular Structure The designer of a software product must structure it in a modular fashion so that it is easy to program, implement, and maintain. A modular design helps in distribution of development task of different modules to different programmers, enabling development of the product in a shorter time. It also helps in easier testing, debugging, and maintenance of the product because respective teams can test, debug, and maintain individual modules independently. Designers can do feature enhancements by adding new modules. Modular design also enables software reusability because if a module exists for a desired functionality, it can be used as it is, or with minor customization. Third party library routines are an example of reusable software modules.

Abstraction As far as practicable, a software product should use abstraction and information hiding. For example, in modular design, a programmer should implement each module in such a manner that its implementation details are hidden inside the module and only module interface is visible outside to allow other modules to interact with the module. Object-oriented programming takes care of this aspect of software engineering. Abstraction helps in easy reusability of existing modules because for reusing a module, a programmer needs to understand only its interface and not its internal details. Uniformity A software product should maintain uniformity in design, coding, documentation, etc. Uniformity ensures consistency, which makes the product easier to develop and maintain, as well as easier to learn and use. For example, if all graphical user interfaces of a software product follow a uniform style (providing the same look-and-feel

Chapter 7 ■ Software

272

throughout), it becomes much easier for a user to learn and use the software. Similarly, if all programmers working on different modules of a software project follow uniform coding and documentation styles, it becomes easier for someone else to understand and maintain the modules. Software organizations define/adapt and use several software engineering standards, such as design standards, coding standards, documentation standards, etc. to take care of this aspect of software engineering.

CASE Tools Software tools play an important role in software engineering. They help in increasing professional capability and eliminate or reduce sources of error in software products. A large number of software tools are available to aid software developers in different phases of a software product’s life cycle. In fact, popularity of these tools has resulted in a new area called CASE (Computer Aided Software Engineering). CASE tools provide a wide range of features for creation of better and more reliable software products within less time and with less effort. A few of the most common features are: 1.

Design specification tools allow programmers to visually design screens, menus, database tables, reports, dialog boxes, and other key components of a program. With individual components defined, a programmer can link the components together and then test the operation of the program, without writing even a single line of program code.

2.

Code generation tools generate source code (programs) from the design specification of a software product. That is, once satisfied with the structure, design, and components of the product, a programmer can invoke a code generator, which creates the source code for the program automatically. Automatic creation of programs by the code generator also leads to error-free program codes.

3.

Testing and debugging tools help programmers in testing and debugging of their programs.

4.

Source-code analysis tools help in optimizing a program by pointing out unreachable lines of code and those functions that the program never uses (calls). They also assist in carrying out program changes consistently and uniformly by indicating, what other parts of a program would be affected by introducing a change in the program.

5.

Documentation tools assist in automatic generation of technical documents for a software product. For example, automatic flowchart generation tools create flowcharts for already written programs. Similarly, as a programmer uses a design specification tool to design the screens, menus, reports, dialog boxes, and other key components of a software product, a documentation tool collects this information for producing the product’s documentation automatically.

Good CASE tools reduce much of the tedious work of creating a software product. Hence, they save several hours of time to get a new program up and running. They allow a programmer to concentrate on important functional parts of the program, rather than spending time in writing the code to display screens, dialog boxes, and menus. CASE tools, however, are not an answer for every situation. Even in case of software products that make extensive use of CASE tools during their development, some hand coding and manual documentation is necessary.

SOME POPULAR APPLICATION SOFTWARE PACKAGES Millions of application software packages are available today. Some popular ones, which many of us use or come across in our day-to-day life are word-processing package, spreadsheet package, graphics package, personal assistance package, education software, and entertainment software.

■ Some Popular Application Software Packages

273

Word-processing Package The term word-processing describes the use of hardware and software to create, edit, view, format, store, retrieve, and print documents (written material such as letters, reports, books, etc.). A word-processing package enables us to do all these on a computer system. Some commonly supported features found in modern word-processing packages are: Importing text, graphics and images

1.

Entering text

9.

2.

Editing text

10. Searching and replacing text string

3.

Formatting page style

11. Checking spelling

4.

Formatting text

12. Checking grammar and style

5.

Entering mathematical symbols

13. Using thesaurus

6.

Displaying documents

14. Creating table-of-contents and index

7.

Saving, retrieving and deleting documents

15. Using mail-merge

8.

Printing documents

Spreadsheet Package Spreadsheet is a numerical data analysis tool that allows us to create a computerized ledger. A manual ledger is a book having rows and columns that accountants use for keeping record of financial transactions and preparing financial statements. Accountants use pencil, erasure, and hand calculator to prepare financial statements using manual ledger. This is a tedious task and takes time to come out with an acceptable and satisfactory financial statement, due to several iterations of formula calculations. A spreadsheet offers considerable ease of performing such tasks by automating all arithmetic calculations, and making it easier to change certain numerical values and seeing the effect of these changes across the worksheet (ledger) immediately. With the availability of spreadsheet packages, we are no longer required to use pencils, erasers, and hand calculators for dealing with tasks that require numerical data analysis. Whereas paper ledgers were tools for accountants, spreadsheets are tools for anyone who needs to record, organize, or analyze numbers as rows and columns of data. Some typical uses of spreadsheets are: 1.

For maintaining and analyzing inventory, payroll, and other accounting records by accountants.

2.

For preparing budgets and bid comparisons by business analysts.

3.

For recording grades of students and carrying out various types of analysis of grades by educators.

4.

For analyzing experimental results by scientists and researchers.

5.

For tracking stocks and keeping records of investor accounts by stockbrokers.

6.

For creating and tracking personal budgets, loan payments, etc. by individuals.

This list gives an idea of how flexible and versatile tool a spreadsheet is. It is not an exhaustive list. Some key features of modern spreadsheet packages are: 1.

Support for a large number of cells

Chapter 7 ■ Software

274 2.

Support for addressing a range of cells by the addresses of the endpoint cells

3.

Support for different types of cell data (such as, label, numeric value, formula, and date and time)

4.

Support for use of relative and absolute cell addresses in formula

5.

Support for a wide range of commands

6.

Support for displaying numeric data in the form of graphs and charts

Graphics Package A graphics package enables us to use a computer system to create, edit, view, store, retrieve and print designs, drawings, pictures, graphs, and anything else that can be drawn in traditional manner. Some commonly supported features found in modern graphics packages are: 1.

Drawing designs

2.

Painting drawings and pictures

3.

Presenting graphs and charts

4.

Dragging-and-dropping graphic objects

5.

Importing graphic objects

6.

Capturing screen snapshots

Personal-assistance Package A personal-assistance package allows us to use personal computers to store and retrieve personal information, as well as to plan and manage schedules, contacts, finances, and inventory of important items. Some commonly supported features found in modern personal-assistance packages are: 1.

Calendar

2.

To-do-list

3.

Address book

4.

Investments book

5.

Inventory book

Education Software An education software package allows us to use a computer as a teaching and/or learning tool. Today, several types of education software packages are available. Examples of some commonly used types are: 1.

Software packages that teach young children to do mathematics, to recognize alphabets, or to read whole words and sentences

2.

Software packages that allow students to prepare for tests and entrance examinations

3.

Software packages that allow an individual to take an on-line examination in which an examinee has to use a computer during the examination

■ Points to Remember

275

4.

Software packages that allow individuals to learn foreign languages

5.

Software packages that allow hard-copy books and other reading material to be made available in soft-copy form on computers

Entertainment Software An entertainment software package allows us to use a computer as an entertainment tool. Two examples of software that belong to this category are: 1.

Computer video games

2.

Interactive television with video-on-demand facility

Points to Remember 1.

The term hardware refers to the physical devices of a computer system. Thus, input, storage, processing, control, and output devices are hardware.

2.

The term software refers to a collection of programs and associated documents.

3.

A program is a sequence of instructions written in a language understood by a computer. It controls a computer’s processing activity, and the computer performs precisely what the program wants it to do.

4.

A software package is a group of programs that solve a specific problem or perform a specific type of job.

5.

Hardware and software of a computer must work together for the computer to produce useful output. Both hardware and software are necessary for a computer to do useful job.

6.

We classify most software into two categories – system software and application software. System software is a set of one or more programs, which controls the operation and/or extends the processing capability of a computer system. Application software is a set of one or more programs, which solves a specific problem, or does a specific task.

7.

A few examples of system software are operating systems, programming language translators, utility programs, performance monitoring software, and communications software.

8.

A few examples of application software are word-processing software, spreadsheet software, graphics software, personal assistance software, education software, and entertainment software.

9.

Figure 7.1 shows the relationship among hardware, system software, application software, and users of a computer system.

10. Firmware is software substituted for hardware and stored in a read-only memory (ROM) chip. 11. Middleware is a set of tools and data that help applications use networked resources and services. It is a separate software layer, which acts as “glue” between client and server parts of an application. It provides a programming abstraction that masks the heterogeneity of underlying network, hardware, and operating system from application programmers. 12. A user can acquire a desired software in one or more of the following ways:  By buying pre-written software  By developing customized software  By ordering customized software  By downloading public-domain software Each of these ways of acquiring software has its own advantages and limitations. 13. Developing software, putting it to use, and maintaining it is a complex process involving the following phases:  Requirement specification  System analysis and design  Implementation (also known as Construction or Code generation)  Testing and debugging  Deployment (also known as Installation)

276

Chapter 7 ■ Software  Maintenance Evolving software products through these phases is known as Software Development Life Cycle (SDLC) model. This model is also known as waterfall model.

14. The three software design approaches used commonly are top-down (also known as decomposition approach), bottom-up (also known as synthesis approach), and out-of-the-middle. 15. Software implementation deals with code generation of various software components specified in system design document and linking them to build the target software system. 16. Testing is the process of making sure that the program performs the intended task. 17. Program errors are known as bugs, and the process of locating and correcting these errors is called debugging. 18. The two types of errors that occur in a computer program are syntax errors and logic errors. Syntax errors occur when the rules or syntax of a programming language are not followed. Logic errors occur when we make errors in planning the program’s logic or while converting the logic into program code. Such errors cause the program to produce incorrect result or behave unexpectedly. 19. As compared to logic errors, syntax errors are easier to locate and correct because language processors detect syntax errors automatically. 20. The commonly used methods for locating and correcting logic errors are doing hand simulation of the program code, putting print statements in the program code, using a debugger, and using memory dump. 21. Debugger is a software tool that assists a programmer in following a program’s execution step-by-step by allowing him/her to display intermediate calculation results and field values whenever desired. 22. The commonly used testing methodologies for testing software systems are:  Unit and integrated testing  Alpha and beta testing  Functional and non-functional testing  Black-box, white-box, and grey-box testing 23. The commonly used test-set-generation techniques are broadly classified into:  Specification-based techniques  Fault-based techniques  Code-based techniques  Usage-based techniques 24. Once the software development team has tested the software, and has removed all known errors in it, the team deploys the software at site, along with associated hardware for use by intended users. At this stage, deployment team and users phase out the old system (manual system in most cases) and phase in the new system. The three methods followed normally to carry out the changeover process are immediate changeover, parallel run, and phased conversion. 25. System evaluation is the process of evaluating a system (after it is put to operation) to verify whether it meets its objectives. The points considered for evaluating a system are performance evaluation, cost analysis, time analysis, user satisfaction, ease of modification, and failure rate. 26. Software maintenance is the process of modifying software system or component after deployment to correct faults, add functionality, improve performance or other attributes, or adapt to a change in environment. 27. Software products undergo one or more of the following types of maintenance:  Perfective maintenance  Corrective maintenance  Adaptive maintenance  Preventive maintenance 28. Documentation is the process of collecting, organizing, storing, and maintaining a complete historical record of programs and other documents used or prepared during the different phases of the life cycle of software. 29. The six commonly used forms of documentation for software are requirement specification document, design document, comments, system manual, user manual, and marketing document. 30. Software engineering is systematic application of principles of computer science and mathematics in creation and building of cost-effective software solutions. 31. A word-processing package enables us to create, edit, view, format, store, retrieve, and print documents on a computer system.

■ Questions

277

32. Spreadsheet is a numerical data analysis tool that allows us to create a computerized ledger. It is useful for any numerical analysis problem, whose data we can organize as rows and columns. 33. A graphics package enables us to use a computer system to create, edit, view, store, retrieve, and print designs, drawings, pictures, graphs, and anything else that can be drawn in traditional manner. 34. A personal-assistance package allows us to use personal computers to store and retrieve personal information, as well as to plan and manage schedules, contacts, finances, and inventory of important items. 35. An education software package allows us to use a computer as a teaching and/or learning tool. 36. An entertainment software package allows us to use a computer as an entertainment tool. Computer video games belong to this category of software.

Questions 1.

Define the terms hardware and software. Explain the relationship between them.

2.

What is a computer program?

3.

What is running/executing a computer program?

4.

What is a software package?

5.

Normally, hardware is a one-time expense, whereas software is a continuing expense. Explain.

6.

Define the and distinguish between application software and system software.

7.

Define the following terms: (a) System software (b) System program (c) System programmer

(d) Application software (e) Application program (f) Application programmer

8.

Write key functions performed by the system software of a computer system.

9.

Explain the importance of system software for a computer system.

10.

Explain the relationship among hardware, system software, application software, and users of a computer system.

11.

How does a normal user interact with the hardware of a computer? Describe the various in-between layers.

12.

What is firmware and what is its importance to a computer system architect?

13.

What is middleware? Why is it so called? How is it useful?

14.

Differentiate among hardware, software, firmware, and middleware.

15.

What are the different ways of acquiring software? What are their relative advantages and limitations?

16.

Write the steps followed typically by a user in selecting and buying a pre-written software package.

17.

Write the steps followed typically by a user in placing an order on another organization for creation of a customized software package.

18.

Write relative advantages and disadvantages of creating customized software in-house by an organization versus getting it created by another organization.

19.

What is a turnkey solution?

20.

Write the steps followed typically in in-house development of a software package.

21.

What is a shareware? What are the advantages and limitations of using a shareware?

22.

Are all public-domain software “freeware”? Explain.

23.

Are all public-domain software “Open Source Software (OSS)”? Explain.

24.

What is Open Source Software (OSS)? What are its advantages as compared to conventional commercial software?

25.

Why is public-domain software also known as community-supported software?

278

26.

Chapter 7 ■ Software

Write the various phases of Software Development Life Cycle (SDLC) model and the main activities performed in each phase.

27.

Why is SDLC model also known as waterfall model?

28.

Write advantages and limitations of SDLC model.

29.

What are lightweight SDLC models? Why are they also known as agile development methods? Name three agile development methods.

30.

How are agile development methods of software development different from the traditional SDLC model?

31.

Describe the three approaches used commonly for software design.

32.

Differentiate between top-down and bottom-up approaches of software design.

33.

What are the two types of errors that can occur in a computer program? Write an example of each type to illustrate their nature.

34.

Differentiate between syntax errors and logic errors in computer programs.

35.

Will a program run if there are syntax errors in it? Write reasons for your answer.

36.

Will a program run if there are logic errors in it? Write reasons for your answer.

37.

What is testing of a program? Why do we need to test a program?

38.

What are the different types of test data used for testing a program?

39.

Why is it not possible to certify for a complex software system that it is error free?

40.

What is alpha version of software? What is alpha testing?

41.

What is beta version of commercial software? What is beta testing?

42.

Differentiate between alpha and beta testing of software.

43.

How can we detect and correct syntax errors in a program?

44.

How can we detect and correct logic errors in a program?

45.

Is it easier to detect a syntax error or a logic error in a program? Write reasons for your answer.

46.

What is a program bug? What is debugging?

47.

In high-level languages, a single syntax error often causes generation of multiple error messages. Explain why.

48.

Describe the various methods to locate and correct logic errors.

49.

What is a debugger? How does it help a programmer?

50.

What is a memory dump? How is it useful for a programmer?

51.

In the context of debugging of a program, what is a checkpoint? What are the two commonly supported types of checkpoints in modern debuggers? How are they useful?

52.

Differentiate between a breakpoint and a watchpoint in the context of program debugging.

53.

Differentiate between testing and debugging.

54.

Testing can begin in the early stages of software development, while debugging can begin only after coding of the program. Discuss.

55.

Differentiate between: (a) Unit and integrated testing (b) Alpha and beta testing (c) Functional and non-functional testing (d) Black-box and white-box testing

56.

What is test-set generation? Describe some commonly used test-set-generation techniques.

57.

How do test-case-selection techniques help software testing teams?

■ Questions

279

58.

Write the operations normally carried out in the system changeover process.

59.

Describe the three methods of system changeover with their advantages and disadvantages.

60.

Immediate changeover is a risky method of deploying a new system. Explain why.

61.

The method of parallel run is one of the safest ways to deploy a new system. Explain why.

62.

In what situations organizations do not prefer the parallel run method of deploying a new system?

63.

Why do we need to evaluate a new system? What parameters do we normally use to evaluate a new system?

64.

What is software maintenance? Why do we need to modify software?

65.

Differentiate among perfective, adaptive, corrective, and preventive maintenance of software.

66.

How can we control frequent program modifications?

67.

What is software documentation? Why do we need it?

68.

Describe different types of documentation normally used for documenting software systems.

69.

What are program comments? Why do we need them?

70.

What is system manual of a software system? What type of information does it typically contain?

71.

What is user manual of a software system? What type of information does it typically contain?

72.

What is documentation standard? Why do we need it?

73.

What is software engineering? Why do we need it?

74.

Write the goals of software engineering.

75.

Write the main principles of software engineering. Explain how each of these principles helps in achieving one or more goals of software engineering.

76.

What is modular structure of a software system? How does it help?

77.

What is abstraction in software systems? How does it help?

78.

Why should software systems maintain uniformity in design, coding, documentation, etc.? How can we ensure uniformity?

79.

What are CASE tools? How are they useful?

80.

Write three types of CASE tools. Explain the use of each.

81.

What is a source-code generator? How is it useful?

82.

What is a source-code analyzer? How is it useful?

83.

CASE tools are not the answer for every situation. Discuss.

84.

What is a word-processing package? Write key features supported by modern word-processing packages.

85.

What is a spreadsheet package? Write its typical uses.

86.

What is graphics software? Write features supported normally in graphics software.

87.

What is a personal-assistance package? Write features supported normally by it. Explain the usefulness of each of these features.

88.

What is education software? Write three examples of such software.

89.

What is entertainment software? Write three examples of such software.

Planning the Computer Program

In Chapter 7, we saw that computer software is a set of computer programs. We also saw that before writing a program, one must first plan the program. That is, to write a correct and effective computer program we must first plan its logic. If we attempt to plan the logic and write the program at the same time, we are likely to become so involved with the required instruction formats that program logic will suffer. Hence, before learning how to write a computer program (in next chapter) we will first learn how to plan its logic (in this chapter).

PURPOSE OF PROGRAM PLANNING If your teacher asked you to solve an arithmetic problem and you are not familiar with the steps involved in solving the problem, you will not be able to solve it. The same principle applies to writing computer programs. A programmer cannot write the instructions for a computer to solve a problem unless the programmer knows how to solve the problem manually. If you know the steps for solving a problem, but while solving it, if you forget to apply some of the steps or you apply the steps in wrong sequence, you get a wrong answer. Similarly, while writing a computer program, if a programmer leaves out some of the instructions or writes the instructions in wrong sequence, the programmer gets a wrong answer when he/she executes the program on a computer. Hence, to ensure that the instructions of a program are appropriate for the problem at hand and are in the correct sequence, we must plan the program before writing it.

ALGORITHM What is an Algorithm? Planning a program involves defining its logic (the correct sequence of instructions needed to solve the corresponding problem). The term algorithm refers to the logic of a program. It is a step-by-step description of how to arrive at a solution to a given problem. It is a sequence of instructions that when executed in the specified sequence, gives the desired results. To qualify as an algorithm, a sequence of instructions must possess the following characteristics:

■ Algorithm 1.

Each instruction should be precise and unambiguous.

2.

Each instruction should execute in a finite time.

3.

No instruction should repeat infinitely. This ensures that the algorithm terminates ultimately.

4.

After executing the instructions (when the algorithm terminates), the desired results are obtained.

281

Sample Algorithms To gain insight into algorithms, let us consider some simple examples. Example 8.1. Fifty students in a class appeared in their final examination. The division column of their mark sheets contains the division (FIRST, SECOND, THIRD, or FAIL) obtained by them. If their mark sheets are available with you, write an algorithm to calculate and print the total number of students who passed in FIRST division. Algorithm: Step 1:

Initialize Total_First_Division and Total_Marksheets_Checked to zero.

Step 2: Take the mark sheet of the next student. Step 3:

Check the division column of the mark sheet to see if it is FIRST. If no, go to Step 5.

Step 4: Add 1 to Total_First_Division. Step 5: Add 1 to Total_Marksheets_Checked. Step 6: Is Total_Marksheets_Checked = 50? If no, go to Step 2. Step 7: Print Total_First_Division. Step 8: Stop. Example 8.2. There are 100 employees in an organization. The organization wants to distribute annual bonus to the employees based on their performance recorded in their annual appraisal forms. Each employee’s appraisal form contains his/her basic salary and grade for his/her performance during the year. Grades are of three categories – ‘A’ for outstanding, ‘B’ for good, and ‘C’ for average performance. Bonus for an employee is 100% of basic salary for outstanding performance, 70% of basic salary for good performance, 40% of basic salary for average performance, and none for all other cases. Write an algorithm to calculate and print the total bonus amount.

Algorithm: Step 1:

Initialize Total_Bonus and Total_Employees_Checked to zero.

Step 2:

Initialize Bonus and Basic_Salary to zero.

Step 3: Take the appraisal form of the next employee. Step 4:

Read the employee’s Basic_Salary and Grade.

Step 5:

If Grade = A, then Bonus = Basic_Salary. Go to Step 8.

Step 6:

If Grade = B, then Bonus = Basic_Salary x 0.7. Go to Step 8.

Chapter 8 ■ Planning the Computer Program

282

Step 7:

If Grade = C, then Bonus = Basic_Salary x 0.4.

Step 8:

Add Bonus to Total_Bonus.

Step 9:

Add 1 to Total_Employees_Checked.

Step 10: If Total_Employees_Checked < 100, then go to Step 2. Step 11: Print Total_Bonus. Step 12: Stop. Programmers design such algorithms to solve complex programming problems. The examples show that algorithm development even for simple problems is not as simple as it might appear initially, and requires some thinking. The examples also show that to solve a problem, every instruction must be carried out strictly in a particular sequence. It is this fact that a beginner to problem solving using computers finds difficult to appreciate.

Quality of Algorithms Given a solvable problem, often there are many methods to solve it, not all of which may be equally good. Similarly, for a given problem, there may be many algorithms, not all of equal quality. Factors often used to judge the quality of an algorithm are: 1.

Time requirement. The lesser is the time required for executing the corresponding program on a given computer, the better is the algorithm.

2.

Accuracy of solution. Although, multiple algorithms may provide correct solutions to a given problem, some of these may provide results that are more accurate. For example, out of two algorithms for calculating the square root of a given number, if one produces results up to three decimal places, while the other one produces results up to six decimal places, the latter is better from the point of view of accuracy of solution.

3.

Generality. While there are occasions when we design an algorithm to solve a single isolated problem, more often we design algorithms to handle a range of input data. A generalized algorithm, which can handle a range of input data, is better than one which can solve a problem for a single input data. For instance, the algorithm given for Example 8.1 is not a generalized one, because in Step 6 it checks if Total_Marksheets_Checked has become equal to 50. Hence, it will work only if there are exactly 50 students’ data as input. The algorithm can be made general by accepting the number of students ( N ) as input and then comparing the value of Total_Marksheets_Checked with N, instead of 50 in Step 6.

Representation of Algorithms Commonly used ways to represent an algorithm are: 1.

As program

3. As flowchart

2.

As pseudocode

4. As decision table

An algorithm represented in the form of a programming language is a program. Hence, any program is an algorithm, but the reverse is not true. Programmers often use flowcharts, pseudocodes, and decision tables for representing algorithms for their programs before coding them in programming languages. Subsequent sections describe these program-planning tools. To plan their programs, programmers generally select one of them depending on their choice.

■ Flowcharts

283

FLOWCHARTS What is a Flowchart? A flowchart is a pictorial representation of an algorithm. Programmers often use it as a program-planning tool for visually organizing a sequence of steps necessary to solve a problem using a computer. It uses boxes of different shapes to denote different types of instructions. Programmers write actual instructions within these boxes using clear and concise statements. Directed solid lines connecting these boxes indicate flow of operations – sequence in which to execute the instructions. The process of drawing a flowchart for an algorithm is known as flowcharting.

Why Use Flowcharts? Normally, we first represent an algorithm as a flowchart, and then express the flowchart in a programming language to prepare a computer program. The main advantage of this two-step approach in program writing is that, while drawing a flowchart, a programmer can concentrate on the logic of the solution to the problem at hand, without paying attention to the syntax and other details of the programming language. Moreover, since a flowchart shows the flow of operations in pictorial form, a programmer can detect any error in the logic with greater ease than in the case of a program. Once the flowchart is ready, the programmer can concentrate on coding the operations in each box of the flowchart as statements of the programming language. Normally, this two-step approach ensures an error-free program. Experienced programmers, sometimes, write programs without drawing a flowchart. However, beginners should first draw a flowchart to reduce the number of errors and omissions in a program. Moreover, it is a good practice to have a flowchart along with a computer program because the flowchart often serves as a document for the computer program. It is useful during the testing of the program, and while incorporating modifications in the program.

Flowchart Symbols Need for Flowchart Symbols A flowchart uses boxes of different shapes to denote different types of instructions. The use of standard symbols makes it easier to communicate program logic through flowcharts because it enables anyone using the flowchart to interpret the logic easily. For example, a diamond always means a decision. Hence, when a programmer looks at a flowchart, he/she can identify the decision points easily by looking for diamond-shaped boxes.

Basic Flowchart Symbols Flowcharts need only a few basic symbols to indicate necessary operations in algorithms. Figure 8.1 shows the basic flowchart symbols standardized by the American National Standards Institute (ANSI). Their functions are described here.

Chapter 8 ■ Planning the Computer Program

284

Input/Output

Terminal

Decision

Processing

Flow lines

Connectors

Figure 8.1. Basic flowchart symbols.

1.

Terminal. Terminal symbol indicates the beginning (Start), the end (Stop), and pauses (Halt) in a program’s logic flow. Normally, we use a pause in program logic under some error condition, or for doing some manual setting during processing of program such as changing forms in a computer’s printer.

2.

Input/Output. In a flowchart, input/output symbols indicate program instructions to input/output data from any type of input/output device (such as keyboard, mouse, scanner, monitor, printer, plotter, etc.). They also indicate instructions to input/output data from/to a storage device (such as disk, tape, etc.).

3.

Processing. A processing symbol represents arithmetic and data movement instructions. Hence, in a flowchart, processing symbols indicate arithmetic processes of adding, subtracting, multiplying, and dividing, as well as logical processes of moving data from one memory location to another (assignment statements). A processing symbol with more than one arithmetic and data movement instructions indicates consecutive execution of these instructions in the order of their placement.

4.

Decision. A decision symbol indicates a decision point, which is a point at which a branch to one of two or more alternative paths is possible. Figure 8.2 shows three different ways of using a decision symbol. The criterion for making a decision is in the corresponding decision box. A decision symbol also accounts for all possible exit paths depending on the result of decision. For each exit path, it has a label indicating the condition upon which the program logic takes that path for further execution.

AB

A=B

Yes (a) A two-way branch decision

(b) A three-way branch decision

I=? =0

=1

=2

=3

=4

=5

= Other

(c) A multiple-way branch decision Figure 8.2. Examples of decision symbols.

5.

Flow lines. Flow lines with arrowheads indicate flow of operation, which is the sequence of execution of instructions. Normal flow of a flowchart is from top-to-bottom and left-to-right. Although, a flowchart

■ Flowcharts

285

requires arrowheads only when normal flow of operation changes, but as a good practice and to avoid ambiguity, we draw flow lines usually with an arrowhead at the point of entry to all flowchart symbols. Good practice also dictates that we should avoid crossing of flow lines as far as practicable. 6.

Connectors. When a flowchart becomes so complex that the number of flow lines and their direction are confusing, or when the flowchart spreads over more than one page, it is useful to utilize connector symbols as a substitute for flow lines. This symbol represents an entry from, or an exit to another part of the flowchart. A connector symbol is a circle with a letter or digit placed in it to indicate the link. A pair of identically labeled connector symbols indicates a continued flow when the use of a line is confusing. Hence, two connectors with identical labels serve the same function as a long flow line. How is it possible to determine if a connector symbol is an entry or exit point? It is simple – if an arrow enters but does not leave a connector, it is an exit point, and program control transfers to the identically labeled connector having an outlet. Connectors help in simplifying the task of drawing large flowcharts that spread over several pages.

Additional Flowchart Symbols The basic flowchart symbols are sufficient to represent any program logic, but they do not specify the type of storage media, type of I/O device, or type of processing. Additional flowchart symbols enable programmers to incorporate such details in their flowcharts. Figure 8.3 shows some commonly used ones. Their functions are described here. 1.

Printed document. This symbol shows that either the input to the program is in the form of printed document or its output is in hard copy printed form.

2.

Display. This symbol shows that the program displays the output on a monitor.

3.

Keyed input. This symbol shows that the program inputs data using a keyboard device.

4.

Manual input. This symbol shows that the program inputs data using an input device, which requires manual operation, such as voice input system, touch screen kiosk, etc.

5.

Auxiliary operation. This symbol represents an auxiliary operation performed by a machine that is not directly under the control of the main computer system. The program must perform auxiliary operation for completion of the job.

6.

Manual operation. This symbol represents an offline activity performed by a person. The program must perform the offline activity for completion of the job.

7.

Online storage. This symbol represents any data stored on an online storage device, such as a disk.

8.

Offline storage. This symbol represents any data stored on an offline storage device, such as a tape.

9.

Magnetic tape. This symbol represents the use of magnetic tape for storage of some data.

10. Magnetic disk. This symbol represents the use of magnetic disk for storage of some data. 11. Communication link. This symbol represents data transmission from one location to another across a

network. 12. Annotation. This symbol provides explanatory notes to some parts of the flowchart to make it easier to

follow and understand. An explanatory note is within a three-sided annotation enclosure and a dotted line connects the annotation enclosure to that part of the flowchart to which the annotation corresponds. 13. Predefined process. This symbol represents a group of operations that form a separate module detailed in a

separate flowchart. 14. Merge. This symbol represents a process that combines two or more sets of items into one set. 15. Extract. This symbol represents a process that separates one or more specific sets of items from a given set of

items.

286

Chapter 8 ■ Planning the Computer Program

Printed document

Auxiliary operation

Magnetic tape

Predefined process

Display

Manual operation

Magnetic disk

Merge

Keyed input

Manual input

Online storage

Offline storage

Communication links

Extract

Sort

Annotation

Collate

Figure 8.3. Additional flowchart symbols.

16. Sort. This symbol represents a process that arranges a set of items in a specified sequence

(ascending/descending). 17. Collate. This symbol represents a process that performs merge and extract operations. The process first

combines two or more sets of items into one set and then separates one or more specific sets of items from the generated set.

Sample Flowcharts We introduce here the art of flowcharting (describing an algorithm in the form of a flowchart) with the help of some simple examples. Example 8.3. A student appears for an examination consisting of total 10 subjects with each subject having maximum marks of 100. The student’s roll number, name, and marks obtained by him/her in various subjects are input data. Such a collection of related data items, treated as a unit, is known as a record. Draw a flowchart for the algorithm to calculate the percentage marks obtained by the student, and to print it with his/her roll number and name.

Solution: Figure 8.4 shows the flowchart of the algorithm for this problem. The first symbol, labeled “Start”, is a terminal symbol indicating the beginning of flowchart logic. It does not mean that someone has to switch on the computer or press a start button. The second symbol is an I/O symbol labeled “Read input data”. This step inputs the roll number, name, and marks obtained by the student from an input device into the main storage of the computer. The third symbol is a processing symbol. Its label indicates that at this step the computer adds the marks obtained by the student in various subjects, and stores the sum in a memory location named Total.

■ Flowcharts

The fourth symbol is again a processing symbol. Its label indicates that at this stage, the program calculates percentage marks by dividing Total by 10, and stores the result in a memory location named Percentage. The fifth symbol is an I/O symbol labeled “Write output data”. This step outputs the roll number, name, and percentage marks obtained on an output device, such as a printer. Note that details such as roll number, name, marks obtained, or percentage being input or output are not part of the logical steps of data input or output operations. Such details are part of the system design document, and are included in the computer program as input and output descriptions. The sixth symbol, labeled “Stop”, is a terminal symbol indicating the end of flowchart logic. Directed flow-lines connect various symbols in the flowchart, indicating the sequence of instructions execution. The logic depicted in Figure 8.4, therefore, will read the student’s record, calculate the percentage marks obtained by him/her, print one line of output, and then stop. Certainly, one would not like to use a computer to solve a trivial problem like this. However, if several students appear for an examination and if we have to compute the percentage marks obtained for each student, we may like to take the help of a computer. The next example illustrates how to do this.

287

Start Read input data Add marks of all subjects giving Total Percentage = Total / 10 Write output data Stop Figure 8.4. Flowchart for Example 8.3.

Example 8.4. Fifty students of a class appear for the examination of Example 8.3. Draw a flowchart for the algorithm to calculate and print the percentage marks obtained by each student along with his/her roll number and name. Solution: Since all students appeared for the same examination, the process of calculating and printing percentage marks obtained by each student will be the same. Hence, an easy solution that comes to our mind for this problem is to repeat the intermediate four symbols of Figure 8.4 fifty times. However, if we do that, 202 (50 x 4 + 2) flowchart symbols will have to be drawn. Obviously, this is a time consuming and tedious job and hence, is not desirable. We will now see how to solve this problem in a simpler way. If the program has to repeat the same logical steps more than once, we use flow line symbols in a flowchart to form a process loop (see Figure 8.5). The flow line pointing upward forms a process loop indicating that after “Write” operation, control flows back to “Read” operation. Hence, the process loop of Figure 8.5 solves the problem of an exceedingly long flowchart by reusing the same logical steps repeatedly. However, the flowchart of Figure 8.5 is incomplete because the process loop does not have a logical ending. It will continue to attempt to repeat the four steps until someone cancels the job manually. This is an example of an infinite loop. Hence, the flowchart of Figure 8.5 does not represent an algorithm because an algorithm must terminate. Therefore, we have to find out a way to terminate the algorithm. We do this by using a decision symbol (see the flowchart of Figure 8.6).

Start Read input data Add marks of all subjects giving Total Percentage = Total / 10

Write output data Figure 8.5. Flowchart for the solution of Example 8.4 with an infinite (endless) process loop.

288

Chapter 8 ■ Planning the Computer Program

The flowchart of Figure 8.6 uses another variable Count. The program logic initializes it to zero outside the process loop and increments it by one, after processing the data for each student. Hence, the value of Count is always equal to the number of students whose data has been processed. The decision step compares the value of Count with 50, the total number of students. The program logic repeats the steps within the process loop until the value of Count becomes 50. When Count becomes 50, the instruction at the decision step causes the control to flow out of the loop, and processing stops because the program logic encounters a terminal symbol labeled Stop. Hence, the flowchart of Figure 8.6 is a complete and correct solution to the problem of Example 8.4. However, the flowchart of Figure 8.6 suffers from two major drawbacks. The first drawback is that for making the decision at the decision step, one must know the exact number of students who appeared for the examination. If the total number of students appearing for the examination of Example 8.4 is too large (say more than ten thousand), counting the total number of input records (data for each student) becomes a tedious job, and the logic will not work if there is a counting error. If the supplied number is less than the number of input records, the computer will not process the data for last few students. On the other hand, if it is more than the number of input records, the computer will try to read more records than supplied, causing an error in the logic. The second drawback is that the flowchart of Figure 8.6 is not a generalized solution to the given problem. If the examination is conducted every year, we will like to use the same program every year. However, the number of students appearing in the examination may not remain the same every year. This year it may be 50, but next year it can be 55, or 60, or anything. Hence, if the computer program to solve this problem is based on the flowchart of Figure 8.6, the statement corresponding to the decision step in that program will have to be changed every time to supply the exact number of students. This is not a good programming practice. A good algorithm (program) should be general in nature. For example, in this case, we should write a program that need not be modified every time even if the total number of students changes. The flowchart of Figure 8.6 suffers from these drawbacks because it uses the method of counting for controlling the process loop. We can overcome these drawbacks by using another method to control the process loop. In this method, a trailer record marks the end of input data. That is, a special record follows the last data record in input, whose sole purpose is to indicate the end of input data. For example, let us assume that the first seven characters of an input record represent a student’s roll number (Rollno). Since 0000000 is never a valid roll number, we can safely use a value of 0000000 as the first seven characters to represent the trailer record. As the program logic processes each input record, it compares the record’s Rollno with 0000000 to determine if processing is complete. Figure 8.7 shows the flowchart for the logic of this process. This logic requires a programmer to include instructions in the program to compare the Rollno of each record with 0000000 for determining whether to continue or stop. The concept of a trailer record uses the idea of selecting a field (a particular item of data) in input record and then selecting a trailer value, also known as sentinel value that never occurs as normal data value for that field. Sentinel value of 0000000 for Rollno field is a good example. When program logic uses a trailer record to mark the end of input data, the decision box for checking the trailer value is usually flowcharted immediately after the input symbol.

■ Flowcharts

289

Start Start Count = 0 Read input data

Read input data

Is Rollno = 0000000?

Add marks of all subjects giving Total

Percentage = Total / 10

No Add marks of all subjects giving Total

Write output data

Percentage = Total / 10

Add 1 to Count No

Is Count = 50? Yes Stop

Yes

Stop

Write output data

Figure 8.7.

Generalized flowchart for the solution of Example 8.4 using the concept of trailer record. Here the process loop is terminated by detecting a special nondata record.

Figure 8.6. Flowchart for the solution of Example 8.4.

Example 8.5. For the examination of Example 8.3, we want to make a list of only those students who passed the examination (obtained 30% or more marks). In the end, we also want to print the total number of students who passed. A trailer record having sentinel value of 9999999 for Rollno terminates input data of all students. Draw a flowchart for an algorithm to process this requirement. Solution: The flowchart of Figure 8.8 is an algorithm for this problem. It has two decision symbols. The first symbol checks for a trailer record by comparing Rollno with sentinel value of 9999999 to determine whether processing is complete. The second symbol checks whether the student has passed or failed by comparing percentage marks obtained by him/her with 30. If student’s Percentage is equal to or more than 30, he/she has passed, otherwise failed. Note from the flowchart that the program logic performs the operation “Write output data” if the student has passed. If he/she has failed, the program logic performs the operation “Read input data” directly without performing the “Write” operation. Hence, output list will contain details of only those students who passed the examination. Another notable point in this flowchart is the use of Count variable. The program logic initializes it to zero in the beginning and increments it by one every time it performs the operation “Write output data”. However, the program

290

Chapter 8 ■ Planning the Computer Program

logic performs the operation “Write output data” only for those students who passed. Thus, the program logic increments Count by one only in case of those students who passed. Hence, the value of Count is always equal to the number of students who passed, out of those whose data has been processed. Eventually, when program logic detects the trailer record, the operation “Write Count” prints the final value of Count, which is equal to the total number of students who passed the examination. Start Count = 0 Read input data

Is Rollno = 9999999?

Yes Write Count

No Add marks of all subjects giving Total

Stop

Percentage = Total / 10

Is Percentage >= 30? Yes

No

Write output data Add 1 to Count

Figure 8.8. Flowchart for the solution of Example 8.5.

Example 8.6. Input data of each student for the examination of Example 8.3 also contains information regarding his/her sex in a field named Sexcode having value M (for male) or F (for female). We want to make a list of only those female students who passed in second division (obtained 45% or more but less than 60% marks). In the end, we also want to print the total number of such students. A trailer record having a sentinel value of Z for Sexcode terminates input data of all students. Draw a flowchart for an algorithm to process this requirement. Solution: The flowchart of Figure 8.9 is an algorithm for this problem. It has four decision symbols. The first symbol checks for a trailer record by comparing Sexcode with sentinel value Z to determine if processing is complete. The second

■ Flowcharts

291

symbol checks whether the student is female by comparing his/her Sexcode with F. If Sexcode is not F, program logic does not process the data of that student and returns the control to the operation of reading input data. This step ensures that program logic takes the data of only female students for further processing.

Start Count = 0 Read input data

Is Sexcode = Z? No No

Is Sexcode = F? Yes Add marks of all subjects giving Total

Yes Write Count Stop

Percentage = Total / 10

No

No

Is Percentage >= 45? Yes Is Percentage < 60? Yes Write output data Add 1 to Count

Figure 8.9. Flowchart for the solution of Example 8.6.

The last two decision symbols check whether the student passed in second division. The first one ensures that she scored 45% or more, and the second one ensures that she scored less than 60%. If she scored less than 45%, she has not passed in second division. Hence, without making any further check, program logic returns the control to the operation of reading input data. If she scored 45% or more, program logic makes another check in the fourth decision symbol to ensure that her percentage is less than 60%. If this condition is false, the student scored 60% or more. Hence, she passed in first division (not second division). Therefore, once again, program logic returns the control to the operation of reading input data without writing any output data. If the condition in the fourth decision symbol is true, the candidate passes all checks for being a female student who passed in second division. Hence, only in this case, program logic performs the operation “Write output data”, and increments Count by one.

292

Chapter 8 ■ Planning the Computer Program

Start Count = 0 Read input data

1

Is Sexcode = Z?

Yes

2

No 1

No

Is Sexcode = F? Yes Add marks of all subjects giving Total Percentage = Total / 10

1

No

Is Percentage >= 45? Yes

1

No

2

Write Count

Stop

Is Percentage < 60? Yes Write output data Add 1 to Count 1

Figure 8.10. Flowchart of Figure 8.9 redrawn to illustrate the use of connectors.

Readers should go through the logic of this flowchart repeatedly until they are convinced that output list will contain details of only those female students who passed in second division. Readers should also get convinced that finally, when program logic encounters the trailer record and the operation “Write Count” prints the value of Count, the printed value is equal to the total number of female students passed in second division. This flowchart is an example of a multiple-decision chart. Figure 8.10 shows the flowchart of Figure 8.9 with the use of connectors. There are four exit connectors having label 1, all of which indicate flow of control to the flowchart symbol having an entry connector labeled 1. This symbol is the input symbol in the flowchart. Similarly, the exit connector having label 2 indicates flow of control to the entry

■ Flowcharts

293

connector labeled 2. Readers should compare the flowcharts of Figure 8.9 and Figure 8.10, and be convinced that both of them represent the same logic. A flowchart may seem simple to prepare, but we need much practice to think through a problem in discrete, logical steps, to assume nothing, and to forget nothing. Moreover, different people often solve a problem in different ways, and therefore, different flowcharts are possible for a problem. Also, note that a completed flowchart is not a complete computer program. It is only an aid to programming. For a problem, it defines the procedure and the logic for solving the problem.

Levels of Flowcharts There are no set standards for the amount of detail required in a flowchart. A flowchart that outlines the main segments of a program (shows only broad details) is a macro flowchart, and a flowchart with more details is a micro flowchart (also called detailed flowchart).

Part of a macro flowchart

Add marks of all subjects giving Total

1 I=1 Total = 0

A micro flowchart

Total = Total + Marks (I) I=I+1 No

Is I > 10? Yes 1

Figure 8.11. Detailed flowchart of add marks of all subjects giving Total.

For example, let us consider the processing box having the instruction “Add marks of all subjects giving Total” in the flowcharts of our examination problem. Figure 8.11 shows a detailed flowchart for the operation in this processing box. The detailed flowchart shows how program logic computes the value of Total. Similarly, we can also convert I/O boxes for “Read” and “Write” operations into detailed flowcharts.

Flowcharting Rules While programmers have a good deal of freedom in creating flowcharts, the American National Standards Institute (ANSI) has recommended a number of general rules and guidelines to help standardize flowcharting process. Various computer manufacturers and data processing departments usually have similar flowcharting standards. The basic flowcharting rules and guidelines are as follows: 1.

First chart the main line of logic, and then incorporate details.

Chapter 8 ■ Planning the Computer Program

294 2.

Maintain a consistent level of details in a flowchart.

3.

Do not chart every detail in a flowchart; otherwise, the flowchart will only be a graphic representation of all the steps of the corresponding program. A reader interested in details can refer to the program itself.

4.

Use easy to understand statements within flowchart symbols. Use descriptive titles written in your own language, rather than machine-oriented language.

5.

Be consistent in using names and variables in a flowchart.

6.

Go from left to right and top to bottom in constructing a flowchart.

7.

Keep a flowchart as simple as possible, and avoid crossing of flow lines.

8.

If you need a new page while drawing a flowchart, break the flowchart at an input or output point. Moreover, use labeled connectors to link portions of the flowchart on different pages.

Advantages and Limitations of Flowcharts Advantages Use of flowcharts for program planning provides the following benefits: 1.

Better communication. A flowchart is a pictorial representation of a program. Therefore, it is easier for a programmer to explain the logic of a program to others through a flowchart, rather than the program itself.

2.

Effective analysis. A macro flowchart, which charts the main line of logic of a software system, becomes the system’s model that can be broken down into detailed parts for study and further analysis of the system.

3.

Effective synthesis. Normally, several programmers are associated with the design of a large software system, with each programmer being responsible for only a part of the entire system. Hence, if each programmer draws a flowchart for his/her part of design, the flowcharts of all programmers put together can help visualize the overall system design. At this stage, we can detect any problem in linking various parts of the system and modify the design accordingly. Thus, we often use flowcharts as working models in the design of new programs and software systems.

4.

Proper program documentation. Program documentation involves collecting, organizing, storing, and maintaining a complete historical record of programs, and other documents associated with a system. Good documentation is needed because: (a) Documented knowledge belongs to an organization, and does not disappear with the departure (resignation/retirement) of a programmer. (b) If an organization decides to postpone a project, documented work helps in restarting the project later from the stopped stage. (c) When a programmer wants to modify an existing program, documented work provides him/her a more understandable record of originally done work. Flowcharts, therefore, provide valuable documentation support.

5.

Efficient coding. Once a flowchart is ready, programmers find it easy to write the corresponding program because the flowchart serves as a roadmap for them. It guides them to go from the starting point of the program to the final point, without omitting any step. The result is an error-free program developed at a faster pace.

■ Decision Tables

295

6.

Systematic debugging. A flowchart is helpful in detecting, locating, and removing mistakes (bugs) in a program in a systematic manner because programmers find it easier to follow the logic of the program in flowchart form. The process of removing errors (bugs) in a program is known as debugging.

7.

Systematic testing. Testing is the process of confirming whether a program does all its intended jobs under specified constraints. For testing a program, the testing team executes the program with different sets of data as input to test the different paths in program logic. For example, to test the complete logic of the program for Example 8.6, the following sets of data are necessary: (a) Data for a male student. (b) Data for a female student, who scored less than 45%. (c) Data for a female student, who scored exactly 45%. (d) Data for a female student, who scored more than 45% but less than 60%. (e) Data for a female student, who scored exactly 60%. (f) Data for a female student, who scored more than 60%. (g) The trailer data having sentinel value.

A flowchart is helpful in designing test data for systematic testing of programs.

Limitations In-spite-of their many advantages, flowcharts have the following limitations: 1.

Flowcharts are time consuming and laborious to draw with proper symbols and spacing, especially for large complex programs. In this chapter, you have seen examples of small flowcharts developed for relatively small programs. You can imagine how difficult it would be to develop a detailed flowchart for a program containing over 50,000 statements.

2.

Owing to the symbol-string nature of flowcharting, any change or modification in program logic usually requires a completely new flowchart. Redrawing a flowchart being a tedious task, many programmers do not redraw or modify the corresponding flowcharts when they modify their programs. This leaves a program and its flowchart in an inconsistent state. That is, the logic used in the program and that shown in its flowchart do not match. This defeats the purpose of use of flowcharts as documentation support for programs. To take care of this problem, many companies use software tools that generate flowcharts automatically from program code. These software tools read a program’s instructions and draw an equivalent flowchart of its logic. This backward approach draws flowcharts from program codes mainly for documentation purpose.

3.

There are no standards determining the amount of detail that should be included in a flowchart.

Because of such limitations, many organizations use alternative tools for representing the algorithms (logic) of their programs, two of which are described here.

DECISION TABLES What is a Decision Table? Decision tables define the word statement of a problem in a tabular form. They define complex program logic by charting what decisions or actions a computer is to take because of input data. Decision tables are preferred to flowcharts for charting the logic of those programs which have a large number of branches.

Chapter 8 ■ Planning the Computer Program

296

Most decision tables have six parts. Figure 8.12 shows the basic format of a decision table. Its first part, called “Table Heading”, contains the name and/or number of the decision table. Some larger applications may use two or more decision tables in the analysis part of program development. The second part, called “Condition Stub”, describes the conditions that could exist in program logic. Thus, the contents of condition stub correspond to the conditions contained in the decision symbols of a flowchart. The third part, called “Action stub”, contains the action statements. These statements correspond to the statements located in non-decision symbols of a flowchart. While the condition statements reveal possible states of input data, the action statements describe possible actions of a computer system. The right hand side of the decision table contains the rule numbers (part 4), the actual conditions (part 5), and the actions taken by a computer (part 6). The condition entries correspond to the paths leading out from decision symbols. Table heading

Decision rules

Condition stub

Condition entries

Action stub

Action entries

Figure 8.12. Format of a decision table.

We follow the following steps for constructing a decision table: 1.

Define the problem that we have to solve.

2.

List all conditions that we need to test in the problem.

3.

List actions that we need to take corresponding to each combination of conditions.

4.

Form a decision table using the two lists.

Sample Decision Table Figure 8.13 shows a decision table for the problem of Example 8.6, whose flowchart is in Figure 8.9. In this table, each rule number is a given condition followed by a specific action by a computer. The six rule numbers, six actual conditions, and associated actions by the computer are described here. Rule 1: The student is a female, and percentage marks obtained is 45% or more, and percentage marks obtained is less than 60%. The computer should write output data, add 1 to Count, and then read the next student’s record. It is a case of a female student, who passed in second division. Rule 2: The student is a female, and percentage marks obtained is 45% or more, and percentage marks obtained is not less than 60%. The computer should read the next student’s record without performing any other operation. It is a case of a female student, who scored 60% or more. Rule 3: The student is a female, and percentage marks obtained is not 45% or more. A dash (-) in this column against the last condition indicates that this condition is irrelevant for arriving at the action. In fact, if Percentage is not equal to or greater than 45, it has to be less than 60. Percentage greater than or equal to 60 is logically impossible. Such conditions in a decision table, which are irrelevant in arriving at an action, are known as don’t care conditions and are denoted by a dash. For this rule, the computer should read the next student’s record without performing any other operation. It is a case of a female student, who scored less than 45%.

■ Decision Tables Examination problem of Example 8.6 1

297

Decision rule number 2 3 4 5 6

Condition statements Sexcode = Z

N

N

N

N

N

Sexcode = F

Y

Y

Y

Y

N

Y -

Percentage = > 45

Y

Y

N

-

-

-

Percentage < 60

Y

N

-

-

-

-

Action taken Calculate Percentage

X

Write output data

X

Add 1 to Count

X

Read next student’s record

X

X

X

X

Write Count

X

Stop

X Figure 8.13. Decision table for the examination problem of Example 8.6.

Rule 4: The student is a female, and other conditions are don’t care. The computer should calculate Percentage after adding marks of all subjects and then proceed to test further conditions. It is a case of a female student whose Percentage is yet to be calculated. Rule 5: The student is a male, and other conditions are don’t care. The computer should read the next student’s record without performing any other operation. It is a case of a male student. Rule 6: In all previous five rules, it was ascertained that the current record is not a trailer record because all these rules have a value N (No) for the condition Sexcode = Z. In this rule, Sexcode is equal to Z, which indicates a trailer record. Hence, the computer should write the value of Count and then “Stop”. Other conditions in this rule are don’t care. It is a case of a trailer record. In a decision table, “Y” means yes, “N” means no, “-” means don’t care, and “X” means the computer should take this action.

Advantages and Limitations of Decision Tables Advantages Normally, we use decision tables in place of flowcharts because: 1.

They provide concise description of logically complex situations.

2.

They are easier to draw and change than flowcharts.

3.

They provide documentation that is more compact. A small table can replace several pages of flowcharts.

4.

It is also easier to follow a particular path down one column than through several flowchart pages.

Chapter 8 ■ Planning the Computer Program

298

Limitations Decision tables, however, are not so widely used as flowcharts because: 1.

Large decision tables can become incomprehensible and difficult to modify.

2.

Flowcharts are better able to express the total sequence of events necessary for solving a problem.

3.

Many programmers and beginners are more familiar with and prefer flowcharts.

PSEUDOCODE What is Pseudocode? Pseudocode is another program-planning tool used for planning program logic. “Pseudo” means imitation or false and “Code” refers to the instructions written in a programming language. Pseudocode, therefore, is an imitation of actual computer instructions. These pseudo-instructions are phrases written in a natural language (e.g., English, French, German, etc.) that a computer cannot understand. However, pseudocode uses a structure that resembles computer instructions. When a programmer uses pseudocode for planning a program, he/she can concentrate solely on developing the logic of the program without worrying about the syntax for writing program instructions because pseudocode does not have any syntax rules for formulating instructions. Once the programmer is convinced that the program logic is sound, he/she can convert the pseudocode easily into a suitable programming language. Since the emphasis of pseudocode is on program design, it is also known as Program Design Language (PDL).

Pseudocodes for Basic Logic (Control) Structures During early days of program development, many programmers developed program logics for large programs with mazes of branches (jumps from one portion of the program to another) that altered the sequence of processing operations. Such programs are now referred to as “spaghetti code” because their program flowcharts appeared more like a plate of spaghetti than like logical analyses of programming problems. Understanding the logic of such programs was difficult for someone other than the developer, and even for the developer after a lapse of few months. Hence, these programs were difficult to modify for incorporating suggested enhancements, and became nightmares for those responsible for their maintenance. Researchers later proved that it is possible to express any program logic, no matter how complex, by using only the following three simple logic (control) structures: 1.

Sequence logic

2.

Selection logic

3.

Iteration (or looping) logic

They also proved that programs structured by using only these three logic structures are easier to understand, because we can read them from top to bottom. That is, by conceptualizing the logic of a program in the form of these three logic structures, programmers can avoid writing spaghetti code, and produce programs that are easy to understand and maintain. This also helps in reducing program errors and the time spent in program testing. Writing of programs by using these three basic control structures soon became widely accepted as a more scientific approach to solving a programming problem, and was termed structured programming technique. As good programming practices, it recommended that programmers should develop program logics and write programs using the three basic logic structures. Therefore, we present here the pseudocodes for the three basic logic structures (along with their flowcharts for those who are more comfortable with flowcharts).

■ Pseudocode

299

Sequence Logic Sequence logic performs instructions one after another in sequence. Thus, for writing pseudocode instructions for sequence logic, we write the instructions in the order (or sequence) of their execution. Logic flow of psuedocode is from top to bottom. Figure 8.14 shows an example of sequence logic structure.

Process 1 Process 1 Process 2 (a) Flowchart

Process 2 (b) Pseudocode

Figure 8.14. Flowchart and pseudocode for sequence structure .

Selection Logic Selection logic, also known as decision logic, makes decisions. It selects a path out of two or more paths in program logic. We depict selection logic as an IF…THEN…ELSE, or an IF…THEN, or a CASE structure. The flowcharts of Figures 8.15, 8.16, and 8.17, respectively illustrate the logic of these structures along with their corresponding pseudocodes.

IF (condition)

Yes

THEN

No

IF Condition THEN Process 1

ELSE

Process 1

Process 2

ELSE Process 2 ENDIF (b) Pseudocode

(a) Flowchart

Figure 8.15. Flowchart and pseudocode for IF…THEN…ELSE selection structure.

Yes

IF (condition)

THEN Process 1

(a) Flowchart

No IF Condition THEN Process 1 ENDIF

(b) Pseudocode

Figure 8.16. Flowchart and pseudocode for IF…THEN selection structure.

300

Chapter 8 ■ Planning the Computer Program

Type 1

Yes

Process 1

No Type 2

Yes

Process 2

No

Type n

Yes

Process n

CASE Type Case Type 1:

Process 1

Case Type 2:

Process 2

Case Type n:

Process n

ENDCASE

No (a) Flowchart

(b) Pseudocode

Figure 8.17. Flowchart and pseudocode for CASE selection structure.

IF…THEN…ELSE structure means that if the condition is true, then do Process 1, else (if the condition is not true) do Process 2. Hence, program logic executes either Process 1 or Process 2 depending on whether the specified condition is true or false. However, if we do not want to choose between two processes, and simply want to decide whether to execute a process or not, then we use IF…THEN structure. IF…THEN structure means that if the condition is true, then do Process 1, otherwise (if the condition is not true) skip over Process 1. CASE structure represents multiple-way selection logic. It allows choosing from more than two control paths in a program logic enabling selection of one of any number of statements or statement groups. The CASE statement of Figure 8.17 indicates that if the value of Type is equal to Type-1, execute Process 1, if it is equal to Type-2, execute Process 2, if it is equal to Type-3, execute Process 3, and so on. In all these structures, Process 1, Process 2, Process 3, etc. can be one or more processes. They are not limited to a single process. In case of IF…THEN and IF…THEN…ELSE decision structures, ENDIF indicates their end; and in case of CASE structure, ENDCASE indicates its end.

Iteration (or Looping) Logic Iteration logic produces loops in program logic whenever there is a need to execute one or more instructions several times depending on some condition. It uses two structures called DO…WHILE and REPEAT…UNTIL. Figures 8.18 and 8.19 show the flowcharts and pseudocodes for DO…WHILE and REPEAT…UNTIL structures respectively. As both DO…WHILE and REPEAT…UNTIL are used for looping, it is important to know the difference between the two structures. In DO…WHILE, looping continues as long as the condition is true, and stops when the condition is not true. Since program logic tests the condition for looping at the beginning of the loop, if the condition is false when it first encounters the loop, it will not execute the statements in the loop at all (not even once). On the other hand, in REPEAT…UNTIL, looping continues until the condition becomes true. That is, program logic repeats execution of statements within the loop as long as the condition is not true. Since it tests the condition for looping at the end of the loop, it will execute the statements in the loop at least once. In both DO…WHILE and REPEAT…UNTIL, the loop must contain a statement, which changes the condition that controls the loop. If it does not, looping will continue without end, becoming an infinite loop. Remember that, no program should contain an infinite loop. ENDDO marks the end of a DO…WHILE structure, and UNTIL followed by some condition marks the end of a REPEAT...UNTIL structure.

■ Pseudocode

301

False

Condition?

DO WHILE Condition

True

Process 1

Process 1 Process n ENDDO Process n

(a) Flowchart

(b) Pseudocode

Figure 8.18. Flowchart and pseudocode for DO…WHILE iteration structure.

Process 1

Process n False

REPEAT Process 1 Process n

Condition?

UNTIL Condition

True (a) Flowchart

(b) Pseudocode

Figure 8.19. Flowchart and pseudocode for REPEAT…UNTIL iteration structure.

Sample Pseudocode Figure 8.20 shows the pseudocode version of the algorithm for the problem of Example 8.6, whose flowchart is in Figure 8.9. In the pseudocode, the first line initializes the value of Count to zero and the second line reads input data of the first student. The third line is the beginning of a loop using DO…WHILE structure. It indicates that the loop continues as long as Sexcode field is not equal to Z, that is, as long as program logic does not find the trailer record. In this example, the loop includes a series of decisions followed by an instruction to read next student’s record. The first statement in DO…WHILE loop checks if Sexcode is equal to F. If it is, the next statement calculates Percentage and again the third statement within the loop checks if Percentage is equal to or greater than 45. If it is, the next statement checks if Percentage is less than 60. This is a series of three IF…THEN decision structures. Each one ends with an ENDIF vertically aligned below the corresponding IF. Program logic performs the two instructions – “Write output data” and “Add 1 to Count” only if all the three conditions (that of Sexcode being F, Percentage being equal to or more than 45, and Percentage being less than 60) are true (answered yes). If any of the three conditions is not true, the logic path goes to the statement of reading the next student’s record. After program logic processes the last student’s record, the next record that it takes for processing is the trailer record with value of Sexcode equal to Z. This causes the DO…WHILE loop to stop because

Chapter 8 ■ Planning the Computer Program

302

the condition (Sexcode not equal to Z) is no longer true. Hence, the next logical step is the instruction following ENDDO. At this stage, program logic prints the value of Count (Write Count), and finally program execution stops (Stop). Set Count to zero Read first student record DO WHILE Sexcode is not equal to Z IF Sexcode = F THEN Calculate Percentage IF Percentage > = 45 THEN IF Percentage < 60 THEN Write output data Add 1 to Count ENDIF ENDIF ENDIF Read next student record ENDDO Write Count Stop Figure 8.20. Pseudocode for the examination problem of Example 8.6.

Set Count to zero Read first student record DO WHILE Sexcode is not equal to Z IF Sexcode = F THEN Calculate Percentage IF Percentage > = 45 THEN IF Percentage < 60 THEN Write output data Add 1 to Count ENDIF ENDIF ENDIF Read next student record ENDDO Write Count Stop Figure 8.21. Non-indented version of the pseudocode of Figure 8.20.

Indentation One important feature of pseudocode as a program-planning tool is use of indentation. Indentation of each statement within DO…WHILE loop, shows that it is part of the loop. Similarly, indentation of statements within each IF…THEN structure specifies the statements that are part of each structure. Use of indentation in pseudocode is the same technique used in various programming languages. Its sole purpose is to represent the logical structure of a program with greater clarity. With this technique, we can easily tell which program statements are part of which logic structure of the total program logic. To appreciate this factor, readers should compare the equivalent non-indented pseudocode of Figure 8.21 with that of Figure 8.20. The difference in clarity would be far greater, if this were a longer pseudocode covering, for instance, one or more pages.

Advantages and Limitations of Pseudocode Advantages 1.

As compared to a flowchart, converting a pseudocode to a programming language is much easier.

2.

As compared to a flowchart, it is easier to modify the pseudocode of program logic when program modifications are necessary.

3.

Writing of pseudocode involves much less time and effort than drawing an equivalent flowchart. Moreover, as compared to writing a program in a programming language, pseudocode is easier to write because it has only a few rules to follow, allowing a programmer to concentrate on the logic of the program.

Limitations 1.

In case of pseudocode, a graphic representation of program logic is not available.

■ Data Structures

303

2.

There are no standard rules to follow in writing pseudocode. Different programmers use their own style of writing pseudocode. Hence, communication problem occurs due to lack of standardization.

3.

As compared to flowchart, beginners often find it more difficult to write pseudocode of program logic or to follow a program’s logic from its pseudocode.

DATA STRUCTURES Another important aspect of program planning is the choice of right data structures for implementing an algorithm. Data structures define ways of organizing and storing different data types used in an algorithm. Knowledge of data structures is important for good program planning because: 1.

Choice of proper data structures allows easy conversion of an algorithm (which is not yet in program form) into a program.

2.

Properly chosen data structures enable execution of a program with minimal resources (CPU time, memory space, disk space, etc.).

3.

Execution time of a program depends heavily on the choice of data structures.

4.

Often, quality of the result produced by a program also depends on the choice of data structures.

Programming languages often implement commonly used data structures as data types and the references and operations they provide. Since data structures are so crucial in program planning and design, most modern programming languages include them as standard libraries in their program development environments. Examples of such program development environments are Standard Template Library Containers of C++, Collections Framework of Java, and .NET Framework of Microsoft.

Types of Data Structures Data structures are of two types: 1.

Primitive types. Basic data types of a programming language are called primitive data types. Programmers compose other data types using these data types. Examples of primitive data types are character (used to store a character), integer (used to store a positive or negative integer whose allowable range is programming language dependent), and real (used to store a positive or negative real number whose allowable range is programming language dependent).

2.

Composite types. These data types use primitive data types and other already defined composite data types. A programming language often defines commonly used composite data types and operations on them. For example, C language defines pointer, array, and string data structures with operations on them. Moreover, most modern programming languages provide the flexibility to programmers to define their own composite data types known as user defined data types. Hence, a user defined data type is a composite data type whose composition is not part of the specification of the user’s programming language. A programmer declares them in a program whenever required. Some commonly used composite data structures are array, linked list, stack, queue, hash table, tree, binary tree, binary search tree, graph, and heap. Their general structure, operations on them, and their uses are described here.

Array An array is a group of data elements in which we identify an individual element by its position in the group, relative to the first element. Hence, we access an individual element of an array by indexing. An array is a homogeneous data

Chapter 8 ■ Planning the Computer Program

304

structure in the sense that all elements of an array are of the same data type. It is also linear in the sense that all elements of an array are stored in contiguous memory locations. Figure 8.22 shows a few examples of arrays in C language.

1010

92

1005

Y

1008

63

1004

A

1006

82

1004

1012 1008

10.25

1003

B

250.00

1002

1004

155.50

1001

M O

1002

66 84

1000

45

1000

82.75

1000

B

int

marks[6];

float

price[4];

char

city[6];

Each element being an int occupies 2 bytes

Each element being a float occupies 4 bytes

Each element being a char occupies 1 byte

marks[0] = 45 marks[1] = 84 . . . marks[5] = 92

price[0] = 82.75 price[1] = 155.50 . . . price[3] = 10.25

city[0] = ‘B’ city[1] = ‘O’ . . . city[5] = ‘Y’

(a) An array of integers having 6 elements

(b) An array of real numbers having 4 elements

(c) An array of characters having 6 elements

Figure 8.22. Illustrating the concept of arrays.

Types of Indexing We access an individual element of an array by specifying its position in the group of elements with a subscript or index. Depending on the programming language, one of the following three implementations of indexing is possible: 1.

Zero-based indexing. In this case, the first element of an array (also called the “origin” element) is always denoted by subscript value of 0 (zero), increasing monotonically up to one less than the declared size of the array (see Figure 8.22). Thus, A[0] is the first element, and A[5] is the fourth element of array “A”. C programming language popularized zero-based indexing.

2.

One-based indexing. In this case, the first element of an array is always denoted by subscript value of 1 (one). Thus, A[1] is the first element, and A[5] is the fifth element of array “A”. Programming languages meant for scientific applications, such as FORTRAN, use one-based indexing.

3.

n-based indexing. In this case, a programmer is free to choose the lower bound of an array (subscript value of first element), which may even be negative to suit the problem at hand.

■ Data Structures

305

Types of Arrays Based on the binding to subscript value ranges and the binding to storage, arrays are of the following four types: 1.

Static arrays. In a static array, the subscript ranges are statically bound and storage allocation is static (done before run time). The main advantage of static arrays is efficiency because they do not require any dynamic allocation or deallocation of storage.

2.

Semi-static arrays. In a semi-static array, the subscript ranges are statically bound, but storage allocation is done at declaration elaboration time during execution. The main advantage of semi-static arrays over static arrays is storage space efficiency. For example, a large array in one procedure can use the same storage space as a large array in another procedure, as long as the two procedures are never active at the same time.

3.

Semi-dynamic arrays. In a semi-dynamic array, the subscript ranges are dynamically bound and storage allocation is dynamic (done during run time). However, once the subscript ranges are bound and storage space is allocated, they remain fixed during the lifetime of the array. The main advantage of semi-dynamic arrays over static and semi-static arrays is flexibility. The size of an array need not be known until the array is about to be used.

4.

Dynamic arrays. In a dynamic array, the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array’s lifetime. The main advantage of dynamic arrays over other types is greater flexibility. A dynamic array can grow and shrink during program execution as the need for space changes.

Multi-dimensional Arrays In Figure 8.22, we saw examples of arrays in which each array element is indexed by a single integer. Such arrays are called one-dimensional arrays. Several numerical and graphics applications use multidimensional arrays in which each array element is indexed by an ordered list of same number of integers. For example, each array element is indexed by an ordered list of two integers (such as A[3, 5]) in a two-dimensional array, and by an ordered list of three integers (such as B[1, 3, 4]) in a three-dimensional array. Hence, an array in which each array element is indexed by an ordered list of k integers is called k-dimensional array. Figure 8.23 shows an example of a two-dimensional array. Normally, we represent matrices as two-dimensional arrays. As Figure 8.22 shows, memory allocation to a one-dimensional array and mapping its elements to the allocated memory space is straightforward. This is because the memory of a computer itself is a large one-dimensional array. However, for an array of higher-dimension, although the allocated memory space is equal to the total storage space required for storing all its elements, the mapping of its elements to the allocated storage space is not straightforward. The two commonly used methods of doing this mapping are: 1.

Row-major order. In which the elements are stored in the allocated memory space row-by-row – first row elements, then second row elements, then third row elements, and so on. Obviously, in this case, the elements are indexed by [row number, column number]. Figure 8.23(b) shows the mapping of the elements of array “A” of Figure 8.23(a) in row-major order.

2.

Column-major order. In which the elements are stored in the allocated memory space column-by-column – first column elements, then second column elements, then third column elements, and so on. Obviously, in this case, the elements are indexed by [column number, row number]. Figure 8.23(c) shows the mapping of the elements of array “A” of Figure 8.23(a) in column-major order.

306

Chapter 8 ■ Planning the Computer Program

Row 1 Row 2 Row 3

1016

4

A [3, 3]

1016

4

A [3, 3]

Col 1

Col 2

Col 3

1014

9

A [3, 2]

1014

6

A [3, 2]

5

7

3

1012

1

A [3, 1]

1012

3

A [3, 1]

1010

6

A [2, 3]

1010

9

A [2, 3]

1008

8

A [2, 2]

1008

8

A [2, 2]

1006

2

A [2, 1]

1006

7

A [2, 1]

1004

3

A [1, 3]

1004

1

A [1, 3]

1002

7

A [1, 2]

1002

2

A [1, 2]

1000

5

A [1, 1]

1000

5

A [1, 1]

2 1

8 9

6 4

(a) A two-dimensional array “A”

(b) Memory allocation and storage of elements of array “A” in row-major order: A[Row, Col]

(c) Memory allocation and storage of elements of array “A” in columnmajor order: A[Col, Row]

Figure 8.23. A two-dimensional array, its memory allocation, and storage of its elements in row-major and column-major orders. The example uses one-based indexing. In case of zero-based indexing, the rows and columns would have been numbered as 0, 1, and 2, and the array elements would have been indexed as A [0, 0], A [0,1], A [0, 2], A [1, 0], A [1, 1], A [1, 2], A [2, 0], A [2, 1], and A [2, 2].

Operation

Meaning

Declare

Declares a new array with details such as array type (static, dynamic, etc.), data type of its elements, its dimension, etc. For instance, int marks [6] declares an array of integers having six elements in C language.

Access (an element)

Enables accessing of an array element by specifying its index value. For instance, the second element of array “marks” is accessed by marks [1] in C language.

Allocate

Allocates memory space to a dynamic array.

Deallocate

Destroys a dynamic array by deallocating memory space allocated to it.

Initialize

Initializes an array at the time it is allocated memory space. For instance, int list [ ] = {5, 8, 6, 2}; declares list to be an array of four integer elements initialized to the values 5, 8, 6, and 2 in C language.

Array operators

Languages for scientific and engineering applications, like FORTRAN 90 and APL, support both unary and binary operators for operations on arrays. Examples of such operators include those for reversing the elements of a vector, reversing the columns of a matrix, reversing the rows of a matrix, obtaining the transpose of a matrix, inverting a matrix, obtaining the sum of two vectors or matrices, obtaining the difference of two vectors or matrices, obtaining the product/multiplication of two vectors or matrices, etc. Several languages have library functions for performing such array operations.

Figure 8.24. Some commonly supported operations for handling arrays.

Operations for Handling Arrays Figure 8.24 lists some commonly supported operations for handling arrays. Note that not all programming languages support all these operations and some programming languages may support additional operations.

■ Data Structures

307

Uses of Arrays A A R R A Y Majority of computer programs need to model 5 collection of objects of same type, which they O F 2 need to process in the same way. Thus, the universal need for arrays is obvious. For 6 A R R A Y S example, computer programs often use arrays for representation of strings, vectors, and Figure 8.25. An array of arrays. Array “A” is an array of three elements. Each element of array matrices. Arrays can also have arrays as “A” is in turn an array of n elements, where elements. Computer programs use arrays of n is the value of the corresponding arrays for creation of ragged arrays (also element of array “A”. called jagged arrays), in which the valid m range of one index depends on the value of another. For example, Figure 8.25 shows an array of arrays in which different rows are of different sizes. Array of arrays are particularly of use for creating multi-dimensional arrays in those programming languages that support only one-dimensional arrays as primitives.

Linked List A linked list consists of a set of nodes linked together. Each node has two basic fields – data field and pointer field (see Figure 8.26). The data field contains the data, while the pointer field links the node to another node belonging to the same linked list. The data field itself may have multiple sub-fields when each node stores multiple data elements. Depending on the type of linked list, the pointer field may have only one pointer (single-linked lists) or two pointers (doubly-linked lists). In addition to the nodes, a linked list has a pointer called “head”, which points to the first node of the linked list. It enables us to keep track of the list. Some implementations of linked lists also use a “tail” pointer, which points to the last node of the linked list. This makes adding of elements to the tail of a list more efficient.

Data

Pointer

(a) The two basic fields of a node of a linked list

Last node’s pointer points to NULL Head

S

I

N

H

A

(b) A linked list having five nodes Figure 8.26. Linked list.

The main advantage of a linked list over a conventional array is that the order of the data elements in a linked list may be different from the order in which a computer stores the data elements in memory or on disk, allowing traversal of the data elements in a different order. Recall that the data elements of an array are stored in contiguous memory locations. Of course, this advantage of linked list comes at the cost of storing a pointer field with each data element, which requires additional storage space for the pointers. Linked lists also have the flexibility to grow and shrink dynamically because they permit insertion and removal of nodes at any point in the linked list. For a newly added node to a linked list, a computer can allocate the required memory space wherever it is available because a linked list does not require contiguous memory space for storage of its nodes. Some programming languages, such as LISP and Scheme, support linked list as a built in data structure with operations to access, insert, and remove data elements from linked lists. Other programming language, such as C, C++ and Java, rely on the use of primitive data types and language supported address referencing mechanism to create linked lists.

Chapter 8 ■ Planning the Computer Program

308

Types of Linked Lists Many different types of linked lists exist. Three of the commonly used types are: 1.

Singly-linked list. In its basic form, each node of a singly-linked list points to its successor node and the pointer of the last node is a NULL pointer [see Figure 8.27(a)]. The “head” pointer points to the first node, and we use it to keep track of the list. Inserting a new node at the head of a list is efficient because of the “head” pointer. However, for adding a node at the end of the list (after the last node), we need to locate the last node first, for which the entire list needs to be traversed, which is inefficient for lists with large number of nodes. To solve this problem, we use a “tail” pointer, which points to the last node of a list [see Figure 8.27(b)]. This simple enhancement allows efficient execution of both “prepend” and “append” operations.

Head S

I

N

H

A

(a) A singly-linked list in its basic form

Head

Tail I

S

N

H

A

(b) A singly-linked list with a tail pointer

Head I

S

N

H

A

(c) A circular list

Head S

I

N

H

A

(d) A doubly-linked list Figure 8.27. Commonly used types of linked lists.

2.

Singly-linked circular list. Each node of a singly-linked circular list (or simply circular list) points to its successor node and the pointer of the last node points to the first node (instead of being a NULL pointer). The “head” pointer also points to the first node. Figure 8.27(c) shows a circular list. Use of circular list instead of singly-linked list often simplifies an application code and makes the application run faster.

3.

Doubly-linked list. Each node of a doubly-linked list has two pointers – “left” and “right”. The left pointer of a node points to its left neighbour (if any) and the right pointer points to its right neighbour (if any). The left pointer of the leftmost node and the right pointer of the rightmost node are NULL pointers. The “head” pointer points to the first node. Figure 8.27(d) shows a doubly-linked list. Some applications are more convenient to program with a doubly-linked list than with a singly-linked list or a circular list.

■ Data Structures

309

Operations for Handling Linked Lists Figure 8.28 lists some commonly supported operations for handling linked lists. Note that all programming languages that support linked list do not necessarily support all these operations and some programming languages may support additional operations. Operation

Meaning

Create

Creates a new linked list. Creates an empty list if no elements are specified

Destroy

Destroys an existing linked list and frees the memory allocated to its various elements

Prepend

Add a new node at the head of the linked list (before the first node)

Append

Add a new node at the tail of the linked list (after the last node)

Insert (k)

Add a new node after the kth node of the linked list

Delete (k)

Delete the kth node of the linked list

Figure 8.28. Some commonly supported operations for handling linked lists.

Uses of Linked Lists We use linked lists primarily for list processing applications, in which we need to represent symbolic data in the form of lists (collection of non-contiguous memory cells linked together with pointers). Compiler development, pattern recognition, games simulation, and Artificial Intelligence (AI) applications need such data representation and their handling capability. We also use linked lists to implement other data structures (such as the one in Figure 8.25).

Stack A stack represents a pile of data items stacked one on top of another. It allows addition or removal of a data item from the top of the pile only. Since we can add or remove a data item from the top of a stack only, it is always the last item put into the stack, which becomes the first removable item from the stack. Hence, we also refer to a stack as last-infirst-out (LIFO) data structure. “Push” and “Pop” operations are commonly associated with stacks to respectively add and remove data items. Figure 8.29 shows a stack with “push” and “pop” operations.

Top Top Top

N H A

Push (I)

I N H A

Push (S)

S I N H A

Top

Pop  S

I N H A

Figure 8.29. A stack. “Push” adds a data item at the top of the stack and “Pop” removes a data item from the top of the stack.

Operations for Handling Stacks Figure 8.30 lists the commonly supported operations for handling stacks. Some programming languages support additional operations.

310

Chapter 8 ■ Planning the Computer Program

Operation

Meaning

Create

Creates an empty stack

Push

Adds a new data item to the stack

Pop

Removes a data item from the stack

Top

Returns data item at the top of the stack without removing it from the stack

IsEmpty

Returns “true” if stack is empty, otherwise returns “false”

IsFull

Returns “true” if stack is full, otherwise returns “false”

Figure 8.30. Commonly supported operations for handling stacks.

Uses of Stacks There are several instances in programming where stacks are natural implementation choice. For example, in case of nested function calls, when a function calls another function, which in turn calls a third function, it is important that the third function returns control to the second function rather than the first function. Using a stack to store the return addresses of functions enforces the proper order of calls. Similarly, in the basic design of an operating system, designers use stacks for interrupt handling and operating system function calls. Compilers also use stacks for parenthesis matching to ensure that a program statement uses the same number of “open” and “close” parentheses in the correct order.

Queue A queue represents a container of data items, which is open from both sides and in which a data item can be added at one end only (called “rear” end) and removed from the other end only (called “front” end). Adding an element to a queue is known as “enqueue” operation and removing an element from the queue is known as “dequeue” operation. A queue data structure is like a line of customers waiting at a service counter (for example, a ticket-booking counter). As new customers arrive, they join at the end of the queue. The customer at the head of the queue receives service first and leaves the queue. Hence, we also refer to a queue as first-in-first-out (FIFO) data structure. Figure 8.31 shows a queue with “enqueue” and “dequeue” operations.

front S

front

rear I

Enqueue (H)

N

N front

H

A rear

S

Dequeue  I

rear I

N

I front

front Enqueue (A)

H

N

H

A

S

rear I

N

H

Dequeue  S

rear

Figure 8.31. A queue. “Enqueue” adds a data item at the rear of the queue and “Dequeue” removes a data item from the front of the queue.

A

■ Data Structures

311

Operations for Handling Queues Figure 8.32 lists the commonly supported operations for handling queues. Some programming languages support additional operations. Operation Create

Meaning Creates an empty queue

Enqueue

Adds a new data item to the queue

Dequeue

Removes a data item from the queue

First

Returns data item at the front of the queue without removing it from the queue

Last

Returns data item at the rear of the queue without removing it from the queue

IsEmpty

Returns “true” if queue is empty, otherwise returns “false”

IsFull

Returns “true” if queue is full, otherwise returns “false” Figure 8.32. Commonly supported operations for handling queues.

Uses of Queues The first-in-first-out property of a queue makes it the preferred data structure for implementing activities, which we need to perform on first-come-first-served basis. For example, we often use queues in programming networks, operating systems, and other situations in which many processes share resources such as CPU, memory, communication channel, I/O devices, etc., and the scheduler allocates resources on a first-come-first-served basis.

Hash Table A hash table is a table for storing data items, which uses a hash function to map data items into positions in the table. The hash function is applied on a data item itself or on a pre-specified field (called “key” field) of the data item (when the data item has more than one field) to map the data item into a specific position (called “index” or “bucket”) in the hash table. Hence, if “f” is the hash function and “ki” is the value of the key of data item “i”, then data item “i” is mapped to index position “pi” of the hash table, where pi = f(ki). A hash table enables quick storage and retrieval of data items. To search for a data item “a” with key “k a”, we compute pa = f(ka) and see if there is an element at position “pa” in the table. If so, we have found the data item, else the table has no data item with this key. If we have found the data item, we can retrieve or delete it from the table. If not found, we can add the data item to the table by inserting it at position “pa”. Here we have assumed an ideal hash table, which is large enough to have a position for each key value. Although, this is possible for applications having small range of key values, there are many applications having so large range of key values that such a large hash table is practically infeasible. For such applications, we use a hash table whose size is smaller than the range of key values and a hash function that maps several different keys into the same position of the hash table. In this case, the most commonly used hash function is the one based on modulo operator, which has the form f(k) = k % S where k is the key, S is the size of hash table (number of positions in it), and % is the modulo operator. The positions in the hash table are indexed from 0 to S-1. Figure 8.33 shows a hash table with 8 positions (indexed 0 to 7), in which data items are mapped using the hash function

312

Chapter 8 ■ Planning the Computer Program f(k) = k % 8

Figure 8.33(a) shows the original status of the hash table with three data items. Figure 8.33(b) and 8.33(c) show the status after inserting data items with key values 76 and 95, respectively. Now suppose we wish to enter another data item with key value 33 into the hash table. Since, f(33) = 33 % 8 = 1, this data item should be entered in position having index value 1. However, this position is already having a data item. In such a situation, we say that a collision has occurred. Hash tables use some mechanism to handle collisions. One such mechanism is to use linked lists with the hash table. In this case, a position itself points to a linked list, which contains all the data items mapped to that position. Figure 8.34 shows a hash table with the use of linked lists for handling collisions. In this hash table, each position has space for a pointer that points to a node of a linked list when the key of a data item maps to that position.

Data items

Table indices 0 1

0 65

1

2 3

1

2

Insert (76)

27

4 5

0 65

05

6

Insert (95)

3

27

3

27

4

76

4

76

5

05

5

05

6

7

65

2

6

7

7

f(05) = 05 % 8 = 5 f(27) = 27 % 8 = 3 f(65) = 65 % 8 = 1

f(76) = 76 % 8 = 4

(a) Original status

(b) Status after inserting 76

95

f(95) = 95 % 8 = 7

(c) Status after inserting 95

Figure 8.33. A hash table with 8 positions and hash function f(k) = k % 8.

Table indices 0

40

1

33

65

3

27

35

59

75

4

76

5

05

21

45

53

2

85

6 7

95

Figure 8.34. A hash table with linked lists for handling collisions. It uses the hash function f(k) = k % 8.

■ Data Structures

313

To search for a data item with key “k”, we first compute f(k) for obtaining the table index, and then search the linked list that is pointed to by the pointer at this position. To insert a data item, we need to first ensure that the hash table does not contain a data item with the same key. For this, we need to search only the linked list pointed to by the pointer at the position to which the hash function maps the key of the data item. As a search precedes each insert, maintaining the linked lists in ascending order of the key values can make search and insert operations more efficient. We delete a data item from the hash table by first searching it in the manner mentioned above, and then deleting the corresponding node from the linked list to which it belongs.

Operations for Handling Hash Tables Figure 8.35 lists the commonly supported operations for handling hash tables. Operation

Meaning

Create

Creates an empty hash table. Table size and hash function are specified

Insert

Adds a new data item to the hash table

Delete

Removes a data item from the hash table

Search (k)

Returns the data item with key “k”. Returns “false” if the data item is not found. Figure 8.35. Commonly supported operations for handling hash tables.

Uses of Hash Tables We often use hash tables for maintaining large tables (containing many data items) for those applications that need almost random access to any data item in the table. Such applications cannot rely on building a sorted table of data items and then using the binary search method for searching a data item because the performance of insert, delete, and search operations in this case are directly proportional to the number of data items. However, with the use of hash tables, performance of insert, delete and search operations are independent of the number of data items and depend largely on the hash function and the load on the hash table (lengths of associated linked lists).

Tree A tree consists of a finite set of elements (called nodes) that are connected by a finite set of directed lines (called branches). A branch coming out of a node is called its out-degree branch, while a branch going in a node is called its in-degree branch. Degree of a node is equal to the sum of its in-degree and out-degree branches. A non-empty tree (which has at lease one node) has a node with in-degree equal to zero. This node is called the root of the tree. All other nodes have in-degree equal to one. The out-degree of any node (including the root) can be zero, one, or more. Figure 8.36 shows an example of a tree.

Chapter 8 ■ Planning the Computer Program

314

Root Level 0

A Branch AD B

Level 1

C

D Branch DI

E

Level 2

Root: A Leaves: C, E, F, G, H, I Internal nodes: B, D Height: 2 + 1 = 3

F

G

H

I

Parents: A, B, D Children: B, C, D, E, F, G, H, I Siblings: {B, C, D}, {E, F, G}, {H, I} Nodes: A, B, C, D, E, F, G, H, I Branches: AB, AC, AD, BE, BF, BG, DH, DI

Figure 8.36. Example of a tree with associated terminologies.

Terminologies Used With Trees In addition to the above terminologies, we also frequently use the following terminologies with trees: 1.

Parent. A parent is a node that has one or more successors. Its out-degree is greater than zero. For example in Figure 8.36, node A is the parent of nodes B, C, D; node B is the parent of nodes E, F, G; and node D is the parent of nodes H, I.

2.

Child. A child is a node that has a parent (a predecessor node). Its in-degree is one. For example in Figure 8.36, nodes B, C, D are children of node A; nodes E, F, G are children of node B; and nodes H, I are children of node D.

3.

Siblings. Two or more nodes with the same parent are siblings. For example in Figure 8.36, sets of siblings are {B, C, D}, {E, F, G}, and {H, I}.

4.

Leaf. A leaf is a node that has no successor. Its out-degree is zero. For example in Figure 8.36, nodes C, E, F, G, H and I are leaves.

5.

Internal node. A node that is neither a root nor a leaf is an internal node. For example in Figure 8.36, nodes B and D are internal nodes.

6.

Path. A path between two nodes is a sequence of nodes between them such that each node in the sequence is adjacent to the next one (has a branch between them). For example in Figure 8.36, the path between nodes A and F is A B F, and the path between nodes G and H is G B A D H.

7.

Ancestor. Any node in the path from the root to a node is the node’s ancestor. For example in Figure 8.36, node E’s ancestors are nodes A and B; node I’s ancestors are nodes A and D; and node C’s ancestor is node A.

8.

Descendent. All nodes in the paths from a node to a leaf are descendents of the node. For example in Figure 8.36, node A’s descendents are nodes B, C, D, E, F, G, H, I; node B’s descendents are nodes E, F, G; and node D’s descendents are nodes H, I.

9.

Level. The level of a node is the number of branches in the path from the root to the node. Hence, the root is at level 0, its children (if any) are at level 1, their children (if any) are at level 2, and so on. For example in Figure 8.36, node A is at level 0; node B, C, D are at level 1; and node E, F, G, H, I are at level 2. Note that siblings are always at the same level, but not all nodes at the same level are necessarily siblings because they may have different parents.

■ Data Structures

315

10. Height. The height of a tree is the level of the leaf in the longest path from the root plus one. The height of

the tree of Figure 8.36 is 3. The height of an empty tree is -1. 11. Subtree. A subtree is any part of a tree below the root. The first node of a subtree is known as its root. A

subtree can be divided into other subtrees. For example in Figure 8.36, nodes B, E, F, G form a subtree with root B; C is a subtree with root C; and D, H, I form a subtree with root D. In addition, E is a subtree of the subtree with root B.

Operations for Handling Trees Figure 8.37 lists the commonly supported operations for handling trees. Operation

Meaning

Create

Create a tree

Delete

Delete a tree and free its nodes

Height

Determine the height of a tree

Size

Determine the number of nodes in a tree

Figure 8.37. Commonly supported operations for handling trees.

Uses of Trees Trees are natural choice as data structures for representing hierarchical relationship among a set of data elements. For example, we use trees to represent family structure, hierarchical administrative structure of an organization, module hierarchy of a software system, etc. We also often use trees in computer science for representing arithmetic expressions and for implementing efficient methods of searching large data sets.

Binary Tree A binary tree is a special type of tree in which the out-degree of any node is less than or equal to two (zero, one, or two). Hence, a node can have maximum two subtrees, which are called left subtree and right subtree of the node. If a node’s out-degree is zero, it is a leaf node, which has neither left subtree nor right subtree. If its out-degree is one, it has either left subtree or right subtree. If its out-degree is two, it has both left and right subtrees. Figure 8.38 shows examples of such binary trees. Linked representation is the most popular way to represent a binary tree. In this representation, each node has three fields – a data field, a “LeftChild” pointer field that points to the left child of the node, and a “RightChild” pointer field that points to the right child of the node. If a node has no left child or right child, the corresponding pointer(s) is set to zero (NULL). Additionally, it uses a pointer “Root” to keep track of the root of the binary tree. We can access all nodes of a binary tree by starting with the “Root” pointer and following “LeftChild” and “RightChild” pointers of the nodes. Figure 8.39 shows the linked representation of the binary tree of Figure 8.38(g).

316

Chapter 8 ■ Planning the Computer Program

A A

B (b) A two-node binary tree. Out-degree of A is one. It has a left subtree.

(a) A single-node binary tree. Out-degree of A is zero. It is a leaf node having neither left subtree nor right subtree.

A

A B

B (c) A two-node binary tree. Out-degree of A is one. It has a right subtree.

C

(d) A three-node binary tree. Out-degree of A is two. It has both left and right subtrees.

A

A B

B

C

C (e) A three-node binary tree. Out-degree of both A and B is one, and they both have a left subtree.

(f) A three-node binary tree. Out-degree of both A and B is one. A has a left subtree and B has a right subtree.

A

A B

B

C E

D

D

(g) A five-node binary tree. Out-degree of A, B, and C is 2, 0, and 2, respectively. Both A and C have both left and right subtees.

C E

F

Figure 8.38. A few examples of binary trees.

Root A 0

B

0 0

C D

0

G

(h) A seven-node binary tree. Out-degree of A, B, and C is 2. They all have both left and right subtrees.

0

E

0

Figure 8.39. Linked representation of the binary tree of Figure 8.38(g).

■ Data Structures

317

Properties of Binary Trees By their very nature, binary trees have the following properties: 1.

A binary tree with n nodes (n > 0) has exactly n-1 branches.

2.

A binary tree of height h (h ≥ 0) has at least h and at most 2h-1 nodes.

3.

The height of a binary tree having n nodes (n ≥ 0) is at most n and at least ┌log2 (n+1)┐.

Binary Tree Traversal Traversing a tree means visiting all its nodes in a defined order and listing (or processing) the data elements of the nodes in the sequence in which the process visits the nodes. The three common methods to traverse a binary tree are preorder, inorder and postorder traversal. They are described here. 1.

Preorder. In this method, the process visits each node first, followed by its left subtree and then its right subtree. For example, if we perform preorder traversal of the binary tree of Figure 8.40, we visit/process the root node (+) first, followed by its left subtree and then its right subtree. To traverse the left subtree, we visit/process its root node (*) first, followed by the only node in its left subtree (a) and then the only node in its right subtree (b). Since we have visited/processed all the nodes in the left subtree of the root node, we are now ready to process the right subtree of the root node (+). Following the rules of preorder traversal, we visit/process the nodes in the right subtree in the order /, c, d. This completes the traversal resulting in the sequence +*ab/cd of the data elements of the nodes (see Figure 8.40).

+ /

*

a

A binary tree representing the algebraic expression: (a * b) + (c / d). Output of its:

b

c

d

Preorder traversal is : +*ab/cd Inorder traversal is : a*b+c/d Postorder traversal is : ab*cd/+

Figure 8.40. Preorder, inorder and postorder traversals of a binary tree.

2.

Inorder. In this method, for each node, the process first visits/processes the node’s left subtree, followed by the node itself, and then its right subtree. For example, if we perform inorder traversal of the binary tree of Figure 8.40, since we have to first visit/process the left subtree of root node (+), we trace from the root to the far-left leaf node (a) before visiting/processing any other node. After visiting/processing node ‘a’, we visit/process its parent node ‘*’, followed by its right subtree node ‘b’. This completes the traversal of the left subtree of root node (+). Hence, we now visit/process the root node (+), followed by its right subtree. Following the rules of inorder traversal, we visit/process the nodes in the right subtree in the order c, /, d. This completes the traversal resulting in the sequence a*b+c/d of the data elements of the nodes (see Figure 8.40).

3.

Postorder. In this method, for each node, the process first visits/processes the node’s left subtree, followed by its right subtree, and then the node itself. For example, if we perform postorder traversal of the binary tree of Figure 8.40, since we have to first traverse the left subtree of root node (+), we trace from the root to the far-left leaf node (a) before visiting/processing any other node. After visiting/processing node ‘a’, we visit/process the right subtree of its parent node ‘*’, which happens to be a single node (b). We then visit/process the parent node ‘*’. This completes the traversal of the left subtree of the root node (+). Hence, we now traverse the right subtree of root node (+). Following the rules of postorder traversal, we visit/process the nodes in the right subtree in the order c, d, /. Finally, we visit/process the root node (+) itself. This completes the traversal resulting in the sequence ab*cd/+ of the data elements of the nodes (see Figure 8.40).

Chapter 8 ■ Planning the Computer Program

318

Operations for Handling Binary Tree Figure 8.41 lists the commonly supported operations for handling binary trees. Operation

Meaning

Create

Create a binary tree

Delete

Delete a binary tree and free its nodes

Height

Determine the height of a binary tree

Size

Determine the number of nodes in a binary tree

IsEmpty

Returns “true” if a binary tree is empty, othersie returns “false”

PreOrder

Output the data fields in preorder traversal method

InOrder

Output the data fields in inorder traversal method

PostOrder

Output the data fields in postorder traversal method

Figure 8.41. Commonly supported operations for handling binary trees.

Uses of Binary Trees We frequently use binary trees in computer science because of the interesting relationship between binary trees and binary number system. As Figure 8.40 shows, we also use them for representation of algebraic expressions involving binary operators (such as +, -, *, /). We will now see how to use binary trees to implement binary search trees and binary heaps.

Binary Search Tree A binary search tree is a binary tree with the following properties: 1.

The data element of each node has a key field and no two nodes have the same key value (all keys are distinct).

2.

The keys of all nodes in the left subtree of the root have values less than the key in the root.

3.

The keys of all nodes in the right subtree of the root have values greater than the key in the root.

4.

Each subtree is itself a binary search tree.

The above definition does not allow multiple data elements with same key value in a binary search tree. A binary search tree with duplicates allows multiple data elements with same key value. It is a binary tree with the following properties: 1.

The data element of each node has a key field and two or more nodes may have the same key value (all keys need not necessarily be distinct).

2.

The keys of all nodes in the left subtree of the root have values less than or equal to (≤) the key in the root.

3.

The keys of all nodes in the right subtree of the root have values greater than or equal to (≥) the key in the root.

4.

Each subtree is itself a binary search tree.

Figure 8.42 shows some valid binary search trees and Figure 8.43 shows some invalid binary search trees.

■ Data Structures

8

319

8

8 5

26

5

26

44

3 (a)

(c)

(b)

8

8 26

5

5

26 44

23 3 (d)

(e)

Figure 8.42. Some valid binary search trees.

8

8

10

26

5

(a) Violates property 2 because 10 > 8

7

(b) Violates property 3 because 7 < 8

8

8 5 6

3

7

(c) Violates property 4 because the left subtree of the root is not a valid binary search tree (6 > 5)

26

5

26

12

(d) Violates property 1 because the left subtree of the root has a node with key value 12 that is not less than the key value 8 of the root

Figure 8.43. Some invalid binary search trees.

Inserting a New Data Element in a Binary Search Tree To insert a new data element with key value ‘k’ in a binary search tree, we must first verify that there is no node in the binary search tree with data element having the same key value ‘k’. For this, we perform a binary search of the nodes for a data element having key value ‘k’. If the search is unsuccessful, we create a new node with the new data element at the point the search terminated. For example, to insert a data element with key 7 into the binary search tree of Figure 8.44(a), we first search for 7. This search terminates unsuccessfully, and the last node examined is the one with key 5. Hence, we insert the new data element in a node, which we create as the right child of this node. Figure 8.44(b) shows the resulting binary search tree. Similarly, Figure 8.44(c) shows the resulting binary search tree after inserting a new data element with key value 25 into the binary search tree of Figure 8.44(b).

Chapter 8 ■ Planning the Computer Program

320

5

8

8

8

3

3 (a) A binary search tree

3

7

26

5

26

5

26

7

25

(c) Resulting binary search tree after (b) Resulting binary search tree inserting a node with a data after inserting a node with a element having key value 25 data element having key value 7

Figure 8.44. Examples of inserting a new data element in a binary search tree.

Operations for Handling Binary Search Trees Figure 8.45 lists the commonly supported operations for handling binary search trees. Operation Create Search (k, e) Insert (e) Delete (k, e) Ascend

Meaning Create an empty binary search tree Search for the data element with key value ‘k’ and return the data in ‘e’. Returns “false” if the search fails Insert the data element in ‘e’ into the binary search tree. Key value ‘k’ is a predefined field of the data element Delete the data element with key value ‘k’ and return it in ‘e’. Ouput all data elements of a binary search tree in ascending order of their key values

Figure 8.45. Commonly supported operations for handling binary search trees.

Uses of Binary Search Trees Organizing data elements with unique key values in the form of binary search trees enables efficient execution of the following types of operations: 1.

Outputting of data elements in ascending order of their key values.

2.

Searching a data element with specified key value.

3.

Inserting a new data element.

4.

Deleting the kth data element.

Several applications need to implement these operations and benefit from the use of binary search trees.

Graph A graph is a collection of nodes (also called vertices) and edges (also called lines). Each edge (i, j) joins two nodes i and j. We frequently use the following terminologies with graphs:

■ Data Structures

321

1.

Directed edge. An edge with an orientation is a directed edge. Hence, a directed edge (i, j) is different from the directed edge (j, i), the former being oriented from node i to node j and the latter from node j to node i. The graph of Figure 8.46(b) has directed edges.

2.

Undirected edge. An edge with no orientation is an undirected edge. Hence, undirected edges (i, j) and (j, i) are the same. The graph of Figure 8.46(a) has undirected edges.

3.

Directed graph. If all edges of a graph are directed edges, then the graph is called a directed graph (also called digraph). The graph of Figure 8.46(b) is a digraph.

4.

Undirected graph. If all edges of a graph are undirected edges, then the graph is called an undirected graph (also called graph). The graph of Figure 8.46(a) is an undirected graph.

5.

Weighted graph/digraph. When we assign weights to the edges of a graph/digraph, we call the resulting graph/digraph a weighted graph/digraph. For example, we can draw a graph to represent major cities of a country connected by roads. In this graph, we can express the distance between two cities by adding weights to the edges. Figure 8.46(c) shows a weighted graph.

6.

Adjacent nodes. Two nodes i and j of a graph are adjacent, if (i, j) is an edge in the graph. In the graph of Figure 8.46(a), nodes a and b, a and c, a and d, b and d, and c and d are adjacent. However, in the digraph of Figure 8.46(b), a is adjacent to b, a is adjacent to d, b is adjacent to d, c is adjacent to a, and d is adjacent to c.

a

a c

b

c

b

b

d

(a) An unidirected graph

(b) A directed graph (digraph)

8 85

60

d

Loop

a

25

d

c 40

(c) A weighted graph

a

a

a c

b

c

b d

d (d) A digraph with a loop

c

b d

(e) Two disconnected (disjoint) graphs

Figure 8.46. Examples of different types of graphs.

7.

Path. A path is a sequence of nodes in which each node is adjacent to the next one. For example, in the graph of Figure 8.46(a), there are three paths from node a to node c. They are (a, c), (a, d, c) and (a, b, d, c). Similarly, (b, a, c), (b, d, c), (b, a, d, c) and (b, d, a, c) are the four paths from node b to node c. However, in the digraph of Figure 8.46(b), there is only one path from node a to node c, which is (a, c); and from node b to node c, which is (b, a, c). This is because of the difference in the definition of adjacent nodes in graph and digraph.

8.

Cycle. A cycle is a path, whose start and end nodes are the same. For instance, (a, b, d, a), (a, c, d, a) and (a, b, d, c, a) are examples of cycles in the graph of Figure 8.46(a); and (a, c, d, a) and (a, c, d, b, a) are examples of cycles in the digraph of Figure 8.46(b).

Chapter 8 ■ Planning the Computer Program

322 9.

Loop. A loop is a self-edge, which is of the form (i, i). It is a single edge, which starts and ends at the same node. Figure 8.46(d) shows a digraph with a loop. Note that a graph/digraph cannot contain any loop because a valid edge connects two different nodes. However, loops are useful in some graphical representations in computer science. For example, we use loops in state transition diagrams.

10. Connected graph. A connected graph has a path from any node to any other node. The graph of Figure

8.46(a) is a connected graph. 11. Disconnected/disjoint graph. A graph, which is not a connected graph, is a disconnected/disjoint graph. In a

disconnected/disjoint graph, certain groups of nodes form an island and do not have any connection with the rest of the graph. Figure 8.46(e) shows two disconnected/disjoint graphs. 12. Complete graph/digraph. A graph/digraph is complete when it has an edge between every pair of nodes.

Notice that a complete graph with n nodes will have n(n-1)/2 edges, and a complete digraph with n nodes will have n(n-1) edges. Figure 8.47 shows complete graphs for n = 1, 2, 3 and 4. Figure 8.48 shows complete diagraphs for n = 1, 2, 3 and 4.

a

a

a

a

c

n=1

c

b

b

b

d

n=2

n=3

n=4

Figure 8.47. Complete graphs for n = 1, 2, 3 and 4. Number of edges in each = n(n-1)/2.

a a

c b

n=1

a

a

n=2

b n=3

c

b d n=4

Figure 8.48. Complete digraphs for n = 1, 2, 3 and 4. Number of edges in each = n(n-1).

13. Strongly and weakly connected digraphs. A digraph is strongly connected, if there is a path from each node

to every other node in it. That is, it has a path from i to j and from j to i for every pair of nodes i and j. A digraph is weakly connected, if each node does not have a path to every other node in it. That is, in a weakly connected digraph there are at least two nodes i and j such that there is no path either from i to j or from j to i. Figure 8.49 shows examples of strongly and weakly connected digraphs.

■ Data Structures

g

h

g

f

f e

e a

323

a

d

b

d

b c

c

(b) A weakly connected digraph

(a) A strongly connected digraph

Figure 8.49. Examples of strongly and weakly connected digraphs.

14. Subgraph. If the set of nodes and set of edges of a graph G1 are subsets of the set of nodes and set of edges of

another graph G2, then G1 is a subgraph of G2. Figure 8.50 (b to i) are subgraphs of Figure 8.50(a). 15. Spanning tree. An undirected graph that is connected and has no cycles is a tree. A subgraph of a graph G

that contains all the nodes of G and is a tree is a spanning tree of G. Figure 8.50 (f to i) are some spanning trees of the graph in Figure 8.50(a).

a c

b

a

a

d

d

d

(a)

(b)

(c)

a

a c

b

c b d

d

(d)

(e)

a c

b

a

c

c

b

a

a c

b

c

b

d

d

d

d

(f)

(g)

(h)

(i)

Figure 8.50. Examples of subgraphs and spanning trees.

Representation of Graphs and Digraphs Adjacency matrix is the most frequently used representation for graphs and digraphs in computers. Let G(V, E) be a graph in which V is the set of nodes (vertices) and E is the set of edges. Let the graph has n nodes and V = {1, 2, …, n}. Then the adjacency matrix of G is an n x n matrix A, in which each element is either zero or one defined in the following manner:

324

Chapter 8 ■ Planning the Computer Program

If G is an undirected graph, then A (i, j) =

If G is a digraph, then

1 if (i, j)  E or (j, i)  E 0 otherwise

A (i, j) =

1 if (i, j)  E 0 otherwise

Figure 8.51 (a) and (b) show the adjacency matrices for the graph of Figure 8.46(a) and the digraph of Figure 8.46(b), respectively.

a ↓

b ↓

c ↓

d ↓

a ↓

b ↓

c ↓

d ↓

1

2

3

4

1

2

3

4



1

0

1

1

1

a →

1

0

0

1

0

b →

2

1

0

0

1

b →

2

1

0

0

0



3

1

0

0

1

c



3

0

0

0

1

d →

4

1

1

1

0

d →

4

1

1

0

0

a c

(a) Adjacency matrix for the graph of Figure 8.46(a)

(b) Adjacency matrix for the digraph of Figure 8.46(b)

Figure 8.51. Adjacency matrices for the graph of Figure 8.46(a) and the digraph of Figure 8.46(b).

The adjacency matrix of a graph/digraph is subsequently stored using the method for storing arrays. There are several optimization methods on storage requirement for storing adjacency matrices of a graph/digraph. For example, notice that the adjacency matrix for undirected graphs is symmetric [A (i, j) = A (j, i)]. Hence, we need to explicitly store only the elements above (or below) the diagonal. Similarly, notice that all diagonal elements for the adjacency matrices of both undirected graphs and digraphs are zero. Hence, we need not store them.

Graph Search Methods In applications based on graphs, we often need to find things such as: 1. Is there a path between two nodes i and j in a given graph/digraph? 2. Does a graph/digraph contain one or more cycles? 3. Is a graph connected or disjoint? 4. Is a graph/digraph complete? 5. Is a digraph strongly or weakly connected? 6. Find one or more spanning trees of a graph. Many of these functions require us to find out all nodes of a graph that can be reached (has a path) from a given node (start node). The two standard methods to do this are breadth-first search and depth-first search. They are described here. A graph/digraph often has multiple paths to a node from a given node (start node). Hence, while performing breadthfirst search or depth-first search, we may arrive at the node from more than one direction. We must, therefore, ensure that we visit each node only once during the search process. The popular method to do this is to use a “Visited” flag at each node. This flag at each node is set to OFF before we start the search process, and is set to ON for a node as soon

■ Data Structures

325

as we visit the node for the first time. We do not revisit a node, whose flag is ON even if we arrive at it again during the search process. Out of the two, we use depth-first search method more frequently to obtain efficient algorithms for analyzing graphs. 1. Breadth-first search. The example of Figure 8.52 illustrates the method. In this method, we pick up the starting node (D) and determine the set of nodes adjacent to D, which is {I} for our example. We now pick up the nodes in this set one-by-one and determine the new nodes (nodes not yet visited) adjacent to each node in the set. The set of nodes adjacent to node I are {G, R}. We repeat this process until we find that there are no more adjacent nodes. For example, the set of new nodes adjacent to node G is {A} and adjacent to node R is {P}. Next, set of new nodes adjacent to node A is {H}, and set of new nodes adjacent to node P is null. Finally, set of new nodes adjacent to node H is null. Hence, the set of nodes reachable from starting node D is {D, I, G, R, A, P, H}. Normally, we use a queue to implement the breadth-first search algorithm. As we process each node, we place all of its adjacent nodes in the queue. We always pick up the node at the front of the queue as the next node in the search process. We delete a node from the queue when we pick it up for processing. Figure 8.52(b) shows the contents of the queue as we progress through the search process. Figure 8.52(c) shows the subgraph formed by the edges used to reach the nodes visited during the search process.

A

G D

I

H

S

P

R (a) A digraph

Front Rear

Empty

D

I

G R

R A

A P

P H

H

1

2

3

4

5

6

7

(b) Queue contents as we progress through the search process. The numbers indicate the sequence in which front node from the queue is picked up for processing.

1

2

D

I

3

5

7

G

A

H

R

P

4

6

(c) Subgraph formed by the edges used to reach the nodes visited during the search process. The numbers indicate the sequence in which the nodes are picked up for processing.

Figure 8.52. Example of breadth-first search method of graph search.

Empty

326

Chapter 8 ■ Planning the Computer Program 2. Depth-first search. In this method, we select a node (starting node is selected first) and determine the set of new nodes (nodes not yet visited) adjacent to it. If this set is empty (there is no new node adjacent to the selected node), the search terminates. Otherwise, we select the nodes in this set one-by-one and initiate a depth-first search for each, selecting the next node in the set when the depth-first search terminates for the previously selected node. The depth-first search for the graph terminates when we complete the depth-first search for all the nodes in the set.

Normally, we use a stack to implement depth-first search algorithm. The search process begins by pushing the first node (starting node) into the stack. We then pop the stack to select the next node for processing. After processing the selected node, we push all its adjacent new nodes into the stack. We repeat the above process until the stack becomes empty. The search process completes when the stack becomes empty. The same example of Figure 8.52(a), which is reproduced in Figure 8.53(a), illustrates the method. We select the starting node D and push it into the stack. We then pop the stack to select node D for processing and push node I into the stack, which is the only new node adjacent to D. We now pop the stack to select node I for processing and push nodes G and R into the stack, which are the new nodes adjacent to I. We now pop the stack to select node R for processing and push nodes A and P into the stack, which are the new nodes adjacent to R (node G is not new since we have already visited it). We now pop the stack to select node P for processing and push node H into the stack, which A

G D

I

H

S

P

R

(a) A digraph

Empty

D

I

R G

1

2

3

P A G

H A G

A G

G

4

5

6

7

Empty

(b) Stack contents as we progress through the search process. The numbers indicate the sequence in which the top node from the stack is selected for processing.

1

2

D

I

7

6

5

G

A

H

R

P

3

4

(c) Subgraph formed by the edges used to reach the nodes visited during the search process. The numbers indicate the sequence in which the nodes are selected for processing.

Figure 8.53. Example of depth-first search method of graph search.

is the new node adjacent to P. We now pop the stack to select node H for processing and do not push any node into the stack because there are no new nodes adjacent to H. We next pop the stack to select node A for processing and do not push any node into the stack because there are no new nodes adjacent to A (nodes P and H are not new since we have already visited them). We next pop the stack to select node G for processing and do not push any node into the

■ Data Structures

327

stack because there are no new nodes adjacent to G (node A is not new since we have already visited it). As the stack is empty now, the search process terminates. Figure 8.53(b) shows the contents of the stack as we progress through the search process. Figure 8.53(c) shows the subgraph formed by the edges used to reach the nodes visited during the search process.

Operations for Handling Graphs/Digraphs Figures 8.54 and 8.55 list the commonly supported operations for handling graphs and digraphs, respectively.

Operation

Meaning

Create(n)

Creates a graph (undirected) having n nodes and no edges

Add(i, j)

Adds the edge (i, j) to the graph

Delete(i, j)

Deletes the edge (i, j) from the graph

Exist(i, j)

Returns “true” if edge (i, j) exists in the graph, else returns “false”

Vertices

Returns the number of nodes in the graph

Edges

Returns the number of edges in the graph

Degree(i)

Returns the degree of node i

Figure 8.54. Commonly supported operations for handling graphs (undirected).

Operation Create(n)

Meaning Creates a digraph having n nodes and no edges

Add(i, j)

Adds the edge (i, j) to the digraph

Delete(i, j)

Deletes the edge (i, j) from the digraph

Exist(i, j)

Returns “true” if edge (i, j) exists in the digraph, else returns “false”

Vertices

Returns the number of nodes in the digraph

Edges

Returns the number of edges in the digraph

InDegree(i)

Returns the in-degree of node i

OutDegree(i)

Returns the out-degree of node i

Figure 8.55. Commonly supported operations for handling digraphs.

Uses of Graphs Graphs are a convenient means of expressing problems that involve relationships between objects, places, or concepts. For instance, we can describe who knows whom in a room as a collection of nodes, each representing a person, and directed edges from a node to other nodes representing all the persons whom that person (represented by the node) knows. Representation of such abstract problems as graphs simplifies the process of creating mental models of problems, which in turn leads to better problem solving. Hence, we often use graphs for modeling and analysis of a variety of situations such as: 1. Analysis of electrical and computer networks. 2.

Study of molecular structure of chemical compounds.

3.

Representation of routes in airline network, railway network, road network, or communication network.

Chapter 8 ■ Planning the Computer Program

328 4.

Representation of dependencies among modules of software.

5.

Representation of dependencies among various activities of a project for better project planning.

6.

In genetic studies.

Modeling a problem as a graph often presents new approaches to solve the problem or even leads directly to a solution derived from graph theory.

Heap A heap is a complete binary tree in which the value of each node is greater (less) than or equal to those of its children (if any). A complete tree is one that has every level filled in before adding a node to the next level, and one that has the nodes in a given level filled in from left to right, with no breaks. For instance, a tree with a root node that has only one child must have its child as the left node. If the value of each node in a heap is greater than or equal to those of its children (if any), then the heap is called a max heap. On the other hand, if the value of each node in a heap is less than or equal to those of its children (if any), then the heap is called a min heap. Obviously, the value of the root node is maximum in the max heap and minimum in a min heap. Figures 8.56(a) and (b) show examples of a max heap and a min heap, respectively. 5

25 20

4

50

15

8

60

3 80

(a) A max heap

12

65

18

15

70 (b) A min heap

Figure 8.56. Examples of a max heap and a min heap.

Operations for Handling Heaps Figures 8.57 and 8.58 list the commonly supported operations for handling max heaps, and min heaps, respectively.

Operation

Meaning

Max

Returns the value of the root node

DeleteMax

Deletes the root node and restructures the heap

Insert(i)

Inserts a new node with value i into the heap and restructures the heap

Delete(i)

Deletes a node with value i from the heap and restructures the heap

Merge

Joins two max heaps to form a new heap containing all the elements of both Figure 8.57. Commonly supported operations for handling max heaps.

■ Points to Remember

Operation

329

Meaning

Min

Returns the value of the root node

DeleteMin

Deletes the root node and restructures the heap

Insert(i)

Inserts a new node with value i into the heap and restructures the heap

Delete(i)

Deletes a node with value i from the heap and restructures the heap

Merge

Joins two min heaps to form a new heap containing all the elements of both Figure 8.58. Commonly supported operations for handling min heaps.

Uses of Heaps A heap serves as a priority queue in which the most important element (node) is always at the front of the queue, and when removed, its replacement becomes the most important element. Such a data structure is useful for implementing algorithms, which require processing of certain things in complete order, but when we do not want to perform a full sort or do not need to know anything about the rest of the elements. For example, we can optimize Dijkestra’s algorithm (a well-known algorithm) for finding the shortest path between two nodes in a graph by using a priority queue. We also use heaps to sort data by using the “heapsort” sorting algorithm.

Points to Remember 1.

To ensure that the instructions of a program are appropriate for the problem at hand and in the correct sequence, we must plan the program before writing it.

2.

The term algorithm refers to the logic of a program. It is a step-by-step description of how to arrive at a solution to a given problem.

3.

Factors often used to judge the quality of an algorithm are the time required to execute the corresponding program on a given computer, memory space required to execute it, accuracy of results produced by it, and its capability to handle a range of input data instead of a single input data (often referred to as generality property).

4.

An algorithm represented in the form of a programming language is a program. Hence, any program is an algorithm, but the reverse is not true.

5.

Programmers often use flowcharts, decision tables, and pseudocodes for representing algorithms for their programs before coding them in programming languages.

6.

A flowchart is a pictorial representation of an algorithm. Programmers often use it as a program-planning tool for visually organizing a sequence of steps necessary to solve a problem using a computer.

7.

We use decision tables to define the word statement of a problem in a tabular form. They define complex program logic by charting what decisions or actions a computer is to take because of input data.

8.

Pseudocode is a program-planning tool that allows programmers to plan program logic by writing program instructions in a natural language, such as English.

9.

Structured Programming is a more scientific approach to solving a programming problem by using only three basic logic (control) structures namely, sequence logic, selection logic, and iteration (or looping) logic.

10. Structured programming helps in producing programs that are easy to understand and maintain. It also helps in reducing program errors and the time spent in program testing. 11. We use sequence logic for performing instructions one after another in sequence. 12. We use selection logic for selecting a path out of two or more paths in program logic. It uses three control structures called IF…THEN, IF…THEN…ELSE, and CASE.

330

Chapter 8 ■ Planning the Computer Program

13. We use iteration (or looping) logic for producing loops in program logic when we need to execute one or more instructions several times depending on some condition. It uses two control structures called DO…WHILE and REPEAT…UNTIL. 14. Data structures define ways of organizing and storing different data types used in an algorithm. 15. Data structures are of two types – primitive and composite. Primitive data structures are basic data types defined in a programming language, while composite data structures are composed using primitive data structures. 16. An array is a group of data elements in which we identify an individual element by its position in the group, relative to the first element. Hence, we access an individual element by indexing. 17. A linked list consists of a set of nodes linked together. Each node has two basic fields – data field and pointer field. The data field contains the data, while the pointer field links the node to another node belonging to the same linked list. In addition to the nodes, a linked list has a pointer called “head”, which points to the first node of the linked list. We use it to keep track of the list. 18. A stack represents a pile of data items stacked one on top of another. We add/remove a data item from the top of the pile only. We also refer to it as last-in-first-out (LIFO) data structure. 19. A queue represents a container of data items, which is open from both sides and in which we can add a data item at one end only (called “rear” end) and remove from the other end only (called “front” end). We also refer to it as first-in-first-out (FIFO) data structure. 20. A hash table is a table for storing data items, which uses a hash function to map data items into positions in the table. If “f” is the hash function and “ki” is the value of the key of data item “i”, then data item “i” is mapped to index position “p i” of the hash table, where pi = f(ki). 21. A tree consists of a finite set of elements (called nodes) that are connected by a finite set of directed lines (called branches). A non-empty tree (which has at lease one node) has a node with in-degree equal to zero. This node is called the root of the tree. All other nodes have in-degree equal to one. The out-degree of any node (including the root) can be zero, one, or more. 22. A binary tree is a special type of tree in which the out-degree of any node is less than or equal to two (zero, one, or two). Hence, a node can have maximum two subtrees, which are called left subtree and right subtree of the node. 23. A binary search tree is a binary tree with the following properties:  The data element of each node has a key field and no two nodes have the same key value (all keys are distinct).  The keys of all nodes in the left subtree of the root have values less than the key in the root.  The keys of all nodes in the right subtree of the root have values greater than the key in the root.  Each subtree is itself a binary search tree. 24. A graph is a collection of nodes (also called vertices) and edges (also called lines). Each edge (i, j) joins two nodes i and j. If all the edges of a graph are directed edges, then the graph is called a digraph. When we assign weights to the edges of a graph/digraph, the resulting graph/digraph is called a weighted graph/digraph. 25. A heap is a complete binary tree in which the value of each node is greater (less) than or equal to those of its children (if any). If the value of each node in a heap is greater than or equal to those of its children (if any), then the heap is called a max heap. On the other hand, if the value of each node in a heap is less than or equal to those of its children (if any), then the heap is called a min heap.

Questions 1.

Why is it advisable to plan the logic of a program before writing it?

2.

What is an algorithm? What are the characteristics necessary for a sequence of instructions to qualify as an algorithm?

3.

Write the factors that we often use to judge the quality of an algorithm.

4.

What are the ways that we commonly use to represent algorithms? Which of these can we use to solve the corresponding problem on a computer?

5.

Any program is an algorithm, but the reverse is not true. Explain why.

6.

What is a program-planning tool? How is it useful? Name three commonly used program-planning tools.

7.

What is a flowchart?

8.

How does a flowchart help a programmer in program development?

■ Questions 9.

Why do flowcharts use standard symbols? Draw basic flowchart symbols and describe their functions.

10.

What is a record? What is a trailer record?

331

11.

What is a sentinel value? Discuss its use.

12.

What is a process loop? What is an infinite loop?

13.

Why is it necessary to avoid infinite loops in program design?

14.

“A loop consists of a body, a test for exit condition, and a return provision.” Explain this with one example each for DO…WHILE and REPEAT…UNTIL loops.

15.

What is a generalized algorithm? Why should programs be general in nature?

16.

Explain the difference between loop control by counting and loop control by the use of sentinel value. Which is preferable and why?

17.

Illustrate the use of a counter to keep track of number of times a process executes a loop.

18.

Can there be more than one flowchart for a given problem? Write reasons for your answer.

19.

What is the difference between a macroflowchart and a microflowchart? Illustrate with an example.

20.

Write the guidelines that a programmer must follow while drawing a flowchart.

21.

Write advantages and limitations of flowcharting.

22.

Why is proper documentation of a program necessary?

23.

What are program bugs? What is debugging?

24.

What is testing of a program? How do we test a program?

25.

What are decision tables? When are they preferred to flowcharts?

26.

What are the various steps that a programmer must follow for constructing a decision table?

27.

Draw the basic format of a decision table and write the role of each part.

28.

What are don’t care conditions in decision tables?

29.

Write advantages and limitations of decision tables.

30.

What is a pseudocode? Why is it so called? Write another name for pseudocode.

31.

What is a spaghetti code? Why is it so called? What are its major drawbacks?

32.

Name the three basic logic structures used in writing structured programs and write the use of each.

33.

What is structured programming? What are its main advantages?

34.

Write an example to illustrate the use of each of the three basic logic structures used in structured programming.

35.

Draw flowcharts for the two commonly used structures for selection logic.

36.

What is the difference between IF…THEN and IF…THEN…ELSE structures?

37.

Draw flowcharts for the two commonly used structures for iteration logic.

38.

We use both DO…WHILE and REPEAT…UNTIL for looping. Explain the difference between the two structures.

39.

If the condition for looping is found to be false when the loop is encountered for the first time, how many times will the instructions inside the loop be executed in case of (a) DO…WHILE loop (b) REPEAT…UNTIL loop

Write reasons for your answer. 40.

What is the purpose of ENDIF and ENDDO statements?

41.

What is indentation? Why do we use it for writing pseudocodes?

42.

Write advantages and limitations of pseudocode.

332

Chapter 8 ■ Planning the Computer Program

43.

Three numbers denoted by variables A, B, and C are supplied as input data. Draw a flowchart for the logic to identify and print the largest one.

44.

Draw a flowchart to print a list of all students above the age of 20 in a class. Input records contain the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record.

45.

Draw a flowchart to print the name and age of the oldest student and the youngest student in a class. Input records contain the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record.

46.

Draw a flowchart for an algorithm to read and print the first 20 records in a data set. Make sure that the processing stops after the twentieth record.

47.

Input data of all employees of a company is supplied. The first field of each input record contains employee number (EmployeeNo). Assume that a trailer record having a sentinel value of 99999 for EmployeeNo terminates the input data of all employees. Draw a flowchart for the logic to count and print the total number of employees.

48.

For the problem of Question 47, we want to count and print the number of only male employees in the age group of 25 to 30. Assume that input records contain SexCode and Age fields to provide this information. Draw a flowchart for an algorithm to process this requirement.

49.

Information collected from a population survey of a city is stored in a computer. Each record contains the name, address, sex, age, profession, etc., of one citizen. We want to print the details of all adults (aged 18 years or more) and finally the total number of adults. Assume a suitable sentinel value for any field in the trailer record, and draw a flowchart for an algorithm to process this requirement.

50.

We need to search a set of examination papers graded with scores from 0 to 100 to find how many of them are above 90. We need to print the total. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for the trailer record.

51.

Each paper in a set of examination papers includes a grade of A, B, C, D, or E. We want to have separate counts of the total number of papers having grade A and those having grade E. We need to print the total counts of both types at the end. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for the trailer record.

52.

A shopkeeper wants a general program for his personal computer to prepare a bill for each customer. His idea is that as soon as a customer purchases some goods from his shop, he will supply the description, unit price, and quantity purchased for each item as input to the computer, and the computer should print each item along with its unit price, quantity purchased, and total price. Finally, the computer should also print the total cost of all items purchased by the customer. Assuming a sentinel value of zero for the quantity purchased field in the trailer record, draw a flowchart for an algorithm to process this requirement.

53.

An employer plans to pay bonus to each employee. Those earning Rs. 5000 or above are to be paid 10 percent of their salary and those earning less than Rs. 5000 are to be paid Rs. 500. Each input record contains employee number, name, and salary of an employee. Printed output should contain employee number, name, and amount of bonus to each employee. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for any field in the trailer record.

54.

An employer wants to calculate and print weekly pay of his employees. An employee’s pay record includes hours worked and pay rate. For each employee, gross pay is equal to hours worked times pay rate. However, for number of hours worked in excess of 40, overtime rate of 1.5 times the regular rate applies. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for any field in the trailer record.

55.

A data file contains a set of examination scores followed by a trailer record with a value of -1. Draw a flowchart for an algorithm to calculate and print the average of the scores.

56.

The expanded form of the data file of Question 55 includes several sets of data, each requiring calculation of its average. A trailer record with a value of -1 follows each data set and a trailer record with a value of -2 follows the last data set. Draw a flowchart for an algorithm to process this requirement.

57.

Five numbers denoted by the variables A, B, C, D, and E are supplied as input. Draw a flowchart for an algorithm to print these numbers in descending order of magnitude.

58.

Draw a flowchart for an algorithm to add up all even numbers between 0 and 100 (both inclusive) and print the result.

59.

Draw a flowchart for an algorithm to find out whether a given triangle ABC is isosceles. Assume that angles of the triangle are supplied as input. Print the answer as yes or no.

■ Questions

333

60.

Draw a flowchart for an algorithm to find out whether a given triangle ABC is a right-angled triangle. Assume that sides of the triangle are supplied as input. Print the answer as yes or no.

61.

Draw a flowchart for an algorithm to find out whether a given quadrilateral ABCD is a rectangle. Assume that all four angles and four sides of the quadrilateral are supplied as input. Print the answer as yes or no.

62.

Draw a flowchart for an algorithm to convert a number from base 10 to a new base using division-remainder technique.

63.

Draw a flowchart for an algorithm to convert a number from another base, to base 10.

64.

Construct a decision table to solve the problem described in Question 43.

65.

Construct a decision table to solve the problem described in Question 48.

66.

Construct a decision table to solve the problem described in Question 51.

67.

Construct a decision table to solve the problem described in Question 59.

68.

Construct a decision table to solve the problem described in Question 60.

69.

Write a pseudocode to solve the problem described in Question 44.

70.

Write a pseudocode to solve the problem described in Question 45.

71.

Write a pseudocode to solve the problem described in Question 48.

72.

Write a pseudocode to solve the problem described in Question 51.

73.

Write a pseudocode to solve the problem described in Question 52.

74.

Write a pseudocode to solve the problem described in Question 53.

75.

Write a pseudocode to solve the problem described in Question 54.

76.

Write a pseudocode to solve the problem described in Question 58.

77.

Write a pseudocode to solve the problem described in Question 59.

78.

What are data structures? Why is knowledge of data structures important for good program planning?

79.

Differentiate between primitive and composite data structures. Write three examples of each.

80.

What is an array? How is an individual element of an array accessed? Explain with an example.

81.

Explain with an example how an array is stored in memory. How many bytes of memory will be occupied by an array of: (a) 100 characters (b) 100 real numbers (c) 100 integers

82.

Differentiate among zero-based, one-based, and n-based indexing of arrays.

83.

Differentiate among static, semi-static, semi-dynamic, and dynamic arrays.

84.

Differentiate between one-dimensional and multidimensional arrays. Write one example of each.

85.

Differentiate between row-major order and column-major order of mapping the elements of a multidimensional array to allocated memory space. Explain with an example of each.

86.

Write five commonly supported operations for handling arrays with the function of each operation.

87.

Write three common uses of arrays.

88.

A[3, 2, 4] is a three-dimensional array in which 3, 2, and 4 are the maximum index values for first, second, and third dimensions respectively. Using zero-based indexing, write the indexes of the array in (a) row-major order and (b) columnmajor order.

89.

What is a linked list? Draw a linked list having four elements (nodes).

90.

What are the two basic fields of a node of a linked list? What is the role of “head” in a linked list? Why do some implementations of linked list use a “tail” in addition to a “head”?

91.

Write advantages of linked list as compared to array.

92.

Differentiate among singly-linked list, singly-linked circular list, and doubly-linked list. Explain each type with a diagram.

93.

Write five commonly supported operations for handling linked lists with the function of each operation.

334

Chapter 8 ■ Planning the Computer Program

94.

Write three common uses of linked lists.

95.

96.

Write pseudocodes for performing the following operations on a singly-linked list: (a) Determining its length (number of nodes) (b) Searching an element in it (c) Deleting the ith element from it (d) Inserting a new element at the head (e) Inserting a new element at the tail (f) Inserting a new element after the ith element What is a stack? Why do we also call it LIFO? Explain with an example.

97.

Write five commonly supported operations for handling stacks with the function of each operation.

98.

Write two common uses of stacks.

99.

Draw a stack with “Push” and “Pop” operations to show the use of stack for matching parentheses in the expression: (a + (b + c) * d * (e + f) – g).

100. What is a queue? Why do we also call it FIFO? Explain with an example. 101. Write five commonly supported operations for handling queues with the function of each operation. 102. Write three common uses of queues. 103. What is a hash table? How it enables quick storage and retrieval of data items? Explain with an example. 104. What is a hash function? What is the most commonly used hash function for hash tables, whose size is smaller than the range of key values it has to handle? 105. When does a collision occur in a hash table? Write a mechanism to handle collisions. Explain the mechanism with an example. 106. Write three commonly supported operations for handling hash tables with the function of each operation. 107. Write two common uses of hash tables. 108. What is a tree data structure? Define the following terminologies used with trees and explain them with an example tree: (k) Descendent (f) Child (a) Root (l) Height (g) Parent (b) Level (h) Siblings (c) Leaf (m) Subtree (d) Internal node (i) Path (j) Ancestor (e) Branch 109. Write four commonly supported operations for handling trees with the function of each operation. 110. Write three common uses of tree data structure. 111. What is a binary tree? Write the properties of binary trees. Draw examples of binary trees having two, five, seven, and ten nodes. 112. Draw a binary tree having six nodes. Now draw the linked representation of this binary tree. 113. What does “traversing” a tree mean? Explain the preorder, inorder and postorder methods of traversing a binary tree. 114. Draw the binary tree corresponding to the expression: ((a + b) + c) + d) Write the results of preorder, inorder and postorder traversals of this tree. 115. Write five commonly supported operations for handling binary trees with the function of each operation. 116. Write three common uses of binary trees. 117. What is a binary search tree? Draw three valid binary search trees and three invalid binary search trees. For the invalid binary search trees, explain why each one is not a valid binary search tree. 118. Explain the process of inserting a new data element in a binary search tree with an example. 119. Write four commonly supported operations for handling binary search trees with the function of each operation. 120. Write three common uses of binary search trees.

■ Questions

335

121. What is a graph? Define the following terminologies used with graphs and explain them with suitable examples: (i) Loop (a) Directed edge (j) Connected graph (b) Undirected edge (k) Disjoint graph (c) Digraph (l) Complete graph (d) Undirected graph (m) Complete digraph (e) Weighted graph (n) Strongly connected digraph (f) Adjacent nodes (o) Subgraph (g) Path (p) Spanning tree (h) Cycle 122. Draw a graph having six nodes, seven edges, and three cycles. Now write the adjacency matrix representation of this graph. 123. Draw a digraph having five nodes, six edges, and two cycles. Now write the adjacency matrix representation of this graph. 124. Explain the breadth-first search method of graph search with an example. 125. Explain the depth-first search method of graph search with an example. 126. Write five commonly supported operations for handling graphs (undirected) with the function of each operation. 127. Write five commonly supported operations for handling digraphs with the function of each operation. 128. Write five common uses of graphs. 129. What is a heap? Differentiate between a max heap and a min heap. Draw an example of each. 130. Write three commonly supported operations for handling max heaps with the function of each operation. 131. Write three commonly supported operations for handling min heaps with the function of each operation. 132. Write three common uses of heaps.

Programming Languages

Once a developer/programmer has finished planning a computer program, he/she is now ready to write the steps of the corresponding algorithm in a programming language. Computer language or programming language is a language acceptable to a computer system, and the process of writing instructions in such a language is called programming or coding. This chapter introduces some popular programming languages.

ANALOGY WITH NATURAL LANGUAGES Language is a means of communication. We use a natural language, such as English, to communicate our ideas and emotions to others. Similarly, a programmer uses a computer language to instruct a computer what he/she wants it to do. All natural languages (English, French, German, etc.) use a standard set of words and symbols (+, -, :, ;, , etc.), which are understood by everyone using that language. The set of words allowed in a language is called its vocabulary. For example, the words used in English form the vocabulary of English language. Each word has a definite meaning. Similarly, every computer language has a vocabulary of its own. Each word in the vocabulary has a definite unambiguous meaning. The main difference between a natural language and a computer language is that natural languages have a large vocabulary, but most computer languages use a limited or restricted vocabulary. This is because a programming language by its very nature and purpose does not need to say much. Every problem to be solved by a computer has to be broken into discrete (simple and separate) logical steps comprising of four fundamental operations – input and output operations, arithmetic operations, operations for data movement within CPU and memory, and logical or comparison operations. Every natural language has a systematic method of using the words and symbols in that language, which is defined by the grammar rules of the language. Similarly, we need to use the words and symbols of a computer language as per the set rules, known as syntax rules, of the language. In case of a natural language, one can use poor or incorrect vocabulary and grammar and still communicate his/her thoughts. However, in case of a programming language, unless a programmer strictly adheres to the syntax rules of the language, even down to the punctuation marks, a computer will not understand his/her instructions.

■ Machine Language

337

Over the years, programming languages have progressed from machine-oriented languages (that use strings of binary 1s and 0s) to problem-oriented languages (that use common mathematical and/or English terms). However, all computer languages are broadly classified into the following three categories: 1.

Machine Language

2.

Assembly Language

3.

High-level Language

The nature and characteristics of these types of languages are described here.

MACHINE LANGUAGE Although we can design a computer to make it understand many computer languages, every computer understands only one language without using a translation program. This language is called its machine language. Normally, the machine language instructions of a computer are written as strings of binary 1s and 0s, and the circuitry of the computer converts them into electrical signals needed to execute them. A machine language instruction normally has a two-part format (see Figure 9.1). The first part is operation code that tells the computer what operation to perform, and the second part is operand that tells where to find or store the data on which the computer has to perform the operation. Every computer has a set of operation codes called its instruction set. Each operation code (or opcode) in the instruction set is meant to perform a basic operation or function. Typical operations included in the instruction set of a computer are: 1.

Arithmetic operations

2.

Logical operations

3.

Branch operations (either conditional or unconditional) for transfer of control to the address given in the operand field

4.

Data movement operations for moving data between memory locations and registers

5.

Data movement operations for moving data from input devices to memory, or from memory to output devices.

Figure 9.1 shows a typical single-address machine language instruction. Although some computers use only singleaddress instructions, many computers use multiple-address instructions that include addresses of two or more operands. For example, augend and addend may be the two operands of an addition operation. OPCODE (operation code)

OPERAND (address/location)

Figure 9.1. Instruction format.

All computers use binary digits (0s and 1s) for performing internal operations. Hence, most computers’ machine language instructions consist of strings of binary numbers. For example, a typical program instruction to print a number on a printer might be 101100111111010011101100 A program to add two numbers in memory, and print the result might appear as follows:

Chapter 9 ■ Programming Languages

338

001000000000001100111001 001100000000010000100001 011000000000011100101110 101000111111011100101110 000000000000000000000000

Obviously, this language is not easy to use because it uses a number system, with which we are not familiar. However, programmers who worked with the first few computers long ago, actually wrote their programs in binary form as this one.

Researchers soon found that without too much effort, a computer can be wired to accept the more familiar decimal numbers, which it can internally convert into binary before operating on them. With this change, the preceding program can be written as: 10001471 14002041 30003456 50773456 00000000

This set of instructions, whether in binary or decimal, which a computer can understand without the help of a translating program, is called machine code or machine language program. Hence, we need not necessarily code a machine language program as strings of binary digits (1s and 0s). We can also write it using decimal digits, if the computer’s circuitry permits this.

Advantages and Limitations of Machine Language A computer executes programs written in machine language at great speed because it can understand machine instructions without the need for any translation. However, writing a program in machine language has the following disadvantages: 1.

Machine dependent. As the internal design of one type of computer is different from other types, machine language differs from computer to computer. Hence, after the programmers of a company have become proficient in the machine language of one type of computer, if the company decides to change to another type, they will have to learn a new machine language, and would have to rewrite all existing programs.

2.

Difficult to program. It is difficult to write a program in machine language because the programmer has to either memorize the dozens of operation code numbers for the commands in the machine’s instruction set, or refer to a reference card constantly. The programmer must also keep track of storage locations of data and instructions for which he/she must be knowledgeable about the hardware structure of the computer.

3.

Error prone. Since a programmer has to remember the opcodes and must keep track of storage locations of data and instructions, it is difficult for him/her to concentrate fully on the logic of the problem, resulting in programming errors. Moreover, due to lack of any immediate visual indication of an error as the programmer writes machine language code, it makes removal of such errors difficult.

4.

Difficult to correct or modify. It is difficult to correct machine language programs because checking machine instructions to locate errors is difficult and time consuming. Similarly, modifying a machine language program later is so difficult that many programmers prefer to code the new logic afresh, instead of incorporating modifications in the old program.

Due to these limitations, present day programmers rarely use machine language for writing programs.

■ Assembly Language

339

ASSEMBLY LANGUAGE Programming in machine language is difficult and error-prone because a programmer needs to: 1.

Write numeric codes for the instructions in a computer’s instruction set.

2.

Write the storage locations of data and instructions in numeric form.

3.

Keep track of storage locations of data and instructions while writing a program.

Assembly language programming, introduced in 1952, helped in overcoming these limitations of machine language programming in the following manner: 1.

By using alphanumeric mnemonic codes instead of numeric codes for the instructions in the instruction set. For example, using ADD instead of 1110 (binary) or 14 (decimal) for the instruction to add, SUB instead of 1111 (binary) or 15 (decimal) for the instruction to subtract, and so on. With this feature, programmers can easily remember and use the instructions in the instruction set.

2.

By allowing use of alphanumeric names instead of numeric addresses for representing addresses of fixed storage locations. For example, we may choose to represent memory locations 1000, 1001, and 1002 as FRST, SCND, and ANSR, respectively in an assembly language program. With this feature, a programmer can easily remember and use the storage locations of the data and instructions used in an assembly language program. This was the same as using memory variables in programming languages.

3.

By providing additional instructions, called pseudo-instructions, in the instruction set for instructing the system how we want it to assemble the program in computer’s memory. For example, there may be pseudoinstructions for telling the system things like: START START SET SET SET

PROGRAM DATA ASIDE ASIDE ASIDE

AT AT AN AN AN

0000 1000 ADDRESS ADDRESS ADDRESS

FOR FOR FOR

FRST SCND ANSR

With this feature, a programmer need not keep track of storage locations of the data and instructions while writing an assembly language program. That is, he/she need not even tell the computer where to place each data item or instruction of a program. A language that allows use of letters and symbols instead of numbers for representing instructions and storage locations is called assembly language or symbolic language. A program written in an assembly language is called assembly language program or symbolic program.

Assembler Since a computer can directly execute only machine language programs, we must convert (translate) an assembly language program into its equivalent machine language program before it can be executed on the computer. A translator program called assembler does this translation. It is so called because in addition to translating an assembly language program into its equivalent machine language program, it also “assembles” the machine language program in main memory of the computer, and makes it ready for execution. As Figure 9.2 shows, input to the assembler is an assembly language program (often referred to as source program), and its output is the equivalent machine language program (often referred to as object program). Since the assembler translates each assembly language instruction into an equivalent machine language instruction, there is a one-to-one correspondence between the assembly language instructions of a source program and the machine language

340

Chapter 9 ■ Programming Languages

instructions of its equivalent object program. Note that during the process of translation of a source program into its equivalent object program by the assembler, the source program is not under execution. The assembler only converts it into a form that the computer can execute. Assembly language program

Input

Assembler

Output

Machine language program

One-to-one correspondence (Source program)

(Object program)

Figure 9.2. Illustrating the translation process of an assembler.

Due to the additional translation process involved, the computer has to spend more time in getting the desired result from an assembly language program as compared to a machine language program. However, assembly language programming saves so much time and effort of a programmer that the extra time and effort spent by the computer is worth it. Translation is a one-time process that requires relatively small time. Once the system obtains the object code, it can save it and subsequently execute it as many times as required. An example can best illustrate the process. Let us assume that a computer uses the mnemonics given in Figure 9.3 for the operation codes mentioned against each. For simplicity, out of more than hundred operation codes available in the instruction set of a computer, we have considered here only five for writing our example program. Mnemonic

Opcode

Meaning

HLT

00

Halt, used at the end of a program to stop Clear and add into A register

CLA

10

ADD

14

Add to the contents of A register

SUB

15

Subtract from the contents of A register

STA

30

Store A register

Figure 9.3. A subset of the set of instructions supported by a computer.

Figure 9.4 shows a simple assembly language program for adding two numbers and storing the result. To get an idea of how the assembler converts this program into an equivalent machine language program, let us follow its instructions one-by-one. Notice that the first five instructions of the program are pseudo-instructions for telling the assembler what to do. They are not part of the main program to add the two numbers. START START SET SET SET CLA ADD STA HLT

PROGRAM DATA ASIDE ASIDE ASIDE FRST SCND ANSR

AT AT AN AN AN

0000 1000 ADDRESS ADDRESS ADDRESS

FOR FOR FOR

FRST SCND ANSR

Figure 9.4. A sample assembly language program for adding two numbers and storing the result.

The first instruction of the assembly language program tells the assembler that the instructions for the main program (to add two numbers) should start at memory location 0000. Based on this directive, the assembler loads the first instruction of the main program (which happens to be CLA FRST in this example) at memory location 0000. It loads

■ Assembly Language

341

each subsequent instruction in the following memory location (that is, ADD SCND at location 0001, STA ANSR at location 0002, and HLT at location 0003). The second instruction of the assembly language program tells the assembler that the data of the program should start at memory location 1000. The next three instructions tell the assembler to set aside addresses for data items FRST, SCND, and ANSR. Based on these four directives, the assembler sets up a mapping table somewhere in the computer memory that looks somewhat like the one in Figure 9.5. That is, the assembler picks up the first free address in the data area of the program, which is location 1000 and calls it FRST. It picks up the next free address in the data area, which is location 1001, and calls it SCND. Finally, it picks up the next free address in the data area, which is location 1002, and calls it ANSR.

Symbolic name

Memory location

FRST

1000

SCND

1001

ANSR

1002

Figure 9.5. Mapping table set up by the assembler for the data items of the assembly language program of Figure 9.4.

The next instruction of the assembly language program is CLA FRST, which the assembler translates into 10 1000, by translating CLA into 10 as in Figure 9.3, and FRST into 1000 as in Figure 9.5. Similarly, the assembler translates the instructions ADD SCND into 14 1001, STA ANSR into 30 1002, and HLT into 00, thus, providing the resulting machine language program of Figure 9.6.

Advantages of Assembly Language over Machine Language Assembly languages have the following advantages over machine languages: 1.

Easier to understand and use. Due to the use of mnemonics instead of numeric op-codes and symbolic names for data locations instead of numeric addresses, assembly language programs are easier to understand and use than machine language programs.

2.

Easier to locate and correct errors. Due to the use of mnemonic op-codes and symbolic names for data locations, and also because programmers need not keep track of storage locations of the data and instructions, fewer errors are made while writing programs in assembly language, and those that are made are easier to find and correct. Additionally, assemblers detect and indicate errors automatically for use of an invalid mnemonic op-code or an undefined name. For example, if an assembly language program instruction reads ADD AREA and the programmer has not defined AREA in the program, the assembler will indicate the error after looking through its table and not finding AREA in it.

3.

Easier to correct or modify. Since they are easier to understand, it is easier to locate, correct, and modify instructions of an assembly language program than a machine language program. Moreover, insertion or removal of certain instructions in a program does not require change in the address part of the instructions following that part of the program. This is required in case of machine language.

4.

No worry about addresses. Assembly language programmers need not keep track of storage locations of data and instructions while writing an assembly language program. For example, let us assume that we have written a long machine language program involving many instructions and several references to itself within the program such as looping, branching, and so on. Towards the end of the program, we discover that we have left out an instruction in the middle. If we insert that instruction, we will have to go through the entire program to check and modify (if necessary) all references to other instructions. This is a tedious job. However, if we write the same program in assembly language, we merely add the extra instruction, and the assembler takes care of modifying the references automatically.

Chapter 9 ■ Programming Languages

342

Memory location

Contents Opcode Address

0000

10

1000

0001

14

1001

0002

30

1002

0003

00

Comments Clear and add the number stored at FRST to A register Add the number stored at SCND to the contents of A register Store the contents of A register into ANSR Halt

1000

Reserved for FRST

1001

Reserved for SCND

1002

Reserved for ANSR

Figure 9.6. Equivalent machine language program for the assembly language program of Figure 9.4.

5.

Easily relocatable. Availability of pseudo-instructions for instructing the system how we want it to assemble a program inside the computer’s memory makes assembly language programs easily re-locatable. This is because we can easily change a program’s location by changing the pseudo-instructions. An example can best illustrate this feature. Let us assume that an assembly language program starts at address 1000, and we suddenly find that this program uses another program, which also starts at location 1000. Obviously, we will have to rewrite one of the two programs to move it to some other location. While this is a complicated task in machine language, in assembly language, we merely have to change the pseudo-instructions for assembling the program for one of the two programs. For example, change the following pseudo-instructions: START PROGRAM AT 1000 START DATA AT 2000 to the following pseudo-instructions: START PROGRAM AT 3000 START DATA AT 4000 and run the assembly language program once again through the assembler. The equivalent machine language program will this time start at memory location 3000 instead of 1000, and there will be no conflict with the other program.

6.

Efficiency of machine language. An assembly language program also enjoys the efficiency of its corresponding machine language program because there is one-to-one correspondence between the instructions of an assembly language program and its corresponding machine language program. Hence, leaving out the translation time required by the assembler, the execution time for an assembly language program and its equivalent machine language program (written independently) would be more or less the same.

Limitations of Assembly Language Assembly language does not help in overcoming the following limitations of machine language: 1.

Machine dependent. Since the assembler translates each instruction of an assembly language program into one machine language instruction, assembly language programs are machine dependent. That is, assembly languages differ from computer to computer, and we can execute an assembly language program only on the

■ Assembly Language

343

computer, in whose assembly language is the program’s code. Hence, a decision to change to another computer will require learning a new language and conversion of all existing programs into assembly language of the new computer. .

2.

Knowledge of hardware required. Since assembly languages are machine dependent, an assembly language programmer must have knowledge of the characteristics and logical structure of his/her computer to write assembly language programs.

3.

Machine level coding. In case of an assembly language, we still have to write instructions at machine-code level. That is, one assembly language instruction corresponds to one machine language instruction. Hence, like machine language programs, writing assembly language programs is also time-consuming and difficult.

Typical Uses of Assembly Language Programmers rarely write programs of any significant size in assembly language today. They write assembly language code only when a program’s execution efficiency is important. Assembly language programming helps in producing compact, fast, and efficient code because it gives the programmer total control of the computer’s CPU, memory, and registers. Hence, programmers use assembly language programming mainly to fine-tune important parts of programs written in a higher-level language. High-level language programs that are candidates for this type of fine-tuning are those whose execution consumes a substantial part of the total computing resources, and hence offer real payoffs for any improvement in execution time. In such circumstances, a clever programmer can rewrite some small but critical section of the high-level language program in assembly language to improve its overall performance.

Assembly Languages with Macro Instructions In general, each instruction of an assembly language program when translated, results in one machine language instruction. However, quite often, a program uses a set of machine language or assembly language instructions repeatedly. For example, suppose we need three instructions, always in the same order, whenever we need to print a value. Instead of forcing a programmer to write the three instructions every time he/she wants to print a value, we might as well design the assembler (program) to substitute these three instructions for a single instruction, say PRINT. Every time the assembler encounters the PRINT instruction in a program, it would translate it into three machine language instructions instead of one, hence, supplying the complete set of instructions required for printing. Any instruction, such as PRINT, which an assembler translates into multiple machine language instructions, is called macro instruction. There might be many such macro instructions permitted by an assembler to speed up coding process. The use of macro instructions adds more work to a computer because the assembler must be able to supply the missing instructions as well, but it means a tremendous saving of work for a programmer. The programmer is relieved of the task of writing an instruction for every machine operation performed. Hence, the use of macro instructions reduces the length of programs, cuts down on errors, and simplifies programming. The macro instruction capability was developed early in the evolution of computer languages. In fact, it is this concept of multiple machine instructions from one macro instruction around which today’s machine-independent, high-level languages are designed.

Chapter 9 ■ Programming Languages

344

HIGH-LEVEL LANGUAGE Both machine and assembly languages have the following limitations: 1.

They are machine dependent. We cannot execute a machine/assembly language program on any computer other than the one for which it was written.

2.

They require programmers to have a good knowledge of the internal structure of the computer used.

3.

It is difficult, error prone, and time consuming to write programs in machine/assembly language because they deal with machine-level coding and require us to write one instruction for each machine-level operation.

Due to these limitations, we often refer to machine and assembly languages as low-level programming languages. High-level programming languages overcome these limitations of low-level programming languages. They have the following features: 1.

They are machine independent. We can easily port and execute a program written in a high-level language on any computer having the translator software for the high-level language.

2.

A programmer need not have knowledge of the internal structure of the computer on which a high-level language program written by him/her is executed. This allows programmers to concentrate on the logic of the problem rather than be concerned with the details of the internal structure of the computer. In fact, since highlevel languages are machine independent, a programmer writing a program in a high-level language may not even know which computer will execute the program.

3.

They deal with high-level coding, instead of machine-level coding, enabling the programmers to write instructions using English words and familiar mathematical symbols and expressions. High-level coding enables use of a single instruction for several machine language instructions. For example, let us consider the same problem of adding two numbers (FRST and SCND), and storing the sum in ANSR. We saw earlier that three low-level (machine/assembly) instructions are required to perform this job. However, if we use a highlevel language, only one instruction is needed to instruct the computer to do this job: ANSR = FRST + SCND This instruction is easy to understand and write because it resembles the familiar algebraic notation for adding two numbers: a = b + c.

Advent of high-level languages has enabled many users without any background in computer science and engineering to become computer programmers. This has resulted in the creation of a large number of computer applications in diverse areas.

Compiler A compiler is a translator program (more sophisticated than an assembler) that translates a high-level language program into its equivalent machine language program. It is so called because it compiles a set of machine language instructions for every program instruction of a high-level language. As Figure 9.7 shows, input to the compiler is a high-level language program (often referred to as source program), and its output is the equivalent machine language program (often referred to as object program). High-level language instructions are macro instructions. The compiler translates each high-level language instruction into a set of machine language instructions rather than a single machine language instruction. Hence, there is a one-to-many correspondence between the high-level language instructions of a source program and the machine language instructions of its equivalent object program. Note that during the process of translation of a source program into its

■ High-Level Language

345

equivalent object program by the compiler, the source program is not under execution. The compiler only converts it into a form that the computer can execute. Input

High-level language program

(Source program)

Compiler

Output

One-to-many correspondence

Machine language program

(Object program)

Figure 9.7. Illustrating the translation process of a compiler.

A compiler can translate only those source programs that are written in the language, which the compiler can translate. For example, a FORTRAN compiler can translate only source programs written in FORTRAN. Therefore, a computer requires a separate compiler for each high-level language that it supports. For example, to be able to execute both FORTRAN and COBOL programs, a computer must have both FORTRAN and COBOL compilers. Figure 9.8 illustrates this.

Program P1 in high-level language L1

Compiler for language L1

Machine code for P1

Program P2 in high-level language L2

Compiler for language L2

Machine code for P2

A computer supporting languages L1 and L2 Figure 9.8. Illustrating the requirement of a separate compiler for each high-level language supported by a computer.

Also, note that an object program for one computer may not be the same as the object program for another computer. Hence, each computer must have its own “personal” compiler for a language, say L1. Figure 9.9 illustrates how we can achieve machine-independence by using different compilers to translate the same high-level language program to machine language programs of different computers. Compilers are large programs residing permanently on secondary storage. To translate a source program, a computer first loads the compiler and the source program from secondary storage into its main memory. The computer then executes the compiler (which is also a program) with the source program as its input data. It generates the equivalent object program as its output, which the computer saves in a file on secondary storage. To execute the program, the computer loads the object program into main memory from secondary storage and executes it. Note that, there is no need to repeat the compilation process every time we wish to execute the program. This is because the object program stored on secondary storage is already in machine language, which we can load into main memory from the secondary storage and execute it whenever required. Also, note that compilation is necessary whenever we modify the program. That is, to incorporate changes in the program, we must load the original source program into main memory from secondary storage, carry out necessary changes in the source program, recompile the modified source program, and create and store an updated object program for execution.

Chapter 9 ■ Programming Languages

346

Compiler for language L1 on computer A

Machine code for P1 that will run on computer A

Program P1 in highlevel language L1

Executed on computer A Same results obtained

Compiler for language L1 on computer B

Machine code for P1 that will run on computer B

Executed on computer B

Figure 9.9. Illustrating the machine independence characteristic of a high-level language. Separate compilers are required for the same language on different computers.

In addition to translating high-level language instructions into machine language instructions, compilers also detect and indicate certain types of errors in source programs. We refer to these errors as syntax errors. They are of the following types: 1.

Illegal characters

3.

Improper sequencing of instructions

2.

Illegal combination of characters

4.

Use of undefined variable names

If a compiler detects one or more errors in a source program, it will not compile it into an object program. In this case, the compiler generates a list of coded error messages indicating the type of errors committed. The programmer uses this error list to re-edit the source program for removing the errors, and creates a modified source program for recompilation (see Figure 9.10). As the figure shows, we have to repeat the process of editing the source program to make necessary corrections and recompiling the modified source program until the source program is free of all syntax errors. Also, notice from the figure that the compiler generates the object program only when the source program is free of all syntax errors. A compiler, however, cannot detect logic errors. It can only detect grammatical (syntax) errors in the source program. It cannot know ones intentions. For example, if one has wrongly entered 35 instead of 45 as the value for second division percentage to be compared with Percentage, or 999999 (only six 9s) instead of 9999999 (seven 9s) as the sentinel value for Rollno, the compiler cannot detect this.

START Edit source program Source program Compile source program Syntax No Generate errors detected? object program Yes Generate list of coded error messages

Object program STOP

Figure 9.10. Illustrating recompilation of a source program, until it is free of syntax errors.

A compiler successfully compiles programs containing such errors, and generates the object code for it without generating any error message. However, such programs, when executed, do not produce correct result or do not behave as expected. Hence, we can detect logic errors in a program only after we execute the program, and find that the result does not tally with the desired result, or the program does not behave as expected.

■ High-Level Language

347

Linker A single programmer can write a small program and can store it in a single source code file. However, large size software often consist of several thousands, even several millions, of lines of program code. For such software, it is impractical to store its entire source code in a single file due to the following reasons: 1.

Large size of the file makes it difficult, if not impossible, to work with. For example, loading the file for compilation on a computer with limited main memory capacity may not be possible. In addition, editing the file may be tedious and time-consuming.

2.

Deploying multiple programmers to work concurrently for developing the software within specified time becomes difficult.

3.

We need to recompile the entire source program whenever we make any change in the source program, no matter how small. Recompilation of large source programs is often a time-consuming process.

To take care of these problems, software developers adapt a modular approach to develop any reasonably sized software. In this approach, they divide the software into functional modules and write separate source programs for each module. Often, they do not need to write source programs for some of the modules because they can find programs offering same functionalities in an already available program library. Software developers maintain these library programs in their object code form. In modular approach of software development, software consists of multiple source program files. We can modify and compile each source program file independent of other source program files to create a corresponding object program file. In this case, we use a program called linker to combine all object program files (modules) of the software, and to convert them into a final executable program, which is sometimes called load module. Hence, a linker is software that takes multiple object program files (modules) of some software and fits them together to assemble them into the software’s final executable form. Figure 9.11 illustrates the process of compiling multiple source program files of various modules of software and linking them to create its executable program (load module). Note that since converting the source programs into an executable program is a two-step process, when we modify the software, we need not recompile all the source programs. Rather, we need to recompile only the changed source programs to produce new object programs for them. We can then use the linker to create a new executable program by reassembling the newly created and the old object programs and library modules.

Compilation process

Prog-1.src

Prog-2.src

Prog-n.src

Source programs

Prog-1.obj

Prog-2.obj

Prog-n.obj

Object programs

Prog-i.lib

Library modules

Linking process Executable program file

Load module

Figure 9.11. Illustrating the process of compiling multiple source program files and linking them to create the executable program (load module).

Linkers are part of the development environment (which consists of a set of program development tools including compilers) of a computer system. One can also purchase third-party linkers that can sometimes improve the performance of a program over the standard linkers that are part of the system’s development environment.

348

Chapter 9 ■ Programming Languages

Interpreter Interpreter is another type of translator used to translate a high-level language program into its equivalent machine language program. It takes one statement of the high-level language program, translates it into machine language instructions, and executes the resulting machine language instructions immediately, before taking up the next statement. Hence, the translation and execution processes alternate for each statement encountered in the high-level language program. This differs from a compiler that merely translates the entire source program into an object program, and is not involved in its execution. The input to an interpreter is a source program, but unlike a compiler, its output is the result of program execution, instead of an object program (see Figure 9.12). Input Interpreter (translates and executes Output Result of program High-level language program statement-by-statement) execution (Source program) Figure 9.12. Illustrating the role of an interpreter.

After compilation of a source program, a user saves the resulting object program for future use, and uses it whenever he/she has to execute the program. Hence, repeated compilation (translation of the source code) is not necessary for repeated execution of a program. However, in case of an interpreter, since a user cannot save the object program for future use, repeated interpretation (translation plus execution) of a program is necessary for its repeated execution. Since an interpreter translates and executes a high-level language program statement-by-statement, it reinterprets (translates and executes) a program statement every time it encounters that statement during program execution. For example, during execution of a program, it reinterprets the instructions in a loop as many times as the process executes the loop. As compared to compilers, interpreters are easier to write because they are less complex programs than compilers. They also require less memory space for execution than compilers require. The main advantage of interpreters over compilers is that an interpreter flags a syntax error in a program statement to a programmer as soon as it interprets the program statement. This allows the programmer to make corrections during interactive program development. Therefore, interpreters make it easier and faster to correct programs. The main disadvantage of interpreters over compilers is that they are slower than compilers when running a finished program. This is because an interpreter translates each statement from the source program every time it executes it. A compiler translates each statement only once and saves it in the object program. We can execute the saved object program many times whenever needed, and no translation of any statement is required during the execution of the program. As the interpreter does not produce an object code for a program, it must perform the translation process each time it executes the program. To combine the advantages of both interpreters and compilers, sometimes, the program development environment of a computer system provides both a compiler and an interpreter for a high-level language. In such systems, a programmer first uses the interpreter to develop and debug his/her program. Then, after reaching a bug-free state, he/she compiles the program to obtain its object code and uses the object code for routine processing subsequently. We also refer to assemblers, compilers, and interpreters as language processors since they process language instructions.

Intermediate Language Compiler and Interpreter Yet another type of compiler and interpreter combination combines the speed, ease, and control of both compiler and interpreter in the same package and provides other features such as machine independence.

■ High-Level Language

349

In this approach, the compiler first compiles the source program to an intermediate object program. This intermediate object program is not a machine language code but a program written in an intermediate language that is virtually machine independent and understood by the combination interpreter. Then the interpreter takes the intermediate object program and converts it into machine language program and executes it on the desired computer (often referred to as host computer as it ‘hosts’ the virtual execution environment). The main benefits of this approach are: 1.

The intermediate object program is in compiled form and thus is not original source code. This makes it safer and easier for a programmer to share his/her programs with others when the programmer does not want to share the source code.

2.

The intermediate object program is in the form of a standard Intermediate Definition Language (IDL). Hence, writing a compiler and an interpreter is easier.

3.

We can write the interpreter for any computer architecture and operating system as long as it can interpret the intermediate object program on the host computer system. This provides virtual machine environment to the executing program.

4.

Another type of interpreter is available that can convert (or compile) the complete or selected sections of intermediate object program, in memory, to final host machine language program and then start execution at a faster speed as compared to line-by-line execution. This technique is called Just-In-Time (JIT) Compilation.

Advantages and Limitations of High-level Languages Advantages of High-level Languages High-level languages enjoy the following advantages over assembly and machine languages: 1.

Machine independence. We can execute a program written in a high-level language on different types of computers with little or practically no effort of porting it on different computers. This means that a company changing its computers, even to one from a different manufacturer, need not rewrite all the programs that it is currently using. This also means that commercial software will have a larger market because it need not be restricted to one type of computer. Hence, developers receive better reward for the time and effort spent on software developed with high-level language programming.

2.

Easier to learn and use. High-level languages are easier to learn because they are similar to the natural languages used by us in our day-to-day life. They are also easier to use because a programmer need not know the internal details of a computer for programming in a high-level language.

3.

Fewer errors. While programming in a high-level language, a programmer need not worry about how and where to store the instructions and data of the program, and need not write machine-level instructions for the computer. This allows the programmer to concentrate more on the logic of the program under development. All these factors lead to fewer programming errors during program development. Furthermore, compilers and interpreters detect and indicate syntax errors automatically. Hence, a programmer can easily locate and correct syntax errors, if any, in a program.

4.

Lower program preparation cost. Writing programs in high-level languages requires less time and effort, leading to lower program preparation cost. Generally, the cost of all phases of program preparation (coding, debugging, testing, etc.) is lower with a high-level language than with a machine/assembly language.

5.

Better documentation. Statements of a program written in a high-level language are similar to natural language statements used by us in our day-to-day life. Hence, a programmer who is familiar with the problem domain can understand them easily. As a result, only few comment statements are required in programs written in high-level languages. Due to this reason, we sometimes refer to high-level languages as selfdocumenting languages.

6.

Easier to maintain. Programs written in high-level languages are easier to maintain than assembly/machine language programs. This is because they are easier to understand, and hence, it is easier to locate, correct, and

Chapter 9 ■ Programming Languages

350

modify instructions whenever desired. We can even insert/remove instructions in/from a program without any complication. Hence, we can incorporate major changes in a program with little effort.

Limitations of High-level Languages The two main limitations of high-level languages are: 1.

Lower efficiency. Generally, a program written in a high-level language has lower time and space efficiency than one written in a machine/assembly language to do the same job. Hence, when a program’s efficiency is important, we write its performance critical parts in assembly language and non-critical parts in a high-level language. However, with the advent of efficient and optimizing compilers, this problem is now a non-issue.

2.

Less flexibility. Generally, high-level languages are less flexible than assembly languages because they do not normally have instructions or mechanism to directly access a computer’s CPU, memory, and registers. An assembly language provides the programmers access to all the special features of the machine they are using. Certain types of operations that a programmer can easily program by using the machine’s assembly language are impractical to attempt by using a high-level language. This lack of flexibility means that a programmer cannot code some tasks or can code it only with great difficulty in a high-level language.

In most cases, the advantages of high-level languages far outweigh the disadvantages. Hence, software developers use high-level languages for writing most programs, and use assembly languages for doing special tasks only, which they cannot do easily otherwise.

OBJECT-ORIENTED LANGUAGES What is Object-Oriented Programming (OOP)? Soon after the advent of the first few programming languages, software industry realized that programming is a difficult and time-consuming task. Hence, researchers have been continuously working towards developing better and better programming languages to make programming simpler, easier, and faster. The goal of the designers of every new programming language was to introduce some aspects or concepts in their programming language that will help to achieve the above-mentioned objectives. Object-Oriented Programming (often referred to as OOP, pronounced “oop”) is one such concept used in programming languages. Developers of Simula-67 programming language first introduced the concept of OOP in 1967. This concept started gaining popularity in 1980s with the development of another programming language named Smalltalk that made extensive use of this concept. Starting in mid-1980s, OOP became a popular term and object-oriented dialects of existing programming languages (like Object-Pascal, Objective C, and C++) started appearing. Subsequently, C++ became a popular object-oriented programming language because of its connection with C and its support by AT&T Bell Labs. Almost all popular programming languages (including Visual Basic and Java) now use OOP philosophy. The basic idea behind OOP is that we use programming languages for simulating real-world problems on computers. Since much of the real world is made of objects, a simulation of such a world must include simulated objects. Hence, the essence of OOP is to solve a problem by identifying the real-world objects of the problem and the processing

■ Object-Oriented Languages

351

required of those objects, and then creating simulations of those objects, their processes, and the required communications between the objects.

Fundamental Concepts of OOP The most essential part of support for OOP is the object mechanism. That is, an OOP language must have mechanisms to define, create, store, and manipulate objects, and some mechanism to allow different objects to communicate with each other. The basic concepts used in OOP languages to support the object mechanism are described here.

Object An object is the primitive element of a program written in an OOP language. Each object consists of a set of procedures (known as methods) and some data. It stores the data in variables and responds to messages received from other objects by executing the procedures (methods). A method is a collection of operations that specifies the reaction of the object when it receives a message that corresponds to that method. A program written in a pure OOP language is a collection of objects that communicate with each other. Virtually everything, from items as simple as an integer constant ‘8’ to a complex file-handling system, is an object. An OOP language treats them all uniformly as objects. They all have local memory, inherent processing ability, the capability to communicate with other objects, and the ability to inherit characteristics from ancestors. We can view an object as an abstract data type because each object is an autonomous entity with its private data and methods. Note that an object contains both functions (procedures/methods) and data that describe the characteristics of the object. In other words, an object encapsulates both data and functions.

Method A method of an object defines the set of operations that the object will execute when it receives a message corresponding to the method. Methods are like function definitions, complete with parameters and the capability to return values. Binding of a message to a method is dynamic. The entire collection of methods of an object is called the message protocol, or message interface, of the object. Figure 9.13 illustrates the object model used in OOP.

Method – 1 Object’s message interface

Method – 2 Method – 3

Object’s private data Implementations of Method – 1, Method – 2 and Method – 3

Figure 9.13. Model of an object used in OOP.

Message The mechanism to support communication between objects is through messages. That is, OOP language programs do any computing by sending a message to an object to invoke one of its methods. A reply to a message is an object, which returns to the sender the result of executing the method. There is a fundamental difference between a message sent to an object and a subprogram call. In the former case, the object executes the appropriate method with its own local data, whereas in the latter case, the caller process sends the data for processing (if any) to the subprogram code unit along with the subprogram call.

352

Chapter 9 ■ Programming Languages

Class A class is a description of one or more similar objects. Class concept is similar to “type” in conventional procedureoriented languages. For example, if “integer” is a type (class), then “8” is an instance (object) of type (class) “integer”. Similarly, “Ram” and “Sita” are two instances (objects) of a class “Person”. A class can have multiple instances. Each instance of a class is known as an object of the class. Each object has its own local data and represents a different instance of its class. Since all objects of a class share the same methods, the only difference between two objects of the same class is the state of their local variables. Also, note that there can be two categories of object variables – class variables and instance variables. Class variables are variables stored in the class. All instances (objects) of the class share its class variables. Instance variables are variables for which local storage is available in the instances (objects). Object-oriented programming languages also support class hierarchies. Sub-classes of a given class are refinements of it, inheriting the functionality and local variables of the parent-class, or super-class. Sub-classes can add new local variables and methods, and can modify or hide inherited methods.

Inheritance In OOP, inheritance is a mechanism to share code and behavior. It allows a programmer to reuse the behavior of a class in the definition of new classes. A program written in an object-oriented language may have a large hierarchy of classes. In fact, good programming in an object-oriented language depends largely on creating sub-classes of existing classes, because this leads to potential reuse of existing code. In a hierarchy of classes, a sub-class inherits all of the instance variables, instance methods, and class methods of its super-class/parent-class. The sub-class can also have its own instance variables, which must have different names than the variable names in its ancestor classes. Finally, the sub-class can define both new methods and methods that already exist in an ancestor class. When a sub-class has a method whose name or protocol is the same as an ancestor class, the sub-class method hides that of the ancestor class. Normally, a user has to prefix the message with the pseudo-variable “super” to access such a hidden method. This causes the method search to begin in the super-class rather than locally. Inheritance need not get limited to one parent-class. A child class can inherit from multiple parent classes. This is called multiple inheritance. Figure 9.14 describes persons by an inheritance hierarchy of classes (representing behaviors). “Person” class has “Male” and “Female” as its sub-classes. “Male” class has “Person” as its super-class and “Boy” and “Man” as its subclasses. Each instance (Ram, Shyam, Mohan, Seeta, and Geeta) has a unique base class. Person Male

Classes Boy

Instances

Ram

Female Man

Shyam

Mohan

Seeta

Geeta

Figure 9.14. Example of an inheritance hierarchy of classes.

Figure 9.15 illustrates the concepts of object, class, and inheritance with the help of an example. In the example, object ‘a’ is an instance of class ‘A’ and object ‘b’ is an instance of class ‘B’. Both A and B define behavior by operations shared by their instances, and have instance variables that cause a private copy to be created for each

■ Object-Oriented Languages

353

instance for the class or sub-class. Instance ‘a’ of class ‘A’ has a copy of A’s instance variables and a pointer to its base class. Instance ‘b’ of class ‘B’ has a copy of the instance variables of both class ‘B’ and its super-class ‘A’ and a pointer to the base class of ‘B’. Representation of class ‘B’ has a pointer to its super-class ‘A’, while class ‘A’ has no super-class pointer, since it has no super-class. When object ‘b’ receives a message to execute a method, it looks first in the methods of class ‘B’. If it finds the method in class ‘B’, it executes it using the instance variables of ‘b’ as data. Otherwise, it follows the pointer to its super-class. If it finds the method in class ‘A’, it executes it on the data of ‘b’. Otherwise, it searches A’s super-class if there is one. If it did not find the method in class ‘A’ and if class ‘A’ has no super-class, it reports an error. Object ‘a’ (Instance of ‘A’)

Class ‘A’ Variables of ‘A’

Class ‘A’

Methods of ‘A’

Instance variables of ‘A’

Class ‘B’ (Sub-class of Class ‘A’)

Object ‘b’ (Instance of ‘B’)

Inherits from ‘A’

Class ‘B’

Variables of ‘B’

Inherited instance variables of ‘A’

Methods of ‘B’

Instance variables of ‘B’

Figure 9.15. An example illustrating the concepts of object, class, and inheritance.

Key Elements of Object-Oriented Paradigm Figure 9.16 summarizes the key elements that a programming language must have for categorization as an objectoriented language. Sr. No.

Element

Meaning

1

Abstraction

Abstraction means that an object’s characteristics are broken into manageable chunks as defined and documented in its class description.

2

Encapsulation

Encapsulation stipulates that code and data are stored as one unit. Encapsulation also enables selective or total information hiding, since it can make portions of the code and data inaccessible from outside the unit.

3

Modularity

Modularity defines the unit reuse. These units group abstractions together.

4

Hierarchy

Hierarchy allows an object’s behaviors to be refined (subclasses) without recoding of the parent object (the superclass). Some OO languages allow an object to have more than one superclass, a feature that is known as multiple inheritance. Inheritance hierarchies enable ranking/ordering of abstractions.

5

Messages

Messages, similar in use to function calls, are requests to perform an operation on an instantiated object. Figure 9.16. Key elements of object-oriented paradigm.

354

Chapter 9 ■ Programming Languages

Procedure-oriented versus Object-oriented Programming Conventional procedure-oriented programming languages use procedural abstractions that encapsulate sequences of operations into procedures (also known as functions, subroutines, or subprograms). On the other hand, object-oriented programming languages encapsulate data as well as sequences of operations into abstract entities called objects, providing a stronger encapsulation mechanism than procedures. Hence, object-oriented programming (OOP) provides a more powerful modeling tool than procedure-oriented programming (POP). Notice that we can consider both procedures and objects to be server modules that clients may call to get certain actions performed. However, the basic difference between the two is in their roles. The role of procedures is to transform input data specified by parameters into values, while the role of objects is to serve as a repository of data (current system state) and to respond (perform the requested action) in a manner determined by the current system state. For example, response of a bank to a withdrawal request depends on the value of current balance. Call Procedure-2 Procedure-1 Algorithm parameters

Receive Return parameters

Procedure-2

Object-1

Object-2

Algorithm parameters

Attributes

Attributes

Methods M11, M12

Methods M21, M22

Receive/ return parameters

Send message 1 Object-3

Procedure-3

Send message 2

Algorithm Call Procedure-3 parameters (a) Communication among software modules in Procedure-Oriented Programming (POP)

Attributes Methods M31, M32

(b) Communication among software modules in Object-Oriented Programming (OOP)

Figure 9.17. Comparison of communication approaches in POP and OOP. In POP, procedures receive and return parameters, while in OOP, objects receive and send messages.

Figure 9.17 compares graphically the communication between modules in POP and OOP. In POP, procedures call each other to receive, return, or update data values through parameter passing, as shown in the left half of the figure. In OOP, a number of interacting objects send messages to one another, as shown in the right half of the figure. Each object responds to a prescribed collection of messages. Each data item can be an attribute of an object or an object and is capable of processing requests known as messages. Thus, the data item or objects are the active computation unit, while the methods or operations are passive. Also, observe that we can construct an object’s method in much the same way as we construct a procedure (function) for a structured program by using the same three basic building blocks: sequence, selection, and repetition. Procedure-oriented programming paradigm has strong organizing principles for managing actions and algorithms, but has weak organizing principles for managing shared data. Object-oriented programming paradigm has strong organizing principles both for managing actions and algorithms and for managing shared data because it provides the capability to restrict applicable operations to those associated with a specific object or class. Inheritance provides further strength to this capability by allowing classification of classes by factoring out properties common to several sub-classes into a super-class. Figure 9.18 provides a comparison of the features of POP and OOP.

■ Object-Oriented Languages Sr. No.

Procedure-Oriented Programming (POP) features

Object-Oriented Programming (OOP) features

1

Uses functional decomposition mechanism and modularizes a system based on functions.

Uses OO decomposition mechanism and modularizes a system based on data structures (objects).

2

In a program module (function), data and procedures are separate.

A program module (object) encapsulates both data and operations.

3

Programmers are responsible for calling the functions and for passing parameters (if any) to them.

Objects communicate with each other by passing messages to activate their operations.

4

Uses procedural abstraction and represents real world by logical entities and control flow.

Uses class and object abstraction, and represents real world by objects mimicking external entities.

5

Unit of structure is statement or expression.

Unit of structure is object treated as a software component.

6

Uses procedure-oriented languages, such as C or Pascal.

Uses OO languages, such as C++, Object Pascal, or Smalltalk-80.

Figure 9.18. Comparison of the features of POP and OOP.

Advantages of OOP Figure 9.19 lists some of the key advantages that OOP paradigm has over conventional POP paradigm. Sr. No.

Advantage

Description

1

Natural modeling

Designing and implementing a system is much easier in OOP because OOP paradigm serves as a more natural modeling tool for programming real world problems.

2

Modular design

In OOP, each object is an autonomous entity, which a programmer can define and implement independent of other objects. This facilitates modular system design. Modular design eases the development and maintenance of software systems.

3

Abstraction

In OOP, each object is an encapsulated entity because its data is private to itself (hidden from other objects) and its interaction with other objects is only through its message interface. OOP, therefore, provides a high degree of abstraction enabling programmers to concentrate more on problem specification rather than implementation details. Abstraction increases software reliability and modifiability by decoupling object specification and object implementation.

4

Dynamic binding

In conventional programming languages, operators, functions, etc. are bound to their respective operations at the time of compilation. This is called static binding. However, in OOP, binding of operator to an operation takes place at run time. This is called dynamic binding. Dynamic binding allows abstract data types to be truly generic because it enables a single operator to have more than one operation, which is called polymorphism. Polymorphism and dynamic binding allow creation of generic software components and new classes using existing code. Hence, they increase flexibility and reusability of code.

5

Code reusability

In OOP, inheritance provides an effective method of code reuse because all the classes and instances down to the whole class hierarchy can access the common operations defined and implemented in a class. This helps in tremendous saving of programming effort.

6

Easy maintenance

Modular design and code reusability features also help in making software systems easy to maintain. In OOP, if we make a change in a super-class, all its sub-classes change at once, without the need to identify and implement the change at a number of places. Moreover, if we make changes in one sub-class to get distinctions, the code in the super-class and the other subclasses remains safe.

Figure 9.19. Key advantages of OOP paradigm over conventional POP paradigm.

355

356

Chapter 9 ■ Programming Languages

SOME HIGH-LEVEL LANGUAGES Since the first high-level language in early 1950s, today there are more than 1000 high-level languages. Only a few of them have been truly significant, and even fewer have been widely used. Figure 9.20 lists some popular high-level languages. The primary objective here is to provide an overview of these languages. Readers interested in detailed knowledge required to write programs in any of these languages should refer to a good book dealing with the syntax and semantics of the language.

DEALING WITH SO MANY HIGH-LEVEL LANGUAGES Why So Many High-level Languages? Since high-level languages are machine independent, you must be wondering why so many high-level languages were developed, and why many of them are in use today, instead of developing and improving just one good high-level language. For an answer to this question, recall that one of the objectives of high-level languages is that they should be easier to learn and use by the intended users. We write computer programs to solve diversified class of problems, such as, systems-related problems, scientific and engineering problems, business and commercial problems, graphics problems, etc. The language statements and notations used in a particular problem domain may be quite different from those used in other problem domains. If we try to incorporate all types of statements and notations for solving all classes of problems in a single high-level language, the features of that high-level language will become too vast and difficult to master. Such a language will be difficult to learn and use. Moreover, designing an efficient compiler for such a language will also be a tedious task. Hence, it is more logical to have different high-level languages for different problem domains. The statements and notations used in a high-level language are picked up especially to be useful for solving a specific class of problems. For example, a scientist using a science-oriented language can use scientific formulae, and a businessman with a business-oriented language can use business terms. This makes a highlevel language, meant for a problem domain, easier to learn and use by the users dealing with problems in that problem domain. Hence, today many different high-level languages exist and are in use because each one was designed for a different purpose and area of applicability. This is also obvious from the discussion of the various highlevel languages in Figure 9.20.

■ Dealing With So Many High-Level Languages

357

358

Chapter 9 ■ Programming Languages

■ Dealing With So Many High-Level Languages

359

360

Chapter 9 ■ Programming Languages

■ Dealing With So Many High-Level Languages

361

Characteristics of a Good Programming Language There are some popular high-level languages, while there are others that could not become popular in-spite-of being powerful. There might be many reasons for the success of a language, but one obvious reason is its characteristics. Several characteristics believed to be important for a good programming language are: 1.

Simplicity. A good programming language must be simple and easy to learn and use. It should provide a clear, simple, and unified set of concepts to a programmer that he/she can grasp easily. The overall simplicity of a programming language affects the readability of the programs written in that language, and programs that are easier to read and understand are easier to maintain. It is also easy to develop and implement a compiler or an interpreter for a simple programming language. However, for achieving simplicity, designers should not sacrifice the power needed for the language. For example, many programmers like BASIC because of its simplicity.

2.

Naturalness. A good language for an application domain should be natural for programming applications of that domain. That is, it should provide appropriate operators, data structures, control structures, and a natural syntax to facilitate programmers to code their problems easily and efficiently. FORTRAN and COBOL are good examples of languages possessing high degree of naturalness in scientific and business application domains, respectively.

3.

Abstraction. Abstraction means the ability to define and then use complicated structures or operations in ways that allows programmers to ignore many of the details. The degree of abstraction allowed by a programming language affects its ease of programming. For example, object-oriented languages support high degree of abstraction. Hence, writing programs in object-oriented languages is much easier. Object-oriented languages also support reusability of program segments due to this feature.

4.

Efficiency. A program written in a good programming language enables a computer system to translate it into machine code efficiently, execute it efficiently, and manage it with less memory space. That is, a good programming language is supported with a good language translator (a compiler or an interpreter) that gives due consideration to space and time efficiency.

5.

Structured programming support. A good programming language should have necessary features to allow programmers to write their programs based on the concepts of structured programming. This property affects the ease with which a programmer can write, test, and maintain his/her programs. Moreover, it forces the programmer to look at a problem in a logical way so that he/she creates fewer errors while writing a program for the problem.

6.

Compactness. In a good programming language, programmers should be able to express the intended operations concisely without losing readability. Programmers do not like a verbose language because they need to write too much. Many programmers dislike COBOL because it is verbose in nature (lacks compactness).

7.

Locality. A good programming language should be such that while writing a program, a programmer need not jump around visually as the text of the program is prepared. This allows the programmer to concentrate on the part of the program around the statement he/she is currently working with. COBOL and to some extent C and Pascal lack locality because data definitions are separated from processing statements, perhaps by many pages of code, or have to appear before any processing statement in the function/procedure.

8.

Extensibility. A good programming language should also allow extension through simple, natural, and elegant mechanisms. Almost all languages provide subprogram definition mechanisms for this purpose, but some languages are weak in this aspect.

9.

Suitability to its environment. In addition to being suitable to its application domain, a good programming language must also be suitable to its operating environment. For example, a language for real-time applications must be interactive in nature. On the other hand, a language for data processing applications like payroll, stores accounting, etc., may operate in batch mode.

Chapter 9 ■ Programming Languages

362

Selecting a Language for Coding an Application Programmers often face the situation of selecting a programming language out of the many options available for coding an application. The following factors generally influence the selection process: 1.

Nature of the application. A programmer should select a language that is suitable for the application domain at hand. For example, FORTRAN is suitable for scientific and engineering applications, while COBOL is suitable for business applications.

2.

Familiarity with the language. If he/she finds that multiple languages are suitable for the application domain, he/she should select the one with which he/she and other programmers in his/her team (who will code the application) are most familiar.

3.

Ease of learning the language. If he/she finds that multiple languages are suitable for the application domain, and the programmers are not familiar with any of them, he/she should select the language that is easy to learn and use.

4.

Availability of program development tools. Before selecting a language, the programmer must also find out if the programming environment of the language has good program development tools like compiler, interpreter, debugger, linker, etc. A language with a good set of program development tools can significantly reduce the time and effort of the team of programmers involved in coding an application.

5.

Execution efficiency. If the execution efficiency of an application is important, the programmers can use an assembly language instead of a high-level language for coding the application. This is because an assembly language program written by a clever programmer usually has a shorter production run time, and takes less storage space than does a program written for the same application in a high-level language.

6.

Features of a good programming language. Finally, the features of a good programming language discussed in the previous section often influence the selection process.

OTHER TYPES OF LANGUAGES Scripting Languages We often use command statements to instruct a computer to do a job. For example, we use “run” or “exec” statement to execute a program and “copy” statement to copy a file from one storage device to another. Often we also need to execute a set of commands to perform a task. For example, to perform a task, a user may be required to execute two independent programs, and after execution of the first program, he/she may be required to copy the output file of the first program on to a device from which the second program expects the input. Therefore, in this case, the user needs to specify two execute commands for executing the two programs and a copy command before the second execute command. A scripting language is a programming language that allows a programmer to integrate several such commands into a single command so that the programmer need not type all the commands every time he/she needs to perform the intended task. We refer to a program written in a scripting language as a script. Scripting languages support variables and simple control structures to allow programmers to write scripts, which can execute conditionally or repeat the execution of certain commands. With these features, scripting languages are useful for defining complex commands execution patterns. Another common use of scripting languages is in specifying execution environment setup for applications that are quite complex, yet flexible enough for use in a variety of contexts. For an individual run of such an application, programmers must configure a setup to customize the application for its current run. A programmer can write a script in a scripting language to specify this setup. The script integrates individual commands into a single command that the programmer can use to drive application execution. A scripting language is interpreted, rather than compiled. Hence, a script can interact with a running program and change during the run. In addition to controlling a running program, scripts can preprocess and postprocess data.

■ Other Types of Languages

363

Scripting languages typically let programmers invoke individual application components. Application components are individual programs (such as data format converters and visualizers) that carry out specific data processing tasks and are usable in different contexts. Some commonly known scripting languages are Unix Shell Script, Perl, Tcl, and Python. A typical script looks like the one shown in Figure 9.21. users = ‘who  wc –l’ if test $users –gt 10 then echo “More than 10 users logged on” fi Figure 9.21. A typical script. The first line of the script sets the variable ‘users’ equal to the value produced by the pipeline of commands ‘who I wc –l’. This is in fact a count of the number of users currently logged on to the system. This value is then compared with the number 10, and if it is greater, then the message is displayed.

Fourth and Fifth Generation Languages (4GLs and 5GLs) Some people prefer to categorize machine languages, assembly languages, and high-level languages as firstgeneration, second-generation, and third-generation languages, respectively. Every new generation of language brought significant improvement in programmer productivity by making programming languages more and more user-friendly. Studies indicate that the move from first-generation machine languages to second-generation assembly languages brought approximately a seven-to-one improvement in programmer productivity. The move from secondgeneration assembly languages to third-generation high-level languages brought much more improvement in programmer productivity. Even after the advent of third-generation high-level languages, researchers continued to make efforts for designing new programming languages, which could further improve programmer productivity. The result of these efforts has been the fourth-generation languages, which claim programmer productivity improvement of 200% to 1000% over third-generation high-level languages. There is a major shift in fourth-generation languages as compared to the languages of previous generations. All previous-generation languages were procedural languages whereas fourth-generation languages are non-procedural. A procedural language (such as C, C++, Java, COBOL, FORTRAN, BASIC) is one that requires a programmer to spell out the steps in the processing procedures needed to achieve a desired result. On the other hand, a non-procedural language allows a user to specify “what” the output should be without describing all the details of “how” to manipulate the data to produce that result. With this type of flexibility provided by fourth-generation languages, many computer users often find it easier and quicker to write a program themselves than to depend on professional programmers. Fourth-generation languages are so user-friendly that with a day or two of training and practice, a computer-competent user can learn to write programs, make inquiries, and generate the desired reports on his/her own. Fourth-generation languages use high-level English-like instructions. They require a programmer to specify only “what” to do, not “how” to do it. The language processor of a 4GL automatically generates most of the procedure portion (steps to carry out a task) of a fourth-generation language program. Fourth-generation language features include limited mathematical capabilities, automatic report formatting, sequencing, and record selection by criteria. They are primarily used in database programming and scripting. A few examples of fourth-generation languages are SQL, MatLab (MatrixLaboratory), FOCUS, RAMIS, Python, Pearl and Ruby. Figure 9.22 shows a typical fourth-generation language program, and Figure 9.23 shows the result of execution of this program.

364

Chapter 9 ■ Programming Languages

Recently, a new generation of programming languages have emerged that have visual tools to develop a program. These are categorized as fifth-generation programming languages (5GL). A few examples are Mercury, Prolog and OPS5. 1. 2. 3. 4. 5.

FILE IS STUDENTS_INFO LIST BY ROLL_NO: NAME SEX PHY CHEM MATH SELECT CLASS = 8 TITLE: “MARKS OBTAINED BY THE STUDENTS OF CLASS 8” COLUMN HEADINGS: “ROLL, NUMBER”; “STUDENT, NAME”; “SEX”; “MARKS IN, PHYSICS”; “MARKS IN, CHEMISTRY”; “MARKS IN, MATHEMATICS” Figure 9.22. A typical fourth-generation language program.

MARKS OBTAINED BY THE STUDENTS OF CLASS 8 ROLL NUMBER 001 002 003

STUDENT NAME

SEX

P. K. Sinha N. C. Rao S. S. Pawar

M M F

MARKS IN PHYSICS 85 72 86

MARKS IN CHEMISTRY 89 76 82

MARKS IN MATHEMATICS 96 77 94

Figure 9.23. Result of execution of the fourth-generation language program of Figure 9.22 (only few records are shown here to illustrate the nature of output).

Markup Languages We use a markup language primarily to format text documents (to specify the structure of a text document – the form in which we want to display/print the document). For example, a user uses it to specify a set of annotations (also called markup conventions) with a text document to indicate what format (such as font type, style, and font size) the user wants to apply to each part of the text document. Figure 9.24 shows an example. Notice from the figure that markup language instructions (known as tags) are enclosed in angle brackets in the main text of the text document. The codes h1, p, and em are examples of structural markup instructions. They describe the structure of the text included within them. For example, h1 means, “first level heading”, p means “paragraph”, and em means “emphasized word or phrase”. A program interpreting such structural markup instructions may apply its own rules or styles for presenting the resulting text document when displayed, using different formatting styles (such as font types, font sizes, bold or italic or underline for emphasize, etc.) as desired. Markup Language

A markup language is used primarily to format text documents. It uses a set of annotations to indicate what format (such as font type , style , and size ) to apply to each part of a text document.

(a) A text document with markup instructions of a markup language embedded in it

Markup Language A markup language is used primarily to format text documents. It uses a set of annotations to indicate what format (such as font type, style, and size) to apply to each part of a text document. (b) Resulting text document when displayed/printed Figure 9.24. An example of markup language usage.

■ Other Types of Languages

365

As the example shows, many markup languages enable embedding of markup language instructions in the main text of the text document in the same data stream or file. However, some markup languages allow isolation of markup language instructions from the main text of the text document by using pointers, offsets, identifiers, or other methods to establish coordination between the two. With the availability of word-processing and document processing software with WYSIWYG (“What You See Is What You Get”) feature, normal users do not use a markup language for preparing text documents. However, users involved in serious publishing work still use markup languages to specify the structure of their text documents. Originally, users used markup languages for specifying the structure of text documents. However, present day users also use them in other areas, which involve presentation of various types of information including pay lists, vector graphics, web services, user interface, and content publishing. Most of these are applications of a popular markup language called XML (Extensible Markup Language). A few popular markup languages are: 1.

SGML (Syntax for Generalized Markup Language). SGML is a meta language for markup languages. The idea behind its design was that markup instructions should focus on the structural aspects of a document, while the interpreter should decide the visual presentation of that structure. Hence, it specifies the syntax for including markup instructions in documents and allows authors to create and use any markup instruction they wish, or select tags of their choice (having terminologies of their domain that make the most sense to them). International Standards Organization (ISO) standardized and released SGML in 1986. After that, SGML has been widely used for large-scale documentation requirements. Many new markup languages have based their design on SGML. However, SGML is cumbersome and difficult to learn because of the vast features it supports to make it highly flexible.

2.

TeX and LaTex. TeX was a major publishing standard in 1970s and 80s. Donald Knuth developed it for typesetting documents in scientific disciplines. Hence, it focused on detailed layout of text and font descriptions for typesetting mathematical formulae and equations. It turned out to be a powerful tool for creating professional quality publications in science and engineering domains. However, it was difficult to learn and use by common and casual users. Hence, academia and research communities were its primary users. LaTex was later introduced as TeX macro package that provides a descriptive markup system on top of TeX. Hence, it is easier to use as compared to TeX and has a wider user base than TeX.

3.

HTML (HyperText Markup Language). HTML is the most widely used markup language for designing contents for the World Wide Web. It played a major role in the success of the Web because of the flexibility and extensibility that it provided to the web content designers. HTML was created using SGML syntax and it resembles other SGML-based tag languages. It is also categorized as a container language (one that follows a hierarchical model) because it restricts the placement of tags, requiring them to be nested fully inside other tags, or the root tag of the document.

4.

XML (eXtensible Markup Language). Researchers developed XML as a simplified form of SGML for creating documents for the Internet (World Wide Web). Like SGML, it is also a meta language and allows users to create any tags needed (hence the name “extensible”) and then describing those tags and their permitted uses. Existing SGML users and software could easily switch to XML because XML is a subset of SGML. Hence, a user can write an XML document in such a way that it is also an SGML document. This led to easy and quick adoption of XML. Although, the original purpose of XML was to create documents for the Internet, it is widely used now for communicating data between applications. XML users have also developed many XMLbased applications, which are in use today. These include Resource Description Framework (RDF), XForms, DocBook, SOAP (Simple Object Access Protocol) and the Web Ontology Language (OWL).

Chapter 9 ■ Programming Languages

366 5.

XHTML (eXtensible HyperText Markup Language) Due to the popularity of XML, all recommendations of the World Wide Web Consortium (W3C) since January 2000 for enhancements in HTML are XML based. XHTML is a result of these extensions in HTML. The language specification requires that XHTML Web documents must be well-formed XML documents. This enables creation of more rigorous and robust Web documents while using tags from HTML.

Interface Definition Languages (IDL) A distributed computing system interconnects multiple computers that communicate with each other to perform tasks. In this type of computing environment, different computers often use different operating systems and computer languages. Hence, the computing environment requires a system-independent and language-independent interface to enable programs on one computer to communicate with programs on another computer. Researchers designed IDLs to fulfill this requirement. They offer a bridge between two different systems by defining an interface in a systemindependent and language-independent manner. Although, IDLs originally served as a bridge between two different systems, they now also serve as a tool for communication between different software components that do not share a common language – for example, between components written in C++ and components written in Java. In general, IDL is a standard language for defining function and method interfaces for distributed or component-based applications. Technologies such as CORBA (Common Object Request Broker Architecture) and COM (Component Object Model) use it heavily. Usually, users are unaware of the fact that they are using an IDL. This is because IDL is normally an integral part of the tools and development platform with which the users work. Open Software Foundation (OSF) first created an IDL as part of their Distributed Computing Environment (DCE). DCE used IDL to create a standard way of calling a function on remote computer, popularly known as Remote Procedure Call (RPC). RPC involves a process called marshalling, which gathers necessary data for calling the function on remote computer. At that time, programmers who needed to reuse code simply compiled header files of C language into an application, to link the application statically with the reused code. When DCE developers were looking for a mechanism to provide the marshalling code needed in RPC automatically, they naturally adapted these header files – which programmers were creating anyway – into a format useful for this task. Hence, IDL’s syntax resembles that of C language. Later, when developers introduced CORBA and COM as dynamic component reuse standards, they looked into the work done earlier with RPC for a standard. Eventually, IDL emerged as a popular way to define object interfaces in a language-independent manner. Note that we cannot use an IDL to write actual programs because it lacks the logic and flow control structures needed to program anything useful. Instead, IDL concentrates on type definitions, both for primitive and class types, and is useful to define interfaces, not implementations. Today, a variety of IDL is in use. A few of the various implementations include Object Management Group’s (OMG) CORBA, Microsoft’s MIDL (Microsoft’s IDL), and IBM’s System Object Model. Vendors supporting each implementation provide compilers that convert IDL source code into type libraries describing the component in question. This enables type checking at compile time for an application using the component.

OTHER RELATED CONCEPTS Subprogram Let us assume that we need to calculate the square root of three different numbers at three different places in a program. We could write the steps required for the calculation of square root each time we need them in the program. However, an easier way of handling the problem would be to write these steps once and then refer to them each time we need them. Every programming language provides a way to do this by defining subprograms. A subprogram is a program written in a manner that a programmer can use it in other programs whenever needed without rewriting.

■ Other Related Concepts

367

We refer to a subprogram by different names in different programming languages. For example, other names used for it are subroutine, subprocedure, and function. Figure 9.25 shows the structure of a subprogram. It consists of a header and a body. The subprogram header, which is the first line of a subprogram, provides a name for the subprogram, and it may optionally specify a list of parameters (also known as arguments). Other programs use the subprogram name to refer to the subprogram when they want to use it. The parameters are specific variable names, numeric values, or other data you want the subprogram to use when it executes the instructions in its body. The list of parameters is optional because there may be subprograms for which you do not need or want to pass any arguments. The subprogram body contains the instructions that perform the intended task of the subprogram. Other programs can use a subprogram as often as needed. A programmer has to insert a statement to call the subprogram at whatever points in a program the function performed by the subprogram is required. Typically, a subprogram call statement contains the name of the subprogram followed by a list of parameters enclosed within a pair of parentheses. If you do not need or want to pass any arguments to the subprogram, the empty parentheses are still required normally to distinguish the statement as a subprogram call. For example, a statement to call a subprogram that calculates square root of a number may be a = sqrt (b). Different programming languages may have different syntax for writing the call statement for calling a subprogram.

Subprogram name sqrt

Parameter

(x)

Set of instructions that perform the intended task

Subprogram header

Subprogram body

Figure 9.25. The structure of a subprogram.

When a computer encounters a subprogram call statement while executing a program, the control flow jumps to wherever the subprogram’s code is, executes the statements in the subprogram body, and then returns to the statement immediately after the call statement in the calling program. Figure 9.26 illustrates the flow of control in case of a subprogram call. Note that the subprogram code appears only once in a program, no matter how often its functionality is required. Subprograms may be intrinsic or programmer-written. Intrinsic subprograms (commonly referred to as built-infunctions) are those provided with the language so that a programmer need only call them in a program to have them invoked automatically. There are functionalities such as those for finding square root, sine, cosine, logarithm, etc. that are used repeatedly by many programmers in their programs. A programming language usually contains such functionalities in the form of built-in-functions. On the other hand, a programmer writes a programmer-written subprogram and uses it whenever required. Subprograms can also return a value to the calling program. This makes it convenient to use a subprogram to set the value of a variable. For example, in case of our subprogram to calculate the square root of a number, you supply the number as its parameter, and the subprogram calculates and returns the square root of the number. Based on this criterion, we categorize subprograms into two basic types: procedures and functions. A procedure is a subprogram that performs an action but returns no value. For example, a procedure might print a value or update a data structure. On the other hand, a function is a subprogram that returns a single value, as do mathematical functions like sine, cosine, absolute, square root. General-purpose, high-level programming languages widely use both functions and procedures.

Chapter 9 ■ Programming Languages

368

2

1 subprogram call statement

subprogram header 6

next statement

4

3 7

subprogram body

5

subprogram call statement 8

next statement 9

A program that calls the subprogram twice

Flow of control

A subprogram

Figure 9.26. Illustrating the flow of control in case of subprogram calls.

Subprograms have the following advantages: 1.

They make it easier to write programs because a programmer can call the same code from many places in a program; instead of duplicating it wherever he/she needs it.

2.

Since the system keeps only one copy of a subprogram’s code instead of duplicating it wherever a program uses it, source programs and their executable codes are shorter for programs that make use of subprograms. This saves the storage space required for storing such programs, and requires less memory space during their execution.

3.

Subprograms allow programmers to create programs in a modular fashion, which is essential to the construction of large software systems.

4.

Modular design of software systems in the form of subprograms also provides the capability to compile parts of a program (individual subprograms) without compiling the whole program (all subprograms used by the program) when a programmer changes the program. With this capability, the programmer needs to recompile only those modules (subprograms) of a software system that he/she has changed during its development or maintenance. The linker program then collects and puts together all the newly compiled and previously compiled modules (subprograms) of the software. Without this capability, every change to a software system would require a complete recompilation. In a large system, this is costly.

5.

Creating a subprogram for a task will obviate the need to do it again. This promise gives its author incentive to invest great care in generalizing it, debugging it, optimizing its performance, documenting it, and otherwise perfecting it. Thus, subprograms are generally well written and documented parts of a program.

Preprocessor A specific user group often needs to extend a standard programming language to support the features needed frequently. For example, a user group dealing frequently with a special type of input data or a special type of input device may like to have statements to accept this input directly. In this case, the usual practice is to extend a standard language, which is most suitable for the user group applications, by adding new statements to it to support the desired

■ Other Related Concepts

369

features. With this extension, users of the user group can program their applications more easily. However, since the original standard language does not support the extended features (additional statements), such a program needs a language processor to translate the additional statements (extensions to the standard language) into a sequence of statements of the standard language before submitting it to the standard language compiler for compilation. Such a language processor is known as a preprocessor. A preprocessor accepts as input a source program written in an extended language (with the added features) and produces an output source program that is acceptable to the compiler of the standard language (without the added features) (see Figure 9.27). The preprocessor reads each statement in the input source program and parses it to check if its syntax pertains to the added statements (extended features). If yes, it generates a sequence of statements in the standard language for the current statement to produce the same effect, else it leaves the statement unchanged. Note that the output source program generated by the preprocessor is longer than the input source program because the preprocessor generates a sequence of statements for each statement in the extended language. As the figure shows, preprocessing inevitably requires two translation passes – the first pass translates the source program in extended language to a standard language source program by using the preprocessor, and the second pass translates the standard language source program to executable object code by using the standard language compiler. However, in most cases of preprocessing, the user gets the feeling of one-pass translation. A preprocessor achieves this through creation of a library of system commands that, when invoked, runs through the two passes in one go.

Source program in extended language First pass

Preprocessor

Source program in standard language

Standard language compiler

Second pass

Executable object code Figure 9.27. Illustrating the use of a preprocessor.

Postprocessor A user often needs to feed the result of computation obtained from a system/software to another system/software for further processing to produce the same result in a specific format/style. The specific formatting of the result may be required either to better visualize the result by the end user, or to feed the result to another system that accepts input only in the specified format. A language processor (software) that processes the result of computation obtained from a system/software to convert it in a specific format/style is known as postprocessor, because it processes the result of original processing to convert it into the desired format/style. The two popular types of postprocessors are: 1.

Data visualization postprocessor. Computers process data and produce results in numeric form (as a set of numbers). To make comprehension of the result easier, end users often use a postprocessor to convert the numeric result into meaningful form such as table, graph, three-dimensional view, or any other domainspecific form. Figure 9.28 shows a few examples of domain-specific data visualization. A postprocessor used for this purpose is known as data visualization postprocessor.

2.

CAD/CAM postprocessor. A CAD/CAM postprocessor is a computer program that translates tool motion data from a CNC (Computer Numeric Control) machine into a part program for a numerically controlled machine tool. It translates data from a part programming system into a part program for a machine tool equipped with a numeric controller. When all the elements (part programming system, postprocessor program, and controller software or firmware) are working correctly, the machine tool – under computer control – produces machined parts as programmed by the part programmer. Hence, a CAD/CAM

370

Chapter 9 ■ Programming Languages postprocessor is a critical link between the toolpath generation from a CAM system and operability of a machine tool. Without a good postprocessor, many machine tools are underutilized.

Visualized data in Bioinformatics domain

Visualized data in Seismic Data Processing (SDP) domain

Visualized data in Computational Fluid Dynamics (CFD) domain

Visualized data in Computational Atmospheric Science (CAS) domain

Figure 9.28. A few examples of domain-specific data visualization.

Points to Remember 1.

A language acceptable to a computer system is called computer language or programming language, and the process of writing instructions in such a language for an already planned program is called programming or coding.

2.

All computer languages are broadly classified into three categories, namely; machine language, assembly language, and highlevel language.

3.

A programming language that a computer understands without using a translation program is called its machine language. It is normally written as strings of binary 1s and 0s.

4.

A language that allows representation of instructions and storage locations by letters and symbols instead of numbers is called assembly language or symbolic language. A program written in an assembly language is called assembly language program or symbolic program.

5.

Assembler is a translator program that translates (converts) an assembly language program (source program) into its equivalent machine language program (object program).

6.

Machine and assembly languages are often referred to as low-level programming languages because they are machine dependent, they require the programmers to have a good knowledge of the internal structure of the computer being used, and they deal with machine-level coding, requiring one instruction to be written for each machine-level operation. High-level programming languages overcome these limitations of low-level programming languages.

7.

Compiler is a translator program that translates (converts) a high-level language program (source program) into its equivalent machine-language program (object program).

■ Points to Remember

371

8.

In addition to translating high-level language instructions into machine language instructions, compilers also detect and indicate automatically certain types of errors in source programs. We refer to these errors as syntax errors. A compiler, however, cannot detect logic errors in source programs.

9.

Linker is a software tool that takes multiple object program files (modules) of any software and fits them together to assemble them into the software’s final executable form, sometimes called load module.

10. Interpreter is a translator program that translates (converts) a high-level language program into its equivalent machinelanguage program. However, unlike a compiler that merely translates an entire source program into an object program and is not involved in its execution, an interpreter takes one statement of the source program, translates it into machine language instructions, and executes the resulting machine language instructions immediately, before taking the next statement for translation. The interpreter does not generate any object code of the source program. 11. Object-oriented programming (OOP) deals with solving a problem by identifying the real-world objects of the problem and the processing required of those objects, and then creating simulations of those objects, their processes, and the required communications between the objects. 12. Conventional procedure-oriented programming languages use procedural abstractions that encapsulate sequences of operations into procedures (also known as functions, subroutines, or subprograms). On the other hand, object-oriented programming languages encapsulate data as well as sequences of operations into abstract entities called objects, providing a stronger encapsulation mechanism than procedure. Hence, object-oriented programming provides a more powerful modeling tool than procedure-oriented programming. 13. Today many different high-level languages are in use because each one was designed for a different purpose. Some of these are FORTRAN, COBOL, BASIC, Pascal, PL/1, C, C++, C#, Java, Python, Ada, ALGOL, LISP, SNOBOL and PROLOG. 14. Several characteristics believed to be important for making a programming language good are – simplicity, naturalness, abstraction, efficiency, structured programming support, compactness, locality, extensibility, and suitability to its environment. 15. The factors that generally influence the process of selecting a programming language out of the many options available for coding an application are – nature of the application, familiarity with the language, ease of learning the language, availability of program development tools, execution efficiency, and features of a good programming language. 16. We often use command statements to instruct a computer to do a job. A scripting language is a programming language that allows a programmer to integrate several such commands into a single command so that the programmer need not type all the commands every time he/she needs to perform the intended task. We refer to a program written in a scripting language as a script. 17. Fourth-generation languages (4GLs) are high-level programming languages that require the programmer to specify only “what” to do, not “how” to do it. The language processor of a 4GL automatically generates most of the procedure portion (steps to carry out a task) of a fourth-generation language program. 18. A procedural language (such as C, C++, Java, COBOL, FORTRAN, BASIC) is one that requires a programmer to spell out the steps in processing procedures needed to achieve a desired result. On the other hand, a non-procedural language (such as 4GLs) allows a user to specify “what” the output should be without describing all the details of “how” to manipulate the data to produce that result. 19. We use a markup language primarily to format text documents. It uses a set of annotations (also called markup conventions) to indicate what format (such as font, style, and font size) to apply to each part of the text document. 20. A few popular markup languages are Syntax for Generalized Markup Language (SGML), TeX and LaTex, HyperText Markup Language (HTML), eXtensible Markup Language (XML) and eXtensible HyperText Markup Language (XHTML). 21. Interface Definition Language (IDL) is a standard language for defining function and method interfaces for distributed or component-based applications. 22. A subprogram is a program written in a manner that a programmer can use it in other programs whenever needed without rewriting. Other names used for it are subroutine, subprocedure, and function. 23. Two basic types of subprograms are procedures and functions. A procedure is a subprogram that performs an action but returns no value, while a function is a subprogram that returns a single value. 24. Subprograms may be intrinsic or programmer-written. Intrinsic subprograms (commonly referred to as built-in-functions) are those provided with the language so that the programmer need only call them in a program to have them invoked automatically. On the other hand, programmers write programmer-written subprograms and use them whenever required.

372

Chapter 9 ■ Programming Languages

25. A specific user group often needs to extend a standard programming language to support the features needed frequently. However, since the original standard language does not support the extended features (additional statements), we need a language processor to translate the additional statements (extensions to the standard language) into a sequence of statements of the standard language before submitting the program to the standard language compiler for compilation. Such a language processor is known as a preprocessor. 26. A language processor (software) that processes the result of computation obtained from a system/software to convert it in a specific format/style is known as a postprocessor. 27. Two popular types of postprocessors are data visualization postprocessor and CAD/CAM postprocessor.

Questions 1.

What is a programming language? Why is it so called?

2.

What is program coding?

3.

Discuss the analogy between a computer language and a natural language.

4.

How does a computer language differ from a natural language?

5.

Define syntax rules of a programming language.

6.

Name the three categories of computer languages in order of their ease of usage.

7.

What is a machine language? Why is it required?

8.

What are the advantages and limitations of machine language?

9.

When do we call a computer language machine dependent? What is the main disadvantage of such a language?

10.

A machine language instruction has two-part format. Identify these parts and discuss the function of each.

11.

Explain why machine language programming is difficult and error-prone. Explain how assembly languages overcome these limitations of machine languages.

12.

What is a mnemonic? How is it helpful in case of computer languages?

13.

What is an assembly language? What are its advantages over machine language?

14.

What is an assembler?

15.

What is the difference between a source program and an object program?

16.

Write advantages of assembly language over machine language.

17.

Write those limitations of machine language that assembly language cannot overcome.

18.

Write typical uses of assembly language.

19.

What is a macro instruction? How does it help in making a programmer’s job easier?

20.

Why do we often refer to machine and assembly languages as low-level languages?

21.

Write characteristic features of high-level languages. Name ten high-level languages.

22.

Why are high-level languages easier to learn and use?

23.

What is a compiler? Why is it required? A computer supports five high-level languages. How many compilers will this computer have?

24.

An assembly language is “one-for-one”, but a high-level language is “many-for-one”. Explain what this means.

25.

Illustrate the machine independence characteristic of a high-level language.

26.

Differentiate between syntax errors and logic errors found in computer programs. Which type of error is more difficult to detect and correct? Write reasons for your answer.

27.

While writing a program, a programmer erroneously instructed the computer to calculate the area of a rectangle by adding the width to its length (that is, AREA = LENGTH + WIDTH) instead of multiplying the length and width. Would you expect the language processor to detect this error? Explain why.

■ Questions 28.

373

A programmer eliminates all language processor errors from a program, and then runs it to get the desired results. The programmer, therefore, concludes that the program is complete. Discuss.

29.

What type of errors in a program a compiler can detect? What type of errors in a program a compiler cannot detect?

30.

What is a linker? Why is it required?

31.

Differentiate between compilation and linking processes of software.

32.

Differentiate among source programs, object programs, library modules, and load module of a software system.

33.

Explain the differences among assembler, compiler, interpreter, and linker.

34.

What is an interpreter? How does it differ from a compiler?

35.

What are the two commonly used approaches to translate high-level languages into machine languages? Write their relative advantages and disadvantages.

36.

What advantages do compilers have over interpreters?

37.

What advantages do interpreters have over compilers?

38.

When would you prefer to use a compiler than an interpreter?

39.

When would you prefer to use an interpreter than a compiler?

40.

What are the advantages and limitations of high-level languages as compared to machine and assembly languages?

41.

What is object-oriented programming?

42.

The most essential part of support for object-oriented programming is the object mechanism. What are the basic concepts used in object-oriented programming languages to support the object mechanism?

43.

With reference to object-oriented programming languages define the following terms: (a) Object (e) Message protocol (b) Method (f) Multiple inheritance (c) Class (g) Instance of a class (d) Inheritance Write a suitable example to illustrate the concepts of object, class, and inheritance used in object-oriented programming languages.

44. 45.

Differentiate between procedure-oriented and object-oriented programming paradigms.

46.

Write advantages of object-oriented programming paradigm over procedure-oriented programming paradigm.

47.

What is polymorphism in the context of programming languages? Explain with an example.

48.

Since high-level languages are machine independent, one good high-level language should have been sufficient for use on all computer systems. In-spite-of this fact, why are there so many high-level languages in use today?

49.

Write briefly about the following programming languages: (k) (f) PROLOG (a) FORTRAN (l) (g) SNOBOL (b) COBOL (m) (h) Pascal (c) BASIC (i) C (d) Python (n) (e) ALGOL (j) C++

PL/1 LISP Java C#

50.

Why do we often refer to COBOL as self-documenting language?

51.

In Java, the compiled code is machine independent. Explain how Java achieves this.

52.

What characteristics are desirable for a good programming language?

53.

Would you be equally likely to choose FORTRAN or COBOL for programming a given problem? Write reasons for your answer.

54.

What is a scripting language? What is a script? Explain with an example.

55.

What are fourth-generation languages? How are they different from conventional high-level languages?

56.

Differentiate between a procedural and a non-procedural programming language.

374

Chapter 9 ■ Programming Languages

57.

What is a subprogram? How do subprograms help in program writing?

58.

We often categorize subprograms into two basic types: procedures and functions. Differentiate between the two types.

59.

What is a built-in-function? Write few examples of built-in-functions.

60.

Illustrate with an example the flow of control in case of subprogram calls.

61.

What is a preprocessor? Explain how a computer system converts a source program written in an extended language into its equivalent executable object code.

62.

What is a markup language? When is it used?

63.

Name some popular markup languages and their typical uses.

64.

What is an IDL? Write some of its uses.

65.

What is postprocessor? Write two examples of postprocessor.

Operating Systems

An operating system is an important component of a computer system. This chapter introduces the concepts related to operating systems and shows how this system software helps in the overall operation and usage of a computer system.

BASIC CONCEPTS What is an Operating System? Operating system (often referred to as OS) is an integrated set of programs that controls the resources (CPU, memory, I/O devices, etc.) of a computer system and provides its users with an interface or virtual machine that is easier to use than the bare machine. According to this definition, the two primary objectives of an operating system are: 1.

Make a computer system easier to use. A computer system consists of one or more processors, main memory, and many types of I/O devices such as disks, tapes, terminals, network interfaces, etc. Writing programs for using these hardware resources correctly and efficiently is a difficult job, requiring in-depth knowledge of functioning of these resources. Hence, to make computer systems usable by a large number of users, we need some mechanism to shield the programmers and other users from the complexity of hardware resources. This is achieved by putting a layer of software on top of the bare hardware. This layer of software manages all hardware resources of the system, and presents the users with an interface or virtual machine that is easier, safer, and efficient to program and use. It is called the operating system. Figure 10.1 shows the logical architecture of a computer system. As shown, operating system layer surrounds hardware resources. Then a layer of other system software (such as compilers, editors, utilities, etc.) and a set of application software (such as commercial data processing applications, scientific and engineering applications, entertainment and educational applications, etc.) surrounds operating system layer. Finally, end users view the computer system in terms of the user interfaces of the application software.

Chapter 10 ■ Operating Systems

376

Users Other system software and application software

Operating system Computer hardware

Figure 10.1. Logical architecture of a computer system. Operating system hides details of hardware from the programmers and other users and provides them with a convenient interface for using the system.

2.

Manage the resources of a computer system. An operating system manages the resources of a computer system. This involves performing such tasks as keeping track of who is using what resources, granting resource requests, accounting for resource usage, and mediating conflicting requests from different processes and users. Efficient and fair sharing of system resources among users and/or processes is a key goal of all operating systems.

Main Functions of an Operating System Most operating systems perform the following functions. A separate module of operating system software performs each of these functions: 1.

Process management. A process is a program in execution. During execution, a process needs certain resources such as CPU time, memory space, files, and I/O devices. At any time, an active computer system normally consists of a collection of processes. Process management module takes care of creation and deletion of processes, scheduling of system resources to different processes requesting them, and providing mechanisms for synchronization and communication among processes.

2.

Memory management. To execute a program, it must be loaded in main memory (at least partially), together with the data it accesses. To improve CPU utilization and to provide better response time to its users, a computer system normally keeps several programs in main memory. Memory management module takes care of allocation and de-allocation of memory space to programs in need of this resource.

3.

File management. All computer systems store, retrieve, and share information. Normally, a computer stores such information in units called files. Processes read information from files and create new files for storing newly generated information. A process makes the information in a file persistent by storing the file on a secondary storage media such as a magnetic disk. To share information, an application can create a file and share it later with different applications. File management module takes care of file-related activities such as organization, storage, retrieval, naming, sharing, and protection of files. It allows programs to use a set of operations that characterize the file abstraction and free the programmers from concerns about the details of space allocation and layout of the secondary storage device.

4.

Device management. A computer system consists of several I/O devices such as terminal, printer, disk, and tape. The device management module of an operating system controls all I/O devices. It keeps track of I/O requests from processes, issues commands to I/O devices, and ensures correct data transmission to/from an I/O device. It also provides a simple and easy to use interface between the devices and rest of the system. Often, this interface is device independent, that is, the interface is same for all types of I/O devices.

5.

Security. Users can trust a computer system and rely on it only if its various resources and information stored in it are protected against destruction and unauthorized access. Security module protects the resources and information of a computer system against destruction and unauthorized access. It also ensures that when the

■ Process Management

377

system executes several disjoint processes simultaneously, one process does not interfere with others or with the operating system itself. 6.

Command interpretation. For using various system resources, a user communicates with the operating system via a set of commands provided by it. The operating system also provides a simple language, known as command language (CL) or job control language (JCL); using which a user can put several commands together from the command set to describe the resource requirements of a job. Command interpretation module interprets user commands, and directs system resources to process the commands. With this mode of interaction with a system, users need not be concerned about the hardware details of the system.

An operating system also performs few other functions such as accounting of usage of system resources by the users (or processes), maintenance of log of system usage by the users, and maintenance of internal time clock.

Measuring System Performance We usually measure the efficiency of an operating system and the overall performance of a computer system in terms of the following parameters: 1.

Throughput. Throughput is the amount of work that a system is able to do per unit time. We measure it as the number of jobs (processes) completed by the system per unit time. For example, if a system is able to complete n processes in t seconds, its throughput is n/t processes per second during that interval. Throughput is normally measured in processes/hour. Note that the throughput of a system does not depend on its jobs processing efficiency only, but also on the nature of jobs processed. For long processes, throughput of a system may be one process/hour; whereas for short processes, it may be 100 processes/hour for the same system.

2.

Turnaround time. From the point of view of an individual user, an important criterion is how long it takes a system to complete a job submitted by him/her. Turnaround time is the interval between the time of submission of a job to the system for processing and the time of completion of the job. Although, higher throughput is desirable from the point of view of overall system performance, individual users are more interested in better turnaround time for their jobs.

3.

Response time. Turnaround time is not a suitable measure for interactive systems because in such a system, a process can produce some output early during its execution and can continue executing while previous results are being output to the user. Hence, another measure used in case of interactive systems is response time. It is the interval between the time of submission of a job to the system for processing and the time of first response from the system for the job.

In any computer system, it is desirable to maximize throughput and minimize turnaround time and response time.

PROCESS MANAGEMENT A process (also called job) is a program in execution. The main objective of process management module of an operating system is to manage the processes submitted to a system in a manner to minimize the idle time of processors (CPUs, I/O processors, etc.) of the system. In this section, we will learn about some of the mechanisms that modern operating systems use to achieve this objective. We will also see how these mechanisms have evolved from the early days of computers.

Chapter 10 ■ Operating Systems

378

Process Management in Early Systems In early computer systems, the process of executing a job was as follows: 1.

A programmer first wrote a program on paper.

2.

The programmer or a data entry operator then punched the program and its data on cards or paper tape.

3.

The programmer then submitted the deck of cards or the paper tape containing the program and data at the reception counter of a computer centre.

4.

An operator then loaded the cards deck or paper tape manually into the system from card reader or paper tape reader. The operator also loaded any other software resource (such as a language compiler), or carried out required settings of hardware devices for execution of the job. Before loading the job, the operator used front panel switches of the system to clear any data remaining in main memory from the previous job.

5.

The operator then carried out required settings of the appropriate switches in the front panel to run the job.

6.

Finally, the operator printed and submitted the result of execution of the job at the reception counter for the programmer to collect it later.

Every job went through the same process. The method was known as manual loading mechanism because the operator loaded the jobs one after another in the system manually. Notice that in this method, job-to-job transition was not automatic. Hence, a computer remained idle while an operator loaded and unloaded jobs and prepared the system for a new job. This caused enormous wastage of valuable computer time. To reduce this idle time, researchers later devised a mechanism (called batch processing) for automatic job-to-job transition. Batch processing ensured that after completing execution of a job, the system transferred control back to the operating system automatically. The operating system then performed housekeeping jobs (such as clearing any data remaining in memory from previous job), which were needed to load and run the next job. Hence, in a batch processing system, the process of executing jobs was as follows: 1.

Programmers prepared their programs and data on decks of cards or paper tapes, and submitted them at the reception counter of a computer centre.

2.

An operator collected all the submitted programs periodically, batched them together, and then loaded them all at one time into the input device of the system.

3.

The operator then gave a command to the system to start executing the batched jobs.

4.

The system then loaded the jobs automatically from the input device, and executed them one-by-one without any operator intervention. That is, the system read the first job from the input device, executed it, printed its result, and then repeated these steps for each subsequent job, until all jobs in the submitted batch of jobs were over.

5.

After the system completed execution of all jobs in the submitted batch, the operator separated and kept the printed output of each job at the reception counter for programmers to collect them later.

Batch processing mechanism helped in reducing idle time of a computer system because job-to-job transition did not require any operator intervention. Another major time saving made possible by batch processing was reduction in setup time by operator by batching of similar jobs together. For example, by batching together all FORTRAN compilation jobs received, the system needs to load FORTRAN compiler once only for processing all these jobs. The obvious question is how a computer separates one job from another from a batch of jobs for automatic job-to-job transition. Moreover, how does the system know which compiler or what hardware devices a job needs for execution, when there is no operator intervention? To facilitate all these, researchers introduced the concept of control statements and job control languages (JCLs) along with the concept of batch processing. Operating systems use control statements to identify a new job and to determine the resources needed by it during its execution. Users write

■ Process Management

379

control statements in a language known as job control language. Hence, each job has, besides its program and data, a set of instructions called JCL instructions, instructing the operating system on identity and requirements of the job. JCL statements specify things such as name of a job, its user's name with account number, its hardware and software resource requirements (I/O devices, language processor, software libraries, etc. required during its processing), etc. Figure 10.2 shows a sample deck of cards for compilation and execution of a COBOL program in a batch processing system. Notice that a control card uses a special character or pattern in pre-decided column(s) of the card to distinguish itself from a data card or a program card. Several systems used dollar-sign character ($) in the first column on each control card, while IBM’s JCL used slash marks (//) in the first two columns. Other systems used some other characters or codes. Basic idea in selection of these special characters or codes was that no program or data card should have these characters or code in the pre-decided column(s). $END Data for program

$RUN $LOAD COBOL program

$COBOL $JOB, ONGC05839, USER=SINHA

Figure 10.2.

Illustrating use of job control statements and structure of a sample deck of cards submitted for processing in a batch processing system. JCL cards are shaded.

Multiprogramming Both manual loading and batch processing systems load and process one job at a time. After such a system loads a job, the job remains in main memory until its execution is over, and the system loads the next job only after completion of the current job. Figure 10.3 shows that in such a situation, the job that is currently loaded in the system is the sole occupant of user’s area of main memory (operating system resides in a separate part of main memory) and has the CPU available exclusively for its execution. Figure 10.3 illustrates a uniprogramming system, which processes only one job at a time, and all system resources are available exclusively for the job until its completion. A job does not need CPU for entire duration of its processing because in addition to computing (for which CPU is needed), it often needs to perform I/O operations (such as reading/writing of data from/to tape/disk, waiting for data input from keyboard/mouse, and printing of results) during the course of its processing. In fact, depending on CPU utilization during the course of processing, jobs are of two types: 1.

CPU-bound jobs. These jobs mostly perform computations with little I/O operations. Hence, their CPU utilization is high. Jobs for scientific and engineering applications usually fall in this category.

2.

I/O-bound jobs. These jobs mostly perform I/O operations with little computation. Hence, their CPU utilization is low. Jobs for commercial data processing applications usually fall in this category.

Chapter 10 ■ Operating Systems

380

Execution in progress

Main memory

In a uniprogramming system, CPU is idle whenever the job executing currently performs I/O operations. CPU idle time may not be significant for CPU-bound jobs, but it may be of the order of 80-90% for I/O-bound jobs. Moreover, since I/O devices are slower than CPU by 20 to 100 times, CPU idle time is significant even for CPU-bound jobs. To minimize the idle time of CPU, researchers introduced the concept of multiprogramming, which uses the idea of organizing multiple jobs in a system so that its CPU always has something to execute. How a system does this is explained here.

Operating system

OS area

User job

User program area

CPU

Figure 10.3. Uniprogramming system model. A uniprogramming system processes only one job at a time, and all system resources are available exclusively for the job until its completion.

Multiprogramming is interleaved execution of two or more different and independent programs by a computer. Figure 10.3 has already introduced the notion of two programs (operating system and user program) resident simultaneously in main memory of a computer. This concept is carried a step further in multiprogramming by enabling two or more user programs to reside simultaneously in main memory and carrying out their interleaved execution. With multiple user programs residing simultaneously in the user program area of main memory, whenever a user program that was executing (using CPU) goes to perform I/O operations, the operating system allocates the CPU to another user program in main memory that is ready to use it, instead of allowing the CPU to remain idle. The CPU switches from one program to another almost instantaneously. Hence, in multiprogramming, several user programs share CPU time to keep it busy. Note that multiprogramming does not mean execution of instructions from several programs simultaneously. Rather, it means that multiple programs are available to CPU (stored in main memory) and a portion of one is executed, then a portion of another, and so on. As a CPU can execute only one instruction at a time, only one of the programs residing in main memory uses the CPU for executing its instructions at any instance of time. Simultaneous execution of more than one program with a single CPU is impossible. Some multiprogramming systems process only a fixed number of jobs concurrently (multiprogramming with fixed tasks - MFT), while others can process variable number of jobs concurrently (multiprogramming with variable tasks - MVT). Main memory

Figure 10.4 shows a typical scenario of jobs in a multiprogramming system. At the time instance shown, there are three user jobs (A, B, and C) residing in memory out of which job A is performing I/O operation (writing to disk), job B is executing (utilizing CPU time), and job C is waiting for CPU to become free. As Figure 10.5 shows, in case of multiprogramming, all jobs residing in main memory are in one of the following three states: Running (it is using CPU)

2.

Blocked (it is performing I/O operations)

3.

Ready (it is waiting for allocation of CPU to it)

Operating system Job A Job B

Secondary disk storage

Execution in progress

1.

Writing output data

Job C (Waiting for CPU)

CPU

Figure 10.4. A typical scenario of jobs in a multiprogramming system.

In Figure 10.4, jobs A, B, and C are in blocked, running, and ready states, respectively. As soon as job B relinquishes the CPU (either its execution is over or it needs to perform some I/O operation), the CPU is given to job C (because it is in ready state) and it starts executing. Meanwhile, if job A completes output operation, its state converts from blocked to ready. Hence, in multiprogramming, CPU is never idle as long as there is always some job to execute.

■ Process Management

381

Note that although many jobs may be in ready and blocked states, only one job can be running at any instance of time, because there is only one CPU.

New job

Job is allocated the CPU for execution Running

Ready

I/O completed

Job processing completed

Job must wait for I/O completion Blocked

Figure 10.5. Three different states of jobs in main memory in a multiprogramming system.

The area occupied by each job residing simultaneously in main memory is known as a memory partition. The number of partitions, and hence number of jobs, which a system can concurrently load in its main memory at any given time depends on its operating system. The operating system maintains a queue of jobs awaiting entry into main memory. The jobs themselves reside on a fast secondary storage device such as magnetic disk. The operating system picks up a job from this queue and loads it from secondary storage into main memory whenever a memory partition becomes free (the job occupying that partition completes its execution).

Requirements of Multiprogramming Systems Multiprogramming systems have better throughput than uniprogramming systems because multiprogramming reduces CPU idle time significantly. However, they are more sophisticated because they require the following additional hardware and software features: 1.

Large memory. Multiprogramming requires large main memory to accommodate a good number of user programs along with the operating system.

2.

Memory protection. Multiprogramming requires a memory protection mechanism to prevent a job (in one memory partition) from changing another job’s program/data (in another memory partition). Operating systems use a combination of hardware and software protection mechanisms for preventing one job from addressing beyond the limits of its own allocated memory area.

3.

Job status preservation. In multiprogramming, when the operating system blocks a running job because the job needs to do I/O processing, it takes CPU away from the job and gives it to another job that is ready for execution. The blocked job resumes its execution sometime later. To enable this, the operating system must preserve the job’s status information when it takes away the CPU from it, and must restore this information back before it gives the CPU to the job again. For this, the operating system maintains a process control block (PCB) for each process, which is loaded in a memory partition. Figure 10.6 shows a typical process control block. With this arrangement, before taking away the CPU from a running process, the operating system preserves its status in its PCB. The operating system restores back the status of this process just before it gives back the CPU to it again later to resume its execution. Hence, the process can continue execution without any problem.

382

Chapter 10 ■ Operating Systems 4. Proper job mix. A multiprogramming system requires a proper mix of I/O-bound and CPU-bound jobs to overlap the operations of CPU and I/O devices effectively. If all loaded jobs need I/O at the same time, CPU will again be idle. Hence, jobs resident simultaneously in main memory should be a good mix of CPU-bound and I/O-bound jobs so that at least one job is always ready to utilize the CPU.

process identifier process state program counter values of various CPU registers accounting and scheduling information I/O status information

Figure 10.6. A typical process control block (PCB).

5. CPU scheduling. In a multiprogramming system, often there are multiple jobs in ready state (waiting for the operating system to allocate the CPU to it). Hence, when the CPU becomes free, the operating system must have a mechanism to decide to which one of these ready jobs it should allocate the CPU. Part of the operating system that takes this decision is called CPU scheduler, and the algorithm it uses for this is called CPU scheduling algorithm.

Multitasking Multitasking is single-user variation of multiprogramming concept. Many authors do not distinguish between multiprogramming and multitasking because both refer to the same concept of a system’s capability to work concurrently on more than one task (job or process). Whenever a task (job or process) needs to perform I/O operations, the system uses its CPU for executing some other task (job or process) that is also residing in the system and is ready to use the CPU. However, some authors prefer to use the term multiprogramming for multi-user systems (multiple users can use such a system simultaneously, such as a mainframe system or a server class system), and multitasking for single-user systems (only one user uses such a system at a time, such as a personal computer or a notebook computer). Note that even in a single-user system, the system often processes multiple tasks at a time. For example, a personal computer user can execute a sorting job in background, while editing a file in foreground. Similarly, a personal computer user may be reading his/her electronic mail in foreground, while compilation of a program is in progress in background. In this manner, a user may work concurrently on many tasks. In a multitasking system, the user can partition the computer’s display screen into multiple windows, and can view the status of different tasks on different windows. Multitasking eases user operation and saves lots of time when a user has to switch between two or more applications while performing a job. For example, let us assume that a user is using a word processor to create an annual report and he/she needs to do some arithmetic calculations for including calculated results in the report. Without multitasking, the user would have to close the annual report file and word processing application, open calculator application, make necessary calculations, write down the results, close calculator application, reopen word processing application with annual report file, and embed calculation results in it. With multitasking, the user simply opens calculator application while working on annual report file creation, makes necessary calculations, and switches back to the annual report file to continue working on it. Hence, for those who like to differentiate between multiprogramming and multitasking, multiprogramming is interleaved execution of multiple jobs (of same or different users) in a multi-user system, while multitasking is interleaved execution of multiple jobs (often referred to as tasks of same user) in a single-user system.

Multithreading Threads are a popular way to improve application performance. In traditional operating systems, the basic unit of CPU utilization is a process. Each process has its own program counter, its own register states, its own stack, and its

■ Process Management

383

own address space (memory area allocated to it). On the other hand, in operating systems with threads facility, the basic unit of CPU utilization is a thread. In these operating systems, a process consists of an address space and one or more threads of control [see Figure 10.7]. Each thread of a process has its own program counter, its own register states, and its own stack. However, all the threads of a process share the same address space. Hence, they also share the same global variables. In addition, all threads of a process also share the same set of operating system resources, such as open files, signals, accounting information, etc. Due to sharing of address space, there is no protection between the threads of a process. However, protection between multiple threads of a process is not necessary because a single user always owns a process (and hence all its threads). Multiple processes need protection against each other because different processes may belong to different users.

Address space Thread

(a)

Address space Thread Thread

Thread

(b)

Figure 10.7. (a) Single-threaded and (b) multi-threaded processes. A single-threaded process corresponds to a process of a traditional operating system. [Reproduced with permission, from the book titled Distributed Operating Systems: Concepts and Design by Pradeep K. Sinha. © 1997 IEEE, USA].

Threads share a CPU in the same way as processes do. At a particular instance of time, a thread is in running, blocked, ready, or terminated state. Due to these similarities, users often view threads as miniprocesses. In fact, in operating systems with threads facility, a process having a single thread corresponds to a process of a traditional operating system [see Figure 10.7(a)]. We often refer to threads as lightweight processes and traditional processes as heavyweight processes.

Motivations for Using Threads The main motivations for using a multi-threaded process instead of multiple single-threaded processes for performing some computation are as follows: 1.

The overhead involved in creating a new process is considerably greater than that for creating a new thread within a process. This is because when the operating system creates a new process, it has to create its address space from scratch, although the new process may inherit a part of its address space from its parent process. On the other hand, when the operating system creates a new thread, it need not create an address space for it because the new thread uses the address space of its process.

2.

Due to sharing of address space and other operating system resources among the threads of a process, the overhead involved in CPU switching among peer threads is small as compared to CPU switching among processes having their own address spaces. This is the reason why threads are called lightweight processes.

3.

An operating system can share resources more efficiently among multiple threads of a process than among multiple processes because all threads of a process share the same address space.

Finally, users find the threads model more intuitive for application programming because a set of threads using a shared address space is the most natural way to program many applications. For example, in an application, which uses producer-consumer model, the producer and consumer processes must share a common buffer. Therefore, programming the application in such a way that the producer and consumer are two threads of the same process makes the software design simpler.

Chapter 10 ■ Operating Systems

384

Multiprocessing Up to this point, we have considered uniprocessor systems (having one CPU only). However, we have already seen that the use of I/O processors improves the efficiency of a computer system by making concurrent input, processing, and output operations possible. CPU performs arithmetic and logical operations, while I/O processors carry out I/O operations concurrently. Figure 10.8 shows the architecture of a computer with its CPU, memory, and I/O processors. Main memory

I/O units

I/O processors

CPU

Figure 10.8. Architecture of a computer system with its CPU, memory, and I/O processors.

Designers carried further the idea of using I/O processors to improve system performance by designing systems with multiple CPUs. Such systems are called multiprocessing systems because they use multiple processors (CPUs) and can execute multiple processes concurrently. These systems use multiple CPUs to process either instructions from different and independent programs or different instructions from the same program simultaneously. Figure 10.9 shows basic organization of a typical multiprocessing system. CPU-1

Main memory

CPU-2

I/O processors

I/O processors

I/O units

I/O units

Figure 10.9. Basic organization of a typical multiprocessing system.

Tightly and Loosely Coupled Multiprocessing Systems Multiprocessing systems are of two types – tightly-coupled systems and loosely-coupled systems. In tightly-coupled systems, all processors share a single system-wide primary memory [Figure 10.10(a)]. In loosely-coupled systems, the processors do not share memory, and each processor has its own local memory [Figure 10.10(b)].

Difference between Multiprogramming and Multiprocessing Multiprocessing is simultaneous execution of two or more processes by a computer system having more than one CPU. Comparatively, multiprogramming is interleaved execution of two or more processes by a single-CPU system. Hence, while multiprogramming involves execution of a portion of one program, then a portion of another, etc., in brief consecutive periods, multiprocessing involves simultaneous execution of several program segments of the same or different programs.

Advantages and Limitations of Multiprocessing Multiprocessing systems have the following advantages: 1.

Better performance. They have better performance (shorter response times and higher throughput) than single-processor systems. For example, if we have to run two different programs, a two-processor system is

■ Process Management

385

evidently more powerful than a single-processor system because the two-processor system can run both programs on different processors simultaneously. Similarly, if we can partition a large computation job into multiple sub-computations (sub-processes) that can run concurrently, a multiprocessor system with sufficient number of processors can run all sub-processes simultaneously, with each one on a different processor (popularly known as parallel processing). However, the speed-up ratio with n processors is not n, but less than n. This is because when multiple processors cooperate to execute the processes or sub-processes, the operating system incurs certain amount of overhead in keeping everything working correctly. This overhead, plus contention for shared resources, lowers the expected gains from additional processors. CPU

Systemwide shared memory

CPU

CPU

CPU

Interconnection hardware (a) A tightly coupled multiprocessor system

Local memory CPU

Local memory CPU

Local memory CPU

Local memory CPU

Communication network (b) A loosely coupled multiprocessor system Fig. 10.10.

2.

Difference between tightly coupled and loosely coupled multiprocessing systems.

Better reliability. They also have better reliability than single-processor systems. In a properly designed multiprocessor system, if one of the processors breaks down, the system can continue to function with remaining processors. Hence, the system can tolerate partial failure of processors and can avoid a complete breakdown. For example, if a system has 4 processors and one fails, then the system can utilize the remaining 3 processors to process the jobs. Thus, the entire system runs only 25% slower, rather than failing altogether. This ability of a system to continue providing service proportional to the level of non-failed hardware is called graceful degradation feature.

Multiprocessing systems, however, require a sophisticated operating system to schedule, balance, and coordinate the input, output, and processing activities of multiple processors. Designing such an operating system is complex and time taking. Moreover, multiprocessing systems have higher initial cost and their regular operation and maintenance is costlier than single-processor systems.

Time-sharing Time-sharing is a mechanism to provide simultaneous interactive use of a computer system by many users in such a manner that all users feel that he/she is the sole user of the system. It uses multiprogramming with a special CPU scheduling algorithm to achieve this. A time-sharing system has many (even hundreds of) user terminals connected to it simultaneously. Using these terminals, multiple users can work on the system simultaneously. Multiprogramming feature allows multiple user programs to reside simultaneously in main memory, and special CPU scheduling algorithm allocates a short period of CPU time one-by-one to each user process (from the first one to the last one, and then again beginning from the first

Chapter 10 ■ Operating Systems

386

one). The short period during which a user process gets to use CPU is known as time slice, time slot, or quantum, and is typically of the order of 10 to 100 milliseconds. Hence, when the operating system allocates the CPU to a user process, the process uses the CPU until its time slice expires (system’s clock sends an interrupt signal to CPU after every time slice), or it needs to perform some I/O operation, or it completes its execution during this period. Notice that the operating system takes away the CPU from a running process when its allotted time slice expires. Figure 10.11 shows the process state diagram of a time-sharing system (compare it with the process state diagram of Figure 10.5). New job

Ready

Job is allocated to CPU for execution

Running

Job processing completed

Allotted time slice is over I/O completed

Job must wait for I/O completion Blocked

Figure 10.11. Process state diagram for a time-sharing system.

Now let us see how the CPU scheduling algorithm, mentioned above, gives an impression to each user that he/she is the sole user of the system. Let the time slice be 10 milliseconds and the processing speed of the system’s CPU be 500 million instructions per second. Hence, the system executes 500 x 10 6 x 10–3 x 10 = 5 x 106 = 5 million instructions in 10 milliseconds. This is large enough for substantial progress of a single user process. Let there be 100 user terminals and 100 simultaneous users using the system. If the operating system allocates 10 milliseconds to each user process one-by-one, a user process will get CPU’s attention once in every 100 x 10 milliseconds = 1 second. As human reaction time is of the order of a few seconds, a user will not notice any delay in execution of his/her commands and will feel that he/she is the sole user of the system, whereas in reality, many users are sharing a single computer.

Requirements of Time-sharing Systems Time-sharing systems require the following additional hardware and software: 1.

A number of user terminals so that multiple users can use the system simultaneously in interactive mode.

2.

Relatively large memory to support multiprogramming.

3.

Memory protection mechanism to prevent a job’s instructions and data from other jobs in a multiprogramming environment.

4.

Job status preservation mechanism to preserve a job’s status information when the operating system takes away the CPU from it, and restores this information back, before it gives the CPU to the process again.

5.

A special CPU scheduling algorithm that allocates CPU for a short period one-by-one to each user process in a circular fashion.

6.

An interrupt mechanism to send an interrupt signal to the CPU after every time slice.

Advantages of Time-sharing Systems Although, time-sharing systems are complex to design, they provide the following advantages to their users: 1.

Reduce CPU idle time. Thinking and typing speed of a user is much slower than processing speed of a computer. Hence, during interactive usage of a system, while a user is engaged in thinking or typing his/her

■ Process Management

387

input, a time-sharing system services many other users. Time-sharing systems, therefore, reduce CPU idle time and provide higher system throughput. 2.

Provide advantages of quick response time. The special CPU scheduling algorithm used in time-sharing systems ensures quick response time to all users, which helps improve interactive programming and debugging efficiency of programmers. Multiple programmers can work simultaneously for writing, testing, and debugging their programs, or for trying out various approaches to solve a problem. The greatest benefit of such a system is that all simultaneous users of the system can detect errors, correct them, and continue with their work immediately. This is in contrast to a batch system in which users have to correct errors offline and then resubmit their jobs for another run. We often measure in hours the time delay between job submission and return of the output in a batch system.

3.

Offer good computing facility to small users. Small users can gain direct access to more sophisticated hardware and software than they could otherwise justify or afford. In time-sharing systems, they merely pay a fee for the resources they use, and are relieved of hardware, software, and personnel problems associated with acquiring and maintaining their own installation.

Mutual Exclusion There are several resources in a system that multiple processes must not use simultaneously, if program operation is to be correct. For example, multiple processes must not update a file simultaneously. Similarly, operating systems must restrict use of unit record peripherals such as tape drives or printers to a single process at a time. Therefore, an operating system must ensure exclusive access to such a shared resource by a process. This exclusiveness of access is called mutual exclusion between processes. We refer to the sections of a program that need exclusive access to shared resources as critical sections. For mutual exclusion, operating systems implement mechanisms to prevent processes from executing concurrently within their associated critical sections. An algorithm for implementing mutual exclusion must satisfy the following requirements: 1.

Mutual exclusion. Given a shared resource, which multiple concurrent processes can access, at any time, only one process must access the resource. That is, if the operating system grants the resource to a process, the process must release it before the operating system can grant it to another process.

2.

No starvation. If every process to which the operating system grants the resource eventually releases it, the operating system must eventually grant the resource to every process requesting it.

Two commonly used approaches, which modern operating systems use to implement mutual exclusion are test-andset and semaphore. They are described here.

Test-and-Set Figure 10.12 shows the basic concept behind test-and-set method of implementing mutual exclusion. The mechanism uses a global Boolean variable lock, which it initializes to false. It also uses an atomic instruction test-and-set, which tests the lock status and sets it to true, if it is false at the time of testing. Test-and-set is an atomic instruction, which means that the mechanism executes both testing of lock variable status and setting it to true (if it is false) as one uninterruptible unit. As Figure 10.12 shows, when a process (P1) wants to enter critical section, it executes test-and-set instruction. If the status of lock variable is false, it is set to true by the test-and-set instruction. Now P1 enters critical section and executes the instructions in critical section. Notice that during this period, if another process (P 2) wants to enter critical section, it will also execute test-and-set instruction, but will find the status of lock variable to be true (the test “Is lock = false?” returns No). Hence, it will go to wait state. When P1 completes executing its critical section, it sets lock variable to false and sends interrupt signal to the operating system, indicating completion of execution of its

Chapter 10 ■ Operating Systems

388

critical section. The operating system then sends a wakeup signal to the waiting process P 2. When P2 executes testand-set instruction this time, test-and-set instruction will find lock variable to be false and will set it to true. Therefore, P2 can enter its critical section this time. A process wants to enter critical section Wait

Is lock = false ?

No

Yes

Test-and-Set atomic instruction

Set lock = true Enter Critical section of program Exit Set lock = false

Signal completion Execute other section of program Figure 10.12. Test-and-set method of implementing mutual exclusion.

In this manner, test-and-set mechanism ensures that only one process out of multiple processes trying to share a mutually exclusive resource will execute in its critical section at a time. If multiple processes try to enter their critical sections during the period in which P1 is executing its critical section, all of them will go to wait state like P 2. To ensure that no waiting process starves for the resource indefinitely, and all waiting processes get the resource eventually, the operating system maintains a waiting queue of all processes waiting on lock variable, and grants them the resource in first-come-first-served order.

Semaphore Test-and-set mechanism of handling mutual exclusion problem is suitable for resources that have only one unit in a system. We cannot generalize it easily to handle mutual exclusion problem for resources that have multiple units in a system. Semaphore mechanism can handle mutual exclusion problem for such resources. A semaphore (say S) is a global integer variable with the following features: 1.

The mechanism initializes it to the total number of units of the resource (to which it is to provide synchronized access).

2.

The mechanism allows its access only through two standard atomic operations wait and signal. Figure 10.13 shows the activities performed by the two operations.

■ Process Management

389

A process wants to enter critical section Wait

“Wait” atomic operation on semaphore(S)

Is S > 0

No

Yes S=S-1 Enter Critical section of program

“Signal” operation on semaphore(S)

Exit S=S+1

Wait operation: If S > 0 S = S – 1; Else Go to wait state; Signal operation: S = S + 1;

Signal completion

Execute other section of program

Activities of the two standard atomic operations (wait and signal) on a semaphore

Figure 10.13. Semaphore method of implementing mutual exclusion.

As Figure 10.13 shows, when a process P1 wants to enter critical section, it executes wait atomic operation on semaphore S. It tests if value of semaphore S is greater than zero and decrements its value by one if S>0. Now P 1 enters critical section and executes the instructions in critical section. Notice that during this period, if another process (P2) wants to enter critical section, it will also execute wait operation on semaphore S. Since the mechanism initializes the value of S to total units of the mutually exclusive resource, if there are multiple units of the resource, P 2 will also find that the value of semaphore S is greater than zero. Hence, it will decrement its value by one and enter the critical section. In this manner, if there are n units of the resource, n processes can enter their critical sections simultaneously. If (n+1)th process wants to enter critical section and executes wait operation on semaphore S, the test “Is S>0” will return false, and the process will go to wait status. When a process completes executing its critical section, it executes signal operation on semaphore S, which increments the value of S by one to indicate that one more unit of the resource has become free for allocation. The process then sends an interrupt signal to the operating system, indicating completion of execution of its critical section. The operating system then sends a wakeup signal to the first process in the waiting queue, which now executes wait operation on semaphore S once again and enters its critical section. In this manner, semaphore mechanism ensures that up to n processes only (n is the number of units of the mutually exclusive resource) can execute their critical sections simultaneously. The semaphore described above is known as counting semaphore, since its integer value can range over an unrestricted domain. Note that if the value of S is initialized to 1 for a counting semaphore, its value can range only between 0 and 1. Such a semaphore is known as binary semaphore. A binary semaphore is suitable for synchronizing access to those mutually exclusive resources that have only one unit in a system. Hence, a binary semaphore serves the purpose of test-and-set approach of implementing mutual exclusion.

Chapter 10 ■ Operating Systems

390

Deadlock There are several resources in a system for which the resource allocation policy must ensure exclusive access by a process. For example, a process needs exclusive access to a printer until it finishes using the printer because simultaneous use of the printer by two or more processes will lead to garbled printed output. Since a system consists of a finite number of units of each resource type (for example, three printers, six tape drives, four disk drives, two CPUs, etc.), multiple concurrent processes have to compete to use a resource. In this situation, a process goes through the following sequence of events to use a resource: 1.

Request. The process first makes a request for the resource. If the resource is not available, possibly because another process is using it, the requesting process must wait until the operating system allocates the resource to it.

2.

Allocate. The operating system allocates the resource to the requesting process as soon as possible. It maintains a table to record which resources are free and which resources are allocated (and to which process). If the requested resource is currently allocated to another process, the operating system adds the requesting process to a queue of processes waiting for this resource. Once the system allocates the resource to the requesting process, that process can exclusively use the resource.

3.

Release. After the process finishes using the resource, it releases the resource. The operating system updates the table records at the time of allocation and release to reflect the status of availability of resources.

The request and release of resources are system calls, such as request and release for devices, open and close for files, and allocate and free for memory space. Notice that out of the three operations, allocate is the only one that the operating system can control. The other two are not in operating system’s control because a process initiates them (not the operating system). With the pattern of request, allocation, and release of resources mentioned above, if the total request made by multiple concurrent processes for resources of a certain type exceeds the number available, the operating system must have a strategy to order the assignment of resources in time. The strategy should not cause a deadlock situation in which competing processes prevent their mutual progress even though no single one requests more resources than are available. It may happen that some of the processes that entered the waiting state (because the requested resources were not available at the time of request) will never again change state, because other waiting processes are holding the resources they have requested. This situation is called deadlock, and the processes involved are said to be deadlocked. Hence, deadlock is the state of permanent blocking of a set of processes each of which is waiting for an event that only another process in the set can cause. All the processes in the set block permanently, because all the processes are waiting and hence none of them will ever cause any of the events that could wake up any of the other members of the set. An example can best explain a deadlock situation (see Figure 10.14). Suppose that a system has two tape drives T1 and T2 and the resource allocation strategy is such that the operating system immediately allocates a requested resource to the requesting process, if the resource is free. Also, suppose that two concurrent processes P1 and P2 make requests for the tape drives in the following order:

T1

P2

P1

1. P1 requests for one tape drive and the operating system allocates

T1 to it. 2. P2 requests for one tape drive and the operating system allocates

T2 to it. 3. P1 requests for one more tape drive and enters a waiting state

because no tape drive is presently available. 4. P2 requests for one more tape drive and it enters a waiting state

because no tape drive is presently available.

T2 Figure 10.14. An example of a deadlock situation involving processes P1 and P2 and resources T1 and T2.

■ Process Management

391

From now on, P1 and P2 wait for each other indefinitely, since P1 will not release T1 until it gets T2 to carry out its designated task, that is, not until P2 has released T2, whereas P2 will not release T2 until it gets T1. Therefore, the two processes are in a state of deadlock. Note that the requests made by the two processes are legal because each is requesting for only two tape drives, which is the total number of tape drives available in the system. However, the deadlock problem occurs because the total requests of both processes exceed the total number of units for the tape drive and the resource allocation policy is such that it immediately allocates a resource on request, if the resource is free.

Necessary Conditions for Deadlock The following conditions are necessary for a deadlock to occur in a system: 1.

Mutual-exclusion condition. If a process is holding a resource, any other process requesting for that resource must wait until the process releases the resource.

2.

Hold-and-wait condition. Processes can request for new resources without releasing the resources, which they are currently holding.

3.

No-preemption condition. If the operating system has allocated a resource to a process, that resource becomes available for allocation to another process only after the process voluntarily releases it.

4.

Circular-wait condition. Two or more processes must form a circular chain in which each process is waiting for a resource that the next member of the chain holds. Figure 10.14 shows such a circular chain.

For a deadlock to occur, all four conditions must hold simultaneously. If any one of them is absent, no deadlock can occur.

Handling Deadlocks Operating system designers commonly use one of the following three strategies to handle deadlocks: 1.

Avoidance. Deadlock avoidance methods use some advance knowledge of the resource usage of processes to predict the future state of the system for avoiding allocations that can lead to a deadlock eventually. Usually, deadlock avoidance algorithms follow the following steps: (a) When a process requests for a resource, even if the resource is available for allocation, the operating system does not allocate it immediately to the process. Rather, the system assumes that the request is granted. (b) With the assumption made in Step (a) and advance knowledge of the resource usage of processes, the system performs some analysis to decide whether granting the process’s request is safe or unsafe. A system is in a safe state, if there exists some ordering of the processes in which the operating system can grant resources to meet resource requests of the processes to run all of them to completion. Deadlock avoidance algorithms perform resource allocation in a manner to ensure that the system will always remain in a safe state. Since the initial state of a system is always a safe state, whenever a process requests a resource that is currently available, the system checks to find out if the allocation of the resource to the process will change the state of the system from safe to unsafe. If no, the operating system grants the request immediately, otherwise it defers allocation of the resource to the process.

2.

Prevention. This approach somehow ensures that at least one of the four necessary conditions for deadlock is never satisfied, making deadlocks impossible. The two commonly known deadlock prevention methods are collective requests and ordered requests. They are described here. (a) Collective requests. This method denies the hold-and-wait condition by ensuring that whenever a process requests a resource, it does not hold any other resources. For example, one way to ensure this is to make a process request all its resources before it begins execution.

Chapter 10 ■ Operating Systems

392

(b) Ordered requests. This method denies the circular-wait condition. It assigns a unique global number to each resource type to impose a total ordering of all resource types. Now, the operating system uses a resource allocation policy in which a process can request a resource at any time, but the process should not request a resource with a number lower than the number of any of the resources that it is already holding. That is, if a process holds a resource type whose number is i, it may request a resource type having the number j only if j > i. 3.

Detection and recovery. In this approach, the operating system does not use any deadlock avoidance or prevention mechanism, and allows deadlocks to occur. Instead, it uses a detection algorithm to detect deadlocks. After it detects a deadlock, it resolves it in one of the following two ways: (a) Asking for operator intervention. The operating system informs the operator that a deadlock has occurred (specifying the list of processes involved in the deadlock), and then the operator deals with it manually. (b) Termination/Rollback of processes. The operating system terminates or rolls back one or more processes involved in the deadlock to break the deadlock.

MEMORY MANAGEMENT Other than CPU, main memory is an important resource of a computer system that the operating system must manage properly for overall system performance. Memory management module of an operating system takes care of this requirement. It keeps track of free and occupied (in use) parts of memory, allocates memory to processes when they need it, and de-allocates when they no more need. In this section, we will learn about different memory management schemes used in earlier and modern operating systems.

Uniprogramming Memory Model Many computer systems process only one job at a time, and all system resources are available exclusively for the job until it completes. Uniprogramming memory model is suitable for such systems. In this memory management scheme, operating system uses one part of memory, and its remaining part is available for use by the currently active user process (see Figure 10.15). The operating system loads a program from disk into user area of memory and executes it. When the process finishes, the operating system cleans up the user area of memory and then loads the next program, which is ready for execution. Although this memory management scheme is simple and easy to implement, it does not lead to proper utilization of main memory resource. This is because the unoccupied memory space in user area (marked unused in the figure) remains unused for entire duration of execution of the currently active user process. Hence, only small or dedicated computer systems (systems used for a specific application only) use this memory management scheme now.

Operating system area Operating system

User process User area Unused

Figure 10.15. Uniprogramming memory model.

■ Memory Management

393

Multiprogramming Memory Models In a multiprogramming system, multiple user processes can reside simultaneously in main memory. The two memory management schemes, which operating systems use to facilitate this, are multiprogramming with fixed number of memory partitions and multiprogramming with variable number of memory partitions. They are described here.

Multiprogramming with Fixed Number of Memory Partitions In this scheme, the operating system divides the user area of memory into a number of fixed-sized partitions. These partitions may be of equal or different sizes, but the size of each partition is fixed. Figure 10.16 shows a multiprogramming memory model with n equal-sized partitions. Each partition may contain exactly one process. Hence, the number of partitions bounds the degree of multiprogramming. That is, in a system with n memory partitions, the system can load maximum n processes at a time. The operating system queues all new jobs in an input queue. When a partition is free, it loads the next job from the input queue into that partition. When a process terminates, the partition it occupies becomes free for use by another process. In a system that uses partitions of different sizes, when a partition becomes free, the operating system loads the first process that fits in it from the input queue.

Operating system area

Operating system Partition 1 Partition 2

User area divided into n equal-sized partitions

Partition 3

Partition n Figure 10.16. Multiprogramming memory model with fixed number of memory partitions (all partitions of equal size).

IBM OS/360 mainframe systems used this scheme of memory management for several years. It was called MFT (Multiprogramming with a Fixed number of Tasks). It is no longer in use.

Multiprogramming with Variable Number of Memory Partitions In the earlier scheme, since all partitions are of fixed size, any space in a partition that is in excess of actual memory requirement of the process loaded into it remains unused. On an average, 50% of memory may remain unused due to this, resulting in under utilization of memory resource. The scheme with variable number of memory partitions overcomes this problem. In this scheme, the number, sizes, and locations of partitions vary dynamically as processes enter and exit the system. Figure 10.17 illustrates this memory management scheme with an example. Initially, all memory in user area is available for user processes. When a process enters the system, the operating system allocates to it only as much memory as it needs, keeping the rest available for future requests. As processes enter and exit, the operating system allocates and de-allocates memory partitions to them, each partition being equal to the size of memory required by the corresponding process. Since memory requirement of different processes is generally different, as processes enter and exit the system, the system’s memory is partitioned into various sizes of free memory blocks. Operating system maintains a table to keep track of free memory blocks. When a new process arrives, the operating system searches for a free block that is large enough for this process. If the free block is too large, the operating system splits it into two parts. One part is large enough for the process, while the other part contains remaining memory from that block. The operating system allocates the former part to the process and enters the latter part as a smaller free block in the free blocks table. When a process terminates, it releases the partition allocated to it. The operating system enters the released partition as a free memory block in the free blocks table. However, if the released partition is adjacent to any free block/blocks, the operating system merges it with the adjacent free block/blocks to create a larger free block, and updates the associated entries in the free blocks table.

394

Chapter 10 ■ Operating Systems

Memory Fragmentation External Fragmentation Notice from Figure 10.17 that in a system with variable number of memory partitions, as processes enter and exit the system, the free memory blocks break into smaller pieces. These pieces are scattered throughout the memory. External fragmentation is a situation when enough total free memory space exists to satisfy the memory need of a process, but the operating system cannot load the process in memory because the available free memory is not contiguous (is fragmented into multiple free blocks of memory). For example, in case of Figure 10.17(h), if the sizes of free blocks Free 1, Free 2 and Free 3 are 400K, 100K and 100K, respectively, then the total available free memory is 600K. Now if a new process arrives whose memory requirement is 500K, the operating system cannot load it because 500K of contiguous free memory space is not available. This is an example of external fragmentation. The amount of unusable memory area due to external fragmentation depends on the total size of main memory and the average memory requirement of the processes. However, statistical analysis indicates that as much as one-third of memory may be unusable due to external fragmentation. Time (a), (b), …, (h) Operating system

Operating system

Operating system

P1

P1

User area

Operating system

P1

P2

enters

enters

P1 P3 enters P2

P2

Free Free

P3 Free Free (a)

P2 exits

(b)

(c)

Operating system

Operating system

Operating system

Operating system

P1

P1

Free 3

P5 Free 3

P2 Free 2

P4 enters which cannot fit in Free 1 so is allocated space from Free 2

P5

P1 P4

exits

(d)

P4

enters which can fit in Free 3

P4 Free 2

Free 2

Free 2

P3

P3

P3

Free 1

Free 1

Free 1

Free 1

(e)

(f)

(g)

(h)

P3

Figure 10.17. An example of multiprogramming with variable number of memory partitions. As shown, the number, sizes, and locations of partitions vary dynamically as processes enter and exit the system.

■ Memory Management

395

Internal Fragmentation Internal fragmentation is a situation when the operating system allocates more memory to a process than its actual memory requirement because of the memory allocation mechanism of the operating system. The additional memory allocated to the process remains unutilized because neither the process uses it, nor the operating system can allocate it to any other process for use. Internal fragmentation may occur in the following situations: 1.

When the system uses fixed number of fixed-sized memory partitions, any space in a partition that is in excess of the actual memory requirement of the process loaded into it is an internally fragmented memory space. Figure 10.18 illustrates this situation with an example. Note that, on an average, 50% of the memory may remain unused in such systems due to internal fragmentation.

2.

When the system uses variable number of variable-sized memory partitions, it may happen that there is a free block of size 200K and a new process arrives whose memory requirement is 199.5K. If the operating system allocates exactly the same size of memory requested, there will be a free block of size 0.5K left. Considering the overhead involved in keeping track of this 0.5K free block, the general approach that operating systems use is to allocate such small memory area as part of the process’s memory request. Thus, the allocated memory may be slightly larger than the requested memory, and the additional memory that the operating system allocates to a process in this way is an internally fragmented memory space. Operating system area

Operating system Process 1 Unused

User area divided into 3 equal-sized partitions

Process 2 Unused

Process 3

Partition 1 allocated to Process 1 Partition 2 allocated to Process 2

Partition 3 allocated to Process 3

Unused Figure 10.18. An example showing internally fragmented memory spaces (shaded and marked as unused) in a system that uses fixed number of fixed-sized memory partitions.

Paging Operating systems often use memory compaction mechanism to solve external fragmentation problem. However, memory compaction is an expensive operation requiring CPU time for copying of memory contents from one memory location to another to make scattered free space contiguous. Paging is another mechanism that operating systems use to solve external fragmentation problem. Operating system designers often consider it better than memory compaction mechanism because it solves the problem of external fragmentation without the need to make scattered free space contiguous. Rather it allows a process’s memory to be noncontiguous, and allocates physical memory to a process from wherever free memory blocks are available. Because of its advantage over memory compaction mechanism, many modern operating systems use paging mechanism (in its various forms). This mechanism is explained here. In this mechanism, the operating system partitions the physical memory of a computer system into fixed-sized blocks called page frames. The operating system also partitions the total memory requirement of a process (including its

396

Chapter 10 ■ Operating Systems

instructions and data) into blocks of the same size called pages. Page sizes are typically of the order of 1 Kilobytes to 1 Megabytes and vary from one system to another. Now when the operating system selects a process for loading it into the memory, it loads its pages into the free page frames, wherever they are available. The operating system maintains a mapping table (called page table) to keep track of which page of the process is loaded into which page frame of the memory. Figure 10.19 shows an example to illustrate this. Notice from the figure that the operating system need not allocate contiguous page frames to the pages of the process. To ensure correct memory addressing in a system that uses paging mechanism, the memory addressing mechanism divides every memory address into two parts consisting of a page number and a page offset. To access a memory location, the operating system uses the page table to obtain the corresponding page frame number from the page number, and adds the page offset to the base address of the page frame number to define the physical memory address of the memory location. .

Page frame number

Pages of a process Page 0 Page 1 Page 2 Page 3 Page 4 Page 5 Before loading

After loading

Page frame number

0 1 2 3 4 5 6 7 8 9 10 11

0 1 Page Page frame number number 2 0 4 1 8 2 9 3 11 4 12 5 Page table created for the process

12 13 14 Status of physical memory partitioned into page frames before loading the process (free page frames are indicated as hashed blocks)

Page 0

2 3

Page 1

4 5

Page 2 Page 3

6 7 8 9 10

Page 4 Page 5

11 12

13 14 Status of physical memory after loading the process (free page frames are indicated as hashed blocks)

Figure 10.19. An example to illustrate paging mechanism.

Notice that there is no external fragmentation problem in a system that uses paging mechanism because the operating system can allocate free page frames to a process from anywhere in the memory (need not be contiguous). However, paging mechanism leads to some unutilized memory space due to internal fragmentation because the unit of memory allocation is a page frame. If memory requirements of a process do not happen to fall on page boundaries, the last page frame allocated to the process will not be completely full. For example, if an operating system uses page size of 2048 bytes, and a process’s memory requirement is 23,548 bytes, the process will need 11 pages plus 1020 bytes. As the unit of memory allocation is a page frame, operating system will allocate 12 page frames to the process, resulting in an internal fragmentation of 2048 – 1020 = 1028 bytes. On an average, in systems that use paging mechanism,

■ Memory Management

397

internal fragmentation leads to wastage of one-half page per process. Hence, the larger the page size, the larger is memory wastage due to internal fragmentation. This suggests the use of small page sizes. However, the smaller the page size, the larger is the size of page tables and the overhead involved in maintaining them. Hence, operating system designers must balance these two factors while deciding a suitable page size.

Virtual Memory What is Virtual Memory? Conventional memory management schemes, discussed till now, suffer from two main limitations: 1.

The operating system cannot load a process (and hence start its execution) until sufficient free memory for loading the entire process becomes available. This may delay a process’s turnaround time.

2.

The operating system cannot load a process (and hence start its execution) in a system whose main memory size is less than the total memory required by the process.

Virtual memory is a memory management scheme that overcomes these limitations by allowing execution of a process without the need to load the process in main memory completely. The process can execute even if it is loaded in main memory partially.

How is Virtual Memory Realized? Virtual memory mechanism uses the following three basic concepts for its realization: 1.

On-line secondary storage. It is an on-line secondary storage device having much larger capacity than main memory. Usually, modern computer systems use high-speed disk storage for this purpose.

2.

Swapping. Swapping is the process of transferring a block of data from on-line secondary storage to main memory or vice-versa. When the operating system transfers data from on-line secondary storage to main memory, it is called swapping in of data, and when it transfers data from main memory to on-line secondary storage, it is called swapping out of data.

3.

Demand paging. In a virtual memory system, the operating system partitions all processes into pages, which reside on on-line secondary storage. The operating system also partitions the physical memory into page frames of same size. Now, instead of loading an entire process before its execution can start, the operating system uses a swapping algorithm (called demand paging). The algorithm swaps in only those pages of the process, which the process currently needs in memory for its execution to continue. This idea is based on the observation that since a computer executes a program’s instructions one-by-one, it does not need all parts of the program in memory simultaneously. When there is no free page frame in memory to accommodate a page that the operating system needs to swap to continue a process’s execution, it invokes a page-replacement algorithm to create one for the accessed page. Page replacement deals with selecting a page that is residing in memory, but is not in use currently. The operating system swaps out the selected page to free the page frame it is occupying, and then swaps in the accessed page of the process in the freed page frame.

Virtual memory is often described as a hierarchy of two storage systems – one is a low-cost, large-capacity, low-speed system (on-line disk storage), and the other is a high-cost, small-capacity, high-speed system (main memory). Operating system manages them in such a way that users feel that they have access to a single, large, directly addressable, and fast main memory. That is, from the point of view of applications programmers, effective (or virtual) size of available main memory is unlimited. However, the mechanism incurs some performance penalty due to paging in of currently needed page(s) of a process, which makes frequent inter-page calls. Modern compilers and linkers arrange memory and instruction calls in a way to minimize inter-page addressing, leading to reduced paging (page swaps).

Chapter 10 ■ Operating Systems

398

Advantages and Disadvantages of Virtual Memory Advantages 1.

It provides a large virtual memory to programmers on a system having smaller physical memory. That is, physical memory size of a system does not constrain its logical memory size.

2.

It enables execution of a process on a system whose main memory size is less than the total memory required by the process.

3.

It enables a system to start a process’s execution even when sufficient free memory for loading the entire process is not available. This helps in improving the turnaround time of processes. A system can also use this feature to increase its degree of multiprogramming by accommodating program segments of a large number of users in main memory simultaneously. This, in turn, results in increasing CPU utilization and throughput of the system.

4.

It makes programming easier because while programming, programmers can concentrate on program logic without worrying about the size limitations of physical memory available.

5.

An analysis of execution of real programs shows that programs often do not execute all parts of their code during a typical execution run. For example, depending on data, a system may skip a large part of code of a program on some condition check and may never need to execute that part of code during that execution run. Similarly, during most execution runs of a program, a system rarely uses certain options and features of the program, such as those for handling unusual error conditions. With virtual memory mechanism, since the operating system loads parts of a program on demand, the system may never need to load certain parts of the program, which the system does not need during a particular execution run of the program. This, in turn, leads to less I/O activity than in the case when the system needs to load whole program before its execution. With less I/O, each user program would run faster, resulting in better throughput, turnaround time, and response time.

Disadvantages 1.

It is difficult to implement because it requires algorithms to support demand paging.

2.

If used carelessly, it may decrease performance instead of increasing. This happens when page-fault rate is high for a process. That is, the process spends more time in swapping out and swapping in of pages than in its execution.

FILE MANAGEMENT A file is a collection of related information. Every file has a name, its data, and attributes. Name of a file uniquely identifies it in a system. We access files by their names. A file’s data is its contents, which is a sequence of bits, bytes, lines, or records. A file’s creator and users define the meaning of its contents. Attributes of a file contain other information about the file, such as date and time of its creation, date and time of last access, date and time of last update, its current size, its protection features (who can access the file and in what way), etc. Different operating systems maintain different attributes for a file. File management module of an operating system takes care of file-related activities, such as structuring, accessing, naming, sharing, and protection of files. In this section, we will learn about important concepts used for file management in operating systems.

■ File Management

399

File Structure Different operating systems structure files in different ways. Most modern operating systems use one of the following two types of files structures: 1.

Files as unstructured sequence of bytes. As Figure 10.20(a) shows, in this case the operating system treats a file as byte sequences. That is, all file access operations at operating system level deal with the number of bytes to be read, written, or skipped. The operating system makes no interpretation of the bytes. This type of file structuring scheme provides maximum flexibility, but minimal support. That is, each application program must include its own code to interpret an input file into the appropriate structure. Two of the most popular operating systems, UNIX and MS-DOS, use this file structure.

2.

Files as sequence of fixed-length records. As Figure 10.20(b) shows, in this case the operating system treats a file as a sequence of fixed-length records. Each record has some internal structure. The creator of the file defines the internal structure and its meaning. In this case, all file access operations at operating system level deal with the number of records to be read, written, or skipped. Older days operating systems used this type of file structure. For example, when the 80-column punched paper cards were popular as input media, and 132 column printers were popular as output device, many operating systems based their file systems on input files containing 80-character records, and output files containing 132-character records. One byte

One record

(a) A file as unstructured sequence of bytes

(b) A file as a sequence of fixed-length records

Figure 10.20. Popular types of file structures.

File Access Methods To use information stored in a file, a system needs to access it and read its contents in main memory. Normally, computer systems support the following two file access methods at operating system level: 1.

Sequential access files. Normally, operating systems use sequential access files for storage of files on sequential access storage media, such as magnetic tape. Applications can access the contents of a sequential access file only sequentially. That is, a process can read the bytes or records in the file in the order in which they are stored, starting at the beginning. Reading of bytes or records randomly or out of order is not possible. An application can, however, rewind and read a sequential access file as often as needed.

2.

Random access files. Normally, operating systems use random access files for storage of files on random access storage media, such as magnetic or optical disks. Applications can access the contents of a random access file randomly, irrespective of the order in which the bytes or records are stored. For example, an application can access a specific byte/record of the file directly without reading all bytes/records before it. Random access files are essential for many applications. For example, a railway reservation system may be storing information about all tickets booked for a particular train in a single file. If a customer wants to cancel an already booked seat, reservation program must be able to access the specific record for that seat without having to read records for hundreds of other booked seats first, so that booking service can be fast enough.

Not all operating systems support both sequential and random access files. Some support only sequential access files, some support only random access files, while there are some, which support both. Those, which support files of both types, normally require the creator of a file to declare it as sequential or random when he/she/it creates the file. Users

Chapter 10 ■ Operating Systems

400

can access the file only in a manner consistent with its declaration. Most modern operating systems support random access files only.

File Operations An operating system provides a set of operations to deal with files and their contents. Figure 10.21 provides a typical set of file operations (actual set varies from one operating system to another). File operation

Usage

Create

Is used to create a new file.

Delete

Is used to delete an existing file that is no longer needed.

Open

Is used to open an existing file when a user wants to start using it.

Close

Is used to close a file when the user has finished using it.

Read

Is used to read data stored in a file.

Write

Get attributes

Is used to write new data in a file. Is used with random access files to first position read/write pointer to a specific place in file so that data can be read from, or written to, that position. Is used to access the attributes of a file.

Set attributes

Is used to change user-settable attributes (such as, protection mode) of a file.

Rename

Is used to change the name of an existing file.

Copy

Is used to create a copy of a file, or to copy a file to an I/O device, such as a printer

Seek

Figure 10.21. A typical set of file operations (actual set varies from one operating system to another).

File Naming When a file creator creates a file, he/she/it gives it a name that users can use later to access the file. The rules for naming files vary from one operating system to another. For instance, consider the following examples: 1.

MS-DOS allowed only up to 8 characters for a file name, Apple’s Macintosh allowed up to 31 characters, and Microsoft Windows allows up to 255 characters. With longer file names, users have greater flexibility in assigning more descriptive and meaningful names to their files.

2.

Some operating systems allow users to use only letters and numbers in file names, whereas others also allow special characters (sometimes barring a few). Hence, names like letter3_from_Ram, reminder2_to_Sham are often valid file names.

3.

Some operating systems (such as UNIX) distinguish between upper-case and lower-case letters, whereas others (such as MS-DOS) do not. Hence, UNIX operating system treats file names Sinha, sinha, and SINHA as three different files, but MS-DOS treated them as same file. Therefore, a user can assign these three names to three different files in UNIX, but not in MS-DOS.

4.

Many operating systems support file names having two or more parts, with a period separating different parts. For example, MS-DOS supports two-part file names in which the first part can have 1 to 8 characters and the optional second part can have 1 to 3 characters (such as letter.txt). In UNIX, a file may have more than two parts, as in prog.c.z, where .c and .z indicate that it is a program file of C language, which is compressed using the Ziv-Lempel compression algorithm. In such file names, the second and subsequent parts are called file extensions. File extensions usually indicate something about the file. Applications often use file extensions to check for the intended type of file before operating on it. For example, a C language compiler may insist that the files it is to compile must end in .c, and it may refuse to compile them, if they do not.

■ File Management

401

Some applications supply their own extensions automatically, such as .doc (for a Microsoft Word file) or .wk4 (for a Lotus 1-2-3 file). Figure 10.22 shows some typical file extensions and their meanings. File extension

Its meaning

.bas .c .ftn .pas

Basic source program file C source program file Fortran source program file Pascal source program file

.obj .bin .lib .dat .hlp .man

Object file (compiler output, not yet linked) Executable binary program file Library of .obj files used by the linker Data file Text file for HELP command Online manual page file

.txt .bak .doc .wav .wk4 .xls

General text file Backup file Microsoft word document file Microsoft windows sound file Lotus 1-2-3 spreadsheet file Microsoft Excel spreadsheet file

.jpg .gif

JPEG graphics file GIF graphics file

Figure 10.22. Some typical file extensions and their meanings.

Directories Operating systems use directories to map file names to their corresponding file attributes and file data, and to provide greater flexibility to users in file naming. We explain here how directories help in achieving these objectives.

Directory Contents A directory has a number of entries, one per file. As Figure 10.23 shows, each entry contains a file name, the attributes of the file or pointer to the data structure containing the attributes, and pointer to the file data (disk address where the file data is stored). When a user creates a new file, the operating system creates an entry for it in the directory. When the user deletes the file, the operating system deletes its corresponding entry from the directory. When a user opens an existing file for use, the operating system searches its corresponding entry in the directory and then extracts its attributes and disk addresses, and loads them in a table in main memory. All subsequent references to the file use this information in main memory.

File name

File attributes or pointer to data structure containing file attributes

Pointer to file data (Disk address)

Figure 10.23. Typical contents of a directory. There is one entry per file.

Chapter 10 ■ Operating Systems

402

Directory Organization Different operating systems use different number of directories and organize them differently. Normally, operating systems use the following types of directory organizations: 1.

Single directory. This is the simplest organization. As Figure 10.24(a) shows, in this case, a single directory contains entries for all files in the system. Although this organization is simple to implement, it has significant limitations when the number of files increases or when there are multiple users. As the number of files increases, it becomes difficult for a user to remember the names of all the files in order to create new

D

Single directory across the system

F2

F1

Fn

Files having unique names across the system (a) Single directory

Root directory

D

D2

D1

F2

F1

Fm

User directories (one per user)

Dn

F1

Fp

F2

F1

Fq

F2

Files need to have unique names only for an individual user. Two users can use the same file name. (b) One directory per user

Root directory

D

D2

D1

F1

F2

D21

Fm

User directories

Dn

F1

Dn2

Dn1

D22

F1 F1

F2

Dn11

F1

F1

F2

Dn12

F1

Files need to have unique names only within a directory/subdirectory (c) Multiple directories per user

Figure 10.24. The three types of directory organizations.

F2

User subdirectories

■ File Management

403

files with unique names. Similarly, in a system having multiple users, if two users choose the same file name, the system will not accept the file name of the user who did so later than the other user because this violates the unique-name rule. Such conflicts and confusions make this directory organization unsuitable for multiuser systems. Hence, only the most primitive microcomputer operating systems use this directory organization. This organization is known as flat directory structure. 2.

One directory per user. As Figure 10.24(b) shows, in this organization, there is a separate directory for each user. A user’s directory contains the names and other attributes of all his/her files. As a file name needs to be unique only within a directory, different users can have files with the same name. This overcomes the limitation of file name conflicts among users in case of single directory organization. However, this organization is inconvenient to use for users with many files because it is difficult for a user to remember the names of a large number of files that he/she creates over a period. This organization is known as two-level directory structure.

3.

Multiple directories per user. As Figure 10.24(c) shows, in this organization also, there is a separate directory for each user. However, each user can create and use as many sub-directories or sub-sub-directories, or sub-sub-sub-directories, and so on to group his/her files in natural ways. For example, a user may like to group his/her files project-wise, in which case he/she creates a sub-directory for each project and keeps all files of a project in that project’s sub-directory. As the operating system requires a file name to be unique only within a directory, a user can have files with the same name in different sub-directories. This feature provides greater flexibility to a user in naming files because the user can group his/her files in logical ways. With this grouping arrangement, the user can easily remember a file name (with reference to its group) even when the number of files for the user becomes large. This organization is known as tree-structured or hierarchical directory structure.

Disk Space Allocation Methods Normally, for permanent storage, a system stores files on disks, and a disk stores many files. Disk space allocation methods deal with how to allocate space to multiple files on disk to meet the following two objectives: 1.

The system makes effective utilization of disk space, and

2.

The system can quickly access a piece of information from any file.

The three methods that operating systems use commonly for disk space allocation are contiguous, linked, and indexed. They are described here. However, before that, it is important to note that operating systems divide the total disk storage space into equal sized blocks (see Figure 10.25). Normally, the size of a block is a multiple of page size in systems that use paging mechanism for memory management. The operating system allocates disk space to files in units of blocks. It is possible to read a block from the disk, to modify the block, and write it back into the same place.

0

1

8 16 24 32

9 17 25 33

40 48

41 49

5

6

36

13 21 29 37

14 22 30 38

44 52

45 53

46 54

2 10 18 26

3 11 19 27

4 12 20 28

34 42 50

35 43 51

7 15 23 31 39 47 55

Figure 10.25. Storage space of a disk partitioned into equal sized blocks.

Chapter 10 ■ Operating Systems

404

Contiguous Allocation In this method, each file occupies a set of contiguous blocks on a disk. Hence, if a disk has 2K blocks, the operating system will allocate 6 contiguous blocks to a file of size 11K. As Figure 10.26 shows, in this method, the operating system stores in the directory the starting block number and total number of blocks for each file as disk addresses of file. File name

File attributes

A B C D

---------

Disk address Starting Total number block number of blocks 0 3 19 6 29 8 5 4 Directory

File ‘A’ occupies 3 blocks numbered 0, 1 and 2. File ‘B’ occupies 6 blocks numbered 19, 20, 21, 22, 23 and 24. File ‘C’ occupies 8 blocks numbered 29, 30, 31, 32, 33, 34, 35 and 36. File ‘D’ occupies 4 blocks numbered 5, 6, 7 and 8. Figure 10.26. Illustrating allocation of disk blocks to files in contiguous allocation method.

Contiguous disk space allocation has the following advantages: 1.

It is simple to implement.

2.

Its performance is excellent because the operating system can read an entire file from disk in a single operation.

3.

It easily supports both sequential and direct access because all blocks of a file are contiguous.

This method, however, has the following drawbacks: 1.

It suffers from external fragmentation problem. External fragmentation is a situation when enough total free disk blocks exist to satisfy the disk space requirement of a file, but the operating system cannot store the file on disk because the available free disk blocks are not contiguous. The amount of unusable disk space due to external fragmentation depends on total disk space and average disk space required by files. However, statistical analysis indicates that as much as one-third of disk space may be unusable due to external fragmentation. To take care of this problem, systems using contiguous disk space allocation method often provide disk compaction facility, which moves files to bring all free blocks together. Disk compaction is a time consuming operation and may take several hours. Hence, the operating system performs disk compaction usually at low-activity hours (such as at night) when the system is otherwise idle.

2.

Another problem with this method is for the operating system to decide how much space it should allocate to a new file so that it has appropriate number of contiguous blocks for the file. In general, it is difficult to estimate the size of an output file. If the operating system overestimates the size, it will lead to unused disk space due to internal fragmentation. On the other hand, if the operating system underestimates the size, it will have to move the file completely to a new area on the disk when the file size grows beyond the originally estimated size. This often leads to external fragmentation problem and slower file access operations.

Linked Allocation As Figure 10.27 shows, in this method, the operating system maintains a linked list of the set of disk blocks that it allocates to a file. It uses the first word of each disk block to store a pointer to the next one, and uses the rest of the

■ File Management

405

words in the block to store file data. Hence, the operating system can allocate disk blocks to a file from anywhere on the disk. As Figure 10.27 shows, in this method, the disk address in the directory indicates the number of the first block of each file. Linked disk space allocation method has the following advantages: 1.

There is no external fragmentation in this method. The operating system can use every disk block. Since there is no loss of disk space due to external fragmentation, there is no need to implement disk compaction facility.

2.

There is no need for the operating system to determine and declare the total anticipated size of a file at the time of its creation. A file can grow freely at any time since the operating system can allocate new disk blocks to the file from anywhere on the disk.

File name

File attributes

Disk address First block number

A

---

2

B

---

11

Directory

Block no. 2 7

Block no. 7 4

Block no. 4 NULL

Block no. 11 3

Block no. 3 6

Block no. 6 14

Block no. 14 NULL

File ‘A’ occupies 3 blocks numbered 2, 7 and 4. File ‘B’ occupies 4 blocks numbered 11, 3, 6 and 14. Figure 10.27. Illustrating allocation of disk blocks to files in linked allocation method.

The method, however, has the following drawbacks: 1.

The method is suitable for use for sequential-access files only because random access of files in this method is extremely slow. For example, to access some data from the ith block of a file, the operating system has to start at the first block and follow the pointers until it gets to the ith block. This is slow because each access to a pointer requires accessing a new block that requires a disk read operation.

2.

Another problem is reliability. Since the operating system maintains a linked list of blocks of a file by using pointers, which are scattered all over the disk, if a pointer is lost due to disk corruption, all file data beyond that disk block becomes inaccessible. This leads to garbage blocks (blocks that are neither free nor in use) and requires implementation of a garbage collection algorithm. This algorithm searches for garbage blocks and adds them to the list of free disk blocks.

Indexed Allocation In this method also, the operating system can allocate disk blocks to a file from anywhere on the disk. However, unlike linked allocation in which the operating system maintains a linked list of the set of blocks it allocates to a file, in this method, it stores the pointers to the set of blocks it allocates to a file in a special block known as index block. Thus, each file has its own index block, which is an array of disk block addresses. The i th entry in the index block points to the ith block of the file. As Figure 10.28 shows, in this method, the disk address in the directory indicates the number of the index block of each file.

Chapter 10 ■ Operating Systems

406

Block no. 2 Block no. 5 2 7 4 NULL

Block no. 7

Block no. 4 File File Disk address name attributes A

---

5

B

---

8

Directory

Index block for file A Block no. 8 11 3 6 10 NULL

Index block for file B

Block no. 11

Block no. 3

Block no. 6

Block no. 10

File ‘A’ uses block no. 5 as index block and occupies three blocks numbered 2, 7 and 4. File ‘B’ uses block no. 8 as index block and occupies four blocks numbered 11, 3, 6 and 10. Figure 10.28. Illustrating allocation of disk blocks to files in indexed allocation method.

Indexed disk space allocation method has the following advantages: 1.

There is no external fragmentation in this method. The operating system can use every disk block. Since there is no loss of disk space due to external fragmentation, there is no need to implement disk compaction facility.

2.

There is no need for the operating system to determine and declare the total anticipated size of a file at the time of its creation. A file can grow freely at any time since the operating system can allocate new disk blocks to the file from anywhere on the disk.

3.

The method is suitable for use for both random-access and sequential-access files. Once the operating system loads the index block of a file into main memory (which is does when a user opens the file for use), the operating system can directly access the block corresponding to any part of the file by using the information in the index block.

The method, however, has the following drawbacks: 1.

It suffers from wastage of disk space, especially when most files are small. This is because the operating system allocates one index block to each file irrespective of the number of data blocks for a file. Hence, if a file has only one or two data blocks, the operating system uses an entire index block for storing just one or two pointers, leaving the index block area largely unused. One way to take care of this problem is to have enough space in the directory so that the operating system can store the first few (say n) block addresses in the directory itself. Hence, for small files, all necessary information is right in the directory. The operating system needs to allocate an index block to a file only when the file requires more than n blocks for storing its data.

■ Device Management 2.

407

It suffers from the problem of handling large files. This is because if the index block has space that is sufficient to store only m disk block addresses, then how can the operating system store files of size larger than m disk blocks? Operating systems often take care of this problem by using the method of multilevel index. In this method, one of the addresses in the index block is the address of a disk block called the secondlevel index block. This block contains pointers to additional disk blocks of a file of size larger than m disk blocks. An operating system can use third or fourth level index blocks to support very large files, but two levels of indexes are generally sufficient.

DEVICE MANAGEMENT For processing data, a computer must first input data and programs for which it needs input devices. Similarly, to produce the results of processing, it needs output devices. Chapter 6 provided a description of several of these I/O devices. Device management module of an operating system takes care of controlling the I/O devices of a computer system and provides a simple and easy to use interface to these devices. We describe here how an operating system takes care of these requirements.

Controlling I/O Devices We saw in Chapter 6 that a computer uses device controllers to connect I/O devices to it. Each device controller is in charge of and controls a set of devices of a specific type. For example, a disk controller controls disk drives, a tape controller controls tape drives, and a printer controller controls printers. A device controller maintains some local buffer storage and is responsible for moving data between an I/O device that it controls and its local buffer storage. Each device controller also has a few registers that it uses for communicating with the CPU. In some computers, these registers are part of the regular memory address space. This scheme is called memory-mapped I/O. In other computers, the operating system uses a special address space for I/O, and allocates a portion of it to each device controller. To perform an I/O operation, the operating system writes the relevant commands and their associated parameters into the appropriate controller’s registers. After loading the commands into the controller’s registers, the CPU resumes with its normal operations. The device controller then examines the contents of these registers and performs necessary actions for the I/O operation. For example, the action for a read request will be to transfer data from the specified input device to its local buffer. Once transfer of data from input device to the controller’s local buffer is complete, the operating system uses one of the following two methods to transfer the data from the controller’s local buffer to the appropriate memory area of the computer: 1.

Non-DMA transfer. In this method, as soon as transfer of data from input device to the controller’s local buffer is complete, the controller sends an interrupt signal to the CPU. The CPU then stops what it is doing currently, and transfers control of execution to the starting address of the service routine, which handles the interrupt. On execution, the interrupt service routine transfers the data from local buffer of the device controller to main memory. As soon as this data transfer is over, the CPU resumes the job that it was doing before interruption.

2.

DMA transfer. In non-DMA transfer method, CPU is involved in transfer of data from device controller’s buffer to main memory. That is, the operating system executes the interrupt service routine, which reads one byte or word at a time from the device controller’s buffer and stores it in memory. It is wastage of precious CPU time, if CPU is involved in reading and storing one byte or word at a time. To free the CPU from data transfer operation, many device controllers support direct memory access (DMA) mechanism. In this method, when the operating system prepares for data transfer operation, it writes the relevant commands and their associated parameters into the controller’s registers. The command parameters include the starting memory address (from/to where data transfer is to take place) and the number of bytes in the data. Now after the controller has read the data from the device into its buffer, it copies it from the buffer into main memory (at

Chapter 10 ■ Operating Systems

408

specified memory address) one byte or word at a time. It does not involve the CPU in this data transfer operation. The device controller sends an interrupt to the CPU only after it completes copying the entire data. Note that in this method, when the operating system starts after the interrupt, it starts performing the subsequent operations directly because there is no need for it to copy the data from the device controller’s buffer to memory (since the data is already there).

Simple and Easy User Interface to I/O Devices Ease of use is an important goal of all operating systems. To meet this objective, operating systems provide simple and easy user interface to the I/O devices. They achieve this by organizing the software for using I/O devices as a series of layers. Lower layers hide internal details of the devices from upper layers, and upper layers present a nice, clean, uniform interface to the users. As Figure 10.29 shows, device management module typically structures the I/O software into the following four layers: I/O software layers

I/O hardware

User-level software

Supports standard I/O system calls as library procedures.

Device-independent software

Performs I/O functions that are common to all devices and maps symbolic device names to the proper device driver.

Device drivers

Converts I/O requests into suitable commands for the appropriate device controller and writes the relevant commands and their associated parameters into the controller’s registers.

Interrupt handlers

Causes interrupt to wakeup the device driver after it completes data transfer.

I/O devices hardware Performs actual data I/O.

Figure 10.29. Layers of I/O system.

1.

Interrupt handlers. As mentioned above, a device controller causes an interrupt after it completes data transfer either from the device to its buffer (in non-DMA transfer) or from the device to memory (in DMA transfer). Interrupt handler software causes this interrupt by sending an interrupt signal to the appropriate device driver, which takes further course of action.

2.

Device drivers. For each type of device in a system, the system has a device driver. For example, a system normally has a disk driver for disks, a printer driver for printers, a tape driver for tapes, and so on. A device driver contains all device-dependent code. It accepts abstract I/O requests from the device-independent software layer above it, and translates it into commands for the appropriate device controller. It then writes these commands and their associated parameters into the controller’s registers.

3.

Device-independent software. This layer performs those I/O functions, which are common to all devices. It provides a uniform interface to user-level software. It maps symbolic device names to the appropriate device driver. Some I/O devices, such as disks, are sharable and many users can use such a device simultaneously. Other devices, such as tapes and printers, are non-sharable and only one user can use such a device at a time. The device-independent software layer handles both shared and non-shared devices in a manner to handle all device-sharing issues.

4.

User-level software. This layer contains the standard I/O system calls in the form of library procedures. Users use these system calls, such as read, write, print, send, and receive for performing various I/O operations.

■ Device Management

409

Spooling Spooling stands for Simultaneous Peripheral Operation On-Line. It is a mechanism to deal with the following issues: 1.

To reduce speed mismatch between slow I/O devices and CPU for better utilization of CPU.

2.

To convert mutually exclusive (non-sharable) I/O devices into non-mutually exclusive (sharable) I/O devices so that multiple processes of a multiprogramming system can use such a device simultaneously.

We explain here how spooling helps in dealing with these issues.

Dealing with Speed Mismatch Speed mismatch between a slow I/O device (such as a printer) and CPU is normally of the order of few thousand. Hence, while a slow I/O device is inputting/outputting a few bytes of data to/from main memory, the CPU can perform several thousands of operations. As a result, during reading/writing of data from/to memory, the CPU is idle for a large percentage of I/O time. Spooling reduces the idle time of CPU by placing all data that comes from an input device or goes to an output device on a magnetic disk (see Figure 10.30). The primary reason for doing this is to make the program and data available readily to the fast and expensive CPU by keeping it on a high-speed I/O medium (such as a disk). Reading/writing of data from/to a disk is much faster than reading/writing it from/to a slow I/O device, resulting in considerable reduction in CPU idle time during I/O operations involving slow devices. Most computer systems use special, low-cost I/O processors for spooling input data from a slow input device to a disk, or for outputting spooled output data from a disk to a slow output device. These I/O processors function independent of the main processor (CPU). This enables the main, high-speed, expensive CPU to be devoted fully to main computing jobs. The process of spooling is transparent to user programs. In general, spooling makes better use of both main memory and CPU.

Dealing with Mutually Exclusive I/O Devices Non-sharable I/O devices, which multiple processes cannot use simultaneously, are called mutually exclusive devices. Printer is an example of such a device. For effective utilization of such devices, an operating system often converts them into non-mutually exclusive virtual devices by using spooling. For this, the operating system creates a special process, called a daemon, and a special directory, called a spooling directory. Now when a process makes a request to use such a device (for example a printer), instead of allocating the printer to the process, the operating system opens a file for the process’s output data in the spooling directory, which it stores on a disk. The operating system writes in this file all output data to the printer by the process. It closes the file when the process completes printing. The daemon then prints the file from the disk to the printer. The daemon is the only process having permission to print the files in the spooling directory on the printer. By protecting the printer against direct use by users, the operating system avoids the problem of having someone keeping it open (engaged) unnecessarily long. Printer is not the only device that can benefit from spooling in this manner. For example, file transfer over a network often uses a network daemon. To send a file over the network, the operating system puts it in a network spooling directory on the disk. Later on, the network daemon transmits it over the network from the directory. Note that in both the examples discussed above, spooling allows a dedicated device (such as a printer or a network) to be shared by multiple users simultaneously. This is because spooling being transparent to users, it gives an impression to users that they are inputting/outputting their data from/to the dedicated device directly, not via the daemon process.

Chapter 10 ■ Operating Systems

410

CPU Main memory

Input device

Output device

(a) Mode of data I/O without spooling facility

CPU Main memory Input device

Disk

Output device

(b) Mode of data I/O with spooling facility Figure 10.30. Illustrating spooling mechanism.

COMMAND INTERPRETATION Command interpretation module (known as command interpreter) of an operating system provides a set of commands, which users use to give instructions to a computer for execution of their jobs. Commands supported by command interpretation module are known as system calls. When a user gives instructions to a computer by using these system calls, command interpreter interprets these commands and directs the computer’s resources to handle the user’s request. Hence, command interpreter provides a user interface to hide hardware details of a system from its users. In this manner, it contributes greatly to the ‘ease of use’ objective of an operating system. Modern operating systems support the following two broad categories of user interfaces: 1.

Command-line interface. Users give instructions to computers by typing commands in this textual user interface. For example, in UNIX, a user has to type “rm report.txt” to delete (remove) a file named report.txt. If a user types a command incorrectly, command interpreter responds with a message indicating that it did not understand the command. When this happens, the user has to retype the command correctly. There is no problem in typing simple commands like the one above. However, users often need to give detail instructions to computers about their jobs. For example, while submitting a job for execution, a user may need to supply the following information: (a) (b) (c) (d) (e)

His/her identification for security and accounting purposes. Software and hardware resource requirements of the job. I/O device requirements of the job. Directories that contain the data files, which the job will use during execution. Action that the system needs to take in exceptional conditions, such as when the input data is missing or incorrect, or when an I/O device malfunctions.

■ Operating System Structure

411

To facilitate this, systems that support command-line interface, also support some type of command language (CL) or job-control language (JCL). Users can write codes in JCL to give detail instructions to computers about their jobs. Command interpreters interpret codes written in JCL and invoke appropriate system actions. 2.

Graphical user interface. User interface plays an important role in ease of use of a computer system. An intuitive user interface allows a user to use the system effectively even if he/she has never used it before. Such a user interface is called user friendly. Graphical user interface or GUI (pronounced “gooey”) is easier to learn and use than command-line interface. Unlike command-line interface in which commands are textual, GUI commands are graphical (pictorial). GUI provides a screen full of graphic icons (small images on the screen) or menus, and allows a user to make rapid selection from these icons or menu items to give instructions to computers. A user uses a point-and-draw device to point to and select a graphic icon or menu item from multiple options on the screen. For example, in case of command-line interface, to delete a file report.txt, a user needs to type a command like “rm report.txt”. However, with GUI, the user can perform the same operation by using a mouse to drag the icon, which represents the file to superimpose it on an icon having shape like a trashcan. Then releasing the mouse button causes the file to disappear into the bulging trashcan.

Shell The command interpreter of an operating system serves as its user interface. We often refer to it as shell, because it forms the outer layer of the operating system covering its other modules. The shell can be a command-line interface or GUI. An operating system may support multiple shells. For example, an operating system can have a commandline shell and a GUI shell, allowing its users to switch from one shell to another. Beginners often find it convenient to work with GUI shell, whereas advanced users find it more convenient to work with command-line shell. Some operating systems also support multiple command-line shells. It is like supporting multiple JCLs and allowing a user to use a language with which he/she is most comfortable. For example, many Unix operating systems support three command-line shells known as C shell, Bourne shell, and Korn shell.

OPERATING SYSTEM STRUCTURE We studied about the various components of an operating system in earlier sections. We will now have a look at how these components are put together to form an operating system.

Layered Structure Most modern operating systems organize their components into a number of layers (levels), each built on top of lower layers. The bottom most layer (layer 0) is the hardware and the top most layer (layer n) is the user interface. The number of in-between layers and their contents vary from one operating system to another. We explain here how operating systems designers decide this. The main advantage of layered approach is modularity. Operating systems designers select the layers such that each layer uses the functions and services of its immediate lower layer. This approach simplifies the design and implementation of the operating system, because the implementers can implement each layer by using only the operations of its immediate lower level layer.

Kernel The kernel of an operating system is its central controlling part, which implements the most primitive of the system’s functions. It is the only part of an operating system, which a user cannot replace or modify. The precise interpretation of the system’s functions that are part of the kernel varies from one operating system to another. However, typical operating system kernels contain basic functions, which an operating system requires for process management,

Chapter 10 ■ Operating Systems

412

memory management, device management, and low-level security features like access control. In some systems, the kernel is larger and provides for more than these functions, whereas in others, it is smaller.

Monolithic Kernel versus Microkernel Operating systems designers commonly use the following two models for kernel design: 1.

Monolithic kernel. In the monolithic kernel model, the kernel provides most operating system services such as process management, memory management, device management, file management, and security. Hence, the kernel has a large, monolithic structure.

2.

Microkernel. The main goal of this model is to keep the kernel as small as possible. Therefore, in this model, the kernel is a small nucleus of software, which provides only minimal facilities necessary for implementing additional operating system services. The minimal facilities include services such as low-level device management, a limited amount of low-level process management, and some memory management. Implementers implement all other operating system services, such as file management, additional process and memory management activities, and security as user-level server processes. Each server process has its own address space. Different implementation teams can implement different user-level services of the operating system independently.

Resident and Non-Resident Operating System Modules Usually, an operating system is large software with all its functionalities. Obviously, users do not need all functionalities of an operating system all the time. As a system has limited main memory, it is customary to keep only a small part of the operating system in system’s memory, and to keep its remaining part on an on-line storage device such as hard disk. Those modules of an operating system, which need to be always resident in system’s main memory, are called resident modules, whereas those that reside on hard disk are called non-resident modules. The operating system loads a non-resident module into the memory on demand (whenever a user process needs it for execution). Readers should not confuse between an operating system kernel and its resident modules. The two are not the same. In fact, for most operating systems they are different. Normally, the following two criteria determine whether a module of an operating system should be resident: 1.

Its frequency of use, and

2.

Whether the system can operate at all without it.

For example, an operating system can maintain its file directories on disk and load a directory into memory when it requires it. Similarly, an operating system can swap out status information for inactive processes on disk. In fact, the resident part of an operating system is a subset of its kernel.

OS CAPABILITY ENHANCEMENT SOFTWARE Users often perform several routine-nature tasks on their computers. For example, compilation of programs, sorting of file contents, and taking backup of important files are tasks of such nature. Not all computer users can write their own programs for performing these tasks. Even if they could write, it would be wasteful, if each user spent time developing these programs. This gap between functionality of an operating system and need for these frequently used programs created a market for a special category of software, which enhances the capability of an operating system. Either operating system vendors or third-party software vendors supply such software. Normally, we group them into three categories – translating programs, library programs, and utility programs. They are described here.

■ OS Capability Enhancement Software

413

Translating Programs Translating programs, also known as language processors, are system programs that translate a source program (written by a user) to an object program (code meaningful to computer hardware). These include assemblers, compilers, and interpreters. This category of software also includes other program development tools used for testing and debugging of programs.

Library Programs Library programs consist of frequently used functions and operations. Commonly used library programs include: 1.

Programs to compute mathematical functions, such as sine, cosine, square root, exponential, and logarithm of numbers.

2.

Programs to perform mathematical operations, such as matrix multiplication, matrix inversion, and statistical analysis.

3.

Programs to convert numbers from one base to another, such as binary to octal, octal to binary, binary to decimal, and decimal to binary.

4.

String processing programs, such as those that perform string comparison, string copy, string concatenation, and calculation of length of a string (number of characters in it).

5.

File manipulation programs, such as those for sorting, merging, concatenating, searching, and editing of files.

A system may have a large number of library programs. Usually, a system also has a librarian program, which controls storage and use of library programs in the system library. It maintains a program directory for this purpose, and facilitates addition of new programs to the library, or deletion of unwanted or old programs from the library.

Utility Programs Utility programs assist users in system maintenance tasks, such as disk formatting, data compression, data backup, and scanning a system for computer viruses. Some frequently used utility programs are: 1.

Disk formatting utility. In file management section, we saw that different operating systems organize and use the available storage space on a disk in different ways. For example, some use contiguous allocation, some use linked allocation, and others use indexed allocation. Moreover, block size may be different for different operating systems, and an operating system may reserve certain areas of disk for storing systemrelated information (not for user files). To use a new disk (hard disk or optical disk) on a computer system, a user needs to format it according to the requirements of the computer’s operating system. Disk formatting utility enables users to perform this task.

2.

Disk compaction utility. This utility is useful for those systems, which use the method of contiguous allocation of disk blocks to files. We saw that in this method, if a system has been in continuous use for some time, external fragmentation may lead to almost 30% of unutilized disk space. Disk compaction utility allows a user to perform disk compaction, which moves files to bring all free blocks together. Disk compaction is a time consuming operation and may take several hours. Hence, users should run this utility at night, when the system is otherwise idle.

3.

Data compression utility. This utility uses a compression algorithm to transform files into a fraction of their normal sizes, so that they occupy less storage space on disk, or the system can transfer them across a network in less time. It has an associated decompression algorithm, which it uses to convert a compressed file into its normal form and size, when a user accesses the file. It helps in significant saving of disk space (might effectively double the capacity of a disk).

Chapter 10 ■ Operating Systems

414 4.

Data backup utility. A disk crash, virus, hardware malfunction, accidental deletion of files, or natural disasters like fire, earthquake, etc. can cause damage/loss of data in a computer system. Hence, we must keep extra copies (called backup data) of important data. A backup utility enables a user to create copy of data on some storage media (such as CD, pen drive, or magnetic tape) from another storage media (such as hard disk). In the event of damage/loss of data, the user can restore it from backup media. To prevent loss of critical data due to natural disasters, users should store the storage media having backup data offline (away from the computer system). However, it is not necessary to keep the backup media off-line. Some computer systems keep their backup devices on-line at a place away from main system. They use high-speed communication network between the backup device and main system, and perform automatic data backup operation over the network.

5.

Antivirus utility. A computer virus is a piece of code attached to a legitimate program that when executed, infects other programs in a system by replicating and attaching itself to them. In addition to this replicating effect, a virus normally does some other damage to the system, such as corrupting/erasing files. Therefore, due to its spreading nature, a virus can cause severe damage to a system. A typical virus works as follows. An intruder writes a new program that performs some interesting or useful function (such as some game or utility) and attaches a virus to it in such a way that when anyone executes the program on his/her system, the system executes the viral code along with the program. The intruder then sends this infected program by mail to other system users, or offers it free or for a nominal charge on CDs. Now, if anyone uses the infected program on his/her system, the system executes its viral code. During its execution, the viral code selects an executable program file on hard disk randomly and checks if it has already infected the file. Most viruses include a string of characters that acts as a marker showing that a file is infected. If the selected file is already infected, the virus selects another executable file. When the virus finds an uninfected file, it infects its program by attaching a copy of itself to the end of that program and replacing the first instruction of the program with a jump to viral code. When execution of viral code finishes, it executes the previously bypassed instruction (the first instruction of original program) and then jumps to the second instruction so that the program now performs its intended function. Notice that a virus spreads because every time the system executes an infected program, the virus tries to infect more programs. Also, notice that a virus does not infect an already infected file in order to prevent an object file from growing ever longer. This allows a virus to infect many programs without increasing disk space usage noticeably. When a computer system suffers from virus infection, the user needs to cure it. To cure an infected system, users use antivirus utilities. These utilities first identify the type of virus that has infected the computer by matching its marker against markers of well-known viruses. Once the utility has identified the type of virus, which has infected the system, it restores original programs from their infected versions by applying a detailed knowledge of the infection method used by the virus. For example, in viruses that modify jump instructions at the beginning of host program, recovery process involves restoring the original jump to the start of the host program code. However, notice that these utilities can cure known viruses only. They cannot cure a newly encountered type of virus. A good antivirus utility can cure several hundred types of viruses. Suppliers of antivirus utilities keep improving the capability of their antivirus utilities to enable them to cure larger types of viruses by updating them frequently as and when they discover new types of viruses. New generation anti-virus applications employ heuristic analyzer to monitor virus like activity and processing to tag or block memory containing seemingly dangerous instructions. This mechanism creates a working solution to tackle new viruses.

SOME POPULAR OPERATING SYSTEMS This section introduces some popular operating systems. These are Unix, MS-DOS, Microsoft Windows, Microsoft Windows Server, Linux, Mac OS, iOS, Watch OS, and Android OS. Many of these systems are evolving continuously with new features in their newer versions. Hence, the section presents only their overall characteristics and some of their most interesting aspects, instead of describing all their features.

■ Some Popular Operating Systems

415

UNIX Development of Unix UNIX is a multi-user, time-sharing operating system. Ken Thompson and Dennis Ritchie developed UNIX in early 1970s at Bell Laboratories for a PDP-11 computer. It was the first operating system written in a high-level language, C. Earlier operating systems were written in assembly language, due to which they were system dependent (were usable only on a system for which they were developed). However, since UNIX was written in C language, moving it to a new system, known as porting it, was much easier. This was an important reason for its popularity and availability on a wide variety of systems.

BSD Unix and Other Unix Versions Unix was versatile and easy to modify. Hence, several universities and research laboratories initiated Unix-based development activities. The most influential of the non-AT&T development groups was the group at the University of California at Berkeley. This group ported Unix to the VAX computer and produced the Berkeley Software Distributions (BSD) versions of Unix. Among the improvements made by this group in the original Unix version, the notable ones were support for virtual memory, demand paging, a new shell (called csh), and the TCP/IP network protocols. BSD version also added several OS capability enhancement software to Unix, including a new text editor (called vi editor), Pascal and Lisp compilers, and many more. Over the years, as Unix grew in popularity, many computer vendors ported it on their systems, and enhanced and maintained their own versions of Unix. This resulted in creation of a wide variety of Unix, and Unix-like operating systems. For example, Unix supported on IBM systems is called AIX, Unix supported on systems supplied by Sun Microsystems is called Solaris, Unix supported on systems supplied by DEC (Digital Equipment Coporation) is called Ultrix, and Unix supported on systems supplied by HP (Hewelett Packard) is called HP-Unix.

Structure of Unix Unix operating system has the following three layers: 1.

Kernel. This layer has all the modules for process, memory, file, device, and security management.

2.

Shell. This layer has the command interpreter. Unix basically provides a command-line interface (some vendors have added GUI to their new versions of Unix). The shell provides a large number of useful commands. Every command does a single, specific task. To do larger, more complex tasks, users can combine several commands in the form of a shell script to produce the result they want. A user can even store a shell script in an executable file. When the user executes the file, it acts like a new shell command. Shell provides an interesting service called pipe (denoted by |), which allows users to send the output of one program to the input of another program without storing the output of the first program in a temporary file. For example, entering: who  sort invokes the command who, which displays the names of all users logged in currently, and pipes its output to sort. The result is a sorted list of currently logged in users. A pipeline is a connection of two or more programs through pipes. The length of a pipeline can be arbitrarily long. Programs that form a pipeline are called filter programs (or just filters) because they act as data filters, transforming the data as it passes from one program to the next program in the pipeline.

3.

Utilities. This layer has all the OS capability enhancement software, including language compilers, text editors, text-processing programs, and a variety of utilities and tools. Over the years, this layer has grown to include several powerful tools, which allow effective program development and system management.

Chapter 10 ■ Operating Systems

416

Because of this, many users refer to Unix as a complete programming environment, not just an operating system.

MS-DOS MS-DOS stands for Microsoft Disk Operating System. It is a single-user operating system for IBM and IBMcompatible personal computers. Microsoft and IBM introduced it jointly in 1981. It was the most popular operating system for personal computers in the 1980s. Because of its popularity, Microsoft later took a decision to independently launch Microsoft Windows operating system in 1990s.

Structure of MS-DOS MS-DOS has the following three layers: 1.

BIOS. BIOS stands for Basic Input Output System. It contains device drivers for standard devices such as keyboard, disk, printer, and display monitor. It also contains basic low-level services such as time-of-day and system configuration analysis. With hardware-dependent services in BIOS, the operating system ensures that it can offer other higher-level operating system services in a hardware-independent manner. This enables those operating system services to be portable to other machines. Usually, computer manufacturers (not Microsoft) supply the BIOS. Generally, the BIOS is located, in part, in a ROM, which is a non-erasable memory. When a user switches on a computer, the computer’s hardware transfers control to the bootstrap procedure of the BIOS in ROM. The bootstrap procedure carries out some hardware tests to check whether the memory and other hardware devices are functioning properly. If the hardware tests pass successfully, the bootstrap procedure loads into memory a small portion of the operating system from disk. This part of the operating system then loads the rest of the memory resident portions of the operating system into memory from disk. This step-by-step process of loading the operating system into memory is known as booting the system.

2.

Kernel. This layer contains all the modules for process management, memory management, and file management. These modules usually are machine-independent, enabling their easy portability to other machines.

3.

Shell. This layer has the command interpreter. MS-DOS provides a command-line interface. MS-DOS shell, known as command.com, has about 70 commands, which are partitioned into two categories – internal commands and external commands. Internal commands are those, which are always memory resident, whereas external commands are those, which normally reside on disk. The operating system loads an external command into memory whenever a user executes it. Due this, the operating system takes more time to execute an external command than an internal command. Later, the designers added a GUI (known as DOS shell) to this layer, which was largely a menu-driven user interface. Figure 10.31 lists some of the shell commands to give an idea of what the shell commands look like and what they do. The figure lists both MS-DOS and Unix versions. Normally, a command’s name signifies its task so that users can remember and use the commands easily. Moreover, note that the commands are usually short so that users have to type a few characters only to invoke a task. Most of these commands require arguments. For example, del command requires the name of the file, which the user wants to delete.

Limitations of MS-DOS In-spite-of its wide popularity in the 1980s, MS-DOS could not continue to be popular like Unix for a long period. Operating systems researchers often quote the following reasons for its failure: 1.

It was a single user, single task operating system (did not support multitasking). That is, it assumed that only one user uses a computer and runs only one program at a time.

■ Some Popular Operating Systems

417

2.

Since it was a single user, single task operating system, it did not have any protection features to protect two or more programs from one another, which are in memory.

3.

It had limited program addressability to 640 Kbytes. Hence, it could execute only those programs whose maximum size was 640 Kbytes. At first, this was not a problem, since in those days computers had only 64 Kbytes of RAM. However, when later models came out with up to 16 megabytes of RAM, the inability to run programs larger than 640 Kbytes became a major limitation.

4.

It supported only 16-bit CPUs that Intel was making in the early and middle 1980s. It could not take advantage of 32-bit CPUs, which Intel made later.

5.

It restricted users to eight-character file names with three-character extensions. Due to the lack of flexibility of using long file names, users often found it inconvenient to choose appropriate file names. No major operating system places this restriction on its users.

6.

It had a command-line interface, which some users found difficult to use and hard to learn. Command name In MS-DOS

Task description

In Unix

copy

cp

Copy a file

del or erase

rm

Delete/Erase/Remove a file

rename or ren

mv

Rename a file or move it from its old name to new name

dir

ls

Display a directory listing

mkdir or md

mkdir

Create/Make a new directory

chdir or cd

cd

Change the current working directory

rmdir

rmdir

Remove an empty directory

date

date

Display or change the current date

type

cat

Display (type/catenate) contents of a file

Figure 10.31. Illustrating some of the shell commands.

Microsoft Windows Microsoft developed Microsoft Windows operating system to overcome the limitations of its own MS-DOS operating system. Windows 3.0 was the first successful version of this operating system. It was released in 1990. Subsequently released versions were Windows 95, Windows 98, Windows 2000, Windows XP, Windows XP Professional, Windows Vista, Windows 7, Windows NT, Windows 8 and Windows 10. The numbers associated with some of these release versions indicate their year of release. Main features of Microsoft Windows are as follows: 1.

Its native interface is a GUI. Hence, for a new user, it is easier to learn and use a computer system.

2.

Microsoft Windows is not just an operating system, but also a complete operating environment. That is, all its programs conform to a standard way of working. For example, a Microsoft Windows word processor works similarly the way a Microsoft Windows spreadsheet (or any other type of Windows program) works. This means that if a user learns one Windows program, this experience is useful while using any other Microsoft Windows program.

3.

It is a single-user, multitasking operating system. That is, a user may run more than one program at a time. For example, while editing a file in foreground, a user can run a sorting job in background. The user can partition the Monitor’s screen into multiple windows and can view the progress of different programs on different windows.

Chapter 10 ■ Operating Systems

418 4.

It allows file names to contain up to 255 characters as well as some punctuation marks, such as periods, commas, and semicolons.

With these features, Microsoft Windows became an operating system of choice for most personal computer users after 1990. Today, Microsoft Windows is an operating system for personal computers, tablets and smart phones.

Microsoft Windows Server (Earlier Known as Windows NT) Microsoft Windows Server is a multi-user, timesharing operating system developed by Microsoft. It has UNIX-like features. Hence, it is suitable for use with powerful workstations, networks, and database servers. Like UNIX/Linux, Windows Server and its subsequent versions have native support for networking and network services. We classify such operating systems as Network Operating System (NOS). Its main features are: 1.

Unlike UNIX, its native interface is a GUI. The look and feel of Microsoft Windows Server GUI is similar to that of Microsoft Windows’ GUI.

2.

It supports multiprogramming and takes advantage of multiprocessing on systems having multiple processors.

3.

It has built-in networking and communications features. Hence, it enables configuration of any computer with Microsoft Windows Server as a network client or server.

4.

It provides strict system security.

5.

It has a rich set of tools for software development and system administration.

6.

It can run Microsoft Windows applications and many UNIX applications directly.

Linux Linux is an open-source operating system. Thousands of programmers worldwide continuously enhance its features and back its development and support. It is a multi-tasking, multiprocessing operating system. Originally, its designers had targeted it for personal computers, but today it is popular on all types of systems. The name “Linux” is derived from its inventor Linus Torvalds. Torvalds was a student at the University of Helsinki, Finland in early 1990s when he wrote the first version of an UNIX-like kernel as a toy project. He later posted the code on the Internet and asked programmers across the world to help him build it into a working system. The result was Linux. Torvalds holds the copyright, but permits free distribution of source code. That is, he oversees development of kernel and owns its trademark. When someone submits a change or a feature, Torvalds and his core team of kernel developers review the merit of adding it to kernel source code.

Linux Development Process Linux being an open-source operating system, various parties participate in its development process. Various participants play the following key roles: 1.

The open-source development community (programmers across the world) develops the source code for the operating system kernel and submits it to the core team of kernel developers headed by Torvalds. This team reviews the merit of adding a submitted change or feature in the kernel and incorporates it into the kernel, if the team sees merit in doing so. This is how the kernel evolves and matures to become better day-by-day.

2.

Application vendors and programmers download the freely available kernel and develop all types of application software for it.

3.

Distribution companies package and sell various Linux versions.

4.

Hardware vendors bundle Linux on their systems and supply their systems along with the Linux operating system and a set of application software.

5.

End users run Linux and applications to meet their processing needs.

■ Some Popular Operating Systems

419

Linux Distribution Versions Because of its unique development and distribution model, Linux has many commercial flavors. Today there are close to 200 Linux distribution versions. Some of the most popular distribution versions include Caldera OpenLinux eServer, Red Hat, SuSE, TurboLinux Server, Linux-Mandrake, Connectiva, and Red Flag. These versions are available from commercial vendors who make money by selling their implementation, as well as installation, maintenance, and other services. A non-profit Debian organization, which is developing a free operating system and related software, also distributes Linux. The existence of multiple Linux distribution versions frees users from vendor locking problem. It also creates healthy competition, which furthers innovation. Additionally, the different versions of Linux have always catered to slightly different markets. For example, the SuSE version is for users in banking and telecommunications industries, and the Connectiva version is primarily for South American market. The main differences among various distribution versions are set of tools and libraries, number and quality of applications, documentation, support, and services.

Linux Distribution and Installation Distributors organize Linux as a series of CDs – the A series containing the basic system, the D series containing the compilers and program development tools, the N series containing the modules for networking features, and so on. Users have the flexibility to choose only the series whose features they need. For example, a user does not need the N series, if he/she is not interested in networking features. A user can install Linux on his/her computer system either as the only operating system or along with other popular operating systems such as MS-DOS or Microsoft Windows. If the user installs multiple operating systems, he/she can boot the machine by choosing the appropriate operating system at the time of booting. For this, the user has to use Linux Loader (LiLo), which is the Linux boot manager. If the user is working with MS-DOS or Microsoft Windows, he/she does not even need to reboot in order to start Linux. He/she can simply use the command LOADLIN to start Linux directly from the MS-DOS command-line interface.

Mac OS Apple Incorporation designed Mac OS in mid 1980s for its Macintosh series of personal computers. Apple’s main focus in designing Mac OS was to develop an operating system with powerful ‘ease of use’ feature to enable much easier use of computer systems. To meet this objective, it introduced the idea of GUI (Graphical User Interface), which was later adopted by almost all OS designers for their operating systems. Before this, all operating systems supported only CLI (Command Line Interface). In 2001, Apple released an upgraded version of Mac OS with many new features, which it named Mac OS X. This version was a total redesign of the earlier version. It ran on a UNIX kernel and had advanced features for memory protection, preemptive multitasking, elegant user interface, automated backup, Internet access, and file sharing. Starting from 2007, Apple launched its mobile devices like iPhone (smart phone), iPad (tablet computer) and iPod (digital music system). For these devices, it designed iOS (described later) and released another upgraded version of Mac OS X. This upgraded version had several new features to enable users to share data among all types of Apple devices (personal computer, laptop, smart phone, tablet computer). Again in 2011, Apple launched iCloud, its cloud computing service, which enabled the users to store their data from any Apple device on to Apple’s cloud and then retrieve their data from the cloud using the same or any other Apple device. Apple once again upgraded Mac OS X to enable this.

Chapter 10 ■ Operating Systems

420

In 2015, Apple launched its Apple Watch device (smart watch) with WatchOS (described later). With this, Apple also released an upgraded version of Mac OS X with features to enable its personal computers and laptops to interoperate and share data with its watch device. The salient features of Mac OS X include the following: 1. Intuitive user interface that makes Apple’s computer systems much easier to use than other systems. 2. Interoperable with iOS and WatchOS, which enables users to share data and activities across various types of Apple devices. For example, while working on his/her laptop, if a user gets a phone call on his/her iPhone, he/she can take it from his/her laptop. Similarly, a user can copy text/image/audio/video files on any Apple device to any other apple device. 3. Supported with a large set of built-in applications. Apple’s AppStore has a large set of built-in applications for its users. Users by default get a powerful set of commonly used applications when they acquire an Apple device. Users can download other applications of their interest from the AppStore. Many of these applications provide interesting user experience with their data. For example, transforming photos into video clips; transforming videos into movies; creating customized messages for your friends/relatives/colleagues with a combination of text, image, audio and video; creating music with collected audio clips of your song and sounds from musical instruments; etc. 4. iCloud facility saves storage and allows a single copy of data to be shared across Apple’s devices. With this facility, a user can store his/her data (photos, videos, music, documents, presentations, etc.) on Apple’s cloud and access the same from any Apple device. For example, a user can create and upload documents from his/her laptop in iCloud, and then access it from his/her iPhone, whenever required. The user can even share his/her iCloud Drive link with his/her friends/relatives/colleagues to share his/her data stored in the iCloud with them. 5. Privacy and security features help users work in a trusted environment. Designers of Mac OS built it from the ground up with privacy and security in mind. Mac OS protects personal information of users and their data with strong encryption and strict security policies that govern how the system handles various types of data. 6. Flexibility to work with Windows OS is another powerful feature of Mac OS. This feature enables users to run Windows OS on their Apple computers, whenever required. It also enables users to transfer documents (files, photos, Excel sheets, PowerPoint presentations, etc.) created on a Windows OS platform to a Mac OS platform. 7. Use by differently abled users. Mac OS also has several features to enable use of its computers by users with physical disabilities. VoiceOver, FaceTime, Text-to-Speech are a few such features.

iOS We saw that Mac OS is the operating system designed by Apple Incorporation for its Macintosh series of personal computers and laptop computers. On the other hand, iOS is the operating system designed by Apple Incorporation for its mobile devices such as iPad, iPhone and iPod. Its first version was released in 2007. Apple originally designed it for iPhone and named it iPhone OS, but later changed its name to iOS because of its use on other mobile devices. Operating systems for mobile devices need to provide a protective shell for each application (app) to prevent other apps from tampering them. Although, the protective shell of an app protects it from other apps, it also prevents direct communication between two apps. iOS introduced an extensibility feature, which lets two apps communicate directly, if approved.

■ Some Popular Operating Systems

421

The salient features of iOS include the following: 1. Highly intuitive user interface with multi-touch features that makes Apple’s mobile devices much easier to use than other similar devices. For example, a user can just swipe his/her finger on the screen to flip through the next page of a displayed document, or can just pinch his/her fingers on the screen to zoom in/out the displayed document. The user can even touch an object (text, photo, file, etc.) on the screen, and drag and drop it from one application to another. 2. Facility to write, mark and draw. In addition to keyboard input, iOS allows a user to use Apple Pencil for writing free-hand notes, marking important portions of a document, and drawing free-hand sketches. Handwritten words in notes are even searchable. 3. Facility to ask for information or instruct using voice interface. Siri is a voice based intelligent assistant facility supported by iOS. A user can ask it to do simple things like setting an alarm at a specific time, sending a message to a registered user, or asking to make a call to a registered user. 4. Interoperable with Mac OS and WatchOS, which enables users to share data and activities across various types of Apple devices. 5. Supported with a large set of applications and games. Apple’s AppStore has a large set of built-in applications and games for its mobile device users. Users of mobile devices by default get a set of commonly used applications when they acquire an Apple device. Users can download other applications and games of their choice from the AppStore. 6. iCloud facility enables a user to store his/her data (photos, videos, music, documents, presentations, etc.) on Apple’s cloud and access the same from any Apple device. For example, a user can create and upload documents from his/her iPad in iCloud, and then access it from his/her iPhone, whenever required. The user can even share his/her iCloud Drive link with his/her friends/relatives/colleagues to share his/her data stored in the iCloud with them. This facility makes users data accessible from anywhere. 7. Multitasking facility of iOS allows a user to open multiple applications simultaneously in either SlipView or SlideOver mode. In former mode, both applications are visible simultaneously in different parts of the screen, while in latter mode, the user slides to the desired application window whenever required. 8. Camera, music and maps are other in-built facilities with supported applications that make user experience exciting with Apple mobile devices. iOS has several features for all these. 9. Privacy and security features help users work in a trusted environment. Designers of iOS built it from the ground up with privacy and security in mind. iOS supports both biometric and password based user authentication. Moreover, it protects personal information of users and their data with strong encryption and strict security policies that govern how the system handles various types of data.

WatchOS In 2015, Apple launched its smart wrist watch (called Apple Watch) along with WatchOS as its operating system. Apple Watch also being a mobile device (although, much smaller), WatchOS is based on iOS and has many similarities with iOS in terms of features. Moreover, many of the applications supported by WatchOS are miniaturized and simplified versions of their iOS counterparts.

422

Chapter 10 ■ Operating Systems

The main features of WatchOS include the following: 1. Intuitive user interface makes it easy to use Apple Watch by anyone. The home screen has circular application icons, which can be zoomed in and out. A user can launch an application by touching its icon on the screen. In addition to being touch-sensitive, the screen is also pressure sensitive. Hence, a user can tap or deep press on the icons to invoke different actions and options. The watch also has side buttons to invoke certain features. 2. HealthKit is a crucial element of Apple Watch and its designers have designed both its hardware and WatchOS to support health-based capabilities. WatchOS along with associated health-based applications allow users to view visual graphs for all-day heart rate, resting rate, walking average, workout average, current and historical details of heart rate, etc. The watch can even notify its user, when his/her heart rate rises above a specified threshold. Hence, Apple Watch encourages users to exercise and diagnoses and notifies illness to users. 3. Music is yet another important element of Apple Watch. WatchOS along with associated music-based applications allow users to quickly select and play songs/music of their choice. It also has the ability to start a synced music playlist automatically when a user starts his/her workout session. 4. Contacts list, calendar with notifications for important dates, appointments, calculator, etc. are a few other useful applications available to Apple Watch users. 5. Ability to share data with other Apple devices. For example, a user can choose to transfer health-based data captured by Apple Watch for storing it on any other Apple device having larger storage (iPhone, iPad, laptop, or desktop).

Android OS Like iOS, Android OS is another operating system for mobile devices such as smart phones and tablet computers. Andy Rubin, Rich Miner, Nick Sears and Chris White first developed it in Palo Alto of California in 2003. Google later purchased it in 2005 and further developed it through Open Handset Alliance (OHA), which is a business alliance of companies to develop open standard for mobile devices. Since then, Android OS has gone through major upgrades to add new features for fast evolving mobile phones and tablet computers. Android is a Linux based operating system in the sense that it uses Linux kernel at its core for basic system functionalities like process management, memory management and management of various devices like display, keypad, camera, etc. It is an open source operating system, meaning that it is free and anyone can download, customize and use it. Android has millions of applications, making it the most versatile software environment for mobile devices. Other than Apple’s mobile devices (which are iOS based), most mobile devices are Android based. Hence, today Android has the largest user base among mobile device users. The main features of Android OS include the following: 1. Intuitive user interface makes it easy to use by anyone. 2. Free and open source enables anyone to download, customize and use it. 3. It lets users choose their hardware device (iOS works only with Apple’s mobile devices). Moreover, Android is portable across current and future hardware platforms. 4. Its architecture is flexible because it is component based. Components are reusable and replaceable modules.

■ Real-time, Network and Distributed Operating Systems

423

5. Millions of applications make it highly versatile for a wide range of users. A set of core applications comes by default including Email, SMS, Calendar, GPS, Maps, Browser and Contacts. 6. It supports all Google services ranging from Gmail to Google search. 7. It supports multitasking, meaning it can run multiple applications at the same time. 8. It supports 2D and 3D graphics, video streaming, and multilingual interface. 9. It supports multiple keyboards and makes them easy to install. This feature enables a user to quickly change up his/her keyboard style. Other mobile operating systems either don’t permit extra keyboards at all, or the process to install and use them are tedious and time-consuming. 10. It supports a built-in infrared transmitter, allowing users to use their phone or tablet as a remote control. 11. Most Android devices support Near Field Communication (NFC), which allows electronic devices to easily interact across short distances. 12. It supports multi-layer security. Most security between applications and the system is enforced at process level through standard Linux security mechanisms such as assigning user and group IDs to applications.

REAL-TIME, NETWORK AND DISTRIBUTED OPERATING SYSTEMS This section describes some special types of operating systems. These are real-time, network, and distributed operating systems.

Real-time Operating Systems For many applications, successful processing means that the application produces correct results when its processing completes. However, in real life, we often come across situations in which it is not only sufficient to obtain correct results, but it is also important to obtain the results within some specified period (deadline) for the results to be useful. A few examples of such applications are: 1.

An aircraft must process accelerometer data within a certain period (say every 20 milliseconds) that depends on the specifications of the aircraft. Failure to do so could cause the aircraft to go away from its right course, or may even cause it to crash. Failure to respond in time to an error condition in a nuclear reactor thermal power plant could result in a melt down.

2.

Failure to respond in time to an error condition in the assembly line of an automated factory could result in several faulty product units, which the quality control department will discard ultimately.

3.

A computerized railway reservation system must process a passenger’s request for booking a ticket within the passenger’s perception of a reasonable time (say 3 minutes).

Such applications require a special type of system, called real-time system, for their processing. That is, a real-time system is a system that satisfies the requirement of producing the desired results before a specified deadline. If it delivers the correct result for a user, but after the deadline, the user considers the system to have failed. Hence, timely production of the result of processing is as important as its correctness in a real-time system. Real-time systems use a special type of operating system called real-time operating system. The goals of CPU scheduling in traditional timesharing operating systems are optimal throughput, optimal resource utilization, and fairness. In contrast, the main goal of CPU scheduling in real-time operating systems is to process as many timecritical processes as possible, and to meet their deadlines.

Chapter 10 ■ Operating Systems

424

Network and Distributed Operating Systems A distributed computing system is a collection of computer systems interconnected by a communication network. Each computer of this system has its own local memory and other peripheral devices. Communication between any two computers in this system takes place by passing messages over the communication network. Two types of operating systems used commonly for distributed computing systems are network operating systems and distributed operating systems. The three most important features used commonly to differentiate between these two types of operating systems are system image, autonomy, and fault tolerance capability: 1.

System image. In case of a network operating system, users view a distributed computing system as a collection of distinct computer systems connected by a communication subsystem. That is, users are aware of the fact that the system has multiple computers. On the other hand, a distributed operating system hides the existence of multiple computers and provides a single-system image to its users. It makes a collection of networked computers appear to its users as a virtual single system by providing similar type of user interface as that of centralized operating systems.

2.

Autonomy. In a network operating system, each computer of a distributed computing system has its own local operating system (the operating systems of different computers may be the same or different). There is essentially no coordination among the computers except for the rule that when two processes of different computers communicate with each other, they must use a mutually agreed communication protocol. Each computer functions independently of other computers in the sense that each one makes independent decisions about the creation and termination of their own processes and management of local resources. Notice that due to the possibility of difference in local operating systems, the system calls for different computers of the same distributed computing system may be different in this case. On the other hand, in case of a distributed operating system, there is a single system-wide operating system and each computer of a distributed computing system runs a part of this global operating system. The distributed operating system tightly interweaves all the computers of the distributed computing system in the sense that they work in close cooperation with each other for efficient and effective utilization of various resources of the system. Hence, the distributed operating system manages processes and several resources globally (each computer system manages some resources locally). Moreover, there is a single set of globally valid system calls available on all computers of the distributed computing system.

3.

Fault tolerance capability. A network operating system provides little or no fault tolerance capability in the sense that if 10% computers of a distributed computing system are down at any moment; at least 10% of users are unable to continue with their work. On the other hand, with a distributed operating system, most users are normally unaffected by the failed computers and can continue to perform their work normally, with only a 10% loss in performance of the distributed computing system. Therefore, the fault tolerance capability of a distributed operating system is usually high as compared to that of a network operating system.

In short, both network operating systems and distributed operating systems deal with multiple computers interconnected together by a communication network. In case of a network operating system, users view the system as a collection of distinct computers, but in case of a distributed operating system, users view the system as a “virtual single system”.

Points to Remember 1.

Operating system (often referred to as OS) is an integrated set of programs that controls the resources (CPU, memory, I/O devices, etc.) of a computer system and provides its users with an interface or virtual machine that is easier to use than the bare machine.

■ Points to Remember

425

2.

Main functions of most modern operating systems are process management, memory management, file management, device management, security, and command interpretation.

3.

We usually measure the efficiency of an operating system and the overall performance of a computer system in terms of its throughput, turnaround time, and response time.

4.

Throughput is the amount of work that a system is able to do per unit time. We measure it as the number of jobs (processes) completed by the system per unit time.

5.

Turnaround time is the interval between the time of submission of a job to the system for processing and the time of completion of the job.

6.

Response time is the interval between the time of submission of a job to the system for processing and the time when the system produces the first response for the job.

7.

A process (also called job) is a program in execution. The main objective of process management module of an operating system is to manage the processes submitted to a system in a manner to minimize the idle time of processors (CPUs, I/O processors, etc.) of the system.

8.

In batch processing method of job execution, job-to-job transition is automatic. This helps in reducing idle time of a computer system because job-to-job transition does not require any operator intervention.

9.

Operating systems use control statements to identify a new job and to determine the resources needed by it during its execution. Programmers write control statements in a language known as job control language (JCL).

10. A uniprogramming system processes only one job at a time, and all system resources are available exclusively for the job until its completion. 11. CPU-bound jobs mostly perform computations with little I/O operations. Hence, their CPU utilization is high. 12. I/O-bound jobs mostly perform I/O operations with little computation. Hence, their CPU utilization is low. 13. Multiprogramming is interleaved execution of two or more different and independent programs by a computer. 14. Some multiprogramming systems process only a fixed number of jobs concurrently (multiprogramming with fixed tasks MFT), while others can process variable number of jobs concurrently (multiprogramming with variable tasks - MVT). 15. In a multiprogramming system, the area occupied by each job residing simultaneously in the main memory is known as a memory partition. 16. Part of the operating system that decides to which one of the ready jobs it should allocate the CPU is called CPU scheduler, and the algorithm it uses for this is called CPU scheduling algorithm. 17. Multitasking is interleaved execution of multiple jobs (often referred to as tasks of same user) in a single-user system. 18. In multithreading, a process consists of an address space and one or more threads of control. Each thread of a process has its own program counter, its own register states, and its own stack. However, all the threads of a process share the same address space. We often refer to threads as lightweight processes and traditional processes as heavyweight processes. 19. Systems having multiple CPUs are called multiprocessing systems. They can execute multiple processes concurrently. These systems use multiple CPUs to process either instructions from different and independent programs or different instructions from the same program simultaneously. 20. Time-sharing is a mechanism to provide simultaneous interactive use of a computer system by many users in such a manner that all users feel that he/she is the sole user of the system. It uses multiprogramming with a special CPU scheduling algorithm to achieve this. 21. There are several resources in a system that multiple processes must not use simultaneously, if program operation is to be correct. An operating system must ensure exclusive access to such a shared resource by a process. This exclusiveness of access is called mutual exclusion between processes. We refer to the sections of a program that need exclusive access to shared resources as critical sections. 22. Test-and-set and semaphore are two commonly used approaches, which modern operating systems use to implement mutual exclusion. 23. Deadlock is the state of permanent blocking of a set of processes each of which is waiting for an event that only another process in the set can cause. All the processes in the set block permanently, because all the processes are waiting and hence none of them will ever cause any of the events that could wake up any of the other members of the set.

426

Chapter 10 ■ Operating Systems

24. Memory management module of an operating system manages the main memory of a system. It keeps track of free and occupied (in use) parts of memory, allocates memory to processes when they need it, and de-allocates when they no more need. 25. Uniprogramming memory model is suitable for those computer systems, which process only one job at a time, and all system resources are available exclusively for the job until it completes. 26. In a multiprogramming memory model, multiple user processes can reside simultaneously in main memory. The two memory management schemes, which operating systems use to facilitate this, are multiprogramming with fixed number of memory partitions and multiprogramming with variable number of memory partitions. 27. External fragmentation of memory is a situation when enough total free memory space exists to satisfy the memory need of a process, but the operating system cannot load the process in memory because the available free memory is not contiguous (is fragmented into multiple free blocks of memory). 28. Internal fragmentation is a situation when the operating system allocates more memory to a process than its actual memory requirement because of the memory allocation mechanism of the operating system. The additional memory allocated to the process remains unutilized because neither the process uses it, nor the operating system can allocate it to any other process for use. 29. Paging is a memory management mechanism that operating systems use to solve external fragmentation problem. It does this by allowing a process’s memory to be noncontiguous, and allocating physical memory to a process from wherever free memory blocks are available. 30. Virtual memory is a memory management scheme that allows execution of a process without the need to load the process in main memory completely. The three basic concepts, which virtual memory mechanism uses for its realization are on-line secondary storage, swapping, and demand paging. 31. A file is a collection of related information. Every file has a name, its data, and attributes. 32. File management module of an operating system takes care of file-related activities, such as structuring, accessing, naming, sharing, and protection of files. 33. Operating systems use directories to map file names to their corresponding file attributes and file data, and to provide greater flexibility to users in file naming. 34. Disk space allocation methods deal with how to allocate space to multiple files on disk. The three methods that operating systems use commonly for disk space allocation are contiguous allocation, linked allocation, and indexed allocation. 35. Device management module of an operating system takes care of controlling the I/O devices of a computer system and provides a simple and easy to use interface to these devices. 36. Spooling (Simultaneous Peripheral Operation On-Line) is a mechanism to reduce speed mismatch between slow I/O devices and CPU, and to convert mutually exclusive (non-sharable) I/O devices into non-mutually exclusive (sharable) I/O devices. 37. Command interpretation module (known as command interpreter) of an operating system provides a set of commands, which users use to give instructions to a computer for execution of their jobs. Two broad categories of user interfaces supported by modern operating systems are command-line interface and graphical user interface (GUI). 38. The kernel of an operating system is its central controlling part, which implements the most primitive of the system’s functions. It is the only part of an operating system, which a user cannot replace or modify. 39. Those modules of an operating system, which need to be always resident in system’s main memory, are called resident modules, whereas those that reside on hard disk are called non-resident modules. The operating system loads a non-resident module into the memory on demand (whenever a user process needs it for execution). 40. OS capability enhancement software is a special category of software, which bridges the gap between functionality of an operating system and needs of users for frequently used programs. Normally, we group such software into three categories – translating programs, library programs, and utility programs. 41. Some popular operating systems are UNIX, MS-DOS, Microsoft Windows, Microsoft Windows Server, Linux, Mac OS, iOS, Watch OS and Android OS. 42. A real-time system is a system that satisfies the requirement of producing the desired results before a specified deadline. Real-time systems use a special type of operating system called real-time operating system. The main goal of CPU scheduling in real-time operating systems is to process as may time-critical processes as possible, and to meet their deadlines.

■ Questions

427

43. A distributed computing system is a collection of computer systems interconnected by a communication network. 44. Two types of operating systems used commonly for distributed computing systems are network operating systems and distributed operating systems. In case of a network operating system, users view a distributed computing system as a collection of distinct computers connected by a communication subsystem. However, in case of a distributed operating system, users view the system as a “virtual single system”.

Questions 1.

What is an operating system? Why is it necessary for a computer system?

2.

What are the two primary objectives of having an operating system in a computer system? Explain how an operating system helps in meeting these objectives.

3.

What is a ‘virtual machine’? Explain how an operating system helps in converting a computer system into a virtual machine.

4.

Draw logical architecture diagram of a computer system. Explain the role of an operating system in this architecture.

5.

Explain the role of an operating system as the resource manager of a computer system.

6.

“Operating system tends to isolate system hardware from users". Discuss.

7.

“Operating system acts as the manager of various resources of a computer system”. Discuss.

8.

Write various functions normally performed by an operating system.

9.

Explain the role of an operating system with respect to the following functions: (a) Process management (d) Device management (b) Memory management (e) Command interpretation (c) File management

10.

What parameters do we normally use to measure the performance of a computer system?

11.

Define the following terms: (a) Throughput (b) Turnaround time (c) Response time

12.

What is a process in a computer system? What is the main objective of process management module of an operating system?

13.

How did users execute a job in early computer systems? What were the major drawbacks of this approach?

14.

What is batch processing? Describe how a batch-processing system executes jobs?

15.

Explain how batch-processing mechanism helped in overcoming the main drawback of manual loading mechanism, which early computer systems used for processing jobs.

16.

Explain how a computer separates one job from another from a batch of jobs for automatic job-to-job transition in a batch processing system.

17.

What are control statements? Why do we need them?

18.

Do all computers use the same type of JCL statements? Write reasons for your answer.

19.

You want to compile and execute a FORTRAN program. In plain English list necessary JCL statements, you will prepare for this job.

20.

Differentiate between a uniprogramming and a multiprogramming system. What are their relative advantages and disadvantages?

21.

Define multiprogramming. Explain how multiprogramming ensures effective utilization of main memory and CPU.

22.

Differentiate between I/O-bound and CPU-bound jobs.

23.

Write hardware and software requirements for a multiprogramming system to work satisfactorily.

428

Chapter 10 ■ Operating Systems

24.

What is a memory partition?

25.

Explain how an operating system switches CPU from one job to another in a multiprogramming system and how it ensures that a temporarily suspended job will execute correctly, when the system gives back the CPU to it after some time.

26.

What is a process control block? Why does an operating system need it? What does it typically contain?

27.

What is multitasking? What similarities and differences (if any) are between multiprogramming and multitasking?

28.

Differentiate among multitasking, multiprogramming and multiprocessing.

29.

What are threads? Differentiate between a single-threaded and a multi-threaded process.

30.

Write motivations for using a multi-threaded process instead of multiple single-threaded processes for performing some computation.

31.

Differentiate between multiprogramming and multithreading.

32.

What is multiprocessing? Draw basic organization diagram of a typical multiprocessing system.

33.

Differentiate between tightly-coupled and loosely-coupled multiprocessing systems.

34.

How is multiprocessing different from multiprogramming?

35.

Discuss advantages and limitations of multiprocessing systems.

36.

Can a system be both multiprocessing and multiprogramming system? Write reasons for your answer.

37.

What is time-sharing? What is a time-slice?

38.

In a timesharing system, explain how each user gets an impression that he/she is the sole user of the system.

39.

What are the three different states in which all processes of a timesharing system can be? Illustrate how a process switches from one state to another.

40.

Does a time-sharing system use multiprogramming? Write reasons for your answer.

41.

Write hardware and software requirements of a time-sharing system.

42.

Write advantages of time-sharing systems.

43.

Why are timesharing systems most suitable for program development and testing?

44.

Multiprogramming and timesharing both allow multiple user processes to reside simultaneously in a computer. Differentiate between the two concepts.

45.

Differentiate among the following terms: (a) Multiprogramming (d) Multiprocessing (b) Multitasking (e) Timesharing (c) Multithreading

46.

What is a deadlock? Illustrate a deadlock situation with an example.

47.

Write the four necessary conditions for a deadlock to occur.

48.

Write the three strategies that operating systems designers use commonly to handle deadlocks.

49.

What is mutual exclusion between processes?

50.

What is a critical section of a program?

51.

What are the two requirements that an algorithm for implementing mutual exclusion must satisfy?

52.

Describe two approaches to implement mutual exclusion.

53.

What is the main objective of memory management module of an operating system?

54.

Differentiate between uniprogramming and multiprogramming memory models. Write their relative advantages and disadvantages.

55.

Differentiate between multiprogramming with fixed number of memory partitions and multiprogramming with variable number of memory partitions.

56.

What is memory fragmentation problem? Differentiate between internal and external fragmentation of memory.

■ Questions

429

57.

What is internal fragmentation of memory? Illustrate with an example.

58.

What is external fragmentation of memory? Illustrate with an example.

59.

What is paging? Illustrate paging mechanism with the help of an example.

60.

Does paging mechanism suffer from internal fragmentation or external fragmentation of memory? Write reasons for your answer.

61.

What is a virtual memory? Why is it so called? How is it useful?

62.

Explain the three basic concepts used for realization of virtual memory.

63.

What is swapping? How does it help in memory management?

64.

What is a page replacement algorithm? What is a victim page?

65.

Write advantages and disadvantages of virtual memory.

66.

If an application uses virtual memory carelessly, its performance may decrease substantially instead of increasing. Discuss.

67.

What is a file? Differentiate between a file’s data and its attributes.

68.

What is a file name? Why is it used?

69.

What jobs does file management module of an operating system perform typically?

70.

Describe two popular types of file structures that operating systems use.

71.

Describe two file access methods supported commonly at operating system level.

72.

Differentiate between sequential access and random access files.

73.

Write eight file operations provided typically by an operating system. Write the use of each operation.

74.

What is a file extension in a file name? What are its typical uses? Write ten typical file extensions and their meanings.

75.

What is a directory? What does a directory contain typically?

76.

Describe three commonly used types of directory organizations. Write their relative advantages and disadvantages.

77.

Describe three commonly used methods of disk space allocation. Write their relative advantages and disadvantages.

78.

What jobs does device management module of an operating system perform typically?

79.

What is memory-mapped I/O?

80.

Explain non-DMA and DMA methods of transferring data from a device controller’s local buffer to the appropriate memory area of a computer. Which method is better and why?

81.

How does an operating system provide simple and easy user interface to the I/O devices?

82.

Draw a diagram showing the various layers of I/O software for device management. Explain the functions of each layer.

83.

What is spooling? How does it help in improving the performance of a computer system?

84.

Explain how spooling can convert a mutually exclusive I/O device into a shared resource.

85.

What jobs does command interpretation module of an operating system perform typically?

86.

What is a command interpreter? How does it contribute to ‘ease of use’ objective of an operating system?

87.

What are system calls? How are they used?

88.

Write the features of the two types of user interfaces that modern operating systems support.

89.

Differentiate between command-line interface and graphical user interface. Write their relative advantages and disadvantages.

90.

What is a job control language (JCL)? Why do we need it?

91.

What is a shell? Why is it so called? Can an operating system have many different shells? Write reasons for your answer.

92.

Why do most modern operating systems use layered structure for organizing their various modules?

430

Chapter 10 ■ Operating Systems

93.

What is a kernel of an operating system? Which of the basic functions of an operating system are typically in its kernel?

94.

Differentiate between monolithic kernel and microkernel approaches of structuring the modules of an operating system.

95.

Differentiate between resident and non-resident operating system modules. What are the main criteria for deciding whether a module should be resident or non-resident?

96.

What is a real-time system? Write three examples of applications that require real-time systems for their processing.

97.

What is a distributed computing system? Write three examples of applications that require a distributed computing system.

98.

What are the two commonly used types of operating systems for distributed computing systems? Write the important features that we use commonly to differentiate between them.

99.

What is operating system capability enhancement software? Write three types of software that belong to this category.

100. What is a translating program? Write three types of software that belong to this category. 101. What is a library program? Write three examples of such programs. 102. What is a utility program? Write three examples of utility programs. 103. What is a computer virus? Explain the working of a virus. Suggest ways to cure a computer system infected by virus. 104. Name four popular operating systems. Describe the main features of any two of them. 105. What was the main reason for the popularity and availability of Unix on a wide variety of systems? 106. Describe the structure of Unix operating system. 107. Explain the concept of pipe in Unix. What is a pipeline? 108. Describe the structure of MS-DOS. 109. What is a BIOS? Where does it reside normally? Who supplies it usually? 110. What is booting of a system? Explain how an MS-DOS system boots. 111. Differentiate between internal and external commands of MS-DOS. 112. What are the main reasons for the failure of MS-DOS? 113. Write key features of Microsoft Windows. 114. Write key features of Microsoft Windows Server. 115. Write key features of Linux. Explain the development process of Linux. 116. Write key features of Mac OS. 117. What is iOS? Write its key features. 118. What is Watch OS? Write its key features. 119. Write key features of Android OS. 120. Write key limitations of Linux.

Database and Data Science

Computer systems store and process large volumes of data, which often come from multiple sources, leading to duplication and inconsistency of data. Moreover, information retrieval operations need to dig out the desired information from large data volumes stored in a computer system. All these require proper organization and management of data stored in a computer system, as well as information retrieval tools to extract the desired information whenever required. There are standard mechanisms to organize and manage data for their storage and retrieval in computer systems. This chapter deals with these standard mechanisms. In this chapter, you will learn about: 1.

Difference between data and information.

2.

How data processing converts data into information?

3.

Data storage hierarchy, which computer systems use to organize pieces of data into meaningful entities to facilitate data processing.

4.

Standard methods of organizing data.

5.

Difference between file management systems (FMS) and database management systems (DBMS).

6.

Different types of database systems.

7.

What is data science?

8.

How data science leads to knowledge discovery from large data volumes?

9.

What is data warehousing? What is the process of data warehousing?

10. What is data mining? What is the process of data mining? 11. Difference between data warehousing and data mining.

DATA VERSUS INFORMATION Data is a collection of facts – unorganized, but able to be organized into useful information. A collection of sales orders, employee time sheets, and class attendance cards are a few examples. We can manipulate data to produce

Chapter 11 ■ Database and Data Science

432

output, such as bills, employee salary slips, and student attendance reports. This output, called information, is organized facts that help people to make decisions. Hence, information is data arranged in an order and form that is useful to people who receive it. Processing, in general terms, is a series of actions or operations that converts some input into useful output. In data processing, input is data, and useful output is information. Hence, data processing is a series of actions or operations that converts data into information. It consists of three sub-activities – capturing input data, manipulating it, and producing output information. A data processing system consists of resources such as people, procedures, and devices, which it uses to process input data for producing desirable output. Hence, data is raw material of information, and just as a manufacturing process transforms raw materials into finished products, data processing transforms raw data into information.

DATA STORAGE HIERARCHY Data processing deals with operations on data. For convenience, system designers define these operations on different levels of aggregated data. These levels form the data storage hierarchy of data processing. Figure 11.1 shows the six levels, which standard data organization mechanisms use in this hierarchy. They are described here.

Level 0 Bit A single binary digit (0 or 1). Level 1 Character Multiple related bits are combined to form a character (byte). Level 2 Level 3 Level 4 Level 5

Field Record

Multiple related characters are combined to form a field. Multiple related fields are combined to form a record.

File

Multiple related records are combined to form a file.

Database

Multiple related files are integrated to form a database.

Figure 11.1. Data storage hierarchy used in data processing.

1.

Bit. Smallest item of data is a single binary digit (a bit), either a 0 or 1.

2.

Character. A character (or byte) is a combination of multiple related bits. For example, M, 8, and $ are characters. A bit is basic unit of primary and secondary storage, and a character is basic unit of human perception.

3.

Field. A field is a combination of multiple related characters. For example, if we are processing employees’ data of a company, we may have one field each for employee code, employee name, worked hours, hourly pay rate, tax rate deduction, etc. A field is a meaningful collection of related characters. It is the smallest logical data entity treated as a single unit in data processing. Note that a field may sometimes have a single character, such as sex-code field may have value M or F.

4.

Record. A record is a combination of multiple related fields. For example, an employee record has fields containing data of an employee, such as employee’s code, name, worked hours, pay rate, tax rate deduction, etc. Similarly, a student record has fields containing data of a student. Hence, a record is a collection of related fields, which data processing applications treat as a single unit.

5.

File. A file is a combination of multiple related records. For example, a collection of employee records of all employees of a company forms an employee file. Similarly, a collection of all inventory records of a company forms an inventory file. Hence, a file is a number of related records, which the system treats as a

■ Data Storage Hierarchy

433

unit. Notice that every record in a file has the same set of fields. A key field uniquely identifies each record in a file. Contents of the key field are unique for every record in the file. For an employee file, employee-code field may serve as the key field. 6.

Database. A database is an integration of multiple related files. For example, an employee database of an organization may integrate records of multiple employee files, such as employee salary file containing details of salary and taxation information of all employees, employee personal information file containing general information (age, sex, address, etc.) of all employees, and employee skill-set file containing details of various types of skills of all employees. A database integrates data from multiple files in a manner to minimize data redundancy. For instance, in case of the example above of three different employee files, if in each file an employee record contains an employee-address field, and if an employee changes his/her residence, the organization must change the employee’s address in all three files. A database requires change in the employee’s address only once because it integrates the three files in such a manner that it needs to store an employee’s address data only once and makes the same copy available to all applications. In essence, a database is a collection of logically related data elements from multiple files.

Figure 11.2 illustrates relationship among character, field, record, and file with an example.

A field having 4 characters

Employee Code First Name Kumar 0004 Employee Code First Name 0003

Pratap

Employee Code First Name 0002

Ravi

Employee Code First Name

A record

0001

Pradeep

Last Name Hours worked Rana 160

Last Name Hours worked 172 Singh

Last Name Hours worked 168 Patel Last Name Hours worked 180 Sinha

Hourly rate Tax rate 14.00 0.09

Hourly rate Tax rate 15.00 0.10

Hourly rate Tax rate 10.00 0.07 Hourly rate Tax rate 12.00 0.08

Fields

Records of a file

Figure 11.2. Illustrating relationship among character, field, record, and file.

STANDARD METHODS OF ORGANIZING DATA Two standard methods of organizing data for data processing applications are file-oriented approach and databaseoriented approach. File-oriented approach was traditional method used in early days of data processing. It has been largely replaced today by database-oriented approach. However, several applications, dealing with simple and small data sets, use file-oriented approach, even today. Hence, both these methods are described here.

Chapter 11 ■ Database and Data Science

434

File-oriented Approach This method organizes an application’s data into one or more files and the application program(s) processes the data stored in these files to generate the desired output. For example, it is customary to use a master file of permanent (and, usually, the latest) data, and transaction files containing data of temporary nature. For instance, in a payroll application, in addition to containing all permanent details of each employee (name, address, employee-code, payrate, income-tax-rate, etc.), master payroll file also contains current gross-pay-to-date total and tax-paid-to-date total. Transaction payroll file contains details of hours worked this month, normal and overtime hours, and if piecework is involved, quantity of goods made. When the user runs monthly cycle of payroll application, the application uses both master and transaction files to generate this month’s pay-slips, and updates the master file to make it ready for following month’s processing (see Figure 5.12).

Database-oriented Approach File-oriented approach of organizing data for data processing applications is simple, inexpensive, and easy to use. It, however, suffers from the following limitations: 1.

Limited query flexibility. File-oriented approach organizes records in a file according to a key field. Hence, it can quickly process queries based on key field value. However, when the key field is not relevant to desired information, it needs to search the entire file. For example, if the key field is employee-code in an employee file, and if a user needs to list names of all employees having certain educational background, the application has to search all records to produce this information. If the user needs this information frequently, he/she needs to create a new file structured on educational background key with a new program to process this file.

2.

Data redundancy. In file-oriented approach, same data items are often present in many different files. For instance, in the example above of creating a new file structured on educational background key, the new file will also have several data items present in the first employee file. Similarly, let us assume that a bank uses file-oriented approach for storing its customers' data, and it maintains separate customer files for its various types of services, such as savings accounts, term deposits, and loan accounts. In this case, many data items for a bank customer (such as home address, age, occupation, and identification information) may be present in multiple files. Repetition of same data items in more than one file is known as data redundancy. It leads to increase in cost of data entry and data storage. It also leads to data integrity problem described below.

3.

Data integrity problem. Data integrity refers to consistency of data in all files. For consistency, the system must carry out any change in a data item in every file containing that data item. For instance, in our example of a bank maintaining separate customer files for each type of account, when a customer moves to a new address, the bank must update his/her address field in all customer files containing this customer’s record. Integrity of data is necessary to avoid confusions that may result when an application updates one file, and does not update the same data present in other files. For example, when an application changes a data item, if it does not update the data item in all files containing the data item, there may be frequent discrepancies among reports, which the application produces from different files, causing confusion.

4.

Lack of program/data independence. In file-oriented approach, an application program usually contains data format statements, which define the format of each data field precisely as the application needs it for processing. Because different applications create different files, this often results in different files having same data item stored using different data formats. Data dependence occurs when data is dependent on application. Due to data dependence problem, whenever there is a need to add, delete, or change data formats, we also need to change application programs. Data dependence problem also causes incompatibility among data files from different applications due to which we cannot link these data files, if such a need arises.

5.

Limited data security flexibility. Normally, a file-oriented approach offers file-level data security feature. Hence, it can enforce data access restrictions on an entire file only, not on a record or a field of data item.

■ File Management System

435

Dissatisfied with these limitations of file-oriented approach, researchers began looking for a better method of organizing data to consolidate activities. Their efforts resulted in database-oriented approach for organizing data. This approach integrates together data from multiple related files in the form of a database having the following properties: 1.

It provides greater query flexibility.

2.

It reduces data redundancy.

3.

It solves data integrity (inconsistency) problem.

4.

It makes data independent of application programs, enabling users to add, change, and delete fields from database without affecting existing programs.

5.

It also includes data security features at database level, record level, and even at field level to provide greater flexibility of restricted data access.

FILE MANAGEMENT SYSTEM File-oriented approach of organizing data provides a set of programs to facilitate users to organize, create, delete, update, and manipulate their files. All these programs together form a File Management System (FMS). Features commonly found in file management systems are describe here.

File Types We categorize data files according to the way an application uses them. A file management system typically supports the following types of files: 1.

Transaction file. A transaction file stores input data until the application uses it during next processing cycle. For example, in a payroll application for generating monthly pay slips of employees, current month’s transaction file contains this month’s data of each employee, such as details of hours worked, normal and overtime hours, and if piecework is involved, quantity of goods made.

2.

Master file. A master file contains all current data relevant to an application. For example, in payroll application mentioned above, master file contains permanent details of each employee (name, address, employee-code, pay-rate, income-tax-rate, etc.), and also current gross-pay-to-date total and tax-paid-to-date total. When the user runs monthly cycle of payroll application, the application consolidates both master and current month’s transaction files to generate this month’s pay-slips, and updates master file to make it ready for following month’s processing.

3.

Output file. Some applications use multiple programs for data processing. These applications often take output of one program and feed it as input to another program. The former program stores its output in a file known as output file, which the latter program uses later.

4.

Report file. A report file holds a copy of a report, which a data processing application generates in computeraccessible form. A user can print a report file to obtain hard copy of the report whenever desired. It is advantageous to keep report files instead of paper documents because files are easier to store and carry.

5.

Backup file. A backup file is a copy of a file, which a user/system creates as a safety precaution against loss of data due to corruption or inadvertent deletion of original file. Regular creation of backup files is important.

File Organizations File organization deals with physical organization of records of a file for convenience of their storage and retrieval. System designers choose to organize, access, and process records of various files in different ways, depending on application type and users’ needs. Three file organizations, which data processing applications use commonly are sequential, direct/random, and indexed sequential.

Chapter 11 ■ Database and Data Science

436

Selection of a particular file organization depends on application type. The best file organization for an application is one that meets the application’s data access and processing requirements in the most effective and economical manner. Hence, an application designer must evaluate the strengths and weaknesses of each file organization, before making a choice of the file organization for his/her application. File organization requires use of some key field in every record in a file. Key field value must be unique for each record of the file because duplications would cause serious problems. A payroll application often uses employee-code field as key field.

Sequential Files A sequential file stores its records one after another in ascending/descending order of their key field values. A payroll application may organize the records of employee file sequentially by employee-code sequence. Sequential files use magnetic tape as principal storage medium. A computer processes a sequential file in the order in which the file stores its records. That is, it first reads and processes the first record, then the second record, and so on. For instance, to locate a particular record in a sequential file, the computer reads each record in sequence, beginning from the first record, and compares its key field value with that of the desired record. The search ends when the desired key value matches with the key field value of the currently read record. Notice that with this processing mechanism, if an application has to process a single record only, on an average, it has to search about half the file to retrieve the record. Hence, sequential files are not suitable for applications that process only one or a few records at a time. Sequential file organization is the most efficient and economical file organization for applications in which we have to update a large number of file records at regularly scheduled intervals. That is, when activity ratio (ratio of total number of records in transaction file and total number of records in master file) is high. A batch processing application can ensure this. A batch processing application accumulates similar type of transactions in batches, then sorts these batches in sequence with respect to the key field, and then processes the entire batch of records in a single pass through the file. Applications such as payroll processing and monthly bill processing are examples of batch processing applications. Advantages of Sequential Files 1.

They are simple to understand and use.

2.

They are easy to organize and maintain.

3.

They need relatively inexpensive I/O media and devices for their storage and processing.

4.

They are efficient and economical to use for applications in which activity ratio is high (the application processes most records during update runs).

Disadvantages of Sequential Files 1.

They are inefficient and uneconomical to use for applications in which activity ratio is low.

2.

Their use is limited to batch-processing environment because of the need to accumulate transactions in batches. Accumulating transactions in batches keeps activity ratio high during processing.

3.

Sequential processing precludes the possibility of up-to-the-minute data because of the need to accumulate transactions in batches before processing them.

4.

Sequential processing requires extra overhead of sorting the files before using them for processing. That is, the application must first sort both transaction and master files in the same sequence before processing.

5.

Sequential processing often leads to data redundancy problem, since a sequential processing application may store the same data in several files sequenced on different keys.

■ File Management System

437

Direct Files Many applications require up-to-the-minute timeliness of data. Users of such applications cannot afford to wait for accumulation of transactions in batches before processing them. They require processing of a transaction immediately whenever it occurs. Examples of such applications are airline or railway reservation systems, teller facility in banking applications, online encyclopedia, etc. Since these applications process only one transaction at a time, activity ratio is very low in these applications, making use of sequential files inefficient and uneconomical. Direct/random file organization is suitable for such an application because the application can directly locate any record by its key field value, without having to search through a sequence of other records. For example, when a passenger makes a reservation request for a train, the computer maintaining and processing the reservation records directly accesses the record for the train and updates its seats position for specified journey date. Obviously, a direct/random file requires a direct access storage device for its storage to enable direct access of records. Direct/random files use magnetic/optical disk as the principal storage medium. Obvious question that arises is how a direct file organizes its records physically so that applications can access any record directly, given its key field value. To enable this, direct file organization uses an address-generating function to convert a record key value into a storage address on the disk, which stores the file. The file stores each record at a location to which the address-generating function maps the record’s key field value. This mechanism is known as hashing and the address-generating function is called hashing algorithm. Although, a hashing algorithm generates a unique address for each record key value, but in practice, it sometimes maps the key values of two or more records to the same storage address. This problem is known as collision. There are many ways to handle a collision. One method is to use a pointer at the address generated by the hashing algorithm. This pointer points to a linked list of addresses containing physical addresses of all records whose key values map to the address generated by the hashing algorithm. To search a record, given its key value, the computer applies the hashing algorithm on the given key to generate its corresponding address. If it finds the record at the generated address, the search ends. Otherwise, the computer uses the pointer stored at the generated address to access the corresponding linked list. It accesses the addresses stored in the linked list elements and the corresponding records one-by-one, and compares the given key with the key of the accessed record. The search ends when it finds a record with matching key. If required, an application can process the records of a direct file sequentially in ascending/descending sequence of key field value. However, if the application needs to process a large number of records sequentially (that is, if activity ratio is high), direct files prove to be inefficient as compared to sequential files, because the computer has to use a hashing algorithm and reposition the read/write head of disk for every record that the application processes. Advantages of Direct Files 1.

Given the key, a direct file can quickly locate and retrieve any record directly.

2.

It does not require sorting of transactions in sequence before processing.

3.

It does not require accumulation of transactions in batches before processing them. An application can process a transaction whenever the transaction occurs.

4.

It can support interactive online applications, which provide up-to-the-minute information in response to inquiries from users.

5.

If required, an application can process direct file records sequentially.

Disadvantages of Direct Files 1.

Direct files require relatively expensive hardware and software resources because they require a direct-access storage device (such as disk) for their storage.

Chapter 11 ■ Database and Data Science

438 2.

Due to address generation overhead involved, they are less efficient and less economical than sequential files for use in sequential applications with high activity ratio.

3.

They often require special security and access synchronization mechanisms because interactive online applications generally access online direct files simultaneously from multiple online stations.

Indexed Sequential Files We are familiar with the concept of an index. For example, a display board at the entrance lobby of a large multistoried building displaying names and apartment numbers of occupants is an index, which helps visitors locate a person’s apartment within the building. For instance, to find Dr. Sharma’s apartment within the building, a visitor would look up his name on the display board (index) and read the corresponding floor number and apartment number. This idea of scanning a logically sequenced table is easier and quicker way of searching an apartment than searching door-to-door. Similarly, if a reader wishes to read the section on printers in this book, he/she would not begin on page 1 and read every page until he/she comes across this topic. Rather, the reader would search this topic in the table of contents at the beginning of the book (which serves as an index), or in the index at the end of the book, to locate the corresponding page number, and then turning to that page to begin reading. Indexed sequential files use the same principle. As Figure 11.3 shows, indexed sequential file organization uses two files for every data file – data file (which contains records of the file), and index file (which contains the index key and disk address of each record of the file). The data file can store the records in random sequence, but the index file stores the index keys in sorted sequence on index key value. With this arrangement, an application can use the file for both random and sequential processing. For processing a search request for a record, the computer first searches the smaller, more accessible index file to obtain the physical location of the record, and then accesses the corresponding record from the data file. For instance, to locate an employee’s record (in the example of Figure 11.3) whose employee-code is 0004, the computer first searches the index file for this employee-code key and obtains the corresponding address value 1002. It then accesses the record stored at address location 1002 in the data file. Employee code (key) 0001 0002 0003 0004

Address location 1003 1001 1004 1002

Index file

Address location 1001 1002 1003 1004

Employee record 0002 0004 0001 0003

R. S. Patel … R. K. Rana … K. P. Sinha … N. P. Singh …

Data file

Figure 11.3. Organization of an indexed sequential file.

This technique of file management is known as Indexed Sequential Access Method (ISAM) and files of this type are called ISAM files. Advantages of Indexed Sequential Files 1.

Applications with high activity ratio can use index sequential files quite efficiently for sequential processing.

2.

Applications with low activity ratio can also use index sequential files quite efficiently for direct access processing.

Disadvantages of Indexed Sequential Files 1.

They require relatively expensive hardware and software resources because they need a direct-access device (such as disk) for storage.

■ File Management System

439

2.

They require more storage space than other types of files because of the need for index file.

3.

They are unsuitable for online applications requiring direct access to records. This is because direct access to records in index sequential files is slower as compared to that in direct files.

File Utilities File utilities are routines, which perform generic operations on data files. Normally, they are quite general in nature in the sense that they can deal with different data formats and different types of storage medium. Some commonly used file utilities are described here.

Sorting Utility A file sorting utility arranges records of a file in some defined sequence. A user of sorting utility specifies the values of certain fields (known as keys) of the file’s records. The keys determine the sorting sequence of the file’s records. The simplest case of sorting is ordering of a file’s records on a single key. For example, the sequence of records of employee file in Figure 11.4 is ascending order of employee-code, which is the key. A more complex sorting would be ordering of a file’s records on two or more keys. For example, the sequence of records of employee file in Figure 11.5 is by ascending order of employee-code within department-code. Here employee-code and department-code are two keys. The sorting utility first lists all records for the lowest department-code for each employee belonging to that department in ascending sequence of employee-code, then all records for next department-code, and so on. Out of these two keys in this sorting example, department-code is called primary key, and employee-code is called secondary key, because order of sorting is employee-code within department-code. A sorting utility enables users to specify their sequencing requirements for a file by means of input parameters. Input parameters such as size and number of keys, and type of ordering (ascending, descending) vary from one sorting utility to another. These parameters decide the extent and sophistication of sorting utilities.

Employee code

Department code

101 123 124 176 178 202 213

2 3 1 2 1 3 1

Other fields (Name, Address, Qualification, Basic salary, etc.) ---------------

Figure 11.4. Sorting on one key in ascending employee-code sequence.

Employee code

Department code

124 178 213 101 176 123 202

1 1 1 2 2 3 3

Other fields (Name, Address, Qualification, Basic salary, etc.) ---------------

Figure 11.5. Sorting on two keys. Ascending employee-code (secondary key) within ascending department-code (primary key).

A sorting utility reads un-sequenced records of an input file, and by means of various copying techniques, ultimately produces an output file that contains the records of the input file in the desired sequence.

Searching Utility A file searching utility finds a particular record in a file. A user of searching utility specifies values of certain fields (known as keys) of the file’s records. The searching utility matches the specified key values with their values in each record to search the desired record. For example, in the employee file of Figure 11.4, a user can specify the value 202 for employee-code field to search the corresponding employee’s record.

440

Chapter 11 ■ Database and Data Science

Efficiency of a search algorithm depends on file organization. For example, to search a record in a sequential file, the search algorithm scans the records of the file sequentially, beginning with the first record. It compares the specified key field value with the key field value of each record one-by-one. Search process terminates when the algorithm finds a record with matching key. On the other hand, direct or index sequential file organizations enable immediate access to a record with the help of either a hashing algorithm (in case of direct file organization) or an index file (in case of index sequential file organization). Users need to specify a file and key field value as input parameters to a search utility, which searches through the file and produces the desired record(s). Normally, searching a record from a direct or index sequential file requires much less time than searching a record from a sequential file.

Merging Utility A file merging utility combines records of two or more ordered (sorted) files into a single ordered file. Merging utility requires that records of each input file be sorted in the same order, although their record layout need not be identical. A merging utility places records from each of the input files in their correct relative order, producing an output file having all records in the same order as input files. Figure 11.6 illustrates merging of two input files A and B to produce an output file C. Input file

Output file

Employee Other code fields … 125 127 137 146 159 File A

… … … …

Input file

Employee code

Other fields

Employee code

Other fields

112

… …

112

… …

… … …

129

119 125 127 129 137

119



139 150

… …

152



139

152

… … …

159



146 150

File B

File C Figure 11.6. Merging of files A and B to produce file C.

Copying Utility A file copying utility produces a copy of a file either from one unit of a storage device to another similar unit (such as from one tape reel to another), or from one storage medium to another (such as from tape to hard disk, or from pen drive to hard disk). Users often use file copying utility to take back-up copies of files. For example, a user may copy a file from a hard disk to a tape for back-up purpose. File copying utilities are also known as peripheral interchange programs (PIP) since users often use them to copy a file from one peripheral device to another.

■ Database Management System

441

Printing Utility A file printing utility prints a file on a printer to produce hard copy of its contents. Printing utilities often provide the facility to print file contents in different formats. They often provide some selection and editing facilities to enable printing of parts of files (such as specified number of records and only certain fields of records). Some printing utilities provide special formats for printing files that contain program instructions rather than data.

Maintenance Utility A file maintenance utility copies data from one or more files to a new file selectively, or updates a file’s contents selectively. For example, a file maintenance utility may provide features to combine data from more than one file into a single file, delete a record from a file by specifying its key value or record count, and select and copy specific fields of records from an existing file to a new file.

DATABASE MANAGEMENT SYSTEM Database-oriented approach of organizing data provides a set of programs to facilitate users to organize, create, delete, update, and manipulate data in a database. All these programs together form a Database Management System (DBMS). Features commonly found in database management systems are described here.

Database Models A database model defines the manner in which a database links its various data elements together. Four commonly used database models are hierarchical, network, relational, and object-oriented. Also known as database structures or database structuring techniques, they are described here.

Hierarchical Databases A hierarchical database links its data elements as an inverted tree structure (root at the top with branches formed below). Below the single-root data element are subordinate elements, each of which, in turn, has its own subordinate elements, and so on. The tree can grow to multiple levels. Like a family tree, data elements of a hierarchical database have parent-child relationship. A parent data element is one that has one or more subordinate data elements. Data elements that are below a parent data element are its children data elements. There may be many children elements under each parent element, but there can be only one parent element for any child element. Note that the branches of a tree structure are not connected. Figure 11.7 shows an example of a hierarchical database. Several database applications use hierarchical database because they can neatly organize their data elements as a hierarchical tree structure. However, the main limitation of a hierarchical database is that it does not support flexible data access. In a hierarchical database, applications can access its data elements only by following paths formed by the branches of the tree structure. Hence, a hierarchical database designer must determine all types of relationships among data elements and map them in a hierarchical tree structure while designing the database. For example, the hierarchical database of Figure 11.7 categorizes employees by their department and within a department by their job functions, such as managers, engineers, technicians, and support staff. If personnel department faces shortage of support staff on a day, an application cannot directly produce a list of all support staff, to take a decision to use some support staff from other departments in personnel department. Instead, the application will have to traverse the database tree department-by-department and obtain the list of support staff assigned to each department, and then consolidate the obtained lists to generate a list of all support staff.

442

Chapter 11 ■ Database and Data Science Organization

Personnel department

Managers

A parent element

Finance department

Support staff

Managers

Technical department

Support staff

Managers

Engineers

Technicians

Support staff

A child element Figure 11.7. An example of a hierarchical database.

Network Databases A network database is an extension of hierarchical database. It also organizes its data elements in such a manner that they have parent-child relationship among them. In a network database, however, a child data element can have more than one parent element or no parent element at all. Due to this structure, the database management system of a network database permits extraction of needed information by beginning from any data element, instead of starting from the root data element. Like in hierarchical database, a network database designer must also determine all types of relationships among the data elements while designing the database. Figure 11.8 shows an example of a network database, which maintains relationships among the courses offered and the students enrolled for each course in a college. Notice that parent and child elements can have many-to-many relationships. That is, a student may enroll for several courses, and a course may have a number of students enrolled for it. With this database structure, an application can easily produce both course-wise-student report (a report showing all students enrolled for each course) and student-wise-course report (a report showing all courses taken by each student). For example, it is easy to tell from the figure that in this semester, the students enrolled for Mathematics course are Seeta, Geeta, Ram, and Sohan; and Geeta has taken three courses – Hindi, Mathematics, and Computer Science. The example also shows a child element that has no parent element (student named Raju – he might be a research student who has not taken any course in this semester). College

English

Courses

Students

Seeta

Hindi

Geeta

Mathematics

Ram

Mohan

Computer Science

Sohan

A child element can have more than one parent element This child element has no parent element Figure 11.8. An example of a network database.

Raju

■ Database Management System

443

Relational Databases A relational database organizes its data elements as multiple tables with rows and columns. It stores each table as a separate file. Each table column represents a data field, and each row represents a data record (also known as a tuple). A common field links data in one table (or file) to data in another table. Figure 11.9 shows an example of a relational database, which is a sample library database. It has three tables – first one contains data of library members, second one contains data of borrowed books, and third one contains data of books in the library. The library issues a library card to each new member with his/her membership number on it. When the library issues a membership card, it uses an application to enter the member’s name, address, and membership number in the first table. When a member borrows a book, the library uses the application to enter borrower’s membership number, book’s ISBN number (which serves as unique identification number for a book), and due date for returning the book in the second table. ‘Membership No.’ common field links the first and second tables, whereas ‘Book No.’ common field links the second and third tables. Membership No.

Member’s name

Member’s address

83569 62853 12859 32228 23466 11348 16185

K. N. Raina D. P. Singh R. Pandey R. S. Gupta S. K. Ray P. K. Sen T. N. Murli

C-15, Sarita Vihar, Pune-7 A-22, Anand Park, Pune-5 D-18, Vrindavan, Pune-7 A-12, Nandanvan, Pune-2 B-05, Royal Villa, Pune-3 B-16, Anand Park, Pune-5 A-11, Vrindavan, Pune-7

(a) Members data table

Borrower (Membership No.) 12859 11348 32228 16185 12859 62853 11348

Book No. (ISBN) 27-21675-2 89303-530-0 13-201702-5 22-68111-7 71606-214-0 13-48049-8 18-23614-1

Due date (DD-MM-YYYY) 10-12-2022 08-11-2022 10-11-2022 05-12-2022 06-11-2022 15-11-2022 12-11-2022

(b) Borrowed books data table

Book No. (ISBN) 13-201702-5 13-48049-8 18-23614-1 22-68111-7 27-21675-2 71606-214-0 89303-530-0

Book title Concepts of Physics Concepts of Chemistry Astrology for You Fundamentals of Computers C++ Programming Computer Networks Database Systems

Author H. C. Verma S. S. Dubey N. K. Sharma K. Ramesh R. P. Rajan A. N. Rai P. N. Dixit

(c) Books data table Figure 11.9. An example of a relational database.

Now, let us assume that the librarian wants a report of overdue books as on 10-11-2022, and wants borrower’s details and book’s details for each overdue book in the report. To produce this report, the database search routine will first search for the due date field in borrowed books data table to surface three overdue books. The database management

Chapter 11 ■ Database and Data Science

444

system will then use ‘Membership No.’ field to cross-reference borrower’s details of each overdue book from members’ data table, and ‘Book No.’ field to cross-reference book’s details of each overdue book from books data table. Final report, thus produced, would look something like that in Figure 11.10. List of overdue books as on 10-11-2022 Membership No.

Member’s name

11348

P. K. Sen

32228

R. S. Gupta

12859

R. Pandey

Member’s address B-16, Anand Park, Pune-5 A-12, Nandanvan, Pune-2 D-18, Vrindavan, Pune-7

Due date

Book No.

Book title

Book author

08-11

89303-530-0

Database Systems

P. N. Dixit

10-11

13-201702-5

Concepts of Physics

H. C. Verma

06-11

71606-214-0

Computer Networks

A. N. Rai

Figure 11.10. A report of overdue books as on 10-11-2022 from the sample database of Figure 11.9.

Relational database model provides greater flexibility of data organization and future enhancements in database as compared to hierarchical and network database models. Many applications can organize their data elements in a relational database in a manner that is identical to real-life relationships between data elements. Hence, users often find relational database model to be closer to their intuitive model of real-life situations, making this model easier to understand and use. Moreover, for adding new data to an existing relational database, there is no need to redesign the database afresh. Rather, users can add new tables containing new data to the database, and can then link these tables to existing tables with common key fields. Users can also reorganize data elements, when necessary, to create new tables by selecting certain rows or specific columns from other tables, or by joining columns and rows from two separate tables.

Object-oriented Databases Hierarchical, network, and relational database models (henceforth referred to as conventional database models) are suitable for conventional business data processing applications, such as inventory control, payroll, accounts, employee information systems, etc. Application designers have found them unsuitable for a variety of other types of applications because of several shortcomings in them. These applications include computer-aided design (CAD), computer-aided engineering (CAE), computer-aided manufacturing (CAM), computer-aided software engineering (CASE), expert systems, and multimedia systems. Some key features that these applications require for effective modeling are (these features are absent in conventional database models): 1.

Ability to model complex nested entities, such as design and engineering objects, and multimedia documents. Conventional database models do not provide mechanisms, such as configuration management, to represent and manage such entities.

2.

Support for general data types found in object-oriented programming languages. Database management systems based on conventional database models support only a limited set of atomic data types, such as integer, string, etc. They do not even allow storage and retrieval of long unstructured data, such as images, audio, and textual documents.

3.

Support for frequently useful object-oriented concepts such as object, class, inheritance, etc. Object-oriented concepts consist of a number of data modeling concepts, such as aggregation, generalization, and membership relationships, which are useful in modeling complex applications. Database management systems based on conventional database models do not provide necessary functions for implementing object-oriented concepts.

■ Database Management System

445

This means that applications programmers must explicitly represent and manage objects and the relationships among the objects in their programs. 4.

Support for proper match between object-oriented programming languages and database languages. Normally, an application programmer implements a database application by using some conventional programming language (such as COBOL, PASCAL, C, or C++), and some database languages (data definition language, data manipulation language, query language) that are part of database management system. With popularity of object-oriented paradigm, use of object-oriented programming languages for implementing applications has become a common practice. However, conventional database languages (which database management systems of conventional database models support) do not use object-oriented concepts for implementing applications. This mismatch between object-oriented programming languages and conventional database languages makes database implementation of many applications inconvenient.

Object-oriented database model overcomes these shortcomings of conventional database models. An object-oriented database is a collection of objects whose behavior, state, and relationships are in accordance with object-oriented concepts (such as object, class, class hierarchy, etc.). An object-oriented database management system allows definition and manipulation of an object-oriented database. Application designers prefer to use object-oriented database model for a large range of database applications such as CAD, CAE, CAM, CASE, expert systems, and multimedia systems. The reason is that object-oriented concepts already include such data modeling concepts as grouping of objects into a class, aggregation relationships between an object and other objects it consists of (nested objects), and generalization relationships between a class of objects and classes of objects specialized from it. The fact that an object-oriented database model includes the aggregation and generalization relationships means that an object-oriented database management system provides direct support for the definition and manipulation of the relationships among objects. This in turn means that application programmers need not program and manage these relationships explicitly. Figure 11.11 shows an example of an object-oriented database structure. Class Vehicle is root of a class-composition hierarchy including classes VehicleSpecs, Company, and Employee. Class Vehicle is also root of a class hierarchy involving classes TwoWheeler and FourWheeler. Class Company is, in turn, root of a class hierarchy with subclasses DomesticCompany and ForeignCompany. It is also root of a class-composition hierarchy involving class Employee. For the database structure of Figure 11.11, a typical query may be “List President’s and Company’s names for all companies that manufacture two-wheeler vehicles and are located in Pune, India”. VehicleSpecs Length Width Height Engine type Fuel type Fuel tank capacity No. of wheels

Vehicle Id Color Specifications Manufacturer TwoWheeler Other details of the vehicle like with/without gear, seating capacity, etc.

FourWheeler Other details of the vehicle like no. of doors, seating capacity, etc.

Class/subclass link Attribute/domain link

Company Name Location President

DomesticCompany Other details of the company

Employee Id Name Age

ForeignCompany Other details of the company

Figure 11.11. An example of an object-oriented database structure.

Chapter 11 ■ Database and Data Science

446

Main Components of a DBMS A DBMS allows users to organize, process, and retrieve data from a database, without the need to know about the underlying database structure (organization and location of data). The four major components of a DBMS are: 1.

Data Definition Language (DDL)

3.

Query Language

2.

Data Manipulation Language (DML)

4.

Report Generator

They are described here.

Data Definition Language (DDL) Database designers use data definition language (DDL) to define the structure of a database. Database structure definition (also known as database schema) typically includes the following: 1.

Definition of all data elements of the database.

2.

Organization of data elements (fields) into records (or tuples), tables, etc.

3.

Definition of field name, field length, and field type for each data element. Users use field name to refer to a data element while accessing it. Field length defines maximum size of a data element (such as employeename field may have a maximum size of 30 characters). Common field types are: (a) (b) (c) (d) (e) (f)

Numeric: Contains numbers formed of digits 0 to 9, a decimal point, and a + or – sign Alphanumeric: Contains a combination of alphabetic characters, special symbols, and digits Logical: Contains one of two possible values – Yes/No or True/False Date/Time: Contains a single date, time, or date-time value Memo: Contains any type of data that user might like to type Binary: Contains binary data

4.

Definition of controls for fields that can have only selective values. For example, in an employee database, sex field can have controls to accept only values M or F. Similarly, age field can have controls to accept only values 18 or more and less than 70. Such controls ensure correctness of input data to some extent.

5.

Definition of access controls to various tables, records, and fields for different categories of users to protect sensitive data items from unauthorized users.

6.

Definition of logical relationships among various data elements of the database.

In short, the schema of a database includes virtually everything about the database structure. It is possible to generate a complete description of a database from its schema. Systems analysts use this description to define new applications on the database. Database administrators are individuals who install and manage a database system and coordinate its usage. They are responsible for: 1.

Establishing and controlling data definitions and standards.

2.

Determining relationships among data elements.

3.

Designing database security system to guard against unauthorized use of data in the database.

4.

Training and assisting applications programmers to use the database.

■ Database Management System

447

A database also has a data dictionary, which contains data definitions. It serves as a useful reference document because it contains an indexed list of all data elements of the database along with their definitions. DDL module of DBMS creates/updates the data dictionary of a database automatically when users define/change the database schema.

Data Manipulation Language (DML) Once a database designer completes defining the structure of a database (database schema), the database is ready for entry and manipulation of data. Data manipulation language (DML) includes commands to enable users to enter and minipulate data in a database. With these commands, users can add new records to the database, navigate through its existing records, view contents of various fields of a record, modify contents of one or more fields of a record, delete an existing record, and sort its records in desired sequence. Some DBMSs combine data definition language and data manipulation language together, while others support them as two separate DBMS components.

Query Language Although it is possible to navigate through a database one record at a time to extract some information from the database, this approach is inefficient and frustrating when there are thousands of records and several files in the database. Hence, all database management systems provide a query language, enabling users to define their requirements as queries for extracting information from a database. For example, for an inventory database, a user may be interested in such information as “list item description and vendor name for all items whose current inventory level is less than 20 units”, or “list stock number and item description for all items with a profit margin greater than 25%”. A query language enables proper formulation of queries for extraction of such information from a database. Earlier, each DBMS had its own query language. In this approach, users were unable to use their queries developed for one DBMS with other DBMSs. To overcome this limitation, the databse industry subsequently developed one industry standard query language called SQL (pronounced “S-Q-L”). It was originally developed by IBM and was based on an earlier query language called SEQUEL, an acronym for “Structured English QUEry Language”. Today, many DBMSs use SQL as the standard Structured Query Language. A non-programmer can easily learn a query language. Hence, normal users of a database can use a query language to retrieve information from the database without the help of any programmer.

Report Generator A report is presentation of inforamtion extracted from a database. A report generator enables a database user to define a report’s format by specifying its layout. For example, the user can specify proper spacing between data items in the report, and can include suitable report titles and subtitles, column heading, page numbers, separation lines, and other elements, making the report more readable and presentable. The user can also instruct the report generator to perform arithmetic operations (such as calculating subtotals and totals) on data found in numeric fields to make the report more meaningful and useful. A user can define the layout of a report and then store it for later use. This facility is useful for generating periodic reports such as generation of employee pay-slips every month from an employee database, or generation of consumer bills every month from a consumers service database. The report layout format remains the same every month, only the data changes.

Creating and Using a Database This section explains how to create and use a database. Normally, professional programmers create and maintain large databases on large computer systems. Users of these databases, however, need not be programmers. Nonprogrammers can use these databases easily to access data and produce reports. On the other hand, many DBMSs for

Chapter 11 ■ Database and Data Science

448

personal computer systems enable non-programmers to not only use, but even to create their own databases. Normally, these databases are simple in structure and small in size.

Creating a Database Creation of a database is a three steps process: 1.

Defining its structure (schema)

2.

Designing forms (custom screens) for displaying and entering data

3.

Entering data into it

These steps are described here. Schema Definition To set up a database, a database designer has to first define its structure (schema definition). This is done by identifying the characteristics of each field in it. A good way to begin defining the schema of a database is to list down on paper all fields that the designer can think of for inclusion in the database, and then to determine the name, type, and size of each field. The designer has to then use a tool called schema builder to capture this information into the system. Schema builder enables the designer to define a database schema interactively by prompting him/her to enter the name, type, size, etc. for each field. While defining the schema of a database, it is important to consider possible future needs and needs of all types of users of the database. That is, while defining the database structure, the designer should include in it all possible fields that all types of users of the database may need. Although it is possible to modify database structure at any time, making such modifications is a time-consuming process. Hence, it is better to carefully design a database in the first instance, and minimize the need to modify its structure later. Designing Forms After defining the structure of a database, the next step is to design forms (custom screens) for convenient data entry. Each form displays a set of fields of database structure with appropriate amount of blank spaces against each to enable data entry in those fields. Figure 11.12 shows such a form. To facilitate easier data entry, a designer often designs these forms with several fancy features, such as: 1.

A list-box for a field listing the options from which users can select a choice. For example, in Figure 11.12, SEX field may have a list-box listing options “Male” and “Female,” out of which a user selects one while entering an employee’s sex information, and the system accordingly enters “M” or “F” in SEX field. Similarly, STATE field may have a list-box listing all states, from which a user can select an option while inputting an employee’s address.

2.

Simple validation checks for a field to ensure correctness of input data to some extent. For example, in Figure 11.12, the designer may define a validation check for POSTAL CODE field to accept only six numeric characters. With this, the field will not accept less than or more than six characters, and will also not accept alphabetic or special characters. Similarly, the designer may define a validation check for AGE field to accept values in the range 18 to 70 only (both inclusive). Validation checks also enable designers to force a certain character position of a field to be a letter or numeral.

■ Database Management System

449

EMPLOYEE DATABASE DATA ENTRY FORM EMPLOYEE ID:

856392

EMPLOYEE NAME:

SEX:

LAST NAME:

SINHA

FIRST NAME:

PRADEEP

MIDDLE NAME: CONTACT ADDRESS:

AGE:

F/8, ANAND PARK

ADDRESS 2:

SOCIETY, AUNDH

STATE: POSTAL CODE:

64

KUMAR

ADDRESS 1:

CITY:

TELEPHONE NO.:

M

PUNE MH 411007

(020) 5680-4892

ANY OTHER INFORMATION:

IS FLUENT IN JAPANESE LANGUAGE

Figure 11.12. A typical database form used for data entry.

3.

Automatic conversion of characters input by a user in certain fields to upper- or lower-case. For example, the system may be designed to accept “mh”, “Mh”, “mH” or “MH” for state code of Maharashtra, and will convert the entry to “MH” automatically. This feature eases data entry and ensures uniformity of data.

4.

Automatic formatting of certain fields. For example, the system may be designed to display the value of TELEPHONE NO. field automatically in the specified format (with parentheses, space, and hyphen). Hence, when a user enters telephone number as “02056804892”, the system automatically displays “(020) 56804892” in that field.

Entering Data After a designer completes designing the forms of a database, the database is ready for entry of data. Users enter data in the database one record at a time. To enter data, a user issues a command that calls up and displays the appropriate form with blank fields. The user then keys in data for each field in its respective space. In this manner, the user enters data for the first record, then for the second record, and so on. Most database systems automatically assign a serial number to each record, when the user enters the record. Usually, a user can use the Tab or Enter key to move to the next field, while entering data in a form. Pressing Enter or Tab key in the last field of the form saves the record in database and moves to a new, blank form for the next record’s data entry. In addition to using the Tab or Enter key to move forward through fields, the user can directly go to any field on the form by clicking on it with the mouse.

Chapter 11 ■ Database and Data Science

450

Viewing, Modifying, Deleting, and Adding Records All database systems provide commands to add, delete, view, or modify records of a database. The command for viewing a record enables a user to display data in various fields of a record in the same screen format as that of the form for data entry. A user selects a record for viewing by specifying its key field value. Usually, database systems also provide the flexibility to users to move between records for viewing different records, such as “go to the first record”, “go to the previous record”, “go to the next record”, and “go to the last record”. Many database systems also provide the facility to set up filters, which allow users to browse through and view those records only that meet some criterion. For example, in an employee database, which a user can create by using the form of Figure 11.12, if the user wants to view the records of only female employees, the user can set a filter for “Sex” field, and the system will display only the records containing “F” in that field. Note that while a filter is set, the user cannot access the records that do not meet the filter criteria. Filters provide a quick and convenient way to narrow down the number of records with which the users have to work. The command for modifying a record enables a user to not only view, but also to update data in various fields of a record. To modify the contents of a field of a record, the user first displays the record, then uses the mouse to position the cursor in the field at the character position where he/she wants to perform editing, and then edits the contents of the field. Similarly, the user can edit data in any other field of the record. Finally, the user presses the Enter key for changes to take effect. Some database systems may prompt the user to confirm the changes made, before effecting the changes and allowing the user to move to another record. The command for deleting a record enables a user to remove records from a database. To delete a record, a user first selects the record, either by specifying its key field value, or by using the facility to move between records just as is done in the case of viewing a record. The user then uses the delete command, to delete the record. Most database systems prompt the user to confirm deletion of the record before deleting it. This feature prevents deletion of a record by mistake. The command for adding a record enables a user to add new records to a database. When a user enables this command, the system displays a blank form and waits for the user to enter the data. The user then keys in the data for each field in its respective space. After keying the data in the last field, the user presses the Enter or Tab key, to save the record. On doing this, the system displays a new blank form for the next record’s data entry. If the user does not want to add any more records, he/she uses the mouse to select the option to terminate the process for adding new records.

Searching for Desired Information A database management system enables its users to quickly search for the desired information from the large volume of data in a database. Modern database systems commonly support the following features for this: 1.

Find command

2.

Query language

3.

Query By Example (QBE)

These features are described here. Find Command Find command is for simple database queries, like searching for records having a particular string pattern in a field. For example, in an employee database, which a user can create by using the form of Figure 11.12, the user can use Find command to list the records of all employees whose last name is “SINHA”. Similarly, the user may use this command to list the records of all employees who belong to the city of “PUNE”.

■ Database Management System

451

To use Find, a user has to type the string pattern that he/she is interested in, and then has to indicate which field to search in. For instance, in the example above, the user has to type “SINHA” and indicate to the system to search this string in the “LAST NAME” field. The user can specify either a single field or all fields to search. Users cannot use Find command for creating an elaborate set of criteria for complex queries. Furthermore, Find command can operate on only one table at a time, and a user cannot save a specified criteria for future use. Query Language For handling complex quieries, all database systems support a query language. Most of these query languages conform to the SQL standard. In SQL, a user has to specify the criteria for search along with the fields and table (or tables) with which to work. Users can build the criteria for search by using relational operators (= [equal to], > [greater than], < [less than], and combinations of these operators), and logical operators (AND, OR, and NOT). For example, an SQL query to list the names of all employees whose last name starts with letter “S”, who belong to “PUNE”, and whose age is more than 40 years, looks as follows: SELECT [LAST NAME], [FIRST NAME], [MIDDLE NAME] FROM Employee WHERE ([LAST NAME] = “S..”) AND (CITY = “PUNE”) AND ([AGE > 40]) Keywords SELECT, FROM, and WHERE tell the SQL engine how to interpret each part of the query statement. SELECT keyword tells the SQL which fields to display for records that match the criteria. FROM keyword tells the SQL which table(s) to work with. WHERE keyword tells the SQL the criteria for selecting records (search criteria). This SQL query uses brackets […] around some field names because these field names contain spaces, and brackets help the database to interpret each field name correctly. Even a non-programmer can learn and use a query language easily, because the complexity of a query language statement is more or less of the same order as the above SQL statement. Furthermore, a query language uses only a few keywords that are easy to remember and use. In fact, SQL has only a few dozen or so basic keywords. Other advantages of a query language are that a user can use it for creating a query statement for an elaborate set of criteria for complex queries. It can operate on multiple tables at a time, and a user can save a specified criteria for future use. Query By Example (QBE) Although query languages are easy to learn and use, many database developers further simplify the job of specifying the search criteria. For this, they provide a simpler user interface (called front end) to a query language. A database user specifies the facts about a query by using this interface, and a query language builder composes query language statements automatically from the facts. Usually, front end consists of a form (called QBE form), and a user specifies a search criteria by inputting values into the fields of this form. The user may input values either by typing them, or by selecting an option from a set of options available for a field. A QBE form collects all information from a user for composing query language statement(s) for a search criteria. Once the user completes the QBE form, the QBE engine converts the user inputs into suitable query language statement(s) for search processing. This front-end feature, called query by example (QBE), relieves the users from remembering query language keywords and using them with correct syntax to form queries. It is userful for many database users, especially the beginners.

Chapter 11 ■ Database and Data Science

452

Creating Reports A user of a database system can use the report generator to create a report by assembling the output of a database query in a desired format. For this, the user specifies the layout of various fields in the report. The user can also specify titles and subtitles for the report, column headings for various fields, and other elements, to make the report more presentable. Furthermore, the user can specify sorting parameters to obtain sorted output with respect to one or more fields in the report. When sorting is on more than one field, the user has to specify the primary, secondary, and tertiary key fields. A user can save a report and use it later for generating similar reports whenever required. Figure 11.13 shows a sample output of a report. It is created for an employee database whose data entry form is in Figure 11.12. The report displays (or prints) a list of employees who belong to the city of PUNE. It contains last name, first name, address-1, address-2, and telephone number of all such employees. It is sorted in alphabetical order on last name of employees. LIST OF EMPLOYEES WHO BELONG TO PUNE DATE: DECEMBER 17, 2022 LAST NAME Gupta Murli Pandey Raina Ray Sen Singh

FIRST NAME Rajiv Tapan Rupa Pushpa Suhas Prakash Deepak

ADDRESS-1 A-12, Nandanvan A-11, Vrindavan D-18, Vrindana C-15, Sarita Vihar B-05, Royal Villa B-16, Anand Park A-22, Anand Park

ADDRESS-2 M. G. Road Pashan Road Pashan Road Aundh Road M. G. Road Aundh Road Aundh Road

TELEPHONE NUMBER 4623-4892 5863-4905 5865-3236 5755-8328 4685-6356 5762-3333 5728-6287

Figure 11.13. A sample output of a report to generate a list of employees who belong to Pune. It is sorted in alphabetical order on last name of employees.

Many database developers further simplify the job of database users by creating commonly anticipated reports, storing them, and providing a simple graphical user interface to select from available reports. In this case, a user has to select one of the reports from the available options while outputting query results. A user needs to create a new report only when none of the available options meets his/her requirement. The user can add the newly created report to the list of available options for future use.

Database Security Data in a database is often confidential. To prevent unauthorized individuals from accessing the data in a database, DBMSs commonly support the following security features: 1.

Normally, from the point of view of access control, a DBMS supports two types of database users – database administrator (having administrative access) and database user (having normal user access). A database administrator of a database has privileges to add new users to the database, delete one or more users of the database, decide and enforce various access rights of different users of the database, make changes to the database schema, and so on. On the other hand, a normal user of a database can only view, modify, delete or add records to the database; can enter data into the database; can search for some information from the database; and can create and generate reports from the database.

2.

All DBMSs have password-based user authentication mechanism. That is, a database user must enter his/her valid password to authenticate him/her to the database for obtaining access to all or part of the data in the database.

3.

Many DBMSs support a program-level of security, which precludes unauthorized users from using particular programs that access the database.

■ Database Management System

453

4.

Many DBMSs support record-level security, which prevents unauthorized users from accessing or updating certain records, such as employee records of top-level managers in an employee database.

5.

Many DBMSs even support field-level security, which prevents unauthorized users from accessing or updating sensitive information in certain fields, such as salary.

6.

Many DBMSs support read-only access, which prevents unauthorized users from modifying certain information (they can only view the information).

7.

All DBMSs maintain a log of database accesses so that in case of any security breach, database administrator can analyze the log records to detect possible cause of the problem.

Client-Server Database Systems With proliferation of computer networks, it became possible to allow users to access a database from any system on the same network. This gave birth to the client-server model of database systems. As Figure 11.14 shows, in this model, a computer system, called database server, stores, and manages the database. It runs important modules of the DBMS. These modules, called server programs, deal with the maintenance and processing of data in the database. On the other hand, database clients are systems on the same network, which users use for accessing the data in the database. They serve as front-end systems to the database and run those modules (called client programs) of the m DBMS, which facilitate specification of access requests. When a database client needs some information from the database, it makes Disk storage a request to the database server. The that stores the request travels on the network from the database database client to the database server, Database server (runs server programs) and the database server retrieves the requested information from the Network database and sends only that connectivity information back to the client. Obviously, there can be many database clients connected to the same database server simultaneously, and all of them Database clients (run client programs) can share the same database. Figure 11.14. Client-server database system architecture.

Client-server database systems have the following advantages over conventional database systems: 1.

Efficient utilization of computing resources, because they do not require a separate database for each user. Hence, only database server needs to have high processing power and large storage. Database clients can be low-end personal computers having low processing power and low storage capacity.

2.

Since they maintain only one copy of a database for all clients, it is easier to maintain the integrity (consistency) of data in the database. That is, all database updates need to be carried out only at one place.

3.

Since they maintain only one copy of a database for all clients, it is easier to ensure better security of data in the database.

4.

System administration cost and maintenance cost are lower because only the database server requires a good system and database administrator.

With the popularity of the Internet, web clients have become popular now. A web client is a computer system on the Internet that runs a web browser. The web browser enables a web client to connect to a database server dynamically, download necessary client software for becoming a database client, and make requests for information to the database server.

454

Chapter 11 ■ Database and Data Science

For vendors, web-based database clients are better than conventional database clients because with web-based database clients, vendors can easily deploy client software to hundreds of database client systems. With conventional database clients, seamless upgrade of client software to new versions was either not possible or involved high maintenance cost.

Distributed Database Systems A distributed database system seamlessly integrates multiple databases, which are on different computers. These computers may be in the same building or may be geographically far apart (such as in different cities). Note that unlike a client-server database system in which there is only one database, a distributed database system has multiple databases. A DBMS integrates them together to serve as a single database. A database often contains data from multiple sources and database clients access the data from multiple locations in a network environment. Main motivation behind using a distributed database system is to store different sets of data of a database in their most convenient locations in a computer network, depending on data entry requirements, storage capacity availability, processing load requirements, data security requirements, and so on. For example, as Figure 11.15 shows, a distributed database system might integrate employee databases of different departments of an organization, which are in different cities. Each department’s database stores the records of employees working in that department. A DBMS for a distributed database manages the multiple distributed databases in such a manner that they appear as a single database to the end users. That is, a user can access a distributed database in much the same way as a centralized database, without being concerned about data locations. For example, in the distributed database system of Figure 11.15, a user can make a single request for a sorted list of all female employees in the organization who are more than 40 years old. The DBMS for the distributed database takes care of sending this request to all four databases, then accumulating the results, sorting it, and presenting it to the user. The DBMS does all this internally without the knowledge of the user. R&D department located in Pune R&D

Pune

Production department located in Chennai Chennai

Production

Employee database for employees of R&D department

Employee database for employees of Production department

Finance

Personnel

Employee database for employees of Finance department

Employee database for employees of Personnel department

Mumbai

Finance department located in Mumbai

Bangalore

Personnel department located in Bangalore

Figure 11.15. A sample distributed database system that integrates databases from different departments of an organization, which are located in different cities.

■ Multimedia Database Systems

455

Active Database Systems Traditional DBMSs are passive in the sense that they execute commands (such as, query, update, delete) for a database only when they receive a request from a user or an application program. However, such DBMSs cannot effectively model some situations. For example, consider an inventory database of items sold by a department store. For each item, it stores current quantity, price, and registered vendor’s details. The database is connected to the pointof-sale terminals of the store. When a customer purchases an item, the sales person makes its entry in a point-of-sale terminal for billing. This information goes from point-of-sale terminal to the database, which updates the current quantity field of the item. To ensure that an item never runs out of stock in the store, the store wants to place an order for the item as soon as its quantity in the inventory falls below a threshold value. To do this in a passive database system would require the store to implement a polling mechanism, which checks periodically the quantity of every item in the inventory and prints a list of those items, whose quantity is less than its threshold value. The store then places new orders for the items in this list. Main difficulty in implementing this mechanism is how to decide the most appropriate polling frequency. If it is too high, there is a cost penalty. On the other hand, if it is too low, the reaction may be too late to meet the requirement of no item running out of stock. The best way to handle such an application would be to make the system place an order with the registered vendor automatically, as soon as the current quantity of an item goes below its threshold value. This is exactly what an active database system does. For instance, if the store implements its inventory database using an active database system, the database system can invoke an application automatically when the quantity of an item goes below its threshold value. This application prepares a purchase order for the item and sends this order to the registered vendor on e-mail. An active database system supports applications of the type seen in the above example by moving the reactive behavior from the application (or polling mechanism) into the database management system. Active databases are, therefore, able to monitor and react to specific circumstances of relevance to an application. An active database system must provide a knowledge model (that is, a description mechanism) and an execution model (that is, a runtime strategy) for supporting such applications. For this, an active database system uses rules that have up to three components – an event, a condition, and an action. The event part of a rule describes a happening to which the rule may be able to respond. The condition part of the rule examines the context in which the event has taken place. The action describes the task, which the rule must carry out, if the relevant event has taken place and the condition has evaluated to true. Such a rule is known as event-condition-action or ECA-rule. In some cases, the event or the condition may be either missing or implicit. For instance, in the application in the example above, there is no condition. Hence, it is an example of event-action rule. The event is “quantity below threshold value” and the action is “invoke the application for placing order”.

MULTIMEDIA DATABASE SYSTEMS Traditional database systems are suitable for storage and management of simple data types such as strings and numbers. Many users now use computers for multimedia applications, which use multimedia data such as text, graphics, animation, audio, and video. To support such applications, researchers designed database technologies for storage and management of multimedia data. We saw that a database consists of a collection of related data, while a database management system is a set of programs to define, create, store, access, manage and query databases. Hence, a multimedia database is a collection of multimedia data items, such as text, graphics, animation, audio, and video, and a multimedia database management system is a set of programs to define, create, store, access, manage, and query multimedia databases.

Requirements for Multimedia Database Systems To deal with multimedia data, multimedia database systems must meet certain special requirements. These requirements are both from the perspective of special hardware and software features of computer systems as well as

456

Chapter 11 ■ Database and Data Science

special database features for handling multimedia data. As Chapter 14 deals with hardware and software requirements for handling multimedia data, here we will deal with only the database features for handling multimedia data.

Support for Multimedia Data Storage and Retrieval By their very nature, multimedia data are huge in volume. A multimedia database should be capable of storing and managing several gigabytes of data for small multimedia data objects such as images, and several hundred terabytes or more of data, if the database must hold large amount of video or animation data. To meet the requirement of huge data volumes, multimedia database systems often use a hierarchy of storage devices. The storage hierarchy typically consists of primary storage (such as random access memories), secondary storage (such as magnetic disks), and tertiary storage (such as CD jukeboxes, or magnetic tape libraries). In a hierarchical storage system like this, performance of data retrieval depends on the efficiency of migration mechanism, which decides optimal level of each multimedia data item in the storage hierarchy. Systems often use data compression and decompression techniques (described in Chapter 14) to deal with the requirement of huge data volumes. Hence, a DBMS for multimedia databases typically requires mechanisms for handling huge data storage (possibly comprising of multi-level hierarchy), migrating data automatically from one level to another in the storage hierarchy for efficient data retrieval, compressing and decompressing data at the time of storage and retrieval respectively, and transferring and distributing huge volumes of data across the network.

Support for Multimedia Data Types A DBMS for multimedia databases must provide type support for common multimedia data types. It is not sufficient for a multimedia database system to serve only as a repository of multimedia data, but the database system must also be intelligent enough to understand the data it manages. Hence, it must have the capability to recognize and operate on several standard multimedia data formats, such as JPEG, GIF, and MPEG. Internally, a DBMS for multimedia databases may support a single (perhaps proprietary) data format for each data type. For example, it may internally treat all types of multimedia data as Blobs (binary large objects), as in simple data repositories that do not recognize or support multimedia data formats. In this case, the multimedia database system must have conversion routines to convert data from original format to internal format on import to the database, and from internal format to original format on export from the database. Some multimedia data types such as video, audio, and animation sequences also have temporal (time-related) requirements, which have implications on their storage, manipulation, and presentation. Similarly, images, graphics, and video data have spatial (space-related) constraints in terms of their content. A multimedia database system designer must design it in such a manner that the database understands and meets these additional requirements of these multimedia data types for handling them.

Support for Multimedia Data Relationships A multimedia database system supports multiple data types. For effective presentation of multimedia data to its users, the system often needs to integrate two or more data types to form a new composite multimedia data type. Often this requires establishment of spatial (space-related), temporal (time-related), and/or synchronization relationships among various data items of different types. Spatial relationships organize the data’s visual layout. For example, superimposition of a text object on a specific part of an image/video object when the system displays them together. Temporal relationships define temporal layout, ensuring timely presentation of the right data. A simple example might be, “Play video v1 and audio a1, and thereafter, play music m1 until slide show s1 is done”. Synchronization relationships define synchronization of two or more objects when the system presents them together to the users(s). For example, maintaining lip synchronization between a video and a sound track while showing a movie. To take care of such multimedia data composition and presentation requirements, a multimedia database system should provide facilities to define and support various types of relationships between multimedia data objects.

■ Multimedia Database Systems

457

Support for Multimedia Data Modeling A multimedia database model must have features to capture static and dynamic properties of a multimedia database contents (multimedia data). Static properties include data items that make up the multimedia data, relationships between the data items, data item attributes, and so on. Examples of dynamic properties include interaction between data items, operations on data items, user interaction, and so on. Object-oriented database model is the most suitable model for multimedia databases. Most multimedia database systems implement multimedia data types as classes, having attributes and methods to support each data type. They may be part of a large class hierarchy or framework. A framework goes beyond a simple type definition to give more complete support for the data types, including several methods and additional supporting classes (to import, view, and export). While type frameworks focus on type-specific support, a database model for multimedia databases must also have features to express various types of relationships between multimedia data types for composition and presentation. Hence, a database model for multimedia databases goes much beyond an ordinary object-oriented database model, which designers use for modeling traditional databases.

Support for Multimedia Data Manipulation A DBMS needs to provide support for easy manipulation of data in a database. Implementing features for manipulation of simple data types is simple. However, multimedia databases require multimedia data manipulation languages (DMLs) or constructs with features to support not only simple cut or crop operations on multimedia data, but also to ensure that these operations adhere to spatial, temporal, and synchronization constraints. For example, for temporal constraints, these operations must provide predictable and worst-case information about the operation overhead. This lets the system determine if it can meet guarantees of quality of service (QoS) when it inserts the operation within the data stream between the source (database server) and the sink (the viewer). Another concept related to data manipulation, which DBMSs for multimedia databases use, is that of derived data. A database needs to store a modified data in the database for future reference. It may either replace the old version or retain it as another version of the data. If users constantly create new versions of data, the database size will grow rapidly. To reduce the need to store new versions of data, a DBMS for multimedia databases stores the operations to generate the new data (called derived data), rather than storing the new data itself.

Support for Multimedia Data Query A user initiates a query to extract some information from a database. A query contains predicates, and in response to the query, the DBMS returns to the user those data from the database, which satisfy (match) the predicates. It is easy to formulate predicates and look for its matching data in conventional databases. For example, “Find all employees for whom CITY = “PUNE” and AGE > 40”. However, this is not easy while dealing with multimedia data. Multimedia database systems use the following three methods for querying multimedia data: 1.

Manual keyword indexing. In this method, descriptive keywords are manually associated with each multimedia data in a multimedia database. For example, a set of keywords for describing an image data of a face could be “long face, sharp pointed nose, broad moustache, no beard, fair complexion, mole on right side of chin”. These keywords are metadata, since they are data about the multimedia data. For querying, a user specifies some keywords and the DBMS looks for images with matching keywords (it does not look at the images at all). It returns all images with matching keywords as the result of the query. This method has the following limitations: (a) Keyword classification is subjective, since a human being does the classification. (b) Exceptions will always exist no matter what keyword classification scheme the system uses. Hence, the system classifies some data incorrectly.

Chapter 11 ■ Database and Data Science

458

(c) Usually, key wording is limited to a well-defined abstraction of data. For example, for every image of a face, a database designer classifies a specific set of features. However, if the designer alters the abstraction of image of a face later, then the system must review all data, adding new keywords as required. This could be a formidable task even for small databases. 2.

Content-Based Retrieval/Querying (CBR/CBQ). In this method, queries are based on the content of multimedia data. When a data is entered to a database, the system subjects it to data analysis to derive certain attributes of the data (called derived data). Derived data could include attributes such as lines, shapes, colors, and textures from which the system can determine objects. Queries against this data then take place on the derived data. For example, “Find all graphic objects having red triangles and green circles”. Similarly, “Find all video clips having a flying aeroplane”. To distinguish CBR on temporal data such as video and audio, from that on images and graphics, CBR on images and graphics are called static CBR (or SCBR), and CBR on video, animation, and audio are called dynamic CBR (or DCBR). With both types of CBR, specifying precise queries (exact matching) is generally not practical. Therefore, multimedia database query languages must have features to support fuzzy predicates such as “Looks like this” to find approximate matches. Furthermore, since queries might not yield exact matches, multimedia database query languages must have facilities for ranking the query results based on how closely they match the given query.

3.

Query By Example (QBE). QBE is a special user interface to support CBR in multimedia database systems. These interfaces allow a user to specify the attributes of object(s) of interest by providing examples to match such as, a drawing, photograph, action, or sound. For example, the user can draw an example of the type of image he/she is interested in by using shape, color, or texture (such as a face sketch). The query manager then uses that example to extract similar images (photographs of people matching the sketch) from the database.

Support for Multimedia User Interface The diverse nature of multimedia data requires an equally diverse user interface for interacting with a multimedia database. Since multimedia database systems require spatial and temporal rendering of multimedia data, user interface of multimedia databases must include features to control and devices to render the presentation. This may include simple VCR-type control panels enabling a user to play, fast-forward, pause, or rewind a presentation, as well as more advanced controls including interactive data filtering, querying, and visual perspective controls. In addition, the user interface should also have features to allow a user to control the quality of service (QoS) parameters to adjust for resource limitations, cost of delivery, and personal visual and aural preferences.

DATA SCIENCE With the success of database technology, all types of industries and organizations started using databases for storage and management of their data. This resulted in availability of large volumes of data in databases. With continuous use of databases for several years, database owners gradually accumulated large volumes of data in their databases. A question that all owners of such databases started facing is “What do we do with so much of gathered data? Should we discard several years old data and keep only the recent ones?” However, after some thought and analysis, they realized that they should not discard old data because it contains some valuable information. It contains an important, and largely ignored, resource – broad knowledge about their activities/businesses that could support better decisionmaking, if they exploit it properly. For instance, consider the following examples: 1.

If an owner of a scientific database analyzes data in his/her database properly, he/she can get useful observations about some phenomenon under study.

2.

If an owner of a business database analyzes data in his/her database properly, he/she can get useful information about critical markets, competitors, and customers.

■ Data Science 3.

459

If an owner of a manufacturing database analyzes data in his/her database properly, he/she can get useful information about performance and optimization opportunities, as well as keys to improve processes and troubleshooting problems.

Traditional method of converting data into knowledge relied on manual analysis and interpretation. However, manual analysis of data gradually became impractical in many domains as data volumes grew exponentially. Furthermore, manual analysis of a dataset is slow, expensive, and highly subjective. When scale of data analysis grew beyond human capabilities, people started looking to computer technology to automate the process. Initially, this resulted in the use of statistical techniques on computers for automatic data analysis. Use of statistical techniques along with file management tools soon became ineffective for analysis of data in databases because of large size of modern databases, mission-critical nature of data, and need to produce analyses results quickly. These limitations of statistical techniques motivated researchers to look for new approaches of data analysis. Ultimately, they introduced a new generation of techniques and tools for automatic analysis of huge volumes of data. These techniques and tools for extraction of knowledge (useful information) from large datasets to help decision makers make meaningful decisions are the subject of the field called data science.

Stages in Data Science Data Science is an umbrella term describing a variety of activities for finding useful patterns in data. It uses tools and techniques based on machine learning algorithms to find unseen patterns in data to build predictive models. In addition to core data mining steps of running specific knowledge discovery algorithms, data science also includes preand post-processing of data and a host of other activities. The five distinct stages involved in data science are (see Figure 11.16): 1.

Data selection. The first step is selection and gathering of both unstructured and structured raw data. This involves data acquisition, data entry and data extraction from various data sources. This step is more significant than it may appear initially, especially when the selection process has to pull data from multiple data sources. In case of multiple data sources, the selection process needs to extract and join data from different databases, and perhaps sample the data.

2.

Data preprocessing. The second step is preprocessing of raw data (also called data cleaning) to prepare it for processing. It involves performing the following activities on the raw data: (a) Looking for obvious flaws in data and removing them. This involves collecting necessary information to model or account for the flaws, and deciding on strategies for handling missing and unknown values in data fields. (b) Removing records having errors or insignificant values in certain fields. (c) Converting certain data items for uniform representation of data in all records. This is often required when selected data is from multiple databases, which use different notations for the same field. For example, one database may represent sex field as 1 for male and 0 for female, while another database uses M for male and F for female. We often refer to the process of data cleaning as data scrubbing.

3.

Data transformation. The third step is data transformation. It involves performing the following activities on the preprocessed data: (a) (b) (c) (d)

Converting one type of data to another. Deriving new variables using mathematical or logical formulae. Finding useful features to represent the data, depending on the goal of knowledge discovery task. Using dimensionality reduction or transformation methods to summarize the data for intended knowledge discovery.

Chapter 11 ■ Database and Data Science

460

4.

Data mining. The fourth step is data mining. It involves application of core discovery procedures on the transformed data to reveal patterns and new knowledge. This includes searching for patterns of interest in a particular representational form or a set of such representations. Algorithms used for this purpose are known as data mining algorithms. Some popular types of data mining algorithms are classification rules or trees, regression, clustering, sequence modeling, dependency, and line analysis. Hence, data mining involves selection of method(s) for searching useful patterns in the data, such as deciding which models and parameters may be appropriate, and matching a particular data mining method with the overall criteria of knowledge discovery.

5.

Data interpretation/evaluation. The final step is data interpretation/evaluation. It involves interpreting the discovered patterns, as well as possible visualization of the extracted patterns. It first removes redundant or irrelevant patterns, and then uses visualization tools to translate remaining patterns into a form that is easily understandable to its user. The user then incorporates this knowledge into performance system, taking actions based on the knowledge, or documenting it and reporting it to interested parties.

Selection

Data from one/more sources

Pre-processing

Target data

Data assimilation

Data mining

Data warehousing Transformation

Preprocessed data

Data mining

Transformed data

Interpretation/ evaluation

Patterns

Knowledge

Iterative process Figure 11.16. The stages involved in data science.

Note from Figure 11.16 that the data science approach of knowledge discovery is not linear, but iterative and interactive. It involves feeding back the results of analysis into the modeling and hypothesis derivation process to produce improved results on subsequent iterations.

DATA WAREHOUSING Data warehousing is the process of creating a repository of integrated data, which users can use for decision support and analysis. A data warehouse is the resulting repository of integrated data. It is a subject-oriented, integrated, timevariant, and non-volatile collection of data, which (with proper analysis) supports management’s decision-making process. Key terms in this definition mean the following: 1.

Subject-oriented. This means that all data in a data warehouse is organized around a specific subject area from end-user perspective (such as, customers, products, or accounts) to rapidly provide information relating to this specific area. This is in contrast to most operational database systems, which organize data around the specific functions or activities of an application (such as, inventory control, pay-roll, or invoicing) to enable efficient access, retrieval, and update.

2.

Integrated. Data residing in many different operational database systems is often inconsistent in terms of coding and formats. On the other hand, even when a data warehouse sources data from multiple database systems (or multiple data sources), it ensures during the data cleaning process that all data in the data warehouse is consistent and uniform, thereby eliminating the issues of data incompatibility and portability.

3.

Time-variant. In operational database systems, data is accurate at the moment of access only. However, a data warehouse keeps all its data accurate until a specific point-in-time, and accumulates data over a long period. Due to this feature, data in a data warehouse provides a historical perspective.

■ Data Warehousing 4.

461

Non-volatile. Operational database systems continuously update their data on a record-by-record basis. On the other hand, a data warehouse loads data periodically in masses and allows access to it later. It does not allow update of its data and retains its integrity. Thus, data in a data warehouse is static, not dynamic. The only operations that occur in data warehouse applications are initial loading of data, access of data, and refresh of data. Due to this reason, physical design of a data warehouse optimizes access of data, rather than focusing on the requirements of data update and delete processing.

Need for a Data Warehouse Typically, an organization needs a data warehouse in one or more of the following situations: 1.

The organization has several operational database systems, but there is no mechanism to present a holistic view of information from the data stored in these databases.

2.

Same data is present on different operational database systems in different departments about which users are not aware, and/or different systems give different answers to same business questions.

3.

Decision makers and policy planners are not able to obtain easily decipherable, timely, and comprehensible information due to non-availability of appropriate tools.

4.

IT or business staff have to spend lot of time developing special reports for decision makers.

Building a Data Warehouse As Figure 11.16 shows, building a data warehouse involves the following processes: 1.

Data selection

2.

Data preprocessing/cleaning

3.

Data transformation

An earlier section has already described these processes. A data warehouse structures the transformed data in the form of multi-dimensional cubes so that different types of users (say from different departments of an organization) can view the same data in different forms depending on their interest. Data transformation tools are known as OLAP (OnLine Analytical Processing) tools. Finally, data access tools allow end users (decision makers) to easily access the desired information from the data warehouse without the help of any IT staff. Figure 11.17 shows the overall architecture of a typical data warehouse. OLAP tools Selection

Pre-processing

Transformation

Access tools Web tools

Data from one/more sources (Operational data, external data, etc.)

Target data

Preprocessed data

Transformed data (multidimensional cubes)

Client/Server tools

Applications Figure 11.17. Overall architecture of a typical data warehouse.

Data Warehousing Terminologies Some terminologies that we often encounter while dealing with data warehousing are described here.

462

Chapter 11 ■ Database and Data Science

OLTP and OLAP OLTP stands for On-Line Transaction Processing. It is the database architecture for transaction processing. OLTP describes systems that support day-to-day business operations. These are transaction-processing systems, with many users concurrently accessing a database to insert, retrieve, update, and delete individual records. Hence, OLTP systems have efficient mechanisms for entry, retrieval, and update of individual pieces of data. However, they do not have mechanisms to support complex, large-scale data analysis. On the other hand, OLAP stands for On-Line Analytical Processing. It is the database architecture for effective data analysis. OLAP describes systems that integrate data from one or more systems, then aggregate and transform the data to support effective decision-making. OLAP systems use the concept of multi-dimensional databases and allow users to analyze the data using elaborate, multi-dimensional, complex views. In short, OLAP helps an organization to decide what to do, and OLTP helps the organization to do it. Figure 11.18 lists the differences between OLTP and OLAP systems. Features

OLTP

OLAP

Stands for

On-Line Transaction Processing

On-Line Analytical Processing

Designed for

Supporting day-to-day business operations

Supporting effective data analysis

Used for

Implementing policy decisions

Making policy decisions regarding what to do

Structure optimized for

Transaction processing (entry, retrieval, and update of individual pieces of data)

Complex, large scale data analysis

Data model

Normalized

Multi-dimensional

Nature of access

Insert, retrieve, update, and delete records

Retrieve summarized information and load data in batches

Access tools

Query language

Query language and advanced analytical tools

Type of data stored

Data that runs the business

Data to analyze the business

Nature of data

Detailed

Summarized and detailed

Performance metric

Transaction throughput

Query analysis throughput

Figure 11.18. Differences between OLTP and OLAP systems.

Data Mart A data mart is a subset of an organization’s data warehouse. It contains data that is of value to a specific business unit or department of the organization, rather than the whole organization. It can contain both detailed and summarized data for each specific business area of an organization. A data mart captures data either from an organization’s operational systems or from the organization’s data warehouse. Users use a data mart to analyze data only for a single business area or department of an organization. Compare this with an organization’s data warehouse, which users use to analyze data across multiple business areas or departments of the organization. An organization can build a data mart at a much lower cost, time, and effort than that involved in building a data warehouse. Because of their low cost and shorter development time, data marts start giving an early payback, thus justifying return of investment.

■ Data Warehousing

463

Metadata Metadata is data about data. It is a catalog of information kept in a data warehouse. Typically, metadata of a data warehouse stores definitions of source data, target data, source to target mappings, transformation information, and update information. It is an integral part of a data warehouse, which exists along with the data warehouse.

Drill-down and Roll-up Analyses An end user can extract and view information from a data warehouse as per his/her requirement. Depending on the nature of analysis that the end user wishes to carry out on the data, he/she can start viewing information from either the highest level (most coarse-grained information summary) to the lowest level (most fine-grained information details) or vice-versa. Drill-down analysis is the process of viewing information from a higher-level view to a lower level view. Conversely, roll-up analysis is the process of viewing information from a lower level up to a higher level. For example, suppose there is a data warehouse containing citizen data for the whole country. A user can perform query analysis on the data warehouse to find the percentage of people area-wise in different occupations at city/village level, district level (each district comprising of several cities and villages), state level (each state comprising of several districts), and country level (the country comprising of several states). The user may perform drill-down analysis by starting the analysis at state level and gradually extracting this information for individual districts and cities/villages of interest. On the other hand, the user may perform roll-up analysis by starting the analysis at city/village level and gradually extracting aggregated information for districts, states, and the country.

ROLAP and MOLAP OLAP systems support effective decision-making. Two popular architectures for OLAP systems to enable this are MOLAP (Multidimensional OLAP) and ROLAP (Relational OLAP). Although, analytical abilities and interfaces of these two architectures are the same, they differ in the way they store data physically. MOLAP stores data in a proprietary multidimensional database (MDDB), from which users can view the data in a multidimensional manner. On the other hand, ROLAP stores data in a conventional relational database and users use query languages (like SQL) to perform analysis on the data. Relative advantages and limitations of the two architectures are as follows: 1.

Pre-identified queries are easier and faster to process with MOLAP than with ROLAP, because MOLAP can structure the multiple dimensions of a multidimensional database to handle such queries efficiently.

2.

Since MOLAP stores the same data in multiple dimensions, storage space requirement is more for MOLAP than for ROLAP. Hence, MOLAP has a limit on the physical database size that it can handle. ROLAP is scalable to several terabytes.

3.

MOLAP can handle a limited number of dimensions. ROLAP does not have any limit on the number of dimensions that it can handle.

4.

A proprietary multidimensional database is essential for implementation of MOLAP. ROLAP can use conventional relational database technology for its implementation.

Chapter 11 ■ Database and Data Science

464

Star and Snowflake Schemas Two commonly used schema models for designing data warehouses are star schema and snowflake schema. A data warehouse using star schema model consists of one fact (major) table and many dimension (minor) tables. Fact table stores the primary keys for all dimension tables. Figure 11.19 shows a simple example of a star schema. Here ‘sales’ is a fact table, whereas ‘customer’, ‘product’, ‘time’, and ‘store’ are dimension tables. The design appears like a star, with the fact table in the center, and radial linear connecting dimension tables to it. Main advantages of star schema are that it is easy to define, reduces the number of physical joins, and provides simple metadata. TIME

STORE SALES

CUSTOMER

PRODUCT

Figure 11.19. A sample star schema.

On the other hand, a data warehouse using snowflake schema model consists of normalized dimension tables by attribute level, with each smaller dimension table pointing to an appropriate aggregated fact table. Each dimension table has one key for each level of the dimension’s hierarchy. The lowest key, for example, store key of store dimension will join store fact table, which will also have product and time keys. Figure 11.20 shows an example of a snowflake schema. A practical way of designing a snowflake schema is to start with a star schema and create snowflakes with queries. Main advantage of snowflake schema is that it provides good performance for queries involving aggregation. TIME

REGION

STORE

REGION SUMMARY

SALES CUSTOMER

PRODUCT

PRODUCT CUSTOMER TIME

Figure 11.20. A sample snowflake schema.

DATA MINING Literal meaning of the term ‘mining’ is operations involved in digging for hidden treasures. Hence, ‘data mining’ means operations involved in digging out critical information from an organization’s data for better decision support. It is the process of identifying useful patterns from large databases or data warehouses. As Figure 11.16 shows, data mining is the core part of data science. Formally, data mining is defined as “the nontrivial process of extracting implicit, previously unknown, and potentially useful information from data”. Key terms in this definition mean the following: 1.

Nontrivial process. The term ‘process’ here means that data mining involves many steps including data preparation, search for patterns, knowledge evaluation, and refinement – all repeated in multiple iterations.

■ Data Mining

465

This process is ‘nontrivial’ in the sense that it goes beyond simple search for quantities, and involves search for structure, models, and patterns. 2.

Implicit information. This means that the information, which data mining process extracts is from within an organization’s data.

3.

Previously unknown information. This means that the structures, models, or patterns, which data mining process extracts are new knowledge that was previously unknown in the organization (hidden in the organization’s data).

4.

Potentially useful information. This means that the information, which data mining process extracts is useful for the users (for better decision support). Obviously, for being useful, it should be easily understandable by the users (if not immediately, then after some postprocessing).

Classification of Data Mining Algorithms Normally, many types of patterns exist in a large database. Extraction of different kinds of patterns requires different types of algorithms. Popular classes of algorithms for data mining are: 1. 2.

Classification, Clustering,

3. 4.

Association, and Trend analysis

They are described here.

Classification Classification algorithms classify the objects of a database (based on their attributes) into one of several predefined categorical classes. A classification algorithm first takes a set of objects as training set, and represents every object in this set by a vector of attributes along with its class. It then constructs a classification function or model by analyzing the relationship between the attributes and the classes of the objects in the training set. It then applies this classification function or model to all objects in a database to classify them into the already defined classes. This helps a user in having a better understanding of the classes of the objects in the database. A simple application of classification algorithm is to classify patient records of a patient database into different classes of diseases. Personal and clinical data of a patient’s record may be the attributes for classification. Hospital management personnel often need such classified information to make decisions such as how many doctors and other staff should they employ with certain speciality and skills, how many beds should they provide in different sections of the hospital, what types of medicines and in how much quantity should they stock.

Clustering Clustering algorithms partition the data space of a database into a set of clusters, and assign each object in a database to a cluster, either deterministically or probabilistically. A clustering algorithm identifies all sets of similar objects in a database, in some optimal fashion. It clusters the objects in a manner to maximize intra-cluster (objects belonging to the same cluster) similarities, and minimize inter-cluster (objects belonging to different clusters) similarities. It does this based on some criteria defined on the attributes of the objects. Once it decides the clusters, it summarizes the common features for objects in a cluster to form cluster description. It is important to understand the difference between classification and clustering algorithms. A classification algorithm classifies the objects of a database into predefined classes, whose number is predetermined before application of the classification algorithm to the database. However, a clustering algorithm groups the objects of a database into clusters, whose number is unknown before application of the clustering algorithm to the database. Thus, if we apply the same classification algorithm to two different databases, both will result in the same predefined

Chapter 11 ■ Database and Data Science

466

number of classes (say n, some of which may be null, if no object maps to them). On the other hand, if we apply the same clustering algorithm to two different databases, both may result in different, previously unknown number of clusters (say m and n). Also note that common features of objects in a class are pre-defined in a classification algorithm, but common features of objects in a cluster are summarized after all the objects have been put in the cluster. A simple application of clustering algorithm is to group the customers of a bank from its customer database into several groups based on similarities of their age, sex, income, and residence. After grouping the customers, bank management can examine summarized characteristics of each subgroup, extract significant statistics, and use them to understand its customers better, for offering more suitable products and customized services. Text mining area also uses clustering algorithms for solving problems such as document indexing and topic identification in research settings.

Association Association algorithms discover association rules hidden in a database. An association rule reveals associative relationships among objects. For example, an association rule may reveal a relationship such as “If some object X is a part of a transaction, then for some percentage of such transactions, object Y is also a part of the transaction”. Thus, association algorithms help in discovery of togetherness, or connection of objects. They are useful in solving those problems, in which it is important to understand the extent to which presence of some variables imply the presence of other variables, and prevalence of this pattern in the entire database under examination. An interesting application of association algorithm is market-basket analysis. It examines databases of sales transactions to extract patterns, which provide answers to sales-related queries such as: 1.

What items sell together?

2.

What items sell better when relocated to new areas?

3.

What product groupings improve department sales?

For example, market-basket analysis of a retail store’s database may reveal that customers tend to buy soft drinks and potato chips together. Store personnel then place potato chips near soft drinks to promote the sale of both items. They may even offer some discount to a customer who buys both the items (on combination purchase). Another useful application of association algorithm is analysis of Internet traffic on a website. Web designers use the results of such analysis to understand the information needs of users, and to organize the locations of web pages and linkages among them to make the website more convenient to use.

Trend Analysis Several large databases have time series data with timestamp (they accumulate records over time). For example, a company’s sales data over several years/months, a customer’s credit card transactions over a period, and fluctuations in stock prices over a period, are examples of time series data. Users can analyze such data to find certain historical trends. Trend analysis algorithms discover patterns and regularities in data evolutions along with time dimension. Users often find such patterns useful in making decisions for larger benefits in future. A simple application of trend analysis algorithm is to analyze historical trend of fluctuations in stock prices of various companies to predict future behavior. Stock market investors use such analysis results effectively to make investment decisions for better profitability.

■ Data Mining

467

Data Mining Techniques Data mining adopts several techniques drawn from different areas for implementing the algorithms discussed in earlier sections. Popular techniques for data mining are: Statistics, Machine learning, 3. Database-oriented,

Neural networks, Fuzzy sets, and 6. Visual exploration

1.

4.

2.

5.

They are described here. Most data mining systems employ multiple of these techniques to deal with different kinds of data, different data mining tasks, and different application areas.

Statistics Usually, statistical models use a set of training data. Statistical methods search for an optimal model among the hypothesis space based on a defined statistical measure. They then draw rules, patterns, and regularities from the model. Commonly used statistical methods in data mining are: 1.

Regression analysis. It maps a set of attributes of objects to an output variable.

2.

Correlation analysis. It studies correspondence of variables to each other, such as X2.

3.

Cluster analysis. It finds groups from a set of objects based on distance measure.

4.

Bayesian network. It represents causal relationships (what object/event is caused by which other objects/events) among variables in the form of a directed graph, which is computed by using Bayesian probability theorem.

Machine Learning Like statistical methods, machine-learning methods search for a model, which is closest to (best matches with) the data under testing. However, unlike statistical methods, searching space of machine-learning methods is a cognitive space of n attributes instead of a vector space of n dimensions. Besides that, most machine-learning methods use heuristics in search process. Commonly used machine learning methods in data mining are: 1.

Decision tree. Decision trees (which consist of nodes and branches) are a way of representing a series of rules for classification of a dataset. Hence, they classify objects in a dataset. A data-mining algorithm based on decision tree determines an object’s class by following a path of a decision tree from its root to a leaf node. It chooses the branches according to the attribute values of the object. Figure 11.21 shows a simple decision tree that classifies the employees of an organization into groups based on their age, sex, and salary. Decision trees are an attractive tool for data mining because they are simple to implement and their intuitive representation makes resulting classification model easy to understand.

2.

Inductive concept learning. It derives a concise, logical description of a concept from a set of examples.

3.

Conceptual clustering. It finds groups or clusters in a set of objects based on conceptual closeness among objects.

Chapter 11 ■ Database and Data Science

468

Age

=>40 and 50 Sex Male

Salary

Group A Female

Group B

0 bytes

Message type

Message length in bytes

Message content (Parameters of this message)

Contains one of the types in table below

Contains parameters corresponding to the message type

Message type

Message content (Parameters)

hello_request

null

client_hello

version, random, session id, cipher suite, compression method

server_hello

version, random, session id, cipher suite, compression method

certificate

chain of X.509v3 certificates

server_key_exchange

parameters, signature

certificate_request

type, authorities

server_done

null

certificate_verify

signature

client_key_exchange

parameters, signature

finished

hash value Figure 15.25. Format of messages in SSL Handshake Protocol.

■ Secure Socket Layer (SSL) and Transport Layer Security (TLS)

621

SSL Handshake Protocol It is a series of messages that a client and server exchange to establish a connection (and security capabilities associated with it) between them. Recall that an SSL connection between two parties is necessary before they can begin to exchange application layer data securely. Figure 15.25 shows the format of these messages. The Handshake Protocol messages can be partitioned into the following four phases (see Figure 15.26): 1.

Establish security capabilities

2.

Server authentication and key exchange

3.

Client authentication and key exchange

4.

Finish Client

Server Phase 1: Establish Security Capabilities client_hello server_hello

Phase 2: Server Authentication and Key Exchange certificate (optional) server_key_exchange (optional) certificate_request (optional) server_done

Phase 3: Client Authentication and Key Exchange certificate (optional) client_key_exchange certificate_verify (optional)

Phase 4: Finish change_cipher_spec finished change_cipher_spec finished

Figure 15.26. Handshake Protocol messages partitioned into four phases.

622

Chapter 15 ■ Information Security

The four phases are described here.

Phase 1: Establish Security Capabilities A client initiates this phase for establishing a SSL connection with a server. The client and server exchange messages in this phase to establish the security capabilities associated with the connection. The client sends a client_hello message with the parameters in Figure 15.27, and waits for server’s response. In response, the server sends a server_hello message with the parameters in Figure 15.28. Sr. No.

Parameter

Content

1

Version

Highest SSL version that the client understands.

2

Random

A structure containing a 32-bit timestamp and 28-bytes random number. The client generates it and uses it as nonce during key exchange to prevent replay attacks.

3

Session ID

A variable-length session identifier. A nonzero value indicates that the client wishes to update the parameters of an existing connection or create a new connection on this session. A zero value indicates that the client wishes to establish a new connection on a new session.

4

Cipher suite

A list containing cryptographic algorithms (in decreasing order of preference) that the client supports. Each element of the list (each cipher suite) defines both a Key exchange algorithm and a CipherSpec. Supported key exchange algorithms are RSA, Fixed Diffie-Hellman, Ephemeral Diffie-Hellman, Anonymous Diffie-Hellman, and Fortezza. CipherSpec contains the following fields – Cipher Algorithm (RC4, RC2, DES, 3DES, DES40, IDEA, or Fortezza), MAC Algorithm (MD5 or SHA-1), Cipher Type (Stream or Block), IsExportable (True or False), Hash Size (0, 16, or 20 bytes), Key Material (Sequence of bytes containing data used in generating the write keys), IV Size (Size of Initialization Vector for CBC encrypytion)

5

Compression method

A list of compression algorithms that the client supports. Figure 15.27. Parameters of client_hello message of Handshake Protocol.

Sr. No.

Parameter

Content

1

Version

Lower of the version suggested by the client and the highest supported by the server

2

Random

A structure containing a 32-bit timestamp and 28-bytes random number. Generated by the server and independent of client’s Random field

3

Session ID

If client’s Session ID field is nonzero, the server uses the same value; otherwise, it contains the value for a new session

4

Cipher suite

It is the cipher suite selected by the server from the list of cipher suites in client’s Cipher suite

5

Compression method

It is the compression algorithm selected by the server from the list of algorithms in client’s Compression method

Figure 15.28. Parameters of server_hello message of Handshake Protocol.

Phase 2: Server Authentication and Key Exchange This phase starts with the server sending a certificate message containing one or a chain of X.509 certificates. This message is optional. It is required for any agreed-on key exchange method except Anonymous Diffie-Hellman. The server then sends a server-key-exchange message. This message is optional. It is not needed either if the server has sent a certificate with Fixed Diffie-Hellman parameters, or if the protocol uses RSA key exchange. The message

■ Secure Socket Layer (SSL) and Transport Layer Security (TLS)

623

is needed in case of Anonymous Diffie-Hellman, Ephemeral Diffie-Hellman, Fortezza, or when the server uses RSA key exchange but has a signature-only RSA key. The server next sends a certificate_request message. This message is optional. It is required when a nonanonymous server (server not using Anonymous Diffie-Hellman) wants a certificate from the client. The message has the following two parameters: 1.

Certificate-type. It contains the public-key algorithm and its use such as RSA for signature only, DSS for signature only, RSA for Fixed Diffie-Hellman, DSS for Fixed Diffie-Hellman, RSA for Ephemeral DiffieHellman, DSS for Ephemeral Diffie-Hellman, or Fortezza.

2.

Certificate-authorities. It contains a list of distinguished names of acceptable certificate authorities.

The server then sends a server_done message, which is the last message of this phase. This message is mandatory and has no parameters. It indicates the end of server_hello and associated messages. The server waits for a client response after this.

Phase 3: Client Authentication and Key Exchange In this phase, the client verifies if the server provided a valid certificate (if the server sent certificates in the previous phase), and checks if the parameters received with server_hello message are acceptable. The client first sends a certificate message. This message is optional and is sent only if the server requested a certificate. If no suitable certificate is available, the client sends a no_certificate alert instead. The client then sends a client_key_exchange message, which is mandatory. The message contains appropriate parameters for the type of key exchange (RSA, Ephemeral Diffie-Hellman, Anonymous Diffie-Hellman, Fixed DiffieHellman, or Fortezza). The client finally sends a certificate_verify message in this phase. This message is optional and is only sent following any client certificate that has signing capability. This message provides explicit verification of a client certificate by signing a hash code based on the preceding message. The purpose is to verify the client’s ownership of the private key for the client certificate. Even if an intruder misuses the client’s certificate, he/she would be unable to send this message.

Phase 4: Finish This phase begins with the client sending a change_cipher_spec message. This message causes copying of pending state (CipherSpec) into current state (CipherSpec), which updates the cipher suite that the client and server use on this connection. Actually, this message is sent using the SSL Change Cipher Spec Protocol, and is not part of the SSL Handshake Protocol. The client then sends a finished message using the new algorithms, keys, and secrets. It verifies that the key exchange and authentication processes were successful. This phase ends with the server sending a change_cipher_spec message and a finished message in response to the client’s messages. The former message causes copying of pending state (CipherSpec) into current state (CipherSpec), and the latter message verifies that the key exchange and authentication processes were successful. With this, the four phases of the SSL Handshake Protocol complete. The client and server are now ready to exchange application layer data securely.

624 Chapter 15 ■ Information Security

Transport Layer Security (TLS) IETF produced TLS as an Internet standard version of SSL. TLS is similar to and backward compatible with SSLv3. As we already presented details of SSLv3 above, we present here the main differences between SSLv3 and TLS.

TLS Record Protocol Differences TLS and SSL record format are same (see Figure 15.21). The header fields have the same meanings. Only the values of Major version and Minor version fields are 3 and 1 respectively for the current version of TLS. TLS uses a different MAC computation algorithm than that used by SSLv3. It uses the HMAC algorithm defined in RFC 2104. In SSL, padding data added prior to encryption of user data is the minimum amount required to make the total size of the data to be encrypted a multiple of the cipher’s block length. However, TLS allows padding data to be of variable length. It can be of any amount so that the total size of the data is a multiple of the cipher’s block length, up to a maximum of 255 bytes. A user can use this feature to frustrate attacks.

TLS Change Cipher Spec Protocol Differences Cipher suites of SSLv3 and TLS are the same with the difference that TLS does not support Fortezza as a key exchange technique and as a symmetric encryption algorithm.

TLS Alert Protocol Differences TLS supports all the alert codes that SSLv3 supports with the exception of no_certificate. It supports additional alerts of both types (warning and fatal). Figure 15.29 lists these additional alerts.

TLS Handshake Protocol Differences TLS Handshake Protocol differs from that of SSLv3 Handshake Protocol in the following aspects: 1.

SSLv3 supports following certificate types in a certificate request message: rsa_sign, dss_sign, rsa_fixed_dh, dss_fixed_dh, rsa_ephemeral_dh, dss_ephemeral_dh, and fortezza_kea. Out of these, TLS does not support rsa_ephemeral_dh, dss_ephemeral_dh, and fortezza_kea.

2.

Parameters and calculation method for calculation of MD5 and SHA-1 hashes for certificate_verify message are different for TLS and SSLv3. TLS dropped certain parameters, which were not adding any additional security.

3.

Algorithms for cryptographic computations are different for TLS and SSLv3.

■ Secure Electronic Transaction (SET)

Alert level

Specific alert decrypt_error

Warning (Level = 1)

user_canceled

no_renegotiation

decryption_failed record_overflow unknown_ca Fatal (Level = 2)

access_denied decode_error

Meaning A handshake cryptographic operation failed. This may be because the party is unable to verify a signature, decrypt a key exchange, or validate a finished message. This handshake is being canceled for some reason unrelated to a protocol failure Client sends it in response to server_hello message, or server sends it in response to client_hello message after initial handshaking. Either of these messages would normally result in renegotiation, but this alert indicates that the sender is unable to renegotiate. Invalid decryption of a ciphertext. This may be due to the ciphertext not being an even multiple of the block length, or its padding values being incorrect Length of payload (ciphertext) of a TLS record exceeds 2 14 + 2048 bytes, or the ciphertext decrypted to a length greater than 2 14 + 1024 bytes Unacceptable certificate because the CA certificate could not be located or could not be matched with a known, trusted CA Sender denied access when access control was applied with a valid certificate Could not decode a message. This may be due to a field of the message being out of its specified range, or length of the message being incorrect

export_restriction

A negotiation is not in compliance with export restrictions on key length

protocol_version

Cleint’s protocol version is recognized but not supported

insufficient_security internal_error

625

A negotation failed because the server requires ciphers more secure than those supported by the client Impossible to continue due to an internal error, which is unrelated to the peer or the correctness of the protocol.

Figure 15.29. Additional alerts in TLS Alert Protocol.

SECURE ELECTRONIC TRANSACTION (SET) Today, credit/debit card transactions on the Internet are common phenomena. Several companies offer their services and products to consumers through the Internet, and consumers make purchases online and pay through credit/debit cards. An important component of online transactions is security component, which enables the parties involved to employ the existing credit/debit-card payment infrastructure on an open network (such as the Internet) in a secure manner. SET is such a security component, whose initial specification was developed in 1996 by a consortium of companies including Microsoft, Netscape, RSA, IBM, and Verisign. It is a set of security protocols and formats, which provides the following three services to ensure secure credit/debit-card transactions (also called electronic transactions) on an untrusted network: 1.

Creates secure communication channels among the parties involved so that they can exchange information securely.

2.

Provides trust to users by using X.509v3 digital certificates.

3.

Ensures privacy of information by handling all information in such a manner that it makes a piece of information in a transaction available to only concerned parties whenever necessary.

Chapter 15 ■ Information Security

626

Parties Involved in an Electronic Transaction An electronic transaction involves the following parties: 1.

Customer. A customer is an individual or corporate who holds a valid payment card (credit/debit card) issued by an issuer. A customer makes on-line purchases of goods or services offered on the Internet.

2.

Issuer. An issuer issues payment cards to customers. Usually, it is a financial institution (such as a bank) supporting electronic payment and SET. An issuer is responsible for making actual payment for purchases made by a customer against a valid payment card issued by the issuer. It maintains accounts for customers to whom it issues payment cards.

3.

Shopkeeper. A shopkeeper is an individual or organization that has arrangements (Website, e-mail, etc.) for on-line selling of products or services to customers. Shopkeepers accept payments from customers through payment cards, and for this they have an account with an acquirer.

4.

Acquirer. It is natural for a shopkeeper to accept payments made using payment cards from multiple issuers. However, a shopkeeper does not want to deal with multiple individual issuers because their number is large. Hence, an acquirer serves as an intermediate entity between issuers and shopkeepers. An acquirer is a financial institution that maintains accounts for shopkeepers and has network connection with issuers’ financial processing systems. When a customer makes card payment to a shopkeeper, the acquirer provides authorization to the shopkeeper that the specified card number is valid and that the proposed purchase does not exceed the credit limit (in case of credit card) of the customer. The acquirer also provides electronic transfer of payments to the shopkeeper’s account for the purchase. Subsequently, the issuer of the payment card used in this transaction reimburses the acquirer for electronic funds transfer over a payment network.

5.

Payment gateway. It is a specially configured system interfacing between SET and the existing payment card networks for authorization and payment functions. Usually, the acquirer or a designated third party owns it, and it has network connection with the acquirer’s financial processing system. A shopkeeper exchanges SET messages with the payment gateway over the Internet, while the payment gateway processes the messages and interacts with the acquirer’s financial processing system to enable electronic transfer of payment to the shopkeeper’s account.

6.

Certification Authority (CA). SET assumes availability of PKI infrastructure having a hierarchy of CAs (discussed later in this chapter). A CA is a trusted entity that issues X.509v3 public-key certificates to customers, shopkeepers, and payment gateways.

An Electronic Transaction Process An electronic transaction process involves the following sequence of events: 1.

A customer applies for and acquires a payment card from an issuer. The issuer verifies the identity of the customer and issues a duly signed X.509v3 digital certificate to the customer. The certificate verifies customer’s RSA public key and its expiration date. It also correlates the customer’s key pair with his/her payment card.

2.

The customer selects items that he/she wants to purchase from a shopkeeper’s products/services information location (say website) and sends a list of items to the shopkeeper.

3.

The shopkeeper prepares an order form for the customer and returns it to the customer. The order form contains the list of items selected by the customer, their price, total price, and an order number. Along with the order form, the shopkeeper also sends a copy of its certificate to enable the customer to verify the shopkeeper’s validity.

4.

The customer then sends order and payment information to the supplier along with a copy of its certificate to enable the shopkeeper to verify the customer’s validity. Order information (OI) confirms the purchase of the

■ Secure Electronic Transaction (SET)

627

items in order form, while payment information (PI) contains customer’s payment card details. The shopkeeper cannot read payment information because it receives only its message digest. 5.

The shopkeeper forwards payment information to payment gateway with a request to validate the customer’s credit limit against the total price of this order.

6.

Payment gateway, in turn, interacts with the acquirer to validate the customer’s payment card and its credit limit, and responds to the shopkeeper’s request.

7.

The shopkeeper then sends a confirmation message to the customer confirming the order, and ships the items or provides the services to the customer.

8.

The shopkeeper then sends a payment request message to the payment gateway, which processes the message and interacts with the acquirer to enable electronic transfer of payment to the shopkeeper’s account.

Security Requirements of an Electronic Transaction Process To be secure, an electronic transaction process requires the following security measures: 1.

Customer account authentication. A shopkeeper should be able to verify that a customer using a payment card is a legitimate user of a valid payment-card account number.

2.

Shopkeeper authentication. A customer should be able to verify that a shopkeeper has a relationship with a financial institution allowing it to accept payment through a payment card.

3.

Confidentiality of information. The system should ensure confidentiality of both order information (OI) and payment information (PI) as they travel across the network. Moreover, the system should reveal information of certain type only to the party concerned (party that needs that information for transaction processing). For example, the system should reveal OI only to the shopkeeper (not to the acquirer) and PI only to the acquirer (not to the shopkeeper).

4.

Data integrity. The system should ensure integrity of both OI and PI as they travel across the network. No one should be able to alter the contents of messages containing this information while the messages are in transit.

How SET Meets These Security Requirements? SET uses the following mechanisms to meet the security requirements of the electronic transaction process: 1.

Customer account authentication. SET uses X.509v3 digital certificates with RSA digital signatures for customer account authentication. Recall that the customer sends a copy of his/her certificate to the shopkeeper along with OI and PI to enable the shopkeeper to verify that the customer is a legitimate user of a valid payment-card account number.

2.

Shopkeeper authentication. SET uses X.509v3 digital certificates with RSA digital signatures for shopkeeper authentication. Recall that the shopkeeper sends a copy of its certificate to the customer along with the order form to enable the customer to verify that the shopkeeper has a relationship with a financial institution for accepting payments through payment cards.

3.

Confidentiality of information. SET uses conventional encryption by DES to ensure confidentiality of information. It further ensures that the system reveals information of certain type only to the party concerned by using a special innovative mechanism called dual signature mechanism. The mechanism links two related messages that are for two different recipients in such a manner that the two items are kept separate, but the link enables resolving of disputes (if required). The mechanism is described later.

4.

Data integrity. SET uses RSA digital signatures, using SHA-1 hash code, to ensure data integrity. It also protects certain messages by HMAC using SHA-1.

Chapter 15 ■ Information Security

628

Note that IPSec and SSL/TLS provide many choices for each cryptographic algorithm, but SET provides only one choice for each cryptographic algorithm. This is because SET is a single application having only a single set of requirements, whereas IPSec and SSL/TLS are general-purpose security solutions for a range of applications.

Dual Signature Mechanism of SET Dual signature mechanism is a special innovative mechanism of SET that it uses to ensure that the system reveals information of certain type to only the party concerned. The mechanism links two related messages that are for two different recipients in such a manner that the two items are kept separate, but the link enables resolving of disputes (if required). For example, in electronic transaction process, the customer sends order information (OI) and payment information (PI) to the shopkeeper. Out of these, OI is for processing by the shopkeeper and PI is for processing by the acquirer. Shopkeeper need not know the details of PI, whereas acquirer need not know the details of OI. The system can win extra trust and confidence of customers by keeping these two items separate. However, the system must maintain a link between the two items to enable the customer to prove that this payment is for this order and not for some other order. The mechanism works as follows (see Figure 15.30). When the customer sends OI and PI to the shopkeeper, SET separately takes hash of the two related messages (OI and PI) using SHA-1 to obtain MDOI (Message Digest of OI) and MDPI (Message Digest of PI). It then concatenates MDOI and MDPI and takes hash of the result to obtain MDHOIPI (Message Digest of Hashed OI and PI). Finally, it encrypts MDHOIPI using the customer’s private (secret) signature key (S c) to obtain DS (Dual signature). Hence, DS = E (Sc, [H (H(OI) ║ H (PI))]) where H and E denote hash and encryption operations respectively.

OI Order Information

H

MDOI



PI Payment Information

H

Sc

H

MDHOIPI

E

DS

MDPI

OI = Order information PI = Payment information H = Hash function (SHA-1) ║ = Concatenation MDOI = Message digest of OI MDPI = Message digest of PI

MDHOIPI = Message digest of concatenated MDOI and MDPI E = Encryption algorithm (RSA) Sc = Customer’s private (secret) signature key DS = Dual signature

Figure 15.30. Dual signature construction process.

Now let us see how the shopkeeper verifies the signature. While placing the order, the customer’s system sends DS, OI, MDPI, and a copy of the customer’s certificate to the shopkeeper’s system. Hence, the shopkeeper has the following information for verification: 1.

Dual signature (DS) received from the customer.

■ Secure Electronic Transaction (SET) 2.

Order information (OI) received from the customer.

3.

Message digest of PI (MDPI) received from the customer.

4.

Customer’s public key (Pc) taken from customer’s certificate.

629

The shopkeeper’s system verifies the signature as follows: 1.

It first decrypts DS using Pc to obtain H (H(OI) ║ H(PI)), which is MDHOIPI (Message Digest of Hashed OI and PI).

2.

It then takes hash of OI using SHA-1 to obtain MDOI.

3.

It next concatenates MDOI and MDPI and takes hash of the result to obtain MDHOIPI = H (MDOI ║ MDPI).

4.

Finally, it verifies the signature by comparing the two values of MDHOIPI obtained in Steps 1 and 3 (they should be equal for successful verification).

Notice that the shopkeeper does not know the details of PI in this process because it receives only the message digest of PI. Now let us see how the acquirer verifies the signature. After receiving customer’s order, the shopkeeper forwards payment information for the order to payment gateway, which in turn interacts with the acquirer to validate the customer’s details. The shopkeeper’s system sends DS and MDOI to payment gateway, which forwards this information to acquirer’s system. Hence, the acquirer has the following information for verification: 1.

Dual signature (DS) received from the shopkeeper.

2.

Message digest of OI (MDOI) received from the shopkeeper.

3.

Payment information (PI) of the customer obtained from customer’s payment card issuer by using the network linkage with it. The issuer maintains a database of PI of all customers to whom it issues a payment card.

4.

Customer’s public key (Pc) taken from customer’s certificate, which it obtains from customer’s payment card issuer. As an issuer issues digital certificates to customers, it maintains a database of digital certificates of all customers to whom it issues a payment card.

The acquirer’s system verifies the signature as follows: 1.

It first decrypts DS using Pc to obtain H (H(OI) ║ H(PI)), which is MDHOIPI (Message Digest of Hashed OI and PI).

2.

It then takes hash of PI using SHA-1 to obtain MDPI.

3.

It next concatenates MDOI and MDPI and takes hash of the result to obtain MDHOIPI = H (MDOI ║ MDPI).

4.

Finally, it verifies the signature by comparing the two values of MDHOIPI obtained in Steps 1 and 3 (they should be equal for successful verification).

Notice that the acquirer does not know the details of OI in this process because it receives only the message digest of OI. Also, notice that the mechanism has enabled the customer to link OI and PI so that the customer can prove the linkage whenever required. Hence, even if the shopkeeper has malicious intention to link another OI (in place of the genuine OI) with this transaction, he/she will not be able to do so.

Chapter 15 ■ Information Security

630

MANAGEMENT OF PUBLIC KEYS Public-key cryptography is the primary mechanism for secured communication between two entities in an open network (where users freely join and quit) like the Internet. This is because: 1.

It enables secure communication between users who do not share a common key (private-key cryptography requires common key sharing).

2.

It also enables signing of messages without the need for a trusted third party to be present.

3.

Signed messages, in turn, enable a receiver to verify the integrity of received messages.

However, when two entities (say A and B) in an open network want to communicate securely using public-key cryptography, they must first exchange their public keys with each other. The two entities must be able to exchange public keys securely to prevent third party intrusion in the communication process. For this purpose, the Internet Engineering Task Force (IETF) has proposed the use of the following two concepts: 1.

Certification Authority (CA)

2.

Public Key Infrastructure (PKI)

Certification Authority (CA) A CA is an organization that issues public key certificates to users. A public-key certificate (known as certificate in short) binds the public key of a user (generated by the CA) with his/her/its details such as name, address, e-mail, etc. Hence, a certificate contains a user’s public key (issued by the CA) and his/her/its details. While issuing a certificate to a user, the CA also issues a signed hash of the certificate to the user. It calculates the hash of the certificate using SHA-1 (Secure Hash Algorithm) hash function and signs it with its own (CA’s) private key. Note that a user may request for a certificate in on-line or off-line mode. In case of on-line request, the CA issues the certificate in the form of a reply message, whereas in case of off-line request, it issues the certificate on an electronic media such as a CD. The CA normally charges a fee for issuing certificates. Public key details Subject’s public key

Other details

ID of the public key algorithm

Field

Detail information (Includes types of fields shown below)

Signature details Certificate’s signature (signed by CA’s private key)

ID of the signature algorithm

Meaning

Version No.

Version number of X.509 (currently it has three versions)

Serial No.

Certificate’s serial number, which when combined with CA’s name/ID uniquely identifies the certificate

Issuer

X.500 or DNS name of the CA

Issuer ID

An optional ID, which uniquely identifies the issuer

Subject

X.500 or DNS name of the subject (user requesting the certificate)

Subject ID

An optional ID, which uniquely identifies the subject

Validity period

Period (starting and ending times) for which the certificate is valid Figure 15.31. Basic fields of an X.509 certificate.

■ Management of Public Keys

631

To simplify the problem of managing certificates of different kinds, the International Telecommunications Union (ITU) has defined a standard for certificates, which is called X.509. It is widely used on the Internet. Figure 15.31 shows its primary fields. A user (say A) can publish his/her/its certificate on his/her/its website because there is no need to keep a certificate secret/protected. When another user B wants to communicate securely with A, it downloads A’s certificate, which includes the public key of A and the signature of the certificate signed by the CA. The signature of the certificate that goes along with the public key prevents third party intrusion in the communication process between A and B.

Public Key Infrastructure (PKI) A single CA to issue all certificates in the world would have the following problems: 1.

Scalability. It is not a scalable solution. It cannot handle all the requests for certificates in the world efficiently, and would become a performance bottleneck.

2.

Reliability. It is not a reliable solution. It suffers from a single point of failure. Failure of the CA would bring down Internet security to a halt.

Hence, in addition to the concept of CA, IETF evolved and proposed the use of an entire infrastructure for issue and management of public keys. This infrastructure is called PKI. It consists of a set of hardware, software, people, policies, and procedures needed to create, manage, store, distribute, and revoke digital certificates based on publickey cryptography. It enables secure, convenient, and efficient issuing and management of public keys. PKI has the following elements: 1.

End entity. It denotes a subject that makes certificate related requests (issue of a new certificate, revocation of a certificate, key pair update, key pair recovery, etc). A subject can be a person (user) or a device (server, router, etc.).

2.

Certification Authority (CA). A CA issues and revokes certificates. Revocation of an issued certificate is required when a subject holding the certificate abuses it in some way, or the subject’s private key is somehow exposed, or the CA’s private key is compromised. PKI’s mechanism for revocation of certificates is that a CA periodically issues a CRL (Certificate Revocation List) giving serial numbers of all certificates that it has revoked. PKI allows existence of multiple CAs. A simple form of PKI is a hierarchy of CAs. The top-level CA is called the root. It certifies second-level CAs, which are called RAs (Regional Authorities) because each RA normally covers a geographic region, such as a country. These in turn certify the next level CAs and so on. Actually, the leaf-CAs issue the X.509 certificates to end entities. When a CA authorizes a new CA below it, it generates an X.509 certificate stating that it has approved the new CA, includes the new CA’s public key in it, signs it, and hands it to the new CA. When a leaf CA issues a certificate to an end entity, it generates an X.509 certificate and issues a signed hash of the certificate to the end entity along with the certificate. The assumption in PKI is that everyone knows the root’s public key. To avoid the problem of deciding who runs the root, PKI allows many roots. Hence, a hierarchical PKI is actually a forest of CAs with many trees of CAs, each tree having its own root. To make public keys of roots known to end entities, modern browsers come pre-loaded with public keys of over 100 roots, which are known as trust anchors. In this manner, PKI avoids the requirement of having a single worldwide trusted authority.

3.

Repository. It denotes the method, which a PKI uses for storing certificates and CRLs so that the system can service requests of end entities easily and quickly. Obviously, the method also decides the place where the system stores the certificates and CRLs. PKI systems use DNS and X.500 directory standards for this purpose.

Chapter 15 ■ Information Security

632

PKI supports the following management functions: 1.

Registration. It enables an end entity (a user) to enroll itself in a PKI. The user first registers itself with a CA using this function. Registration process involves mutual authentication of the user and the CA, and issue of one or more shared secret keys to the user by the CA. The user uses it for subsequent authentication.

2.

Initialization. It installs necessary client software on a client’s system (an end entity’s system) to enable it to operate securely in the PKI system of which the client system becomes part on registration with a CA. Client software establishes relationship with keys stored elsewhere in the infrastructure.

3.

Certification. It issues a certificate for a user’s public key and returns the certificate to the user’s system (client system) and/or publishes that certificate on a website or a public bulletin board.

4.

Cross certification. It enables two CAs to establish a cross certificate. A cross-certificate is a certificate, which a CA issues to another CA that contains a CA signature key for issuing certificates (recall the hierarchical PKI structure in which the root certifies second-level CAs, which in turn certify the next-level CAs, and so on).

5.

Revocation. It enables an authorized entity to request a CA for revocation of a certificate. The request includes the reason for revocation (such as compromise of private key, change of name or affiliation of a user, etc.)

6.

Key pair recovery. It enables a user (end entity) to recover a lost key of a key pair. We saw that several security mechanisms (such as encryption and decryption of information; creation and verification of digital signatures; etc.) deal with a pair of keys, and will cease to function if one of the keys is lost. Loss of key may happen due to various reasons such as a user forgetting a password, a hard disk crash, etc. In such a situation, a user uses this function to recover a key of a key pair from an authorized backup facility, which the CA that issued the user’s certificate normally maintains.

7.

Key pair update. A certificate normally has a lifetime associated with it, after which it expires. Hence, a certificate needs update either when its lifetime expires or on a valid revocation request. The system uses this function to update certificates (key pairs).

STEGANOGRAPHY What is Steganography? Criminals, spies, and terrorists are always in search of better ways to communicate with one another without detection by police and intelligence officers. With proliferation of information technology, they have found a new way to communicate with one another called steganography. Steganography is derived from Greek words steganos (meaning “covered”) and graphein (meaning “writing”). Hence, steganography is a technique of hiding secret messages within the code representing a standard computer file in such a way that normal users cannot make out the difference between a file without the hidden secret message and a file with the hidden secret message. Only communicating entities can make out this difference and extract the hidden secret message from such a file. The file could be that of any media such as word-processed text, static image, audio recording, or video. Intruders use a steganography algorithm to embed such secret messages in a file, and usually share it only within the closed community of beneficiaries. Typically, a key parameterizes such embedding, and it is difficult for anyone to detect or extract the embedded secret message without the knowledge of this key. The most common method of steganography makes small changes to a JPEG or other image via bits of information that represent the hidden message, which could be plain or encrypted text or another image. Each pixel in an image has at least one visually unimportant bit whose value can be altered to accommodate hidden information without making any noticeable change in the image. Figure 15.32 shows an example of such an image.

■ Steganography

Image without hidden message

633

Image with hidden message

Figure 15.32. An example of image steganography.

Mechanism to Detect Steganographically-hidden Message Steganalysis deals with techniques to determine whether a file contains a steganographically-hidden message. It employs mathematical techniques or artificial neural networks to statistically scan digital files and then examine them for changes in pixel values to detect the likely presence of steganographically-hidden data. For example, in an image with no steganogrpahy, the number of pixels with even values, based on their position on a gray or color scale, and the number with odd values will be very different. In an image with steganographically-hidden data, the numbers are almost equal. This provides a simple statistical test for steganography. Figure 15.33 shows how a steganalysis system typically works. Note that a steganalysis system of the type in Figure 15.33 can only detect if a file contains steganographically-hidden message or not. It cannot decrypt hidden data. Steganalysis systems, which can also decrypt hidden data, require different tools and are quite sophisticated.

Input image

Extract statistical features

Neural net computations

Output > Threshold value

Compare output with threshold value

Image probably contains steganographically-hidden message

Output , =, etc. Logo An easy-to-learn programming language used to teach problem-solving skills to children. Long Term Evolution (LTE) A standard for 4G technology. Loop A sequence of instructions executed repeatedly until a terminal condition occurs. Loop structures Statements provided in programming languages to repeat the execution of a statement or a block of statements. Looping logic See Iteration logic. Loosely-coupled system A multiprocessing system in which processors do not share memory, and each processor has its own local memory. Low-level languages Programming languages that normally translate from one source instruction to one object instruction. They are machine dependent. LSI (Large Scale Integration) The process of integrating a large number of electronic circuits on a single, small chip of silicon or other material.

673

Lycos An Internet search engine.

M Mac OS The operating system designed by Apple Incorporation for its Macintosh series of personal computers. Machine language A low-level language directly understandable by a computer. Each model of a computer has a unique machine language. Macro A sequence of frequently used operations, or keystrokes bundled together as a single command, or keystroke by software, so that the invocation of a single command or keystroke leads to the invocation of all the operations/keystrokes in the specified sequence. This helps speed user interaction with a system. Macro flowchart A flowchart that outlines the main segments of a program, or shows less detail. Macro instruction An instruction in a source language that is equivalent to a specified sequence of machine instructions. Magnetic core Tiny rings made of magnetic material that can be polarized to represent a binary 1 or 0. Magnetic disk See Disk. Magnetic Ink Character Recognition (MICR) A technology used by banking industry for faster processing of large volume of cheques. This technology also ensures accuracy of data entry, because most information on the cheque is pre-printed and fed to the computer directly. Magnetic storage Storage devices such as disks, drums, tapes, cores, etc., which utilize the magnetic properties of materials to store data. Magnetic strip card An electronic card having a magnetic strip on its back in which encoded data is stored. It can store much more data per unit of space than printed characters or bar codes can store. Magnetic tape A secondary storage device that uses a long plastic strip coated with a magnetic material as a recording medium. Magneto-optical disk A storage disk that integrates optical and magnetic disk technologies to enable rewritable storage with laser-beam technology. Mail-merge A feature of word-processing packages that enables merging of information from a database with a document generated by word-processing to create multiple copies of the document. For example, merging a letter with the addresses in a database to generate personalized letters.

674

■ Foundations of Computing

Main memory

See Primary storage.

Mainframe system A computer system that is mainly used for handling the bulk of data processing of such organizations as banks, insurance companies, hospitals, railways, etc. They are also used in such environments where a large number of users need to share a common computing facility such as in research groups, educational institutions, engineering firms, etc. Maintenance utility A file utility that copies data from one or more files to a new file selectively, or updates a file’s contents selectively. Management Information System (MIS) An organized collection of people, procedures, and devices used to provide the right information to the right person at the right time for proper decisionmaking. Manufacturer-programmed ROM ROM in which data is burnt in by the manufacturer of the electronic equipment in which it is used. Markup language A language that is used primarily to format text documents. A user uses it to specify a set of annotations (also called markup conventions) with a text document to indicate what format (such as font type, style, and font size) the user wants to apply to each part of the text document. Hence, a user uses a markup language to specify the structure of a text document, (the form in which the user wants to display/print the document). Masquerading A method of passive attack in which an intruder masquerades as an authorized user or program in order to gain access to unauthorized data or resources. Mass storage Storage systems that provide access to several terabytes of stored data. They use multiple units of storage media (such as multiple disks, multiple tapes, multiple CD-ROMs) as a single secondary storage device.

Maxterm A Boolean quantity consisting of all terms (in its normal form or complement form) ORed together. Any combination (2 n for n variables) of terms and complements is permissible, provided all are included in the term. Mechanical mouse A mouse having a ball inside it that partially projects out through an opening in its base and rolls due to surface friction when the mouse is moved on a flat surface. Media center computer A general-purpose electronic equipment for homes that can alone serve the purpose of all types of electronic entertainment equipment (such as television, music system, DVD/VCD player/recorder, videogame gadgets like playstation/gameboy, etc.) in addition to performing the jobs of a personal computer. Medical informatics Deals with computer applications in medical domain. The main objective of such applications is to optimize acquisition, storage, retrieval, and use of healthcare data for offering better healthcare services. Medium Scale Integration (MSI) A circuit with about 100 transistors fabricated on a single chip. Megabytes (MB) Memory storage equal to 1,048,576 (220) bytes in a computer. Memory A device or medium that can accept data, hold them, and deliver them on demand at a later time. Memory Address Register (MAR) A register that holds address of the active memory location and is loaded from program control register when an instruction is read from memory. Memory Buffer Register (MBR) A register that holds contents of the memory word read from, or written in, memory. Memory card Flash memory based cards that are available as removable storage device in different types of electronic equipment (such as digital camera).

Massive MIMO A key technology used in WWWW (5G).

Memory dump Contents of memory duplicated on another storage device or printed on a printer.

Massively Parallel Processing (MPP) An approach to designing supercomputers in which thousands of processors are integrated within a single computer, so that the supercomputer can perform thousands of tasks simultaneously.

Memory interleaving A technique used to minimize memory-processor speed mismatch. The memory is divided into multiple equal-size modules, which can be simultaneously accessed for better performance.

Master file A file containing relatively permanent data. This file is often updated by records in a transaction file. Max heap If the value of each node in a heap is greater than or equal to those of its children (if any), then the heap is called max heap.

Memory management A module of an operating system that takes care of main memory for overall system performance. It keeps track of free and occupied (in use) parts of memory, allocates memory to processes when they need it, and deallocates when they no more need.

■ Glossary Memory partition In a multiprogramming system, the area occupied by each job residing simultaneously in the main memory. Menu A list of processing choices displayed on the screen from which a user may select. Menu bar A menu in which options are displayed on a horizontal bar (usually at the top of the screen) displayed across the screen. Merging utility A file utility that combines records of two or more ordered (sorted) files into a single ordered file. Message In OOP, message serves as the mechanism to support communication between objects. Message interface See Message protocol. Message protocol In Object-Oriented Programming (OOP), the entire collection of methods of an object is called its message protocol or message interface. Message switching A data communication method in which data (message) to be sent is first appended with destination address, and then sent across the network to its destination. Message-passing system A distributed memory system in which all interactions between processes running on different computers take place by message passing. Messages A key element of object-oriented paradigm similar in use to function calls. Messages are requests to perform an operation on an instantiated object. Metadata A catalog of information that keeps track of what is where, in a data warehouse. In short, it is data about data, which provides users and developers with a road map to the information in the data warehouse. Method In OOP, a method of an object defines the set of operations that the object will execute when a message corresponding to the method is received by the object. Metropolitan Area Network (MAN) Networks that share some of the characteristics of both LANs and WANs. They usually interconnect computers spread over a geographical area of about 50 kilometers. Micro Channel Architecture (MCA) bus A 32-bit data bus that transmits data along 32 data lines. It was designed to accept and use the old ISA expansion slots. Micro flowchart A flowchart with more details. It is also called a detailed flowchart. Microarray data analysis A branch of bioinformatics that deals with use of computational methods for

675

monitoring and analyzing gene expression profiles of thousands of genes simultaneously. Microbrowser A browser for use with Internetenabled mobile devices. Microcode The very basic directions that tell the CPU how to execute an instruction; located in control unit. Microcomputer The smallest category of computer fabricated using a microprocessor, and other integrated circuits, namely a ROM, RAM, and I/O interface chips. Microfiche An output device that uses combined electronic, photo-optical, and electromechanical techniques to convert digital computer output to records that can be stored as rolls of microfilm or as frames of microfilm stored on cards called microfiche. Microfilm See Microfiche. Microkernel Technology that allows operating systems to be modeled and designed in a modular fashion. Microprocessor An IC chip that contains all the circuits needed to perform arithmetic, logic, and control functions, (core activities of all computers), on a single chip. Microprogram Firmware programs residing in readonly memory (ROM). They deal with low-level machine functions, and are essentially substitutes for additional hardware. Microsecond One-millionth of a second. Microwave system A data transmission media that uses very high frequency radio signals to transmit data through space (wireless communication). However, at microwave frequencies, electromagnetic waves cannot bend or pass obstacles like tall buildings or hills. Hence, transmitter and receiver of a microwave system, mounted on very high towers, should be in line-of-sight. Middleware A separate software layer that acts as “glue” between the client and server parts of an application and provides a programming abstraction as well as masks the heterogeneity of the underlying networks, hardware, and operating systems from the application programmers. Millimeter Wave Mobile Communication A key technology used in WWWW (5G). Millisecond One-thousandth of a second. Min heap If the value of each node in a heap is less than or equal to those of its children (if any), then the heap is called min heap.

676

■ Foundations of Computing

Minicomputer A mainframe system having smaller configuration (slower host and subordinate computers, lesser storage space, and fewer user terminals). Minterm A Boolean quantity consisting of all terms (in its normal form or complement form) ANDed together. Any combination (2 n for n variables) of terms and complements is permissible, provided all are included in the term. MIPS Millions of Instructions Per Second. Mirroring A RAID technique in which the system stores the same data on two disks, so that it improves fault tolerance capability. Mnemonic Any kind of mental trick used to help us remember. For example, a computer may be designed to interpret the machine code of 1111 (binary) as subtract operation, but it is easier for a human being to remember it as SUB. Mobile computing Wireless computing systems that support mobility of computing equipment, which users use to access the resources associated with a wireless network. It enables mobile users to access information from anywhere and at anytime. Also known as nomadic computing. Mobile radio networks Wireless networks which employ narrow bands for creating mobile radio network infrastructure.

Monitor A popular output device used for producing soft-copy output. It displays the output on a screen. Monolithic kernel An operating system design approach in which the operating system kernel provides most operating system services such as process management, memory management, device management, file management, and security. Motherboard Main circuit board of a computer system. It has CPU chip, RAM chips, ROM chips, I/O handling chips, etc. mounted on it. Also known as system board. Motion Pictures Experts Group (MPEG) A standard data compression technique for digital video. Motion video card A hardware that enables integration of full-motion color video/audio with other output on monitor’s screen. Mouse A small, hand-held input device that serves as an effective point-and-draw device in today’s computers. MPEG audio A standard data compression technique for digital audio. MS-DOS Stands for Microsoft Disk Operating System. A single-user operating system that was popularly used for personal computers in the 1980s.

Mobile wireless system See Mobile computing.

Multhithreading A popular technology that is used to improve application performance through parallelism.

Moderated newsgroup A newsgroup in which only selected members have right to post (write) a message directly on a virtual notice board.

Multi-access bus network A network in which a single transmission medium is shared by all nodes.

Modularity A key element of object-oriented paradigm, which defines the unit of reuse. These units group abstractions together.

Multicomputer system A system that consists of multiple computers interconnected together by a communication network.

Modulation Technique of converting a digital signal to its analog form. Three forms of modulation are Amplitude Modulation (AM), Frequency Modulation (FM), and Phase Modulation (PM).

Multicore operating system A system, which can run multiple programs simultaneously on a multicore chip with each core handling a separate program.

Modulation protocols To make modems of different manufacturers interoperable, Consultative Committee for International Telephony and Telegraphy (CCITT) has defined standards (called modulation protocols) for modems. MOdulator-DEModulator (Modem) Devices used to convert digital signals to analog form at sending end, and back to digital form at receiving end, when an analog communication channel (such as telephone line) is used for data communication. Molecular phylogenetics A branch of bioinformatics that deals with using computers to make classes, super classes, and abstract classes of all organisms.

Multicore processors It is a new approach for building faster processors. A multicore processor chip has multiple cooler-running, more energy-efficient processing cores instead of one increasingly powerful core. The multicore chips do not necessarily run as fast as the highest performing single-core models, but they improve overall performance by handling more work in parallel. For instance, a dual-core chip running multiple applications is about 1.5 times faster than a chip with just one comparable core. Multidimensional array An array in which each array element is indexed by an ordered list of same number of integers.

■ Glossary Multihop wireless networks Wireless networks designed to provide wireless communications capability in an environment where there is no wired infrastructure yet connectivity must be maintained among users who can move around arbitrarily and can at times not be in direct transmission range of each other. Multimedia Use of more than one media (such as text, graphics, animation, audio, and video) for information presentation. Multimedia books A multimedia application in education sector that uses audio, animation, and video to enrich text and still images of printed books, and provide better understanding of the subject matter. Multimedia computer system A computer system having the capability to integrate two or more types of media (text, graphics, animation, audio, and video) for the purpose of generation, storage, representation, manipulation, and access of multimedia information. Multimedia database A collection of multimedia data items, such as text, graphics, animation, audio, and video. Multimedia DBMS A set of programs to define, create, store, access, manage, and query multimedia databases. Multimedia presentation A multimedia application that enables a presenter to explain a subject matter more effectively than conventional presentation to an audience because it enhances a person’s comprehension capability. Multimedia synchronization Deals with mechanisms to ensure the desired temporal ordering among a set of multimedia objects in a multimedia presentation. Multiple inheritance In OOP, inheritance need not get limited to one parent-class. A child class can inherit from multiple parent classes. This is called multiple inheritance. Multiple Input Multiple Output (MIMO) A key technology used in LTE (4G). Multiple SubNyquist Sampling Encoding (MUSE) An HDTV broadcasting standard used in Japan. Multiplexing Method of dividing a physical channel into multiple logical channels to enable a number of independent signals to be transmitted on it simultaneously. Multiprocessing A term used to describe interconnected computer configurations, or computers with two or more independent CPUs, which have the ability to execute several programs simultaneously.

677

Multiprocessor A computer system consisting of two or more CPUs under a common control. Multiprogramming Interleaved execution of two or more different and independent programs by same computer. Multiprogramming with Fixed Tasks (MFT) Multiprogramming system that processes only a fixed number of jobs concurrently. Multiprogramming with Variable Tasks (MVT) Multiprogramming system that processes variable number of jobs concurrently. Multi-session disk A disk in which information added in a recording session can be hidden in a subsequent session by creating the File Allocation Table (FAT) at a new location, but the etchings on disk surface cannot be removed. Multitasking Concurrent execution of multiple jobs (often referred to as tasks of same user) in a singleuser system. Musical Instrument Digital Interface (MIDI) An international standard developed for digital music that determines the cabling, hardware, and communications protocol needed to connect a computer with electronic musical instruments and recording equipment. Mutual exclusion Exclusive access to shared resources (such as tape drive or printer) by a process.

N Nanosecond One-billionth (10-9) of a second. Narrowband channel Communication channels that handle low volumes of data, typically from 45 to 300 baud. They are used mainly for telegraph lines and low speed terminals. National Television Systems Committee (NTSC) A television broadcasting standard used in the US, Japan, and some Asian countries. Near-line storage A device that is an intermediate storage between on-line storage and off-line storage. It is slower than on-line storage, but data can still be accessed from it without any human intervention. Need-to-know principle Requirement of secure system according to which at any time a subject (person or program) should have access to only those resources that it needs currently to complete its task. It is also called principle of least privilege. Netiquette Deals with the rules of framing messages while interacting with other Internet users. Network See Computer network.

678

■ Foundations of Computing

Network Address Translating (NATing) sever A firewall that hides true IP addresses of critical hosts in a trusted network. Network Attached Storage (NAS) A storage device consisting of its own processor and disk storage, which can be attached to a TCP/IP network, and accessed using specialized file access or file sharing protocols. Network database A database model in which data elements are organized to have parent-child relationships. Network Interface Card (NIC) A hardware device that enables a computer to be connected to a network, both functionally and physically. Network operating system An operating system for a distributed computing system in which the users view the system as a collection of distinct computers. Network topology Interconnection structure of nodes of a computer network. Neural network A technology used to design experimental computers that can perform human-type tasks. The circuits of these computers are patterned after the complex interconnections existing among the human brain’s neurons, or nerve cells. Newsgroup A group of Internet/Intranet users, who use the usenet facility of the Internet to exchange their views/ideas/information on some common topic that is of interest to all group members. Next generation Internet Protocol (IPV6) Addresses the limitations of the current Internet Protocol (IPV4). Key features of IPV6 are large address space to ensure that the world will not run out of IP addresses; flow labeling and priority concepts to support real-time services; better security features for secure business transactions; enhanced routing capability to support mobile hosts; provision for anycast addressing; autoconfiguration facility; and improved packet header format for more efficient packet handling. Node An end point of a branch in a network, or a common junction of two or more network branches. Nomadic computing See Mobile computing. Nonce An information that is guaranteed to be fresh; that is, it has not been used or appeared before. Non-functional testing Software testing that verifies whether the software behaves properly even when it receives invalid of unexpected inputs (such as incorrect, incomplete, or inappropriate data). Nonimpact printer A printer that performs some type of operation to the paper (like spraying ink on it, heating it, electrically charging it, etc.), instead of

physically striking it (as in the case of an impact printer) to print. Non-moderated newsgroup A newsgroup in which any member can post a message on it directly. Non-positional number system A number system in which each symbol represents the same value, regardless of its position in the number, and the symbols are simply added to find out the value of a particular number. It is very difficult to perform arithmetic with such a number system. Non-procedural languages Programming languages that allow the users to specify “what” the output should be without describing all the details of “how” the data should be manipulated to produce that result. For example, 4GLs. Non-resident modules Modules of an operating system that reside on hard disk and are brought to main memory on demand. Non-volatile storage A storage medium that retains its contents when the power is turned off or interrupted. Notebook computer A small, portable computer mainly for use by people who need computing power wherever they go. Numeric Pertaining to a character set that contains the numbers 0 to 9.

O Obfuscation A scheme to protect software against reverse engineering techniques. Object The primitive element of a program written in an OOP language. Object Linking and Embedding (OLE) A feature found in application software packages that allows joining of documents in different applications, so that changes in either document are reflected in the other document. Object program A fully compiled or assembled program that is ready to be loaded into a computer. It results from translation of a source program by a language processor. Objected-oriented software design A technology to make programs generalized and to build software systems by combining reusable pieces of program codes called objects. Object-oriented database A database model that captures object-oriented concepts such as class hierarchy, inheritance, and methods.

■ Glossary Object-oriented database management system A system that allows definition and manipulation of an object-oriented database. Object-Oriented Programming (OOP) A programming methodology that deals with solving a problem by identifying real-world objects of the problem and the processing required of those objects, and then creating simulations of those objects, their processes, and the required communications between the objects. Object-oriented programming languages Programming languages that encapsulate data and sequences of operations into abstract entities called objects, providing a stronger encapsulation mechanism than procedure. Hence, object-oriented programming provides a more powerful modeling tool than procedure-oriented programming. Octal number system A number system with a base of 8. The octal digits range from 0 to 7. It is used commonly as a shortcut notation for groups of three binary digits. Off-line A device or system not under direct control of a computer system. Off-line data entry devices Input devices through which data is recorded on some media such as floppies or tapes, and then entered later into a computer from the media for processing. Off-line storage A storage in which data is recorded on it using a computer and then it is physically removed or disconnected from the computer for storing away from the computer. On-line A device or system connected to and under direct control of a computer system. On-Line Analytical Processing (OLAP) A database architecture designed specifically for effective data analysis. On-line data entry devices Input devices that are directly connected to the computer on which the entered data is processed. On-line storage A device that is under direct control of processing unit of a computer to which it belongs. On-Line Transaction Processing (OLTP) A database architecture designed specifically for transaction processing. Open System Interconnection (OSI) model A framework for defining standards for linking heterogeneous computers in a packet switched network. Each layer of this seven-layer (Physical layer, Data-link layer, Network layer, Transport layer, Session layer, Presentation layer, Application layer) architecture defines a separate set of protocols and

deals with one communication.

or

more

679

specific aspects of

Operand The part of a machine level instruction that specifies the location of the data to be manipulated. Operating system An integrated set of programs that controls the resources of a computer system, and provides its users with an interface or virtual machine, which is more convenient to use than the bare machine. Operation code (op code) The part of a machine level instruction that specifies the operation to be performed. Operation phase The phase in software life cycle during which the constructed system is used. Operators Symbols used in a programming language to show relationship between two data items. Programmers use them to form all types of expressions in programs. Optical bar-code reader An input device that is able to interpret combinations of marks (bars), which represent data. Optical Character Recognition (OCR) device An input device (a scanner) equipped with a character recognition software. It is used for inputting text documents, and store them in a form suitable for doing word processing of the documents. Optical disk A storage medium that consists of a rotating disk coated with a highly reflective metal or some other material. Laser beam technology is used for recording/reading of data on the disk. Also known as laser disk. Optical fiber Hair-thin threads of glass or plastic used as a data transmission medium. They use light signals for data transmission. Optical Mark Reader (OMR) An input device (a scanner) that is capable of recognizing a pre-specified type of mark made by pencil or pen. Any input data that is of a choice or selection nature can be recorded for OMR input. Optical mouse A mouse having a built-in photodetector that comes with a special pad with gridlines printed on it. Orthogonal Frequency Division Multiplexing (OFDM) A key technology used in LTE (4G). OS capability enhancement software A special category of software that bridges the gap between functionality of an operating system and needs of users for frequently used programs.

680

■ Foundations of Computing

OSI protocol A communication protocol to interconnect geographically dispersed heterogeneous computers. This protocol has been standardized by the International Standards Organization (ISO). Out-degree Total number of edges coming out of a node in a directed graph is called the node’s outdegree. Out-of-the-middle approach An approach to system design or program design, in which the designer combines both top-down and bottom-up approaches. Output Information generated as a result of data processing by a system. Output device A device used in a computer system to supply information and results of computation to the outside world. Examples are monitor, printer, plotter, screen image projector, and voice response system. Outputting Process of producing useful information or results for a user, such as printed report or visual display.

P Packed decimal format A modified form of zoned decimal number that places two decimal digits into each byte of the field with the exception of the rightmost byte, which contains one digit and the sign of the field. Packet switching A data communication method in which data (message) to be sent is first split up into packets of fixed size; each packet is then appended with source and destination addresses, and some control information; and then the packets are sent across the network to their destination. At the receiver end, the packets are reassembled to recreate the message.

physical memory to a process wherever free memory blocks are available. Palmtop computer A battery-operated computer with personal assistance tools. It can fit in ones pocket, and a user can operate it by keeping it on palm. Parallel binary adder An adder in which all bits of two binary numbers are added simultaneously. Parallel port An I/O port that can handle a higher volume of data than a serial port because it transfers 8 or 16 bits of data at a time. It is used for connecting faster I/O devices such as printer, analog-to-digital and digital-to-analog converters, etc. Parallel processing A technology in which a multiprocessor system is used to solve complex problems faster by breaking the problem into sub-problems, and allowing different sub-problems to be processed simultaneously by different processors of the system. Parallel program A program which divides a problem into smaller computation modules that can be allocated to different processors, and multiple processors process different modules and cooperate to solve the problem faster. Parallel representation A method of data recording on tape in which each head operates independently and stores information on nine tracks parallel to the edge of the tape and stores data in adjacent bit configuration. Para-virtualization Allows a single server to be treated as multiple virtual servers so that a powerful server can be shared by and service multiple user requests simultaneously. Parity bit An extra bit added to a string of bits. It enables a computer to detect internal errors in transmission of binary data.

Packet-filtering router A firewall that examines each incoming/outgoing packet and then forwards/discards the packet based on a set of packet-filtering rules defined by the security policies.

Pascal A high-level programming language named after Blaise Pascal. It facilitates use of structured programming techniques.

Page A program segment that is loaded into main memory only when it is needed for execution.

Passive attack An attack to a computer system, in which the intruder somehow tries to steal unauthorized information from the system without interfering with its normal functioning.

Page frames In paging mechanism of memory management, operating system partitions a computer’s main memory into fixed-sized blocks called page frames. Page printer A high-speed printer with a mechanism to print an entire page at a time. Paging A memory management scheme used to solve the problem of external fragmentation of memory. It does this by allowing a process’s memory to be noncontiguous. Hence, the system can allocate

Password A code by which a user gains access to a computer system. It is used for security purposes. Password book A method used to implement onetime passwords in which a user gets a password book containing a list of passwords. For each login, the user uses the next password in the list. Patch A patch (modification) is created to fix a newly discovered bug in software. All patches created since

■ Glossary the last release version are incorporated in a new release version of the software. Pen drive A plug-and-play storage device that simply plugs into a USB (Universal Serial Bus) port of a computer enabling easy transport of data from one computer to another. It is a compact device of the size of a pen, comes in various shapes and stylish designs (such as pen shape, wallet shape, etc.), and may have different added features (such as camera, radio, MP3 player, etc.)

Peripheral devices See Input-Output devices. and

Personal assistance software Software that enables users to use personal computers for storing and retrieving personal information, and planning and managing personal schedules, contacts, finances, and inventory of important items. Personal Communications Services (PCS) A wireless communication technology that is used to offer greater network complexity and lower end-toend latency in wireless networks. Personal Computer (PC) A small and inexpensive computer used by individuals for carrying out personal jobs, or for applications such as entertainment, education, home management, and hobbies. Personal Digital Assistant (PDA) A pocket-sized computer having facilities such as calendar, calculator, notepad, Internet access, word-processing application, spreadsheet application, etc. It is also known as pocket PC. Petaflop 10 second.

15

Platform as a Service (PaaS) A service layer of cloud computing that contains tools for software development and testing, known as Integrated Development Environment (IDE). Software developers are the primary users of services offered by this layer. Plotter An output device used frequently by architects, engineers, city planners, and others who need to routinely generate high-precision, hard-copy, graphic output of varying sizes. PocketPC See Personal Digital Assistant (PDA). Also see Handheld computer.

Perfect induction See Exhaustive enumeration.

Peripherals Various input/output devices auxiliary storage units of a computer system.

681

floating-point arithmetic operations per

Phase Alternating Line (PAL) A television broadcasting standard used in India and Western Europe (except France). Phase modulation A form of modulation in which two binary values of digital data are represented by shift in phase of carrier signal. That is, a sine wave with phase = 00 represents a digital 1, and a sine wave with phase = 1800 represents a digital 0. Picosecond One trillionth of a second. Pixel A picture element. It represents one point in a raster scan display device. Plain Old Telephone Service (POTS) Term coined by users and service providers to describe standard analog service.

Point-and-draw devices Input devices that can be used to rapidly point to, and select a particular graphic icon, or menu item from multiple options displayed on screen. Many of these devices can also be very effectively used to create graphic elements such as lines, curves, and freehand shapes on the screen. Some commonly used point-and-draw devices are mouse, trackball, joystick, electronic pen, and touch screen. Pointer A data type supported in some programming languages (such as C). It is a special modifier of any other data type that has a variable name and storage associated with it. It enables programmers to directly access memory addresses where variables are stored. Point-Of-Sale (POS) device An I/O device capable of immediately updating sales and inventory records on a central computer, and producing a printed sales transaction receipt. Portrait mode A mode of printing in which the printed lines are parallel to the shorter edge of the paper. Positional number system A number system in which there are only a few symbols called digits, and these symbols represent different values, depending on the position they occupy in a number. The value of each digit in such a number is determined by the digit itself, the position of the digit in the number, and the base of the number system. Postorder traversal A binary tree traversal method in which for each node the left subtree is visited/processed first, followed by its right subtree and then the node itself. Postprocessor A language processor (software) that processes the result of computation obtained from a system/software to convert it in a specific format/style. Posttest loop A loop in a program in which a condition is tested after each iteration to check if loop should continue. In posttest loop, at least a single iteration of the loop occurs.

682

■ Foundations of Computing

Power On Self Test (POST) A self diagnosis test performed when a computer is first turned on. It tests a computer’s memory, its storage and peripheral devices for their proper functioning and connectivity.

Private line See Leased line.

Power-aware processor technology See Energyefficient processor technology.

Procedural languages Programming languages that require the programmer to spell out the steps in processing procedures needed to achieve a desired result. For example, FORTRAN, COBOL, BASIC languages.

Predication A technique, used in EPIC-based processors for improved performance, which reduces the number of branches and branch mispredicts. Preorder traversal A binary tree traversal method in which each node is listed first, followed by its left subtree and then its right subtree. Preprocessor A program that does some preparations for a compiler before a program is compiled. Preprocessor directives Instructions supported in a programming language to tell the preprocessor how to prepare a program for a compiler before the program is compiled. Pretest loop A loop in a program in which a condition is tested before each iteration to check if loop should occur. Pretty Good Privacy (PGP) An open source software package for e-mail security. It is freely available (including its source code) on the Internet. Preview A feature of a word-processing package that permits users to see what a document will look like (almost, if not exactly) when it is printed. Primary storage A temporary storage area built into computer hardware, and in which instructions and data of a program reside mainly when the program is being executed. Principle of least privilege See Need-to-know principle.

Private-key-cryptosystem cryptosystem.

See

Symmetric

Procedure A subprogram that performs an action but returns no value. Procedure-oriented Programming Languages Programming languages that use procedural abstractions that encapsulate sequences of operations into procedures (also known as functions, subroutines, or subprograms). Process A program in execution. Also known as job. Process Control Block (PCB) A data structure that an operating system maintains for each process. It records the complete status information of a process. Process management A module of an operating system to manage the processes submitted to a system in a manner to minimize idle time of its processors (CPUs, I/O processors, etc.). Processing Performing a series of actions or operations on data to convert them into information. Processor A unit of a computer that interprets instructions and executes them. Profiler A performance monitoring software that helps a user in analyzing the performance of various hardware components and the overall performance of a computer system.

Printer An output device used to produce hard-copy output.

Program A set of sequenced instructions (written in a language that can be understood by a computer) used to direct and control the operations of a computer to solve a problem, or perform a particular task.

Printing utility A file utility that prints a file on a printer to produce hard copy of its contents.

Program Control (PC) register A register that holds address of the next instruction to be executed.

Privacy Enhanced Mail (PEM) A scheme for adding privacy to Internet mail applications. It uses cryptography and digital signature techniques.

Program Design Language (PDL) See Pseudocode.

Privacy filters Specially designed plastic/glass plates used with monitors to prevent others sitting/standing nearby the monitor from viewing the contents displayed on it. Private clouds A private cloud works in a manner similar to a public cloud with the exception that only employees within the organization (which owns the private cloud) can make use of its services.

Program library A collection of complete programs, subroutines, and program modules, which have already been developed, tested, and documented, usually as a result of other programming projects. Programmable Read-Only Memory (PROM) Similar to read only memory with the exception that these chips can be reprogrammed by using special external equipment. Programmer One who designs, writes, tests, and maintains computer programs.

■ Glossary Programming See Coding. PROgramming in LOGic (PROLOG) A nonprocedural programming language that deals with the use of a formal logic notation to communicate some computational process to a computer. Programming language A language used to express algorithms in computer understandable form. Progressive scan A scanning process of a CRT screen in which, in one pass of scanning the entire screen, the electron beam travels all scan lines from top to bottom sequentially. Proof by knowledge An approach of authentication, which involves verifying something that only an authorized principal knows. Proof by possession An approach in which a user proves his/her identity by producing some item that only an authorized principal can posses. Proof by property An approach in which a system verifies the identity of a user by measuring some physical characteristic of the user that is hard to forge. Protection rules Rules that define possible ways in which subjects and objects are allowed to interact. Protocol See Communication protocol. Prototyping Process of developing a small working model of a final operational system to demonstrate the concepts, look, and feel of the final system. Proxy server A computer system that is specially configured to allow other computers of an organization to interact with the Internet only through it. Pseudo disk See RAM disk. Pseudocode A programming analysis tool used for planning program logic. It is an imitation of actual computer instructions written in a natural language such as English. Also known as Program Design Language (PDL). Pseudo-instructions Additional instructions in instruction set for instructing a computer system how we want it to assemble a program in computer’s memory.

683

Public-domain software Software available free, or for a nominal charge from the bulletin boards, or usergroup libraries on the Internet. Also known as shareware or user-supported software. Public-key cryptosystem cryptosystem.

See

Asymmetric

Publicly accessible site A site from which a user can download files that have been stored for sharing on the site (computer), because any user on the Internet can access them. Python A high-level programming language that is easy to learn to program and simple to read and understand. Its creator, Guido van Rossum, released it as a Free and Open Source Software (FOSS).

Q Quantum See Time slice. Quarter inch cartridge (QIC) standard A data format used in streamer tapes, which helps in easy use of these tapes for exchanging data between different computers. Query By Example (QBE) A software tool that enables database users to specify search criteria by providing a front end for the query language, which collects the facts about a query from the user, and composes query language statements internally. Query language A language that enables users to define their requirements for extracting desired information from a database in the form of queries. Queue A data structure type that represents a container of data items which is open from both sides and in which a data given can be added at one end only (called “rear” end) and removed from the other end only (called “front” end). Also known as FIFO (first-in-first-out) data structure.

R Radio-router technology An emerging wireless technology designed to make links in an IP network mobile. Radix See Base.

Public clouds A service provider owns and maintains a public cloud and charges for the services it offers. A public cloud accepts requests for services from many customers and offers services to its customers from the resources in the cloud.

RAM disk A block of semiconductor RAM chips (other than the RAM chips used for the main memory) used in some computers as a simulated disk to make applications execute faster. Also known as silicon disk or pseudo disk. Note that RAM disk is not really a disk.

Public Key Infrastructure (PKI) In addition to the concept of CA, IETF evolved and proposed the use of an entire infrastructure for issue and management of public keys. This infrastructure is called PKI.

Random Access Memory (RAM) Memory in which time to retrieve stored information is independent of the address where it is stored.

684

■ Foundations of Computing

Random file See Direct file. Random/direct-access storage device Storage device in which access to any stored information is direct, and approximately equal access time is required for accessing any information irrespective of its location. Magnetic, optical, and magneto-optical disks are typical examples of such a storage device. Rapid Application Development (RAD) A methodology for developing applications software for computers. The methodology ensures quicker development and greater user involvement than traditional methods. Raster graphics Graphic objects composed of patterns of dots called pixels. Raster scanning Process of painting a video image on a CRT monitor screen. An electron gun illuminates every pixel as it sweeps across the screen, one line at a time, from left to right and from top to bottom and then back on the top. It repeats several times every second (called refresh rate) to provide continuity of motion and avoid flicker. Read-Only Memory (ROM) Non-volatile memory chip in which data are stored permanently, and cannot be altered by programmers. Real-time operating system An operating system that is designed to handle the processing requirements of real-time systems. Real-time system A system that must satisfy the requirement of producing the desired results before a certain deadline. Record Collection of related items of data treated as a unit. Record length A measure of size of a record, usually specified in units such as number of characters. Reduced Instruction Set Computer (RISC) Architecture An architecture of CPUs with a small instruction set, fixed-length instructions, and reduced references to memory to retrieve operands. Redundant Array of Inexpensive Disks (RAID) A technology that allows a bunch of disks to be configured as a single large disk. Refresh rate Number of times the electron beam of a display monitor scans the entire screen per second. Registers Small, high-speed storage units that hold data temporarily when there is an interpretation and execution of instructions by CPU. Data stored in a specific register have special meaning to CPU. Relational database A database model in which data elements are organized in the form of multiple tables,

and data in one table is related to data in another table through use of a common field. Relevance score Search engines often list search results in accordance to a relevance score that reflect the number of times a search term appears in a web page. Reliability Refers to the degree of tolerance of a system against errors and component failures in the system. Remote access Accessing a computer from a distant station using communication facilities. Remote dial-up connection A method of connecting a computer to the Internet via a gateway computer of an Internet service provider. Report file A file that holds a copy of a report, generated by a data processing application in computer-accessible form, until it is convenient to print it. Report generator Software that enables users of a database to design the layout of a report, so that it can be presented in the desired format. Reserved word See Keyword. Resident modules Modules of an operating system that need to be always resident in system’s main memory. Resolution Number of points to which electron beam can be directed (pixels) on a CRT screen. Response time Elapsed time between submission of a job to a system for processing, and the first response produced by the system for the job. Ring network A computer network in which there is no host computer for controlling other computers, and each computer in the network has communicating subordinates. Rivest-Shamir-Adleman (RSA) RSA is the first published and practically the most satisfactory asymmetric cryptosystem. Roll-up The process of viewing information from a lower level up to a higher level. Root A node in a non-empty tree with in-degree equal to zero. Router An internetworking tool used to interconnect those networks that use same high-level protocols above the network layer. Routing Selection of actual path to be used to transmit a message/packet from one node to another in a WAN.

■ Glossary RS-232-C interface A standard interface used for interconnecting user terminals to computers. It was defined by the Electronics Industrial Association (USA). Run server A special server that manages a pool of processors and allocates processors from the pool to different jobs on demand. Run time Time required to complete a single, continuous, execution of an object program.

S Satellite See Communication satellite. Scalability testing Software testing that tests if the software can handle large quantities of data or large number of users. Scan line A complete line, which the electron gun of a CRT display traces from left to right on the screen. Scanner An input device used for direct data entry into a computer from source documents.

languages like FORTRAN and COBOL programming, and batch operating systems.

685 for

Sector The smallest unit with which any disk can work. Disk drives are designed to access a whole sector at a time. Secure Electronic Transaction (SET) A set of security protocols and formats for ensuring secure credit/debit card transactions (also called electronic transactions) on an untrusted network, such as the Internet. Secure Socket Layer (SSL) See Web security. Secure/Multipurpose Internet Mail Extensions (S/MIME) An Internet standard for e-mail security. It provides authentication, data integrity, secrecy, and non-repudiation by using digital signatures and encryption. Security Policies and mechanisms that deal with protecting the various resources and information of a computer system against destruction and unauthorized access.

Schema builder Software tool that enables a user to define a database schema interactively by prompting the user to enter field name, field type, field size, and so on for each field.

Security Association (SA) Association established by IPSec between two entities that want to transfer data between them securely. SA is a one-way connection (simplex connection) between two entities and has a security identifier associated with it.

Screen image projector An output device used to project information from a computer on to a large screen (such as a cloth screen or a wall), so that it can be viewed simultaneously by a large group of people.

Security mechanisms Methods to achieve security goals of a computer system.

Script A set of related characters. For example, all characters used in Devnagari form the Devnagari script. Scripting language A programming language that allows programmers to integrate several command statements (used to instruct a computer to do some job) into a single command so that the programmer need not type all the commands every time he/she needs to perform the intended task. Scrolling Using program-specified ways (by use of keys or mouse) to move the items displayed in a window up or down, or left or right to see parts of a file that extend past the bottom or top or sides of the window. Searching utility A file utility that finds a record in a file. Secondary storage See Auxiliary memory. Second-generation computers Computers built during the period 1955 and 1964. They used transistors in CPU, and magnetic cores for main memory. On software front, they used high-level

Security policies Security policies of a computer system define its security goals. Security testing Software testing that tests if the software can protect use of confidential data by unauthorized users. Seek time In a disk system, time required for a read/write head to move to the track where the data to be read/written is stored. Maximum seek time equals the time taken for the head to move from the outermost track to the innermost track. Selection logic A program construct that is used to select a path out of two or more alternative paths in program logic. Also known as decision logic. Selective Laser Sintering (SLT) A technique used by 3D printers to print (create) three-dimensional objects. It uses small particles of plastic, ceramic or glass in powder form as the build material. The printer uses high power laser to melt and fuse (sinter) the particles to create the desired 3D object. Self-documenting languages Programming languages that do not require much explanation to be understood by someone reading the program instruction. For example, COBOL language.

686

■ Foundations of Computing

Semaphore A method of implementing mutual exclusion for resources. Semiconductor storage A storage device whose storage elements are formed as solid-state electronic components on an integrated circuit chip. Semi-dynamic array An array in which subscript ranges are dynamically bound and storage allocation is dynamic (done during run time). Semi-static array An array in which subscript ranges are statically bound, but storage allocation is done at declaration elaboration time during execution. Sequence logic A program construct used to perform instructions one after another in sequence. Sequential circuit A digital circuit, which comprises of both combinational circuits and storage components. It uses both logic gates and flip-flops.

resource and provides a set of shared user services to clients. It runs the server process that services client requests for use of the resource managed by the server. Set-top box A device that connects to a customer’s TV monitor and enables the customer to connect to a video server, browse video selections, and interact with the video server via VCR-like functions. Its major functions include receiving of incoming video streams; demodulating, de-multiplexing, and decoding of signals; performing necessary signal conversion, such as D/A transformation for playback on TV monitor; and sending outgoing control messages. Shared memory system A system in which a single system-wide primary memory is shared by all processors. Shareware See Public-domain software.

Sequential Couleaur Avec Memoire (SECAM) A television broadcasting standard used in France, Eastern Europe, Russia, and Middle East.

Shell Command interpreter of an operating system that serves as its user interface. It is so called because it forms the outer layer of the operating system, covering its other modules.

Sequential file A file in which records are stored one after another in an ascending or descending order determined by the value of the key field of records.

Silicon disk See RAM disk.

Sequential processing A technique in which a number of similar items or transactions to be processed are grouped together and processed in a designated sequence.

Simple statement A statement to perform a single operation.

Sequential-access storage device A storage device in which information can only be retrieved in the same sequence in which it is stored. Magnetic tape is an example of such storage device. Serial Advanced Technology Attachment (SATA) An industry standard storage interface that is meant primarily for desktop and mobile computing systems. Serial Attached SCSI (SAS) A type of SCSI, which uses SCSI commands, but transmits data serially (one bit at a time). Serial mouse A mouse that plugs into a serial port (a built-in socket in a computer’s back panel to connect external devices). Serial port An I/O port used to connect any device that can send or receive a stream of bytes serially, one bit at a time. It is used for connecting slow I/O devices such as terminal, keyboard, mouse, modem, etc. Serial representation A method of data recording on tape in which data bits are aligned in a row, one after another in tracks. Server computer In a client-server computing environment, a computer that manages a shared

Simple character A letter, like ‘A’, which is treated as a code element in Unicode.

Simplex A data transmission mode in which data can flow in one direction only. Simulation To represent and analyze properties or behavior of a physical or hypothetical system by the behavior of a system model. Single In-line Memory Module (SIMM) A memory board with memory chips on it. Memory chips can be added on the board to increase a computer’s main memory capacity. Singly-linked circular list A linked list in which each node points to its successor node and the pointer of the last node points to the first node. Singly-linked list A linked list in which each node points to its successor node and the pointer of the last node is a NULL pointer. SLIP/PPP connection SLIP (Serial Line Internet Protocol) and PPP (Point-to-Point Protocol) are software that allow a client computer to be connected via a modem to a geteway computer of an Internet service provider in such a manner that all the software tools that are on the client computer can be used by a user of the client computer to access the Internet, rather than depending on the gateway computer’s software.

■ Glossary Small Computer System Interface (SCSI) A drive interface standard that uses a generic device controller (called SCSI controller) on the computer system and allows any device with an SCSI interface to be directly connected to the SCSI bus of the SCSI controller. Small Scale Integration (SSI) Integration of only about ten to twenty electronic components on a single chip. Smart card An electronic card having a built-in microprocessor chip. Data can be stored permanently in the chip’s memory. Smart object Any object (device) with any kind of built-in sensors and having the ability to collect and transfer data over a network without manual intervention. Smart phone A fully functional mobile phone with computing power. Also see handheld computer. Smart terminal A terminal having local data editing capability, and ability to consolidate input data, before sending them to main computer. It has a microprocessor, some internal storage, and I/O capabilities. Snowflake schema A model for designing data warehouses. It consists of normalized dimension tables by attribute level, with each smaller dimension table pointing to an appropriate aggregated fact table. Soft keys Keys on a keyboard whose additional functionalities are defined in software. For example, a word processing software may define and enable use of F1, F2, and F3 keys to make selected text underline, italic, and bold respectively. Soft-copy output Computer output that is temporary in nature, and vanishes after use. For example, output displayed on a terminal screen, or spoken out by a voice response system. Software A set of computer programs, procedures, and associated documents (flowcharts, manuals, etc.) related to the effective operation of a computer system. Software as a Service (SaaS) A service layer of cloud computing that contains a set of applications offered as a service to end users. For example, applications like e-mail, chat, webcasting, etc. form part of this layer. Software Development Life Cycle (SDLC) Evolving software products through a set of well-defined phases including requirement specification phase, system analysis and design phase, implementation phase, testing and debugging phase, deployment phase, and

687

maintenance phase. Also known as waterfall model of software development. Software documentation Process of collecting, organizing, storing, and maintaining a complete historical record of program and other documents used or prepared during different phases of software life cycle. Software engineering A branch of engineering that deals with the systematic application of the principles of computer science and mathematics in creating and building cost-effective software solutions. Software implementation Deals with code generation of various software components specified in system design document and linking them properly to build the target software system. Software maintenance Process of modifying software system or component after deployment to correct faults, add functionality, improve performance or other attributes, or adapt to change in environment. Software package A group of programs that solve a specific problem, or perform a specific type of job. For example, a word-processing package. Software piracy Deals with illegal copying and resale of software. Software pirate Anyone who breaks a system’s security for stealing intellectual property in software on the system. Solid state Electronic components (such as transistors and diodes), whose operation depends on the control of electric or magnetic phenomena in solids. Solid State Drive (SSD) A new type of non-volatile storage device used as secondary storage. It consists of interconnected flash memory chips. Sorting utility A file utility that arranges records of a file in some defined sequence and enables users to specify their sequencing requirements for a file by means of input parameters. Source program A program written in a symbolic or high-level language such as assembly language, COBOL, BASIC, etc. Spam e-mail An unsolicited (unwanted, not asked for) e-mail message, which is sent in large quantities to an indiscriminate set of e-mail users. It is also called Unsolicited Bulk E-mail (UBE). Special character A graphic character that is neither a letter or digit, nor a space character. For example, dollar sign, comma, period, etc. Special purpose computer A computer for doing only a particular type of jobs.

688

■ Foundations of Computing

Speculation A technique, used in EPIC-based processors for improved performance, which reduces the effect of memory-to-processor speed mismatch. Speech recognition device An input device that allows a person to input data to a computer system by speaking to it. Speech synthesizer A voice response system that converts text information into spoken sentences. Spoofing The act of an intruder masquerading as a trusted server to a client requesting a service from the system.

Steganalysis Deals with techniques to determine whether a file contains a steganographically-hidden message. It employs mathematical techniques or artificial neural networks to statistically scan digital files and then examine them for changes in pixel values to detect likely presence of steganographicallyhidden data. Steganography A technique of hiding secret messages within the code representing a standard computer file in such a way that normal users cannot make out the difference between a file without the hidden message and a file with the hidden message.

Spooling A mechanism to reduce the speed mismatch between slow I/O devices and CPU, and to convert mutually exclusive I/O devices into non-mutually exclusive I/O devices.

STereoLithography (STL) A technique used by 3D printers to print (create) three-dimensional objects. It uses photo-polymerization technique, which involves solidification of photosensitive resin (sticky substance) by means of a laser light source.

Spreadsheet A numeric data analysis tool (software package) that enables users to create a kind of computerized ledger.

Storage See Memory.

SQL A standard query language for relational databases. Stack A data structure type that represents a pile of data items in which data items are stacked one on top of another and a data item can be added to or removed from only the top of the pile. Also known as LIFO (last-in-first-out) data structure. Stand-alone In a distributed data processing system, it refers to a computer system that has an independent (from a central-site computer) processing and storage capability. Standard forms The sum-of-products and product-ofsums forms of Boolean expressions. Star network A network in which multiple computers are connected to a central host computer. These computers are not linked directly to each other, and can communicate via the host computer only. Star schema A model for designing data warehouses. It consists of one fact (major) table and many dimension (minor) tables. Statement In programming, an expression generalized instruction in a source language.

or

Statement block See Compound statement. Static array An array in which subscript ranges are statically bound and storage allocation is static (done before run time). Static RAM (SRAM) A type of RAM that does not need any special generator circuit to retain the stored data. It is faster, costlier, and consumes more power than dynamic RAM.

Storage Area Network (SAN) A method in which one or more processors and one or more storage devices are interconnected, forming a dedicated network. Storage hierarchy A hierarchy of storage technologies (such as cache memory, main memory, secondary storage, and mass storage) used in a computer system. This is usually done because a single type of storage is not superior in speed of access, capacity, and cost. Stored program computer A computer where the program to solve a problem, and the necessary data are stored in its memory. Storing Process of saving data and instructions to make them readily available for initial or additional processing whenever required. String A one-dimensional array of characters. StriNg Oriented symBOlic Language (SNOBOL) A programming language designed to manipulate strings of characters and used for nonnumeric applications. Striping A RAID technique in which the system partitions a piece of data into smaller pieces and distributes the pieces across multiple disks. Striping with parity A RAID technique in which the system partitions a piece of data into smaller pieces, distributes the pieces across multiple disks, generates a parity for the data, and stores the parity on one or more disks. Structure A user defined data type that is made by using primary data types and other user defined data types. A structure has contiguous memory allocation.

■ Glossary

689

Structured design A system design approach in which a difficult problem is broken into smaller problems that are small enough to manage, but independent enough to solve separately.

Synchronized password generator A method used to implement one-time passwords which relies on the use of a special equipment such as smart cards or synchronized password generators.

Structured programming An organized approach to programming involving use of the three basic control structures – sequence, selection, and iteration, and use of top-down concepts to decompose main functions into lower-level components for modular coding purposes.

Synchronous communication Data transmission mode in which a sender and receiver must synchronize with each other to get ready for data transmission, before it takes place.

Study phase A system life-cycle phase during which a problem is identified, alternative solutions are studied, and the most feasible solution is selected. Subject An active entity wishing to access and perform operations on objects. Subprocedure See Subroutine. Subprogram See Subroutine.

Syntax A set of rules of a programming language, which define the pattern or structure of the word order and punctuation of an instruction. It is analogous to rules of grammar in English language. Syntax rules See Syntax. Syntax errors Errors in computer programs that typically involve incorrect punctuation, incorrect word sequence, undefined terms, or misuse of terms. These errors are automatically detected, and pointed out by language processors.

Subroutine A standardized program written in a manner that it can be used as part of another program whenever necessary. A subroutine is normally invoked through other programs by the use of CALL statements. Also known as subprogram and subprocedure.

Syntax for Generalized Markup Language (SGML) A meta language for markup languages.

Subtractive Manufacturing A technique to create three-dimensional objects, in which material is carefully removed/cut out/hollowed from a piece.

System analysis A detailed step-by-step investigation of related procedures to see what must be done, and the best way of doing it.

Supercomputer Computer systems characterized by their very high processing speeds. They are generally used for complex scientific applications.

System analyst An individual responsible for planning a computer data processing system. He/she utilizes tools such as flowchart, decision table, program design language, etc. These plans are then passed to the computer programmer.

Superscalar architecture An architecture which permits more than one instruction to be executed in each clock cycle. Swapping Storing programs on disk, and then transferring these programs into main storage whenever they are needed. The technique is used to process large programs, or several programs with limited memory.

System A group of integrated parts (people, methods, machines, and materials) that have a common purpose of achieving some objective(s).

System calls Commands supported by command interpretation module of an operating system. System clock A built-in electronic clock that helps in synchronizing CU and ALU operations. It emits millions of regularly spaced electric pulses per second (known as clock cycles).

Switched line See Dial-up line.

System commands See System calls.

Switching techniques Methods of establishing communication links between a sender and receiver in a communication network such as circuit switching, message switching, and packet switching.

System program A program included in a system software package.

Symbolic language See Assembly language. Symbolic program See Assembly program. Symmetric cryptosystem Cryptosystem in which either both encryption key (Ke) and decryption key (Kd) are the same or one is easily derivable from the other. Symmetric cryptosystems are also known as shared-key or private-key cryptosystems.

System programmer A programmer who prepares system software. System software A set of one or more programs designed to control the operation, and extend the processing capability of a computer system.

690

■ Foundations of Computing T

Tablet PC A miniaturized laptop that qualifies as handheld computer. Tag Markup language instructions. Tamper-proofing A technique to protect software from tampering attacks. Tape controller A device which is connected to and controls a tape drive, and interprets the commands for operating a tape. Tape density Amount of data that can be placed over a given length of tape. Tape density is usually expressed in bytes or characters per inch. Tape drive A device used for storage and retrieval of data stored on magnetic tape. Tape header label A label between BOT marker and the first file header label, which contains the tape’s attributes such as its identifier, number of files it contains, date when it was last used, and other control information, which help to prevent an important tape from being erased accidentally. Telecommunications Transmission of data between computer systems and/or terminals through telephone facilities. Telemedicine system A medical informatics application that enables patients to consult remote doctors for their medical problems using information and communication technologies. Telnet An application level protocol that enables a user to log in to another computer from his/her current computer in a network environment. Template A standard format used to quickly create new documents in the same format. Terabytes (TB) Memory storage equal to about one trillion (1012) bytes. Teraflop 1012 floating-point arithmetic operations per second. Terminal See Video Display Terminal (VDT). Terminal emulator A program that runs on a PC or workstation and pretends that it is a terminal when the PC or workstation is connected to a network and communicates with other computers on the network. Test-and-set A method of implementing mutual exclusion that tests a lock’s status and sets it to true if the lock’s status is found to be false at the time of testing. Test-and-set is an atomic instruction meaning that both testing of status of lock variable and setting

it to true (if it is false) are executed atomically (as one uninterruptible unit). Testing Process of making sure that a program performs its intended task. TeX A major publishing standard in 1970s and 80s for type setting documents in scientific disciplines. Text A multimedia component alphanumeric and special characters.

that

contains

Thermal printer A printing device that utilizes paper, which is sensitive to heat. Third-generation computers Computers built between 1964 and 1975. They used integrated circuits in CPU, high speed magnetic core main memories, powerful high-level languages, and time-sharing operating system. Thread In a multithreading system, the basic unit of CPU utilization is a thread. A process consists of an address space and one or more threads of control. All the threads of a process share the same address space, but each thread has its own program counter, its own register states, and its own stack. Also known as light-weight process. Threat monitoring Management technique that detects security violations by checking for suspicious patterns of activity. Throughput Total amount of useful processing carried out by a computer system within a given time period. It is measured as the number of processes completed by the system per unit time. Tightly-coupled system A multiprocessing system in which all processors share a single system-wide primary memory. Time division multiplexing A method of sharing a communication channel in which the total time available in the channel is divided among several users and each user of the channel is allotted a time slice during which he/she may transmit a message. The channel capacity is fully utilized by interleaving a number of data streams belonging to different users into one data stream. Time log A log documentation automatically maintained by many computer systems. It describes in detail how a computer system was used during a day. Time slice Short period of time during which a user process gets attention of CPU in a time-sharing system. Also known as time slot or quantum. Time slot See Time slice. Time-sharing A mechanism to provide simultaneous, interactive use of a computer system by many users in

■ Glossary a manner that each user is given the impression that he/she has his/her own computer. It uses multiprogramming with a special CPU scheduling algorithm to achieve this. Top-down approach A disciplined approach to system/program design in which top-level functions are decomposed into a hierarchy of understandable lower-level modules for better management and easy handling. Touch screen A simple, intuitive, and easy to learn input device that enables users to choose from available options by touching with their finger the desired icon or menu item displayed on a touchsensitive computer screen. Track In case of magnetic disk, one of many circular concentric rings used for storing data. In case of magnetic tape, a horizontal strip, or channel, running the full length of the tape, and used for recording data. Trackball An input device that serves as an effective pointing device. Transaction file A file in which current data are stored for subsequent processing usually in combination with a master file. Transducer A device capable of changing signals from analog to digital form, or vice-versa. Transistor A controlled electronic switch fabricated using a semiconductor. It is extensively used in the design of various electronic equipment. Translating program See Language processor. Transponder A device mounted on a communication satellite that receives, amplifies, and retransmits signals from earth stations. Transport Control Protocol (TCP) A connectionoriented transport protocol, which uses end-to-end mechanisms to ensure reliable, ordered delivery of data over a logical connection and achieves these goals by using packet sequence numbers and positive acknowledgements with timeout and retransmission. Transport Layer Security (TLS) See Web security. Transport network A component of Video-onDemand (VoD) system that delivers video programs from video server to customers. It possesses high data transfer rate to meet real-time delivery requirement of video traffic. Tree A data structure type that consists of a finite set of elements (called nodes) that are connected by a finite set of directed lines (called branches). Tree traversing Process of visiting all nodes of a tree in a defined order and listing (or processing) the

691

data elements of the nodes in the sequence in which the nodes are visited. Trojan horse program A program that consists of clandestine code to do nasty things in addition to its usual function, but appears to be benign. Trust anchors To make public keys of roots known to end entities, modern browsers come pre-loaded with public keys of over 100 roots, which are known as trust anchors. Truth table A table that gives output values for various input combinations for a logical expression. Tuple A group of related fields (a row of a table) in a relational database. Turnaround time Elapsed time between submission of a job to a computer system for processing, and completion of the job. Turnkey solution See End-to-end solution. Twisted-pair cable A simple, inexpensive, and slow wired transmission medium. It consists of two bunches of thin copper wires, each bunch enclosed separately in a plastic insulation, then twisted around each other to reduce interference by adjacent wires. It is also called Unshielded Twisted-Pair (UTP) cable.

U UART A chip on a device controller’s card that converts parallel data from system bus of computer into serial data that can flow through a serial cable or telephone wire. Ultra Large Scale Integration (ULSI) Integration of about ten million electronic components on a single chip. Ultra Voilet EPROM (UVEPROM) An EPROM chip in which stored information is erased by exposing the chip for some time to ultraviolet light. Unbundled Application software priced separately from hardware. Unconditional branch statement A branch statement that causes alteration in sequential flow of execution of a program without any condition test (such as goto statement). Unconditional branching When transfer without condition test causes flow alteration, the branch statement is called unconditional branching. Unconditional transfer A program instruction that causes program control to flow out of normal sequence unconditionally.

692

■ Foundations of Computing

Unibus architecture An interconnection architecture in which there is a single data bus, a single address bus, and a single control bus used to interconnect the CPU with both the memory and I/O devices.

Unix A multi-user, time-sharing operating system. It is a popular operating system, and can be used on a wide variety of computers, ranging from notebook computers to supercomputers.

Unicode A universal character-encoding standard used for representation of text for computer processing. It provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language. It has the capacity to encode as many as a million characters.

Unshielded Twisted-Pair (UTP) cable See Twistedpair cable.

Unicode Transformation Format-16 (UTF-16) A word-oriented format having all Unicode characters represented as a variable-length encoding of one or two words.

Uptime Time duration when a computer system is in operation.

Unicode Transformation Format-32 (UTF-32) A double-word oriented format having all Unicode characters represented as a fixed-length encoding of two words. Unicode Transformation Format-8 (UTF-8) A byteoriented format having all Unicode characters represented as a variable-length encoding of one, two, three, or four bytes. Uniform Resource Locator (URL) An addressing scheme used by WWW browsers to locate sites on the Internet. Uninterrupted Power Supply (UPS) A batterysupported power unit between an external power source and a computer system. It supplies clean and continuous power even during power failures. Union A user defined data type that refers to a memory location using several data types. Each data member begins at the same memory location.

Unsolicited Bulk E-mail (UBE) See Spam e-mail. Uploading Moving a file from ones own computer to a remote computer in a network environment.

Upward compatible Ability of hardware or software to function with all of the same equipment and software with which its predecessors could function. Usability testing Software testing that tests if the software is easy to learn and use. Usenet A service on the Internet that enables a group of Internet users to exchange their views/ideas/information on some common topic, which is of interest to all members belonging to the group. User authentication Deals with the problem of verifying the identity of a user (person or program), before permitting access to a requested resource. User Datagram Protocol (UDP) A connectionless transport protocol. It is an unreliable protocol because, when it is used, message packets can be lost, duplicated, or arrive out of order. Therefore, only those applications that do not need reliable communication should use UDP.

Uniprogramming system A system that processes only one job at a time, and all system resources are available for the job until its completion.

User Defined Data Type (UDT) A composite data type whose composition is not included in language specification. A programmer declares it in a program where it is used.

Unit testing Software testing phase in which each module of software is tested independently for its functionality by the programmer who developed the module.

User-friendly A program or computer system designed in a manner that even individuals who lack computer experience can easily use the system without much training.

Universal gate A logic gate that is alone sufficient to implement any Boolean function. For example, NAND and NOR gates.

User-programmed ROM A PROM in which a user can load and store “read-only” programs and data.

Universal Mobile Telecommunication System (UMTS) A standard for 3G technology in Europe. Universal Product Code (UPC) A universal or standardized optical bar code that normally appears on retail packages, and is read by a laser beam scanner. Universal Serial Bus (USB) standard A serial bus standard for connecting I/O devices to a computer.

User-supported software.

software

See

Public-domain

Utility programs A set of programs supported by an operating system to assist its users in system maintenance tasks, such as disk formatting, data compression, data backup, and scanning a system for computer viruses.

■ Glossary V Value Added Network (VAN) Enhanced data transmission service provided by adding value to standard services of common carriers. Added value may include features such as electronic mail, data encryption/decryption, access to commercial databases, and code conversion for communication between incompatible computers.

693

Video Graphics Array (VGA) An add-on board that enables interfacing of very high-resolution monitors to a computer system. Video server A component of Video-on-Demand (VoD) system that consists of massive storage and media controllers. It stores a large number of digitized videos, and on demand serves simultaneous requests to the same or different videos.

Value-added carrier A communications company that leases networks from a common carrier and combines messages from customers into packets for point-to-point transmission.

Virtual classroom A learning environment created by using computing technologies. Students can join and leave the learning environment at their own convenient time and can learn at their own pace.

Variable name In a program, name assigned to a data field that can assume any value out of a given set of values.

Virtual machine Concept of adding operating system layer on top of bare hardware to manage all parts of a system, and present to the users an interface, which is easier to program and use.

Vector graphics Graphic objects composed of patterns of lines, points, circles, arcs, and other geometric shapes (vectors), which can be represented by few geometric parameters. Verification Process by which a system verifies the identity claimed by a user.

Virtual memory A memory management scheme that enables execution of processes, which might not be completely loaded in main memory. The three basic concepts used for realization of virtual memory are on-line secondary storage, swapping, and demand paging.

Vertical blanking interval Time for the electron gun of a CRT display to move from the end of the bottommost scan-line to the beginning of the top-most scanline.

Virtual reality A technology using which a user can put a pair of goggles and glove and tour a threedimensional world that exists in the computer, but appears realistic to the user.

Vertical resolution Total number of scan lines of a CRT screen.

Virtual shop A shopping environment created by using computing technologies. It remains open 24 hours and allows customers to do purchases at any time without leaving the comfort of their homes.

Vertical trace In the process of scan of a CRT screen, after scanning all scan lines, when the beam gets to the right end of the bottom-most scan line, the device turns it off and moves it to the starting point of the top-most scan line. This is called vertical trace. Very Large Scale Integration (VLSI) An electronic circuit with about 10,000 transistors fabricated on a single silicon chip. Very Small Aperture Terminals (VSATs) Smaller disk antennas having lower power transmitters and receivers, which can be installed at users’ sites. It enables a large number of users to benefit from satellite communication. Video A multimedia component that contains a sequence of images (called frames) displayed at a reasonable speed to create an impression of motion. Video conferencing A system in which persons sitting far apart can see and talk to each other via a computer-communications network. It saves traveling cost and valuable time of executives. Video Display Terminal (VDT) A monitor and keyboard used together as both an input and output device. Also known as terminal.

Virtual uniprocessor A collection of networked computers that appears to its users as a large uniprocessor system. Its operating system provides similar type of user interface as that of centralized operating systems to achieve this. Virtualization Key design concept that allows servers, storage devices, and other hardware and software resources to be treated as a pool of resources (rather than discrete systems), so that they can be shared. Virus A computer virus is a piece of code attached to a legitimate program, which, when executed, infects other programs in the system by replicating and attaching itself to them. In addition to this replicating effect, a virus normally does some other damage to the system such as corrupting/erasing files. Vision input system An input device that enables a computer to accept input by seeing an object. Input data in this case is normally an object’s shape and features in the form of an image.

694

■ Foundations of Computing

Visualization A multimedia application in science and engineering that deals with exploring data and information in a form that is easier to comprehend.

White list A configurable list of addresses approved by a user from which the user agrees to receive emails.

Vocabulary Set of words allowed in a language.

White-box testing Software testing method in which the tester has good knowledge of internal implementation of software. He/she has access to the internal data structures, algorithm, and the code of the software.

Voice recognition device An input device that enables a person to input data to a computer by speaking to it. Voice reproduction system A voice response system that produces audio output by selecting appropriate audio output from a set of pre-recorded audio responses. Voice response system An output device that enables a computer to talk to its users. Voiceband Data communications system that handles moderate volumes of data, typically from 300 to 9600 bauds. Phone lines, which we use to talk to other people is an example. Volatile storage A storage medium that loses its contents when power fails, or when power is switched off.

W WatchOS The operating system designed by Apple Incorporation for its smart wrist watch.

Waterfall model See Software Development Life Cycle (SDLC). Web client A computer on the Internet that can access web servers. Web page A hypertext document on the Internet. Web security Deals with mechanisms to deal with various types of security issues (integrity, confidentiality, denial of service, and authentication) faced in using the Web. SSL and TLS are generalpurpose solutions for Web security, which implement security just above TCP within the TCP/IP protocol stack. Web server A computer on the Internet that uses HTTP protocol. Web Services (WS) It is a result of convergence of the Web and distributed object technologies. It is used extensively for building large Web-based applications for e-commerce, information distribution, entertainment, collaborative working, surveys, and numerous other activities. It allows anyone to create an electronic service and anyone else to use it, thus enabling anyone-to-anyone communications, coordination, and interaction. Webinar A new terminology that refers to web casting of a seminar.

Wide Area Network (WAN) A computer network that interconnects computers spread over a large geographical area. It may also enable LANs to communicate with each other. This type of network may be developed to operate nationwide or worldwide, and the transmission medium used are normally public systems such as telephone lines, microwave, and satellite links. Wildcard (character) A special character, usually a? or *, which is used in software commands as a generic reference to any character, or any combination of characters, respectively. WiMAX Stands for Worldwide Interoperability for Microwave Access. It is a technology based on the IEEE 802.16 standard that aims at WMANs (Wireless Metropolitan-Area Networks). Winchester disk Medium-sized, non-interchangeable metal disks permanently housed in sealed, contamination-free containers, with built-in read/write heads. Window A rectangular portion of a computer screen that is dedicated to a specific activity or application. The display screen can be separated into several windows to simultaneously show the status of different applications at any instance of time. Windows An operating system developed by Microsoft for use on personal computers. Its various release versions are Windows 3.0, Windows 95, Windows 98, Windows 2000, Windows XP, and Windows Vista. Windows Server A multi-user, timesharing operating system developed by Microsoft. It has Unix-like features. It is designed to be used for powerful workstations, and network and database servers. Wired mouse A mouse that is connected to a computer with a small cord (wire). Wireless Application Protocol (WAP) A technology that allows development of wireless applications that are independent of the underlying wireless access technology and that also enables access of information from existing web sites using mobile devices. Wireless computing system A computer network that uses wireless communication technologies. It

■ Glossary enhances the functionality of computing equipment by freeing communication from location constraints of wired computing systems. Wireless LAN (WLAN) A LAN having a wireless interface to enable wireless communication among the equipment that are part of the LAN. Wireless Local Loops (WLLs) A wireless communication technology designed to support fixed wireless systems. Wireless Markup Language (WML) A version of HTML optimized for mobile devices. Wireless World Wide Web (WWWW or W4) A standard for 5G technology. Word A group of bits or characters considered as an entity, and capable of being stored in one storage location. Also fixed-size storage areas, which form the primary memory of a computer system. Word length A measure of size of a word, usually specified in units such as characters or bits. Each location of a computer system can store a fixed number of characters or bits, called its word length.

695

Worm A program that spreads from one computer to another in a network of computers. It spreads by taking advantage of the way in which a computer network shares resources and, in some cases, by exploiting flaws in standard software, which computer networks use. It may perform destructive activities after arrival at a network node. Write-Once, Read-Many (WORM) disk An optical disk that looks like a standard CD-ROM disk, but allows a user to record his/her own information on it by using a CD-Recordable (CD-R) drive. WWW browser A special software tool that a user needs to load on his/her computer to use it as a web client, which provides navigation facilities to help users save time while Internet surfing. WYSIWYG Stands for What You See Is What You Get. This feature of a word-processing package allows users to display a document on screen in a form, which closely resembles the document in printed form.

X

Word wrap A word processing feature that automatically moves words down to the beginning of next line, if they extend beyond the right margin.

X terminal A graphics terminal that has a rich set of commands to display characters, move the cursor position, draw graphics and images, and manage multiple windows on the screen.

Word-addressable storage Storage designed to store a fixed number of characters (equal to its word-length in bytes). For such a storage device, storage space is always allocated in multiples of word-length. Its another name is fixed-word-length storage.

X.25 protocol A connection-oriented protocol, which establishes a virtual circuit between the sender and receiver before actual communication starts between them.

Word-processing package A software package that describes use of hardware and software to create, edit, view, format, store, retrieve, and print documents, enabling its user to do all these on a computer system.

Y

Workstation A powerful desktop computer designed to meet the computing needs of engineers, architects, and other professionals, who need greater processing power, larger storage, and better graphics display facility than what PCs provide. World Wide Web (WWW or W3) Network of computers across the world interconnected together on the Internet, and using the concept of hypertext to link Internet sites and information on the Internet.

Yahoo An Internet search engine.

Z Zip disk See Bernoulli disk. Zoned decimal numbers Numbers coded in EBCDIC are called Zoned decimal numbers because each decimal digit has a zone with it.

Index

1 1G, 505

2 2G, 505

3 3D Printers, 224 Applications of 3D Printers, 226 Types of 3D Printers, 225 3G, 505

4 4G, 505 4GL, 363

5 5G, 505 5GL, 363

A Access control, 578, 595, 601 control mechanism, 595 control terminologies, 595 matrix, 597, 598, 601 validation, 601 Adder, 93, 94 Full-adder, 94 Half-adder, 93 Parallel binary adder, 96 Additive Manufacturing (AM), 225 Additive method, 56 Add-on boards, 12 Add-on cards, 12

Address, 124 Address bus, 132 Advanced Mobile Phone System (AMPS), 505 Agile development method, 251 Algorithm, 280 Quality of algorithms, 282 Representation of algorithms, 282 Alpha version, 258 Alphanumeric keys, 198 Amplifiers, 483 Android OS, 422 Animation, 546 films, 556 Anonymous FTP site, 519 Anti-spam software, 612, 613 Application layer, 499 server, 525 Application software packages, 272 Education software package, 274 Entertainment software package, 275 Graphics package, 274 Personal-assistance package, 274 Spreadsheet package, 273 Word-processing package, 273 Application-level gateway, 604 Arithmetic logic unit (ALU), 114, 117 ARPANET, 494, 518 Array, 303, 306, 307 Dynamic arrays, 305 Jagged array, 307 k-dimensional arrays, 305 Multidimensional arrays, 305 One-dimensional arrays, 305 Ragged array, 307 Semi-static arrays, 305 Static arrays, 305 Arrow keys, 198 Aspect ratio, 551 Assembler, 339 Assembly language, 339, 341, 342, 343 program, 339 Association, 466

■ Index Asynchronous transmission, 486 Attack, 578 Active attack, 579, 582 Authenticity attack, 582 Chosen-plaintext attack, 584 Ciphertext-only attack, 584 Delay attack, 583 Denial attack, 582 Integrity attack, 582 Known-plaintext attack, 584 Passive attack, 578 Replay attack, 583 Attacker, 578 Attribute focusing, 468 Attribute-oriented induction, 468 Audio, 547, 550 Authentication, 586 One-way authentication, 590 server, 591 Two-way authentication, 594 Authorization, 595 Automatic Teller Machines (ATMs), 210 Autorepeat feature, 200

B Back-end computer, 13 Backup, 187 Data backup, 187 Full backup, 187 Incremental backup, 187 policy, 188 Backward compatibility, 117 Bandwidth, 475 Bar codes, 208 reader, 208 Basic Multilingual Plan (BMP), 47 Baud, 475 Bayesia network, 467 Beginning of Tape (BOT), 152 Beta version, 258 Binary, 49 addition, 49 arithmetic, 48 division, 55, 56 multiplication, 53, 55 subtraction, 50, 51 Binary counter, 105 Bio databases, 647 Bioinformatics, 645 Biometric device, 587 BIOS, 416 BIPS, 119, Bit, 125, 432 Check bit, 151 map representation, 205 Blade servers, 140 Blaise Pascal, 2

697

Block, 151 Block size, 130 Blocking, 151 factor, 151 Blocks, 403 Bluetooth, 11 Boolean algebra, 62, 64, 65 Laws of Boolean algebra, 64 Postulates of Boolean algebra, 64 Boolean functions, 68, 69 Booting, 416 Bottom-up approach, 252 Bourne shell, 411 Breakpoint, 256 Bridges, 500 Broadband, 476 Broadcast, 489 Brouters, 501 Browser, 521 Graphical browser, 522 Java-enabled browser, 522 Microbrowser, 531 Browsing, 578 Bugs, 255 Built-in-functions, 367 Bus, 131 Bus width, 131 Busy wait, 135 Bytes per second (bps), 153

C C shell, 411 Cache, 128 Data cache, 129 Instruction cache, 129 L1 cache, 130 L2 cache, 130 memory, 128 size, 130 Canonical forms, 72, 76 CASE (Computer Aided Software Engineering), 272 CASE tools, 272 C-band, 478 CD-ROM, 168 jukebox, 176 Cello, 522 Cellular, 503 Analog cellular, 503 Digital cellular, 503 Digital Packet Data (CDPD), 503 Central processing unit (CPU), 114, 116 architectures, 116 Instruction set, 117 scheduler, 382 scheduling, 382 scheduling algorithm, 382 Certification Authority (CA), 630

698

■ Foundations of Computing

CGA (color graphics adapter), 216 Changeover, 262 Immediate changeover, 263 methods, 263 operations, 262 Character coding schemes, 35 Character, 432 Characters-per-second (cps), 218 Charles Babbage, 2 Chips, 126 Ciphertext, 583 Circuit-level gateway, 605 Class, 352 Class variables, 352 Classification, 465 Cleartext, 583 Client, 17 authentication, 623 computers, 17 processes, 17 Client-server computing, 17 Clip art, 545 Clock, 119 cycles, 119 speed, 119 Cloud, 513 Hybrid clouds, 513 Private clouds, 513 Public clouds, 513 Cloud computing, 511, 513 Cluster, 159 Cluster analysis, 467 Cluster of Workstations (COWs), 140 Clustering, 465 Coaxial cable, 476 Code, 35 American Standard Code for Information Interchange (ASCII), 40 Binary Coded Decimal (BCD), 36 Extended Binary-Coded Decimal Interchange Code (EBCDIC), 38 point, 45 Unicode, 44 Code Division Multiple Access (CDMA), 505 Code Division Multiple Access 2000 (CDMA 2000), 505 Code generation, 250 tools, 272 Codespace, 47 Coding, 336 Collating sequence, 47 Collision, 437 Color and graphics adapter card, 12 Combinational Circuits, 93 Combinational logic circuits, 87 Command interpretation, 377, 410 interpreter, 410

Language (CL), 377, 411 line interface, 410 Comments, 268 Common carriers, 483 Communication, 474 processor, 484 protocol, 495 satellite, 477 security, 578 Compiler, 344 Complement, 51, 71 Complementary subtraction, 51 Complementation, 63 Complex Instruction Set Computer (CISC), 119 Compression, 559 techniques, 560 Computer, 1, 2 Characteristics of computers, 2 Evolution of computers, 2 generations, 4 language, 336 network, 474 organization, 113 virus, 414, 579 Computer Aided Design (CAD), 544, 558 Computer Aided Manufacturing (CAM), 544 Computer Emergency Response Team (CERT), 636 Computer Output Microfilm (COM), 228 Computer-aided drug design, 647 Computer-Supported Cooperative Working (CSCW), 510 Concentrators, 486 Conceptual clustering, 467 Console, 14 Content-based retrieval/querying, 458 Contiguous allocation, 404 Control bus, 132 Control characters, 38 Control statements, 378 Control Unit (CU), 115, 117 Correlation analysis, 467 Critical section, 387 CRT monitor, 214 Cryptography, 583 Cryptosystem, 583 Asymmetric cryptosystem, 585, 592 Private-key cryptosystem, 584 Public-key cyptosystem, 585 Symmetric cryptosystem, 584, 590 Cursor, 198 Cyber crime, 635 forensic, 635 infrastructure, 635 law, 635 Cylinder, 160 Cylinder-Head-Sector (CHS) addressing, 160

■ Index D Daemon, 409 Data, 1, 431 Alphabetic data, 35 Alphanumeric data, 35 archiving, 169 communication system, 475 Compressed data, 559 compression, 482, 559 Decompressed data, 559 dependence, 434 dictionary, 447 Enveloped data, 611 integrity, 434 interpretation/evaluation, 460 -link layer, 497 Manipulation Language (DML), 447 mart, 462 Numeric data, 35 preprocessing, 459 processing, 1, 432 processing system, 432 processor, 1 recording density, 153 redundancy, 434 security, 434 selection, 459 Signed and enveloped data, 611 Signed data, 611 storage hierarchy, 432 structure, 303 transfer rate, 153 transformation, 459 transmission media, 476 transmission service, 483 Data bus, 131 Data Definition Language (DDL), 446 Data mining, 460, 464, 469 algorithms, 465 techniques, 467 Data science, 458, 459 Data warehouse, 460, 461, 469 Database, 433, 434 Active database system, 455 clients, 453 Client-server database system, 453 Distributed database system, 454 Hierarchical database, 441 management system, 441 model, 441 Network database, 442 Relational database, 443 schema, 446 security, 452 server, 17, 453 Dead stores, 127 Deadlock, 390, 391

Debugger, 256 Debugging, 255, 256, 257 Deciphering, 583 Decision logic, 299 Decision table, 295, 296, 297 Decision tree, 467 Decoder, 117 Decomposition approach, 252 Decryption, 583 Dedicated line, 483 Default-deny, 604 Default-permit, 604 Demand Based Switching (DBS), 123 Demand paging, 397 Demodulation, 480 Design specification tools, 272 Device controllers, 231 drivers, 408 I/O devices, 197 management, 376, 407 Peripheral devices, 197 Speech recognition device, 211 Device-independent software, 408 Diacritics, 44 Dialpad, 530 Dial-up line, 483 Digital Audio Tape (DAT), 156 Digital library, 554 Digital Light Processing (DLP), 226 Digital signature, 602 Digital Video (or Versatile) Disk (DVD), 169 DVD-audio, 170 DVD-R, 170 DVD-RAM, 170 DVD-ROM, 170 DVD-RW, 170 DVD-video, 170 Digital watermarking, 607 Digitization, 548 Digitizer, 209 Digitizing tablet, 210 Digraph, 321, 323 Direct Memory Access (DMA), 232, 407 architecture, 135 controller, 136 Non-DMA transfer, 407 transfer, 407 Directory, 401 contents, 401 organization, 402 Disk, 158 access time, 161 CD Read/Write (CD-RW) disk, 169 CD-Recordable (CD-R) disk, 169 compaction, 404 controller, 163 drive, 163

699

700

■ Foundations of Computing

formatting, 162 geometry, 160 Laser disk, 165 Low-level disk formatting, 162 Magnetic disk, 158, 163, 164, 165 Multi-Session disk, 169 Optical disk, 165, 168, 170, 171 pack, 159, 164 space allocation, 403 Winchester disk, 164 WORM disk, 169 Zip/Bernoulli Disk, 164 Distributed object, 525 Distributed computing system, 17, 424, 509 Distributed Memory Systems, 139 Distributed system, 17 Documentation, 267 standard, 270 tools, 272 Domain, 596 Don’t care conditions, 83 Dongle, 606 Downloading, 519 Drill down analysis, 463 Dual bus architecture, 134 Dynamic binding, 355 content, 523 data type, 524 protocol, 524 Dynamic RAM (DRAM), 127

E Earliest playback time, 569 Edutainment, 569 EGA (extended graphics adapter), 216 Electro-luminescent display (ELD), 217 Electronic mail (e-mail), 518 Electronic mail (E-mail) security, 607 Electronic pen, 204 Electronic Programming Guide (EPG), 570 Electronic transaction process, 626, 627 Electronic-card reader, 210 Electronic-governance (E-governance), 640, 642 Electronic-mail (E-mail), 518 Spam e-mail, 612 spammer, 612 Unsolicited Bulk E-mail (UBE), 612 Encoding forms, 45 Encryption, 583 End of Tape (EOT), 152 End-to-end solution, 247 Enhanced Data Rate for GSM Evolution (EDGE), 505 Ergonomically designed devices, 231 Ergonomics, 231 ERNET, 494 Ethernet, 494

Excitation tables, 99 Exhaustive enumeration, 66 Expansion slot, 235 Expansion slots, 12 Explicitly Parallel Instruction Computing (EPIC), 120 Extended graphics, 545 External fragmentation, 394, 404

F Fall back feature, 481 Fax modem card, 12 Fiber Channel (FC), 181 FC-AL, 181 FC-P2P, 181 FC-SW, 181 Field, 432 Field stores, 127 File, 398, 432, 434 access, 399 Allocation Table (FAT), 162 Backup file, 435 Data file, 438 Direct file, 437 extensions, 400 header label, 152 Indexed sequential file, 438 management, 376, 398 management system, 435 Master file, 434, 435 naming, 400 operations, 400 organizations, 435 Output file, 435 Random access files, 399 Report file, 435 Sequential access files, 399, 436 server, 17 structure, 399 trailer label, 152 Transaction file, 434, 435 Transfer Protocol (FTP), 519 types, 435 utilities, 439 Filters, 415, 450 Find command, 450 Firewall, 530, 603, 604, 605 FireWire, 182 Firmware, 244 Fixed and Variable word-length memory, 125 Flash Drive (Pen Drive), 173 Flash memory, 174 Flat panel monitors, 216 Flip-flop, 97, 101 D (Data) flip-flop, 99 Edge-triggered flip-flop, 100 input equations, 102 JK (Jack Kilby) flip-flop, 99

■ Index Master-slave flip-flop, 101 SR (Set-Reset) flip-flop, 98 T (toggle) flip-flop, 99 Flowchart, 283, 286, 294 Macro flowchart, 293 Micro flowchart, 293 Symbols, 283, 285 Flowcharting, 283 rules, 293 FOCUS, 363 Font, 206 E13B font, 209 OCR-A fonts, 207 OCR-B fonts, 207 Forked, 581 Forms, 448 Fractional number, 34 Frames, 500, 546, 550 Freeware, 248 Frequency Shift Keying (FSK), 481 Front-end computer, 13 Front-End Processors (FEP), 486 Full-duplex, 475 Function, 367 Fused Deposition Modeling (FDM), 225 Fuzzy set, 468

G Garbage collection, 405 Gas-plasma display (GPD), 217 Gateways, 501 Gene expression, 647 Genomics, 646 Geo-informatics, 643 GFLOPS, 119 Gigabytes (GB), 126 Global Positioning System (GPS), 19 Global System for Mobile (GSM), 505 Glyph, 46 Google, 527 Graceful degradation, 385 Granting rights, 601 Graph, 320, 327 Graph search, 324 Breadth-first search, 325 Depth-first search, 326 Graphical User Interface (GUI), 200, 411 Graphics, 543, 544, 545 Cognitive graphics, 544 cursor, 201 Generative graphics, 544 Graphics adapter board, 216 Graphics tablet, 209 Grid computing, 511 Groupware, 510

H Half-duplex, 475 Handheld computers, 18 Hard Disk Drive (HDD), 172 Hardware, 242 Hash function, 311 Hash table, 311, 313 Hashing, 437 algorithm, 437 HD-MAC, 553 Heap, 328, 329 Heavyweight processes, 383 Helical scan, 156 Herman Hollerith, 2 Hierarchical Storage Management (HSM), 190 Hierarchical Storage System (HSS), 189 High Definition Television (HDTV), 553 Hit ratio, 130 Horizontal blanking interval, 551 Horizontal resolution, 215 Horizontal trace, 215 Host computer, 13 Hot list, 522 HotBot, 527 Hottelephone, 530 HP-Unix, 415 Hybrid Secondary Storage Drives, 175 Hypertext, 520, 543 HyperText Markup Language (HTML), 521

I I/O buses, 132 I/O interfaces, 231 Identification, 586 Images, 544 Impact printers, 218 In-degree branch, 313 Index block, 405 Indexed allocation, 405 Indexed Sequential Access Method (ISAM), 438 Indexing, 304 n-based indexing, 304 One-based indexing, 304 Zero-based indexing, 304 Inductive concept learning, 467 Industry 4.0, 536 Inference Find, 527 Inferencing, 579 Infopedia, 168 Information, 1, 432 Infoseek, 527 Infotainment, 569 Inheritance, 352 Multiple inheritance, 352 Input device, 197 Input unit, 114

701

702

■ Foundations of Computing

Instance variables, 352 Integrated circuits, 5 Integrated Services Digital Network (ISDN), 483 Broadband ISDN, 484 Narrowband ISDN, 484 Interactive TV, 556 Inter-Block Gaps (IBG), 151 Interface Definition Languages (IDL), 366 Interlaced scan, 215, 551 Intermediate Definition Language (IDL), 349 Intermediate language compiler, 348 Intermediate object program, 349 Internal fragmentation, 395 Internet, 518 protocol, 498, 521, 532 search engine, 526 services, 518 surfing, 521 telephony, 530 Uses of Internet, 527 Internet of Things (IoT), 533 Benefits of IoT, 533 Challenges in Adopting IoT, 536 Uses of IoT, 534 Internetwork, 500 Internetworking, 500 tools, 500 Interpreter, 348 Inter-Record Gaps (IRG), 151 Interrupt, 135 Interrupt handlers, 408 Intranet, 529 Intruder, 578 iOS, 420 IP Security (IPSec), 614, 616 functionality, 615 Iteration logic, 300 Iterative database scanning, 468 Ixquick, 527

J Job, 377 CPU-bound jobs, 379 I/O-bound jobs, 379 Job Control Language (JCL), 377, 378, 411 Joint Photographic Experts Group (JPEG ), 561 Joystick, 203 Just-In-Time (JIT) compilation, 349

K Kernel, 411, 415, 416 Microkernel, 412 Monolithic kernel, 412 Kernel mode, 597 Key exchange, 622 Key field, 436

Keyboard, 197 buffer, 200 devices, 197 Foreign Language Keyboard, 199 Special-purpose Keyboards, 199 templates, 200 Kilobytes (KB), 126 Kiosk, 204 K-map, 77, 79 Korn shell, 411 Ku-band, 478

L Language processors, 348 Laptops, 11 Large Scale Integration (LSI), 6 Latency, 162 Layered structure, 411 Leaking, 579 Leased line, 483 Least recently used (LRU) algorithm, 130 Lightweight processes, 383 Linked allocation, 404 Linked list, 307, 308, 309 Doubly-linked list, 308 Singly-linked circular list, 308 Singly-linked list, 308 Linker, 347 Link, 521 Linux, 418, 419 Liquid-crystal display (LCD), 217 Load module, 347 Local Multipoint Distribution Systems (LMDS), 504 Locality of reference, 129 Logic bombs, 582 Logic circuits, 87, 88 Logic errors, 255, 256, 346 Logic gates, 84 AND gate, 84 Exclusive-NOR (Equivalence) gate, 87 Exclusive-OR (XOR) gate, 86 NAND gate, 85 NOR gate, 85 NOT gate, 85 OR gate, 85 Universal gate, 88, 90 Logical addition, 63 Logical multiplication, 63 Long Term Evolution (LTE), 505 Loosely-coupled systems, 136 Lossless techniques, 559, 560 Lossy techniques, 559, 560 Lycos, 527

M Mac OS, 419

■ Index Machine language, 337, 338, 341 Machine learning, 467 Macro instruction, 343 MacWeb, 522 Magnetic disk, 158 Magnetic strip cards, 210 Magnetic tape, 150, 154, 157 cartridge, 155 drive, 153 Magnetic-Ink Character Recognition (MICR), 208 Mainframe systems, 13 Manual keyword indexing, 457 Manual loading mechanism, 378 Map simplification, 77 Markup language, 364 HTML (HyperText Markup Language), 365 SGML (Syntax for Generalized Markup Language), 365 TeX and LaTex, 365 XHTML (eXtensible HyberText Markup Language), 366 XML (eXtensible Markup Language, 365 Masquerading, 579 Mass storage device, 175 Massive MIMO, 505 Massively parallel processors, 16 Master file, 157 MatLab, 363 Maxterms, 72 Media center computer, 569 Media center OS, 571 Media center PC, 569 Medical informatics, 644 Medium Scale Integration (MSI), 5 Megabytes (MB), 126 Memory, 123 arcitecture, 123 Auxiliary memory, 149 capacity, 126 card, 174 dump, 25, 257 Flash memory, 128 fragmentation, 394 interleaving, 130 Main memory, 114, 123 management, 376, 392 -mapped I/O, 407 organization, 124 partition, 381 Random Access Memory (RAM), 124 read operation, 125 Storage Device, 171 write operation, 125 Message, 351, 583 interface, 351 protocol, 351 Message-passing systems, 139 Metadata, 457, 463

Method, 351 MFLOPS, 119 Microarray data analysis, 647 Microcode, 117 Microfiche, 228 Microfilm recorder, 228 Microprocessor, 6, 117 Microprograms, 127 Microsoft Windows, 417 Microsoft Windows NT, 418 Microsoft Windows Server, 418 Microwave system, 476, 504 Middleware, 244, 245 MIDI (Musical Instrument Digital Interface), 548 Millimeter Wave Mobile Communications, 505 MIMO (Multiple Input Multiple Output), 505 Minterms, 72 MIPS, 119 Mobile computing, 502 Mobile Radio Networks, 503 Modem, 481 External modem, 482 FAX modem, 482 Intelligent modem, 483 Internal modem, 482 Smart modem, 483 Modulation, 480 Amplitude Modulation (AM), 480 Frequency Modulation (FM), 481 Phase Modulation (PM), 481 Modulation protocol, 481 Molecular modeling, 648 phylogenetics, 647 Monitors, 213 Mosaic, 522 Motherboard, 12 Motion Pictures Experts Group (MPEG), 563 audio, 566 video, 563 Motion video card, 12 Mouse, 201 Mechanical mouse, 202 One, two, and three buttons mouse, 202 Optical mouse, 202 Serial and bus mouse, 203 Wired and cordless mouse, 203 MS-DOS, 416 Multicomputer systems, 139 Multidimensional OLAP (MOLAP), 463 Multimedia, 541 applications, 554 books, 554 catalogue, 557 components, 542 compression techniques, 561 computer system, 542 conferencing, 558

703

704

■ Foundations of Computing

content description interface, 566 data manipulation, 457 data modeling, 457 data query, 457 data relationships, 456 data storage and retrieval, 456 data types, 456 database, 455 database management system, 455 framework, 566 kiosk, 557 presentation, 555, 557 synchronization, 567 user interface, 458 Multiplexer, 484 Multiplexing, 484 Frequency-Division Multiplexing (FDM), 485 techniques, 485 Time-Division Multiplexing (TDM), 485 Multiprocessing, 16, 384 Multiprocessing system, 384 Loosely-coupled systems, 384 Tightly-coupled systems, 384 Multiprogramming, 379, 380, 384 memory models, 393 system, 381 with fixed number of memory partitions, 393 with Fixed Tasks (MFT), 380 with variable number of memory partitions, 393 with Variable Tasks (MVT), 380 Multitasking, 382 Multithreading, 382 MUSE, 553 Mutual exclusion, 387

N Name Server, 17 Narrowband, 475 Near-letter-quality (NLQ), 218 Near-typeset-quality (NTQ), 218 Need-to-know principle, 578 Net2phone, 530 Netiquette, 520 NetScape, 522 Network, 17, 474 Campus Area Networks (CANs), 493 card, 496 Interface Card (NIC), 12, 496 layer, 498 Local Area Networks (LANs), 493 Long-haul networks, 493 Metropolitan Area Networks (MANs), 493 Personal Area Networks (PANs), 493 protocol, 495 topologies, 491 Transport network, 556 Value Added Network (VAN), 484

Wide Area Networks (WANs), 493 Network interface card, 12 Network Operating System (NOS), 418, 424 Neural network, 468 Newsgroup, 520 Moderated newsgroup, 520 Nonmoderated newsgroup, 520 NICNET, 494 Nomadic computing, 502 Nonce, 583 Nonimpact printers, 218 Non-resident modules, 412 Notebook computers, 11 NTSC, 552 Number system, 24, 26 Binary number system, 25, 30, 31, 32, 33 Decimal number system, 25, 26 Hexadecimal number system, 26, 32, 33 Octal number system, 26, 30, 31 Numeric keypad, 198 Nyquist theorem, 548

O Obfuscation, 606 Object, 351, 595 Object monitor, 598 Object-based coding, 565 Object-Oriented database, 444, 445 database management system, 445 paradigm, 353 Programming (OOP), 350, 355 programming language, 354 OFDM (Orthogonal Frequency Division Multiplexing), 505, 507 One-way cipher, 588 Online Analytical Processing (OLAP), 462 communication, 528 journals and magazines, 528 shopping, 529 teaching/learning, 527 Transaction Processing (OLTP), 462 Open System Interconnection (OSI), 496, 499 model, 496 Operating system, 375, 376 Distributed operating systems, 424 Network operating systems, 424 Real-time operating systems, 423 structure, 411 Operator precedence, 64 Optical Character Recognition (OCR), 206 Optical disk drive, 167 Optical fibers, 479 Optical Mark Reader (OMR), 207 Out-degree branch, 313 Out-of-the-middle approach, 253

■ Index Output device, 213 Hard-copy output, 213 Soft-copy output, 213 unit, 114

P Packed decimal, 39 Page, 396 -fault rate, 398 frames, 395 table, 396 Page printer, 218 Pages-per-minute (ppm), 218 Paging, 395 PAL, 552 Palmtop, 18 Parallel computers, 16 port, 233 processing, 16, 385 processing systems, 16, 142 program, 16 representation, 154 run, 263 PARAM, 16 Parity bit, 151 Even-parity, 151 Odd-parity, 151 Partial revocation, 634 Passing rights, 601 Password, 587, 588, 589 book, 589 One-time password, 589 Pen drive, 173 Perceptual coding, 566 Perfect induction, 66 Peripheral Processing Unit (PPU), 136 Perl, 363 Permanent stores, 127 Personal Communications Services (PCS), 503 Personal computers, 12 Personal Digital Assistant (PDA), 19 Personal Information Manager (PIM), 19 PFLOPS, 119 Phased conversion, 264 PhoneFree, 530 Physical layer, 497 Pipeline, 415 Pixel, 205, 544 Plain Old Telephone Service (POTS), 484 Plaintext, 583 Playback deadline, 568 Playback schedule, 568 Plotter, 224 Drum plotter, 224 Flatbed plotter, 224

Pocket PC, 19 Point-and-draw devices, 200 Ports, 231 Postprocessor, 369 Potential attacks, 578 Predictive encoding, 560 Preprocessor, 368 Presentation layer, 499 Pretty Good Privacy (PGP), 608 Primary key, 439 Principle of duality, 64 Principle of least privilege, 578 Print server, 17 Printer, 218 Chain/band printer, 222 Character printer, 218 Dot-matrix printer, 219 Drum printer, 221 Hydra printer, 223 Inkjet printer, 220 Laser printer, 223 Line printer, 218 Privacy Enhanced Mail (PEM), 609 Privacy filter, 218 Private line, 483 Private use area, 47 Procedure, 367 Process, 376, 377 management, 376, 377, 378 Process Control Block (PCB), 381 Processing, 432 Processor, 119 Multicore processor, 121 Power-aware processor, 122 Power-efficient processor, 123 speed, 119 Product-of-sums, 74 simplification, 82 Program, 242 Application program, 243 Application programmer, 243 Client program, 453 Computer program, 242 design language (PDL), 298 errors, 255 Library programs, 413 Object program, 339, 344 Peripheral interchange program, 440 planning, 280 Server program, 453 Source program, 339, 344 Symbolic program, 339 Translating programs, 413 Programming, 336 Structured programming, 298 Programming language, 336, 361 Fifth-generation languages (5GLs), 363 Fourth-generation languages (4GLs), 363

705

706

■ Foundations of Computing

High-level language, 344, 349, 350, 356 Low-level language, 344 Markup language, 364 Non-procedural language, 363 Object-oriented programming language, 350, 354 Procedural language, 363 Procedure-oriented programming language, 354 Scripting language, 362 Selecting a Language for Coding, 362 Symbolic language, 339 Progressive scan, 215, 551 Proof by knowledge, 586 Proof by possession, 586 Proof by property, 587 Protection Domain, 596 rules, 596 state, 598 Proteomics, 646 Protocol, 495, 590, 592 Connectionless protocol, 498 Connection-oriented protocol, 498 family, 496 File Transfer Protocol (FTP), 499 HyperText Transport Protocol (HTTP), 521 rlogin (Remote Login Protocol), 499 stack, 496 suite, 496 Transport Control Protocol (TCP), 498 User Datagram Protocol (UDP), 498 X.25 protocol, 498 X.400 (electronic mail protocol), 499 X.500 (directory server protocol), 499 Pseudo disk, 175 Pseudocode, 298, 301, 302 Pseudo-instructions, 339 Public Key Infrastructure (PKI), 631 Public-key certificate, 630 Publicly accessible sites, 519 Python, 363

Q QIC (Quarter Inch Cartridge) standard, 156 Quantization, 549 Quantum, 386 Query By Example (QBE), 451, 458 Query language, 447, 451 Queue, 310, 311

R Radio-router Technology, 507 RAMIS, 363 Random Access Memory (RAM), 126 disk, 175 Rapid manufacturing, 227 Rapid prototyping, 227

Raster scanning, 551 Read/write heads, 161 Read-Only Memory (ROM), 127 Electrically EPROM (EEPROM), 128 Erasable Programmable Read-Only Memory (EPROM), 128 Manufacturer-programmed ROM, 128 Programmable Read-Only Memory (PROM), 128 Ultra Violet EPROM (UVEPROM), 128 User-programmed ROM, 128 Real-time system, 423 Record, 432 Reduced Instruction Set Computer (RISC), 120 Redundant Array of Inexpensive Disk (RAID), 176 levels, 178 storage, 177 techniques, 177 Refresh rate, 215, 546, 551 Registers, 117 Accumulator register, 118 Input/Output register (I/O), 118 Instruction register, 118 Memory Address Register (MAR), 118 Memory Buffer Register (MBR), 118 Program Control register (PC), 118 Regression anaysis, 467 Relational OLAP (ROLAP), 463 Relevance score, 526 Remote login, 519 Replacement policy, 130 Report, 447, 452 generator, 447 Resident modules, 412 Resolution, 215 Response time, 377 Retrieval schedule, 568 RGB monitors, 216 Rights Data Dictionary (RDD), 566 Rights Expression Language (REL), 566 Rights revocation, 602 Robots, 526 Roll up analysis, 463 Rotational delay time, 162 Router, 501 Packet-filtering rout, 604 Routing, 490 decisions, 491 Dynamic routing, 491 Hop-by-hop routing, 491 Hybrid routing, 491 Source routing, 491 Static routing, 491 techniques, 490 Ruby, 363 Run-length coding, 560

■ Index S Sampling, 548 rate, 548 Satellite, 504 Scan-line, 551 Scanner, 205 Flat-bed scanner, 205 Hand-held scanner, 206 Image scanner, 205 Scanning devices, 204 Schema, 448 builder, 448 Screen image projector, 229 Screen size, 215 Script, 47 Search engine, 526, 527 Natural language search engines, 526 Subject directories search engines, 526 Subject guide search engines, 526 SECAM, 552 Secondary key, 439 Sector, 158 number, 159 Secure Electronic Transaction (SET), 625, 627 Secure Socket Layer (SSL), 616 alert protocol, 619 architecture, 618 change ciper spec protocol, 619 handshake protocol, 621 record protocol, 618 Secure systems design, 634 Secure/Multipurpose Internet Mail Extensions (S/MIME), 610 Security, 376, 577 Communication security, 578 External security, 578 Internal security, 578 Seek time, 161 Selection logic, 299 Selective Laser Sintering (SLS), 226 Selective revocation, 634 Semaphore, 388 Binary semaphore, 389 Counting semaphore, 389 Sequence logic, 299 Sequential circuits, 102, 104 Serial Advanced Technology Attachment (SATA), 181 Serial ports, 232 Serial representation, 156 Server, 17 Application server, 525 authentication, 622 computer, 17 Connection-establishment server, 605 Network Address Translating (NATing) server, 605 process, 17 Proxy server, 530, 604

Resource server, 525 Server-key-exchange, 622 Session layer, 498 Set-top box, 556 Shared memory systems, 137 Cache memory architecture, 137 Crossbar switch architecture, 139 Multiport memory architecture, 139 Omega switching network architecture, 139 Shared bus architecture, 137 Shared-key, 584 Shareware, 248 Shell, 411, 415, 416 Shell script, 363 Silicon disk, 175 Simplex, 475 Single in-line memory modules (SIMMs), 126 Single sign-on, 590 Single-system image, 424 Small Computer System Interface (SCSI), 179 controller, 179 interface, 179, 234 Internet SCSI (iSCSI), 183 Serial Attached SCSI (SAS), 180 Small Scale Integration (SSI), 5 Smart Agriculture, 536 Smart cards, 210 Smart City, 534 Smart Energy Management, 535 Smart Healthcare, 535 Smart Home, 534 Smart Manufacturing, 536 Smart objects, 533 Smart Transportation System, 536 Smartphone, 19 Snowflake schema, 464 Soft keys, 198 Software, 242, 243, 246 Application software, 243 Community-supported software, 248 Customized software, 246, 247 Development Life cycle (SDLC), 248 documentation, 267, 268 engineering, 270, 271 Image-processing software., 205 maintenance, 265, 266 Open Source Software (OSS), 248 OS capability enhancement software, 412 package, 242 piracy, 606 Public-domain software, 248 sharing, 528 System software, 243 User-supported software, 248 Software simulated keys, 200 Software testing, 255 Alpha testing, 258 Beta testing, 258

707

708

■ Foundations of Computing

Black-box testing, 259 Functional testing, 258 Grey-box testing, 259 Integrated testing, 258 Internationalization testing, 258 Localization testing, 258 Non-functional testing, 258 Scalability testing, 258 Security testing, 258 Unit testing, 250, 258 Usability testing, 258 White-box testing, 259 Solaris, 415 Solid State Drive (SSD), 172 Source-code analysis tools, 272 Spam e-mail, 612 Spatial relationships, 456 Special function keys, 198 Speech synthesizer, 230 Spiders, 526 Spoofing, 579 Spooling, 409 SQL, 447, 451 Stack, 309, 310 Standard Generalized Markup Language (SGML), 521 Star schema, 464 State diagram, 104 State table, 102 Static binding, 355 Static RAM (SRAM), 127 Statistics, 467 Steganography, 632 STereoLithography (STL), 226 Storage, 123 Area Network (SAN), 181, 185 Auxiliary storage, 114 capacity, 123 Direct access storage device, 162 Direct Attached Storage (DAS), 181, 184 dump, 257 evaluation criteria, 123 hierarchy, 189 interfaces, 179 Near-line storage, 190 Network Attached Storage (NAS), 186 Non-volatile storage, 124 Offline storage, 190 Online storage, 190 Primary storage, 114, 123, 149 Random access storage device, 150, 162 Secondary storage, 114, 149 Sequential-access storage device, 149 unit, 114 Volatile storage, 124 Store-and-forward, 489 Streamer tape, 155 Stylus, 209 Sub-classes, 352

Subprocedures, 367 Subprogram, 366 body, 367 header, 367 Intrinsic subprogram, 367 name, 367 Programmer-written subprogram, 367 Subroutines, 367 Subtractive Manufacturing (SM), 225 Sum-of-products, 73 Supercomputers, 15 Superscalar architecture, 119 Swapping, 397 Switched line, 483 Switching, 487 Circuit switching, 488 Message switching, 489 Packet switching, 490 techniques, 487 Synchronization relationships, 456 Synchronous transmission, 487 Syntax errors, 255, 346 Syntax rules, 336 Synthesis approach, 253 System, 115 board, 12 calls, 410 evaluation, 265 manual, 269 performance, 377 program, 243 programmers, 243

T Tablet PC, 18 Tamper-proofing, 607 Tape, 150, 154, 157 Automated tape library, 176 header label, 152 Tcl, 363 Telnet, 519 Temporal relationships, 456 Temporal specification, 567 Temporal synchronization, 568 Terabytes (TB), 126 Terminal, 213 Dumb terminal, 217 Intelligent terminal, 217 Smart terminal, 217 Terminal emulators, 217 Test-and-Set, 387 Testing and debugging tools, 272 Text, 542 TFLOPS, 119 Things, 533 Threads, 382, 383 Three-tier system architecture, 245

■ Index Throughput, 377 Tightly-coupled systems, 136 Time slice, 386 Time slot, 386 Time-sharing, 385 system, 386 Top-down approach, 252 Topology, 491 Touch screen, 204 Trackball, 203 Tracks, 158 Trailer record, 288 Trailer value, 288 Transaction file, 157 Transducer, 547 Transfer rate, 162 Transform encoding, 560 Transport layer, 498 Transport Layer Security (TLS), 616, 624 Tree, 313, 314, 315 Binary search tree, 318, 320 Binary tree, 315, 317, 318 Binary tree traversal, 317 Trend analysis, 466 Trojan horse attack, 579 program, 579 Truth table, 63 Tuple, 443 Turnaround time, 377 Turnkey solution, 247 Twisted-pair wire, 476 Two-tier model, 524 Two-tier system architecture, 244 Typeset-quality (TQ), 218

U Ultra Large Scale Integration (ULSI), 8 Ultrix, 415 Unibus architecture, 134 Unicode, 44 transformation format-8, 45 transformation format-16, 45 transformation format-32, 45 Uniform Resource Locator (URL), 522 Unimedia, 541 Uniprogramming, 379 memory model, 392 system, 379 Universal Mobile Telecommunication System (UMTS), 505 Universal Product Code (UPC), 208 Universal Serial Bus (USB) Standard, 235 Unix, 415 Unshielded twisted-pair (UTP), 476 Uploading, 519 Usenet news, 520

User authentication, 578 User-level software, 408 User manual, 269 User mode, 597 Utility, 413, 415 Antivirus utility, 414 Copying utility, 440 Data backup utility, 414 Data compression utility, 413 Disk compaction utility, 413 Disk formatting utility, 413 Maintenance utility, 441 Merging utility, 440 Printing utility, 441 programs, 413 Searching utility, 439 Sorting utility, 439

V Validating access, 598 Variable-length coding, 560 Vehicle-to-Infrastructure (V2I) communication, 536 Vehicle-to-Person (V2P) communication, 536 Vehicle-to-Vehicle (V2V) communication, 536 Verification, 586 Vertical blanking interval, 551 Vertical resolution, 215 Vertical trace, 215 Very Large Scale Integration (VLSI), 6 Very Small Aperture Terminals (VSATs), 478 VGA (Video Graphics Array), 216, 545 Video, 550, 554 conferencing, 558 server, 556 Video card, 216 Video Display Terminal (VDT), 213 Viola, 522 Virtual machine, 375 memory, 397, 398 organization, 511 Private Network (VPN), 605 reality, 546, 558 shopping malls, 558 shops, 558 single system, 424 Virtualization, 512 Para-virtualization, 512 Vision-input system, 212 Visual exploration, 469 Visualization, 559 Voice Over IP (VOIP), 531 Voice reproduction system, 230 Voice response system, 229 Voiceband, 476

709

710

■ Foundations of Computing W

WatchOS, 421 Watchpoint, 257 Waterfall model, 249 Web casting, 529 client, 451, 521 crawler, 526 pages, 521 security, 616 server, 521 service, 524 Webinar, 529 White list, 613 Wireless, 501 Application Environment (WAE), 509 Application Protocol (WAP), 508 applications, 502 communication technologies, 503 computing system, 501 Datagram Protocol (WDP), 509 Fixed wireless system, 502 Local Area Network (WLANs), 506 Local Loops (WLLs), 507 Markup Language (WML), 508

Mobile wireless system, 502 Multihop wireless networks, 508 networks, 501 Session Protocol (WSP), 509 technologies, 504 Transaction Protocol (WTP), 509 Transport Layer Security (WTLS), 509 Wireless World Wide Web (WWWW), 505 Word length, 124 Word size, 117 Workstation, 13 World Wide Web (WWW), 520 browser, 521 Worldwide video conferencing, 529 Worms, 580 Write policy, 130

Y Yahoo, 527

Z Zip drive, 164 Zoned decimal, 39

KNOW YOUR AUTHOR

Dear Reader, I am proud to share with you that Dr. Pradeep K. Sinha, the main author of this book, has been associated with our publication house for more than thirty-five years. During this period, I have seen him grow from strength-tostrength in the computing field. This is also reflected by the recognitions that various national and international professional bodies have conferred upon him for his contributions to the computing field. For example: 1. In 2009, the Association for Computing Machinery (ACM), New York, USA conferred upon him the recognition of “ACM Distinguished Engineer” for his contributions to both the practical and theoretical aspects of Computing and Information Technology. ACM confers this recognition to members who have demonstrated creativity, leadership, and dedication to computing and computer science. ACM (www.acm.org) is the world’s largest educational and scientific computing society, which strengthens the computing profession's collective voice through strong leadership, promotion of the highest standards, and recognition of technical excellence. 2. In 2012, the Institute of Electrical and Electronics Engineers (IEEE), New York, USA conferred upon him the recognition of “IEEE Fellow” for his leadership in distributed and parallel processing systems. IEEE Fellow is a distinction reserved for select IEEE members who have extraordinary accomplishments in any of the IEEE fields of interest. IEEE (www.ieee.org) is the world’s largest technical professional organization dedicated to advancing technology for the benefit of humanity. 3. In 2017, Dr. Sinha was awarded the “Fellowship of Computer Society of India (CSI)” in recognition of his contributions to the society and for his boundless effort for the growth and betterment of IT fraternity. 4. In 2022, the Society for Data Science (S4DS) conferred upon him the “Lifetime Achievement Award” for being among the select list of peerless scientists who have dedicated their lives for advancing science and technology for the betterment of society. Dr. Sinha is the recipient of several other awards and recognitions for his contributions to the field of Computer Science & Engineering. I have reproduced overleaf a few news articles covering some of the recognitions of Dr. Sinha. I am sure you will greatly benefit from this and other books authored by such an authority in Computer Science.

January, 2023

Manish Jain BPB Publications

712

■ Foundations of Computing