Computer Science Fundamentals: Architecture, Data Structures, Networks & Operating Systems

Agricultural Statistics & Data Science · Foundations · also Computer Application core, Computer Organisation, Data Structures and Algorithms

11units
11chapters
5,589words
100practice questions

The computer-science core of the Computer Application sub-subject in the ICAR Statistical Sciences group: number systems and architecture, data structures and algorithms, operating systems, networks, compilers, software engineering and web programming. Statisticians need the data-structure and algorithm units; Computer Application candidates need all of it.

In the exams: AICE-JRF subject 70 Computer Application Units 1-9 (heavy: the whole paper); AIEEA-PG Group 07 computer unit (heavy for sub-subject 7.2); GATE DA data structures and algorithms (present)

Syllabus

  1. Number systems, Boolean algebra and logic circuits
  2. Computer organisation: CPU, memory hierarchy and input/output
  3. Data structures: arrays, stacks, queues, linked lists, trees, heaps and graphs
  4. Sorting and searching algorithms and their complexity
  5. Object-oriented programming: encapsulation, inheritance and polymorphism (C++/Java)
  6. Operating systems: processes, scheduling, memory management, deadlocks and file systems
  7. Networking: topologies, OSI and TCP/IP models, security and cryptography basics
  8. Compilers: regular expressions, finite automata and parsing
  9. Software engineering: process models, testing, metrics and PERT/CPM for projects
  10. Internet programming: HTML, client- and server-side scripting with databases
  11. Office tools and spreadsheets for data work

Study manual

Agricultural statisticians and computer-application specialists in agricultural research work on top of a deep stack of computing technology: hardware that represents numbers in binary, operating systems that schedule thousands of processes, data structures and algorithms that decide whether an analysis runs in seconds or days, networks that move survey data from tablets in the field to servers, compilers that turn code into machine instructions, software processes that decide whether a crop-advisory system works, and web applications through which farmers and extension workers reach information. This subject covers the computer-science core that such work assumes.

The manual covers number systems, Boolean algebra and logic circuits; computer organisation, with the CPU, memory hierarchy and input/output; data structures, including arrays, stacks, queues, linked lists, trees, heaps and graphs; sorting and searching algorithms and their complexity; object-oriented programming, with encapsulation, inheritance and polymorphism; operating systems, with processes, scheduling, memory management, deadlocks and file systems; networking, with topologies, the OSI and TCP/IP models, security and cryptography basics; compilers, with regular expressions, finite automata and parsing; software engineering, with process models, testing, metrics and project scheduling; internet programming with client- and server-side scripting and databases; and office tools and spreadsheets for data work.

Doctoral and research-service examinations in computer applications for agriculture test this whole field, typically with short conceptual and numerical questions: base conversions and two's complement, Boolean simplification, cache access times, traversal orders and complexity, scheduling waiting times, page replacement, OSI layers and subnetting, regular expressions and automata, cyclomatic complexity and PERT estimates. Master's admission examinations in statistical sciences include a computer unit, and graduate entrance examinations in data science test data structures and algorithms in depth.

1. Number systems, Boolean algebra and logic circuits

Number systems and representation

Computers store everything in binary digits (bits). A number in base b has digits whose place values are powers of b: binary 1101 is 8 + 4 + 0 + 1 = 13, and decimal 45 is binary 101101, found by repeated division by 2 and reading the remainders upwards. Octal (base 8) and hexadecimal (base 16, digits 0–9 and A–F) are compact ways of writing binary, because each octal digit corresponds to three bits and each hexadecimal digit to four: hexadecimal 2F is 2 × 16 + 15 = 47, binary 0010 1111. Negative integers are almost always stored in two's complement: to negate a number, invert all its bits and add one, so −5 in eight bits is 11111011. An n-bit two's complement integer ranges from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1, which is −128 to 127 for n = 8; adding beyond this range overflows. Real numbers are stored in floating point following the IEEE 754 standard: a double-precision number uses 64 bits (1 sign bit, 11 exponent bits and 52 fraction bits), giving about 15 to 17 significant decimal digits, which is why decimal fractions such as 0.1 cannot be represented exactly. Characters are stored as numeric codes, with Unicode and its UTF-8 encoding able to represent the scripts of all languages. Storage is measured in bytes of eight bits, with binary prefixes (a kibibyte is 1,024 bytes) distinguished from decimal ones (a kilobyte is 1,000 bytes), although the two are often confused in practice.

Boolean algebra and logic gates

Boolean algebra works with values 0 and 1 and the operations AND (product, A·B), OR (sum, A + B) and NOT (complement, A′). Its laws include the identity laws A + 0 = A and A·1 = A, the null laws A + 1 = 1 and A·0 = 0, idempotence A + A = A, complements A + A′ = 1 and A·A′ = 0, absorption A + AB = A, distribution A(B + C) = AB + AC and also A + BC = (A + B)(A + C), and De Morgan's laws (A + B)′ = A′B′ and (AB)′ = A′ + B′. Expressions are simplified algebraically or with Karnaugh maps, which group adjacent ones in a grid of the truth table. Logic gates implement these operations in circuits: AND, OR and NOT, plus NAND, NOR, XOR (exclusive OR, 1 when the inputs differ) and XNOR. NAND and NOR are each universal: any Boolean function can be built from NAND gates alone, or from NOR gates alone.

Combinational and sequential circuits

Combinational circuits produce outputs that depend only on current inputs. A half adder adds two bits, with sum A XOR B and carry A AND B; a full adder adds two bits and an incoming carry, and chaining full adders gives a multi-bit adder. Multiplexers select one of several inputs according to control lines, decoders activate one of 2ⁿ outputs for an n-bit input, and encoders do the reverse. Sequential circuits have memory: their outputs depend on past inputs as well. The basic memory element is the flip-flop, such as the SR, D, JK and T types, which stores one bit and changes state on a clock signal; registers and counters are built from flip-flops. These building blocks make up the arithmetic logic unit and the registers of a processor.

Remember

2. Computer organisation: CPU, memory hierarchy and input/output

The processor

Most computers follow the von Neumann architecture, in which programs and data are stored in the same memory and fetched by a central processing unit (CPU). The CPU contains an arithmetic logic unit (ALU) that performs arithmetic and logical operations, a control unit that decodes instructions and directs the other parts, and registers, small and very fast storage locations, including the program counter (address of the next instruction), the instruction register, the accumulator or general-purpose registers, and the status register of flags. The CPU repeats the instruction cycle: fetch the instruction at the address in the program counter, decode it, execute it, and store the result. Clock speed sets how many basic cycles occur per second, but performance also depends on how much work is done per cycle. Pipelining overlaps the stages of successive instructions, like an assembly line, and multicore processors run several instruction streams in parallel; graphics processing units contain thousands of simpler cores suited to the same operation on many data, which is why they accelerate matrix-heavy statistical and machine-learning computations.

The memory hierarchy

Memory is organised as a hierarchy trading speed against size and cost: registers, then several levels of cache (small, fast memory near the processor), then main memory (random-access memory, RAM, which is volatile and loses its contents without power), then secondary storage (solid-state drives and hard disks, non-volatile and much slower), and finally archival storage. Read-only memory holds firmware. The hierarchy works because programs show locality of reference: temporal locality (recently used data are likely to be used again) and spatial locality (data near recently used data are likely to be used next). When the processor finds the data it needs in cache, it is a hit; otherwise a miss, and the data are fetched from slower memory. In a simple model the effective access time is h × T_cache + (1 − h) × T_memory, where h is the hit ratio; with h = 0.9, a cache time of 2 ns and a memory time of 100 ns, the effective time is 0.9 × 2 + 0.1 × 100 = 11.8 ns. This is why processing a large matrix column by column or row by row, in the order it is stored, can be many times faster than jumping across it.

Input and output

Input/output devices communicate with the processor and memory over buses. Three main techniques handle I/O: programmed I/O, in which the CPU polls the device and waits; interrupt-driven I/O, in which the device signals the CPU when it is ready, letting the CPU do other work meanwhile; and direct memory access (DMA), in which a controller transfers blocks of data between device and memory without CPU involvement, interrupting only when the transfer is complete. Disk access is slow compared with memory, so reading a large data file in big sequential chunks is much faster than many small random reads, a consideration when designing data pipelines for large surveys or sensor streams.

Remember

3. Data structures: arrays, stacks, queues, linked lists, trees, heaps and graphs

Linear structures

A data structure organises data so that particular operations are efficient. An array stores elements contiguously, giving constant-time, O(1), access to any element by index, but inserting or deleting in the middle requires shifting elements, O(n). A linked list stores elements in nodes, each holding a value and a pointer to the next node (and, in a doubly linked list, the previous node); inserting or deleting at a known position is O(1), but reaching the k-th element requires following pointers, O(n). A stack is a last-in, first-out (LIFO) structure with push and pop operations at the top; it is used for function calls (the call stack), undo operations, depth-first search and evaluating expressions. In postfix (reverse Polish) notation, operators follow their operands, and a stack evaluates expressions without brackets: '3 4 + 2 *' pushes 3 and 4, adds them to give 7, pushes 2 and multiplies to give 14. A queue is first-in, first-out (FIFO), with enqueue at the rear and dequeue at the front; it is used for scheduling, buffering and breadth-first search. A circular queue reuses array space, and a deque allows insertion and removal at both ends.

Trees and heaps

A tree is a hierarchical structure of nodes with a root and no cycles; a binary tree gives each node at most two children. A binary tree of height h (counting levels from 1) has at most 2ʰ − 1 nodes, and a complete binary tree with n nodes has height about log₂ n. Traversals visit nodes in different orders: preorder (node, left, right), inorder (left, node, right) and postorder (left, right, node), plus level order (breadth first). In a binary search tree (BST), every key in the left subtree of a node is smaller and every key in the right subtree larger, so inorder traversal lists keys in sorted order, and search, insertion and deletion take time proportional to the height: O(log n) for a balanced tree but O(n) in the worst case, when keys inserted in sorted order produce a chain. Self-balancing trees, such as AVL and red–black trees, keep the height O(log n). A binary heap is a complete binary tree in which each parent is no larger (min-heap) or no smaller (max-heap) than its children; it implements a priority queue, with insertion and removal of the minimum in O(log n), finding the minimum in O(1), and construction from n items in O(n). Heaps are stored compactly in arrays: with zero-based indexing, the children of node i are at 2i + 1 and 2i + 2.

Hash tables and graphs

A hash table maps keys to array positions with a hash function, giving average O(1) insertion and lookup; collisions, when two keys hash to the same position, are resolved by chaining or open addressing, and performance degrades as the table fills. Dictionaries in Python and environments in R are hash-based. A graph consists of vertices and edges, directed or undirected, weighted or unweighted. It is stored as an adjacency matrix, an n × n array that uses O(n²) space but answers 'is there an edge?' in O(1), or as adjacency lists, which use space proportional to the number of edges and suit sparse graphs. Breadth-first search (BFS) explores neighbours level by level using a queue and finds shortest paths in unweighted graphs; depth-first search (DFS) goes as deep as possible first using a stack or recursion and underlies cycle detection and topological sorting. Dijkstra's algorithm finds shortest paths with non-negative weights, and minimum spanning trees are found by Prim's or Kruskal's algorithm. Graphs model road networks for crop collection, pedigrees in breeding, gene regulatory networks and trade flows.

Remember

4. Sorting and searching algorithms and their complexity

Complexity analysis

Algorithms are compared by how their running time and memory grow with input size n, using asymptotic notation: O(f(n)) gives an upper bound, Ω(f(n)) a lower bound and Θ(f(n)) a tight bound. Common classes, from fastest to slowest growth, are O(1), O(log n), O(n), O(n log n), O(n²), O(n³) and O(2ⁿ). Best, average and worst cases can differ greatly. Recursive divide-and-conquer algorithms are analysed with recurrence relations: T(n) = 2T(n/2) + n, which describes merge sort, solves to Θ(n log n), and T(n) = T(n/2) + 1, which describes binary search, solves to Θ(log n); the master theorem gives such solutions directly. Any sorting algorithm based on comparing pairs of elements must make Ω(n log n) comparisons in the worst case, because there are n! possible orderings and each comparison can at best halve the possibilities.

Sorting algorithms

Bubble sort repeatedly swaps adjacent out-of-order elements; selection sort repeatedly selects the smallest remaining element; insertion sort inserts each element into its place in the sorted part. All three are O(n²) in the worst case, but insertion sort is O(n) on data that are already nearly sorted and is efficient for small arrays. Merge sort splits the array in halves, sorts each recursively and merges them, taking O(n log n) in every case and needing O(n) extra memory; it is stable, keeping equal keys in their original order. Quicksort partitions the array around a pivot and sorts the parts recursively; it is O(n log n) on average and very fast in practice, but O(n²) in the worst case, for example when the pivot is always the smallest element, which randomised pivot choice makes unlikely. Heap sort builds a heap and repeatedly extracts the maximum, O(n log n) in all cases and in place, but not stable. Non-comparison sorts escape the Ω(n log n) bound when keys are restricted: counting sort runs in O(n + k) for integer keys in a range of size k, and radix sort sorts by digits. Stability matters when sorting by one key after another, as when sorting plots by block and then by treatment.

Searching

Linear search examines elements one by one and takes O(n). Binary search on a sorted array compares the target with the middle element and discards half the array each step, taking O(log n): at most about 20 comparisons for a million items. It requires sorted data and random access, so it suits arrays but not linked lists. Hash tables give average O(1) lookup without sorting, and balanced search trees give O(log n) lookup with ordered traversal. For repeated searches it pays to sort once (O(n log n)) or build an index, which is what databases do.

Remember

5. Object-oriented programming: encapsulation, inheritance and polymorphism (C++/Java)

Classes and objects

Object-oriented programming (OOP) organises software around objects that combine data (attributes or fields) and behaviour (methods). A class is a template defining the attributes and methods; an object is an instance of a class. A class Plot might have attributes such as identifier, area and treatment, and methods such as yield_per_hectare. Constructors initialise new objects; in C++ destructors release resources when an object is destroyed, while Java relies on automatic garbage collection to reclaim unused memory. The four principles of OOP are encapsulation, abstraction, inheritance and polymorphism.

Encapsulation, abstraction and inheritance

Encapsulation bundles data with the methods that operate on it and hides internal details behind a public interface. Access specifiers control visibility: public members are accessible anywhere, private members only within the class, and protected members within the class and its subclasses (and, in Java, within the same package). Getter and setter methods let a class validate changes, for example refusing a negative plot area. Abstraction presents only the essential features of an object; abstract classes and interfaces define what operations exist without saying how they are carried out. Inheritance lets a subclass acquire the attributes and methods of a superclass and add or modify behaviour, expressing an 'is-a' relationship: a class IrrigatedPlot might inherit from Plot. C++ supports multiple inheritance of classes, which can create ambiguity when two parents share an ancestor (the diamond problem), resolved with virtual inheritance; Java allows a class to extend only one class but implement several interfaces. Composition, in which an object contains other objects ('has-a'), is often preferred to deep inheritance hierarchies.

Polymorphism

Polymorphism lets the same interface work with objects of different types. Compile-time (static) polymorphism includes function overloading, several functions with the same name but different parameter lists, and operator overloading in C++. Run-time (dynamic) polymorphism is achieved by method overriding: a subclass provides its own version of a method declared in the superclass, and the version called is determined by the actual type of the object at run time. In C++ this requires the method to be declared virtual in the base class; in Java non-static methods are virtual by default. A program can then hold a list of different model objects and call fit() on each, with each class doing the right thing. Statistical software uses the same ideas: in R, generic functions such as print, summary and predict dispatch on the class of the object, so summary of a linear model and summary of a data frame give different outputs.

Remember

6. Operating systems: processes, scheduling, memory management, deadlocks and file systems

Processes and scheduling

An operating system manages hardware resources and provides services to programs. A process is a program in execution, with its own memory space and state; a thread is a lighter unit of execution within a process, sharing its memory with other threads of the same process. Processes move between states: new, ready (waiting for the CPU), running, waiting (blocked for I/O or an event) and terminated. The scheduler decides which ready process runs next. First-come, first-served (FCFS) runs processes in arrival order: with burst times 24, 3 and 3 arriving in that order, the waiting times are 0, 24 and 27, an average of 17. Shortest job first (SJF) runs the shortest burst first and minimises average waiting time: the same jobs in the order 3, 3, 24 wait 0, 3 and 6, an average of 3; its pre-emptive form is shortest remaining time first. Round robin gives each process a fixed time quantum in turn, which suits interactive systems; a very large quantum makes it FCFS, and a very small one wastes time switching. Priority scheduling can starve low-priority processes, which ageing (gradually raising the priority of waiting processes) prevents. Context switching, saving one process's state and loading another's, has overhead.

Deadlocks

A deadlock occurs when a set of processes each wait for resources held by others, so none can proceed. Coffman's four necessary conditions are mutual exclusion (a resource can be held by only one process), hold and wait (a process holds resources while waiting for others), no pre-emption (resources cannot be taken away) and circular wait (a cycle of processes each waiting for the next). Deadlock can be prevented by breaking one condition, for example by ordering resources so circular wait cannot arise; avoided by checking each request for safety, as in the banker's algorithm, which grants a request only if the system stays in a safe state; or detected and recovered from by terminating processes or pre-empting resources. Database transactions face the same problem with locks.

Memory management and file systems

Memory management allocates main memory among processes. Paging divides memory into fixed-size frames and processes into pages of the same size, with a page table mapping pages to frames; it avoids external fragmentation. Virtual memory lets a process use more memory than is physically present by keeping only active pages in RAM and the rest on disk; a reference to a page not in memory causes a page fault, and a replacement algorithm chooses which page to evict: FIFO (oldest page), LRU (least recently used) or the optimal algorithm (the page used furthest in the future), which is a benchmark but cannot be implemented in practice. FIFO can suffer Belady's anomaly, in which adding frames increases page faults. Thrashing occurs when processes spend more time paging than computing because there is not enough memory for their working sets, a common reason why statistical jobs on very large data slow to a crawl. File systems organise data on storage into files and directories, track free space, control access with permissions, and use allocation methods such as contiguous, linked and indexed allocation; journaling protects against corruption after crashes.

Remember

7. Networking: topologies, OSI and TCP/IP models, security and cryptography basics

Topologies and devices

A computer network connects devices to share data and resources. Physical topologies include bus (all devices on one cable; a cable fault stops the network), star (each device connected to a central switch; easy to manage, but the centre is a single point of failure), ring (each device connected to two neighbours), mesh (many or all devices interconnected; a full mesh of n devices needs n(n − 1)/2 links, 15 for six devices, giving high redundancy at high cost) and hybrids. Networks range from local area networks (LANs) in a building to wide area networks (WANs) such as the internet. Hubs repeat signals to all ports at the physical layer, switches forward frames to the correct port using hardware (MAC) addresses at the data link layer, and routers forward packets between networks using IP addresses at the network layer.

Layered models and protocols

The OSI reference model describes networking in seven layers, from bottom to top: physical (bits on the medium), data link (frames between neighbouring nodes, error detection, MAC addresses), network (routing of packets between networks, IP), transport (end-to-end delivery, segmentation, reliability), session (managing dialogues), presentation (data formats, encryption, compression) and application (services to users, such as web and email). The TCP/IP model used in practice has four layers: link, internet, transport and application. At the transport layer, TCP is connection-oriented and reliable, with acknowledgements, retransmission and ordered delivery, while UDP is connectionless and faster but unreliable, suited to streaming and time-critical messages. IPv4 addresses are 32 bits, written as four decimal numbers; IPv6 addresses are 128 bits. A /24 subnet has 2⁸ = 256 addresses, of which 254 can be assigned to hosts after reserving the network and broadcast addresses. The Domain Name System (DNS) translates names into IP addresses, and HTTP carries web traffic, by default on port 80, with HTTPS, its encrypted form using TLS, on port 443.

Security and cryptography

Network security protects confidentiality, integrity and availability. Symmetric encryption uses the same secret key to encrypt and decrypt (the Advanced Encryption Standard, AES, is the common standard) and is fast, but the key must be shared securely. Asymmetric (public-key) cryptography, such as RSA and elliptic-curve methods, uses a public key to encrypt and a private key to decrypt, or a private key to sign and a public key to verify, solving the key-distribution problem; in practice, protocols such as TLS use public-key methods to agree on a symmetric session key. Cryptographic hash functions, such as SHA-256, map data to a fixed-length digest that changes completely if any bit changes, and are used to check integrity and to store passwords (with a salt). Digital signatures combine hashing and private keys to prove origin and integrity. Firewalls filter traffic, virtual private networks encrypt connections over public networks, and multi-factor authentication protects accounts. For agricultural data systems holding farmer records and survey responses, encryption in transit and at rest, access control and regular updates are basic obligations under data protection laws in many countries.

Remember

8. Compilers: regular expressions, finite automata and parsing

Phases of compilation

A compiler translates a program in a high-level language into machine code (or another lower-level form) before execution; an interpreter executes the program statement by statement without producing a separate machine-code program. Many modern languages combine the two, compiling to an intermediate bytecode run by a virtual machine with just-in-time compilation. Compilation proceeds in phases: lexical analysis breaks the source text into tokens such as keywords, identifiers, numbers and operators; syntax analysis (parsing) checks that the token sequence follows the grammar and builds a parse tree or abstract syntax tree; semantic analysis checks meaning, such as type compatibility and declared variables; intermediate code generation produces a machine-independent representation such as three-address code; optimisation improves it, for example by removing dead code and moving invariant computations out of loops; and code generation produces target machine instructions. A symbol table records identifiers and their attributes throughout, and errors are reported at the phase that detects them.

Regular expressions and finite automata

Tokens are described by regular expressions, built from symbols with concatenation, alternation (|) and repetition (the Kleene star *, zero or more). For example, (a|b)*abb describes all strings over a and b ending in abb, and [0-9]+ describes unsigned integers. Regular expressions are recognised by finite automata. A deterministic finite automaton (DFA) has a finite set of states, a start state, accepting states and exactly one transition for each state and input symbol; a non-deterministic finite automaton (NFA) may have several transitions or none, and ε-transitions. NFAs and DFAs recognise exactly the same class of languages, the regular languages, and any NFA can be converted to an equivalent DFA by the subset construction, though the DFA may have up to 2ⁿ states for an NFA with n states. Regular languages are closed under union, concatenation, Kleene star, intersection and complement. Some languages are not regular: balanced parentheses, or strings of the form aⁿbⁿ, need unbounded memory to count, which a finite automaton lacks. Regular expressions are also everyday tools for data cleaning, such as finding plot codes that do not match an expected pattern.

Grammars and parsing

Programming-language syntax is described by context-free grammars, sets of production rules such as E → E + T | T, which generate the language's valid sentences and handle nesting, such as balanced brackets, that regular expressions cannot. A grammar is ambiguous if some sentence has two different parse trees, and ambiguities such as operator precedence are resolved by rewriting the grammar. Context-free languages are recognised by pushdown automata, which add a stack to a finite automaton. Parsers are top-down, building the tree from the root, such as recursive-descent and LL(1) parsers, which require grammars without left recursion; or bottom-up, reducing the input to the start symbol, such as shift–reduce and LR parsers (SLR, LALR, canonical LR), which handle a larger class of grammars and are generated by parser-generator tools. The Chomsky hierarchy ranks grammars as regular, context-free, context-sensitive and unrestricted, recognised respectively by finite automata, pushdown automata, linear-bounded automata and Turing machines.

Remember

9. Software engineering: process models, testing, metrics and PERT/CPM

Process models

Software engineering applies disciplined methods to building software that meets requirements reliably, on time and within budget. The software development life cycle covers requirements analysis, design, implementation, testing, deployment and maintenance, and maintenance often costs more over a system's life than its development. Process models organise these activities. The waterfall model performs them in strict sequence, which suits stable, well-understood requirements but handles change poorly. The V-model pairs each development phase with a testing phase (requirements with acceptance testing, design with integration testing, coding with unit testing). Incremental and iterative models deliver the system in pieces, and prototyping builds quick versions to clarify requirements with users. The spiral model, proposed by Boehm, organises development in cycles driven by risk analysis. Agile methods, such as Scrum with short sprints, daily stand-ups and a product backlog, value working software, collaboration with users and response to change, and suit projects such as farmer advisory apps whose requirements evolve with field feedback.

Testing and metrics

Testing finds defects; it can show their presence but not their absence. Levels of testing are unit (single functions or classes), integration (interactions between units), system (the whole system against requirements) and acceptance (by users, to decide whether to accept it). Black-box testing derives tests from specifications without regard to code, using techniques such as equivalence partitioning and boundary-value analysis (testing at and just beyond the edges of valid ranges, such as ages 0 and 120); white-box testing derives tests from the code's structure, aiming at statement, branch or path coverage. Regression testing reruns tests after changes. Software metrics quantify size, complexity and quality: lines of code; function points, which measure functionality from inputs, outputs, inquiries, files and interfaces independently of language; and McCabe's cyclomatic complexity, V(G) = E − N + 2P for a control-flow graph with E edges, N nodes and P connected components, which equals the number of independent paths and the minimum number of test cases for branch coverage; a graph with 9 edges and 7 nodes has V(G) = 9 − 7 + 2 = 4. Cost models such as COCOMO estimate effort from size.

Project scheduling with PERT and CPM

Project schedules are planned as networks of activities with dependencies. The critical path method (CPM) finds the longest path through the network, the critical path, whose length is the minimum project duration; activities on it have zero float (slack), and delaying any of them delays the project, while activities off it can slip by their float. Float is the latest start minus the earliest start of an activity. The programme evaluation and review technique (PERT) handles uncertain durations with three estimates per activity, optimistic a, most likely m and pessimistic b, and uses the expected time tₑ = (a + 4m + b)/6 and variance ((b − a)/6)². For a = 2, m = 4 and b = 12 days, tₑ = (2 + 16 + 12)/6 = 5 days and the variance is (10/6)² ≈ 2.78. Summing expected times and variances along the critical path and assuming approximate normality gives the probability of completing by a deadline. These tools plan field surveys, census operations and software projects alike.

Remember

10. Internet programming: HTML, client- and server-side scripting with databases

The web and HTML

The World Wide Web runs on the client–server model: a browser (client) sends an HTTP request for a resource identified by a URL, and a web server returns a response with a status code and content. Common methods are GET, which requests data and places parameters in the URL, and POST, which sends data in the request body, as from a form; status codes include 200 (OK), 301 (moved permanently), 404 (not found) and 500 (internal server error). HTTP is stateless, so cookies and server-side sessions are used to remember users between requests. Web pages are written in HTML (HyperText Markup Language), which structures content with elements marked by tags: a document has head and body sections; headings, paragraphs, lists, links (a elements with href attributes), images, tables and forms with input fields. Cascading Style Sheets (CSS) control presentation, such as layout, fonts and colours, separately from structure, and responsive design adapts pages to phone screens, important because many farmers and field staff reach the web by mobile phone.

Client-side and server-side scripting

Client-side scripts, written in JavaScript, run in the browser and make pages interactive: validating form entries before submission, updating parts of a page without reloading it by requesting data asynchronously from the server, and drawing interactive charts. Server-side scripts run on the web server and generate pages or data dynamically: they receive requests, apply business logic, query databases and return HTML or data. They are written in many languages, including scripting languages designed for the web and general-purpose languages such as Python with web frameworks. Web applications commonly expose application programming interfaces (APIs) following REST principles, in which resources are addressed by URLs and manipulated with HTTP methods, exchanging data in JSON format. Statistical dashboards and interactive applications built in R or Python follow the same pattern: a server computes results and a browser displays them.

Databases and security

Dynamic sites store data in databases, usually relational databases queried with SQL: a server-side script might run SELECT variety, AVG(yield) FROM trials GROUP BY variety and render the result as a table. The most dangerous and common web vulnerability is SQL injection, in which text typed into a form is inserted directly into an SQL statement and executed, allowing an attacker to read or destroy data; it is prevented by parameterised queries (prepared statements), which keep data separate from code. Cross-site scripting, in which malicious script is injected into pages viewed by others, is prevented by escaping output. Input validation must be done on the server, since client-side checks can be bypassed; passwords are stored as salted hashes, never in plain text; and all traffic should use HTTPS.

Remember

11. Office tools and spreadsheets for data work

Spreadsheets for statistics

Spreadsheets are the most widely used data tool in agriculture, and statisticians must use them well and understand their limits. Cells hold values or formulas; a relative reference such as A1 changes when a formula is copied (a formula =A1*2 copied one row down becomes =A2*2), an absolute reference such as $A$1 does not change, and mixed references such as $A1 or A$1 fix only the column or the row. Built-in functions compute AVERAGE, MEDIAN, sample and population standard deviations (the sample form divides by n − 1, the population form by n, and choosing the wrong one is a common error), COUNT, COUNTIF and SUMIF for conditional counts and sums, correlation and simple regression coefficients, and lookups that retrieve a value from a table by key. Pivot tables summarise data by groups, much like grouped means in R or pandas, and charts display them. Many spreadsheet programs include data-analysis add-ins that perform descriptive statistics, t-tests, one-way ANOVA, correlation and regression from menus; these are adequate for simple problems but limited for designed experiments with blocks, unbalanced data or mixed models.

Pitfalls and good practice

Spreadsheets cause well-documented errors. Automatic conversion turns codes into dates or numbers: gene and variety codes that look like dates are silently converted, a problem found in a large share of published genomics supplementary files, and leading zeros in identifiers are dropped. Sorting a single column instead of whole rows scrambles records. Hidden rows, merged cells and formulas overwritten with typed values make results irreproducible, and copied formulas with wrong reference types give wrong answers that look plausible. Spreadsheets also have row limits that very large data sets exceed. Good practice, described in guidance on data organisation in spreadsheets, is to keep one rectangular table per sheet with one header row, one variable per column and one observation per row; to use consistent codes and ISO 8601 dates; to never use colour or formatting to encode information; to keep raw data unchanged on a separate sheet or file; to record a data dictionary; and to do serious analysis in a scripted environment that reads the spreadsheet. Word processors and presentation software are used for reports and talks: styles for headings, automatic numbering of tables and figures, and reference managers keep long documents consistent, and figures should be inserted from files generated by analysis code so that they can be updated.

Remember

What the exams ask

How it is used, across a career

As a student

A student of computer applications or statistics uses this subject to understand what happens beneath their code: why 0.1 cannot be stored exactly, why a matrix processed in storage order runs faster, which data structure makes a lookup or a queue efficient, why an analysis slows when memory runs out, and how a web form reaches a database. In examinations, typical tasks are converting between number bases, simplifying Boolean expressions, computing effective memory access times and scheduling waiting times, tracing tree traversals and sorts, naming OSI layers, writing regular expressions and computing cyclomatic complexity or PERT estimates.

Five years in

A computer-application scientist or statistician five years into practice builds and maintains systems: databases of trial and survey data, web portals and mobile applications for extension advice, data pipelines from field tablets and sensors, and analysis servers shared by many users. Daily decisions include choosing data structures and algorithms that scale, configuring scheduling and memory for large jobs, securing networks and applications against injection and data leaks, testing changes before release, and planning projects with realistic schedules. They also document systems so that colleagues can maintain them after staff move on.

Twenty-five years in

A senior professional with twenty-five years of experience leads the information systems of an institute or programme, deciding architectures, development processes and security policies, choosing between building and buying systems, managing teams and contracts, and ensuring that systems holding farmer and research data comply with data protection rules. They estimate effort and risk for new projects, arbitrate between agile delivery and the documentation that public bodies require, and plan for maintenance over many years. They balance new technology against the skills and budgets available to keep systems running.

PhD, twenty-five years in

A researcher with a PhD and long experience works at the junction of computer science and agricultural science: designing algorithms and data structures for very large genomic, remote-sensing and sensor data, distributed and parallel computing for statistical models, secure and privacy-preserving data sharing, and software engineering practices for research code. Such researchers supervise doctoral work in computer applications, review system designs for national programmes and set the computer-science questions of fellowship examinations. They also evaluate emerging hardware and software for research computing.

Written from

This manual summarises a broad field at the level of short-answer examinations; each chapter corresponds to a full course and textbook. It does not cover computer graphics, artificial intelligence, distributed systems, cloud computing or database theory in depth (databases are treated in the agricultural data systems subject). Technical details such as default ports, address formats and standards are stated in their standard current form but evolve, and specific products and their limits are deliberately not named.

Original practice questions written to the syllabus and pattern of the exams named in each question's examTags. They are not past papers and do not reproduce any board's questions.

Practise it, and prove it

These notes are free to read here, with no account.

What the Laisha app adds:

Free for ten days, then a subscription. We would rather write that here than have you find it later.

Open Laisha →