šŸ“˜Computer Science - Important Notes

Hardware & Operating Systems

Introduction to Computer Hardware

  • Hardware refers to the tangible, physical components of a computer system that can be seen and touched by the user.
  • The functionality of hardware is dictated by the software instructions provided through various programming languages and system utilities.
  • Basic hardware components are classified into four categories: Input devices, Output devices, Storage devices, and the Processing unit.
  • Internal hardware includes components inside the computer case such as the motherboard, Central Processing Unit, and Random Access Memory.
  • External hardware, often called peripherals, includes devices like keyboards, monitors, mice, and external hard drives connected to the system.
  • The interaction between hardware and software is facilitated by the Operating System, which acts as a bridge for communication.
  • Hardware lifecycle management involves procurement, maintenance, and eventual decommissioning to ensure system reliability and data security.
  • Computer architecture defines the conceptual design and fundamental operational structure of a computer system's hardware components.

Central Processing Unit (CPU) Architecture

  • The Central Processing Unit is known as the brain of the computer, responsible for interpreting and executing most commands.
  • Control Unit (CU) manages the flow of data through the processor and coordinates the activities of other hardware components.
  • Arithmetic Logic Unit (ALU) performs all mathematical calculations and logical comparisons like addition, subtraction, AND, and OR operations.
  • Registers are small, high-speed storage locations within the CPU used to hold data and instructions currently being processed.
  • The Program Counter (PC) is a specific register that holds the memory address of the next instruction to be executed.
  • CPU clock speed is measured in Hertz (Hz), representing the number of cycles the processor can execute per second.
  • Example: A CPU with a clock speed of 3.0 GHz can perform 3.0 Ɨ 10⁹ cycles per second to execute instructions.
  • Multi-core processors contain multiple independent processing units on a single chip to perform parallel processing and improve performance.
  • Cache memory is a small amount of very fast SRAM located on or near the CPU to store frequently accessed data.

Memory Hierarchy and Primary Storage

  • Memory hierarchy organizes storage based on response time, with faster but more expensive memory placed closer to the CPU.
  • Primary memory consists of RAM and ROM, which are directly accessible by the CPU during system operation.
  • Random Access Memory (RAM) is volatile memory used to store data and programs that are currently in use by the system.
  • Read-Only Memory (ROM) is non-volatile memory containing permanent instructions like the BIOS needed to start the computer.
  • Static RAM (SRAM) is faster and more expensive than Dynamic RAM (DRAM) and is typically used for CPU cache.
  • Dynamic RAM (DRAM) requires constant refreshing of electrical charges to retain data and is used for the main system memory.
  • The speed of memory is often measured in nanoseconds (ns), where 1 ns = 10⁻⁹ seconds, indicating the latency of data retrieval.
  • Memory bandwidth refers to the rate at which data can be read from or stored into a semiconductor memory by a processor.

Secondary Storage and Data Persistence

  • Secondary storage provides non-volatile, long-term data retention even when the computer system is powered off.
  • Hard Disk Drives (HDD) use rotating magnetic platters and a moving read/write head to store and retrieve digital information.
  • Solid State Drives (SSD) use flash memory technology with no moving parts, offering significantly faster access speeds than traditional HDDs.
  • Optical storage devices like CDs, DVDs, and Blu-ray discs use laser technology to read and write data onto reflective surfaces.
  • Magnetic tape is a sequential access storage medium primarily used for large-scale data archiving and backup purposes.
  • Storage capacity is measured in units of bytes, where 1 Kilobyte (KB) = 1024 bytes and 1 Megabyte (MB) = 1024 KB.
  • RAID (Redundant Array of Independent Disks) technology combines multiple physical drives into one unit for data redundancy or performance.
  • Example: RAID 1 uses disk mirroring to ensure that if one drive fails, the data remains accessible on the second drive.

Input and Output (I/O) Management

  • Input devices like keyboards, mice, and scanners allow users to provide data and control signals to the computer system.
  • Output devices like monitors, printers, and speakers translate processed data into human-readable or audible formats.
  • The I/O controller acts as an interface between the CPU and specific peripheral devices to manage data transmission.
  • Interrupt-driven I/O allows the CPU to perform other tasks while waiting for a peripheral device to become ready.
  • Direct Memory Access (DMA) allows hardware subsystems to access main system memory independently of the CPU, reducing processor overhead.
  • The resolution of a monitor is defined by the number of pixels displayed, such as 1920 Ɨ 1080 for a standard High Definition screen.
  • Printers are classified into impact (dot matrix) and non-impact (laser, inkjet) types based on their printing mechanism.
  • Device drivers are specific software programs that allow the Operating System to communicate with and control hardware peripherals.

Motherboard and System Bus

  • The motherboard is the main printed circuit board (PCB) that connects all the essential components of a computer together.
  • Chipsets on the motherboard manage the communication between the CPU, memory, and various peripheral devices.
  • The System Bus is a communication pathway consisting of the Data Bus, Address Bus, and Control Bus.
  • Data Bus carries the actual information being processed, while the Address Bus carries information about where the data is going.
  • Control Bus carries signals that report the status of various devices and provide timing for system operations.
  • Expansion slots like PCIe (Peripheral Component Interconnect Express) allow for the addition of sound cards, graphics cards, and network cards.
  • Form factors like ATX and Micro-ATX define the physical dimensions and layout of the motherboard for compatibility with cases.
  • The CMOS battery provides power to a small chip that stores system settings like the date and time when the PC is off.

Introduction to Operating Systems

  • An Operating System (OS) is system software that manages computer hardware, software resources, and provides common services for programs.
  • The Kernel is the core part of the OS that remains in memory and handles low-level tasks like memory and process management.
  • User Interface (UI) allows humans to interact with the OS through a Command Line Interface (CLI) or a Graphical User Interface (GUI).
  • Resource allocation is a primary function of the OS, ensuring that hardware like the CPU and RAM are used efficiently by applications.
  • Security and protection mechanisms in an OS prevent unauthorized access to data and ensure system stability against malicious software.
  • Error detection and handling services in the OS monitor the system for hardware malfunctions or software crashes.
  • The Shell is a program that provides a user interface for access to an operating system's services and executes user commands.
  • Examples of popular Operating Systems include Microsoft Windows, macOS, Linux, Android, and iOS for mobile devices.

Types of Operating Systems

  • Batch Operating Systems process a series of jobs in a sequence without manual intervention between the user and the computer.
  • Time-Sharing Operating Systems allow multiple users to share resources simultaneously by allocating small time slices of CPU to each user.
  • Distributed Operating Systems manage a group of independent computers and make them appear to be a single, coherent system to the user.
  • Network Operating Systems (NOS) run on a server and provide the capability to manage data, users, groups, and security over a network.
  • Real-Time Operating Systems (RTOS) are designed for applications where data processing must occur within strict time constraints.
  • Example: An RTOS is essential in medical imaging systems or flight control software where delayed processing could be fatal.
  • Multi-user Operating Systems allow more than one user to access the computer system at the same time.
  • Embedded Operating Systems are designed for specific tasks in devices like washing machines, microwaves, and automotive systems.

Process Management and Scheduling

  • A process is a program in execution, consisting of the program code, current activity, and a set of associated resources.
  • Process states include New, Ready, Running, Waiting, and Terminated as the process moves through its lifecycle.
  • A Process Control Block (PCB) is a data structure used by the OS to store all the information about a specific process.
  • CPU Scheduling is the process of deciding which process in the ready queue will be allocated the CPU next.
  • First-Come, First-Served (FCFS) is a non-preemptive scheduling algorithm where the process that requests the CPU first gets it first.
  • Shortest Job First (SJF) selects the process with the smallest execution time, minimizing the average waiting time for all processes.
  • Round Robin (RR) scheduling gives each process a fixed time unit called a quantum, after which the CPU is preempted and given to another.
  • Context switching is the procedure of saving the state of a current process and loading the state of the next process during scheduling.

Memory Management: Paging and Segmentation

  • Memory management involves the coordination and control of the computer's main memory to ensure optimal system performance.
  • Logical address is generated by the CPU during execution, while the physical address refers to the actual location in RAM.
  • The Memory Management Unit (MMU) is a hardware component responsible for mapping logical addresses to physical addresses.
  • Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory by dividing memory into fixed-size blocks.
  • Pages are fixed-size blocks of logical memory, while Frames are fixed-size blocks of physical memory used in paging.
  • Segmentation is a technique where memory is divided into logical units like functions, objects, or arrays based on the programmer's view.
  • Virtual Memory allows the execution of processes that are not completely in main memory, enabling the system to run larger programs.
  • Demand Paging loads a page into memory only when it is actually needed during execution, reducing unnecessary I/O operations.

File Systems and Directory Structure

  • A file system is the method and data structure an operating system uses to keep track of files on a disk or partition.
  • Files are collections of related information defined by a name, extension, size, and specific access permissions.
  • Directory structures like single-level, two-level, or tree-structured directories help organize files for easy retrieval and management.
  • File Allocation Table (FAT) and New Technology File System (NTFS) are common file systems used by the Windows operating system.
  • Ext4 (Fourth Extended Filesystem) is the standard file system for many Linux distributions, supporting high-capacity storage.
  • Access control lists (ACLs) define which users or system processes are granted access to specific files and directories.
  • Metadata is data about data, such as file creation date, modification time, and owner information stored by the file system.
  • File fragmentation occurs when a file is stored in non-contiguous blocks on a disk, which can slow down read and write operations.

Deadlock Concepts and Handling

  • Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another.
  • The four necessary conditions for deadlock are Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait.
  • Mutual Exclusion means only one process can use a resource at a time; if another process requests it, it must wait.
  • Hold and Wait occurs when a process holding at least one resource is waiting to acquire additional resources held by others.
  • No Preemption implies that resources cannot be forcibly taken from a process; they must be released voluntarily.
  • Circular Wait exists when there is a set of processes {Pā‚€, P₁, ..., Pā‚™} such that Pā‚€ is waiting for P₁, P₁ for Pā‚‚, and Pā‚™ for Pā‚€.
  • Deadlock Prevention involves ensuring that at least one of the four necessary conditions never occurs in the system.
  • The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety before granting resource requests.

Disk Scheduling Algorithms

  • Disk scheduling is the process of managing I/O requests for the disk to minimize seek time and maximize throughput.
  • Seek time is the time taken by the disk arm to move to the specific cylinder where the data is located.
  • First-Come, First-Served (FCFS) disk scheduling processes requests in the order they arrive, regardless of the disk arm position.
  • Shortest Seek Time First (SSTF) selects the request that requires the least movement of the disk arm from its current position.
  • SCAN (Elevator) algorithm moves the disk arm from one end of the disk to the other, servicing requests along the way.
  • C-SCAN (Circular SCAN) provides a more uniform wait time by moving the arm in one direction and jumping back to the start.
  • Latency is the delay before a transfer of data begins following an instruction for its transfer from memory or disk.
  • Example: If disk requests are at 10, 80, and 20, and the head is at 50, SSTF would move to 20 first, as |50 āˆ’ 20| = 30 is less than |50 āˆ’ 80| = 30.

BIOS, UEFI, and Boot Process

  • Basic Input/Output System (BIOS) is firmware used to perform hardware initialization during the booting process on IBM PC compatible computers.
  • Unified Extensible Firmware Interface (UEFI) is a modern successor to BIOS that supports larger hard drives and faster boot times.
  • POST (Power-On Self-Test) is a diagnostic testing sequence run by the BIOS/UEFI to ensure hardware is functioning correctly before booting.
  • The Master Boot Record (MBR) is a small section at the start of a hard drive containing information about how the partitions are organized.
  • The Bootloader is a small program responsible for loading the Operating System into the main memory after the hardware is initialized.
  • Dual-booting refers to the configuration where two different operating systems are installed on a single computer system.
  • Safe Mode is a diagnostic start-up mode of an operating system used to troubleshoot system issues by loading only essential drivers.
  • Firmware is a specific class of computer software that provides the low-level control for a device's specific hardware.

Common Mistakes and Traps

  • Mistake: Confusing RAM with Storage capacity. Trap: RAM is volatile and used for running tasks; Storage is permanent for saving files.
  • Mistake: Thinking that a faster CPU clock speed always means a faster computer. Trap: Architecture and core count also significantly affect speed.
  • Mistake: Believing that formatting a disk permanently deletes all data. Trap: Formatting often just removes the file pointers; data can still be recovered.
  • Mistake: Assuming that multi-tasking OS runs all tasks at the exact same time on a single core. Trap: It switches between tasks very rapidly.
  • Mistake: Confusing a Process with a Thread. Trap: A process is an independent program execution; a thread is a smaller segment of a process.
  • Mistake: Believing that adding more RAM will always fix a slow computer. Trap: A slow CPU or a failing HDD might be the actual bottleneck.
  • Mistake: Assuming that 32-bit and 64-bit OS can handle the same amount of RAM. Trap: 32-bit systems are limited to 4 GB of addressable memory.
  • Mistake: Thinking Linux is an Operating System. Trap: Linux is strictly a Kernel; distributions like Ubuntu or Fedora are the Operating Systems.

Quick Reference / Formula Summary

  • Storage Units: 1 Byte = 8 bits; 1 Kilobyte = 1024 bytes; 1 Megabyte = 1024 Kilobytes.
  • CPU Clock Speed: Frequency (f) = 1 / Period (T); measured in GHz.
  • Instruction Execution: CPU Time = Instruction Count Ɨ CPI Ɨ Clock Cycle Time.
  • CPI (Cycles Per Instruction) = Total Cycles / Total Instructions.
  • Memory Access Time: T(avg) = (Hit Rate Ɨ Cache Access Time) + (Miss Rate Ɨ Main Memory Access Time).
  • Disk Capacity = Number of Platters Ɨ Surfaces per Platter Ɨ Tracks per Surface Ɨ Sectors per Track Ɨ Bytes per Sector.
  • Baud Rate vs Bit Rate: Bit Rate = Baud Rate Ɨ Number of Bits per Signal.
  • Amdahl's Law: Speedup = 1 / [(1 āˆ’ P) + (P / S)], where P is the parallel portion and S is the speedup factor.
  • Logic Gate Symbols: AND (Ɨ), OR (+), NOT (').
  • Binary Conversion: 2⁰=1, 2¹=2, 2²=4, 2³=8, 2⁓=16, 2⁵=32, 2⁶=64, 2⁷=128.