Comprehensive Study Notes on Computational Problem Solving and Networking

Fundamentals of Problem Solving through Decomposition

  • Definition of Decomposition: In the context of problem solving, decomposition is defined as the process of breaking a single, large, and complex problem into several smaller, simpler sub-problems.
  • Primary Purpose and Human Limitations: Decomposition is necessary because the human brain has a limited capacity, generally only able to hold a few pieces of information at once.
  • Benefits for Programmers:     - Simplification of Complexity: It reduces the perceived difficulty of a task, making an "impossible" problem feel "doable."     - Teamwork Facilitation: Breaking a project down allows different programmers to work on different sub-problems simultaneously.     - Easier Testing: Each sub-problem can be isolated and tested independently.     - Reusability: Well-designed sub-problems can often be repurposed for use in other programs.
  • Example: Snake Game Decomposition: Developing a Snake game involves identifying and solving various sub-problems, including:     - Displaying the snake.     - Moving the snake (specifically changing the position of the head and shifting body blocks).     - Generating food (picking a random empty position).     - Checking if food has been eaten.     - Increasing the score and snake length.     - Detecting collisions.     - Ending the game.
  • Example: Library Management System Decomposition: A library system can be broken into five core sub-problems:     - Add a new book: Involves inputting the title, author, and ISBN; checking for duplicate ISBN entries; and storing data in a database.     - Search for a book: Involves inputting a search term and outputting matching books with their availability status.     - Borrow a book: Involves checking availability, marking the item as borrowed, recording the student ID, and setting a due date.     - Return a book: Involves marking the item as available and calculating any applicable late fees if the book is overdue.     - List borrowed books: Involves inputting a student ID and listing all books currently on loan to them.     - Sub-problem Independence: These tasks are considered independent because one (like the search function) can be coded and tested before another (like the borrow function) is finished, provided they share the same database structure.

Iterative Development and Programming Best Practices

  • The Iterative Development Cycle: This refers to building a program step-by-step through a four-step cycle: Write \rightarrow Test \rightarrow Fix \rightarrow Repeat.
  • Benefits of Iterative Development:     - Early Bug Detection: Bugs are identified when only 5105-10 lines of code have been written, making them significantly easier to fix.     - Stability: The program never remains completely broken for a long period.
  • Predicting Outcomes: Programmers should predict outcomes before running code to train the brain to "think like a computer" and identify mistakes early.
  • Comparison to the "Write All at Once" Approach:     - Writing extensive amounts of code (e.g., 200200 lines) before testing for the first time often results in a high volume of errors (e.g., 5050 errors simultaneously).     - Finding a bug in this manner is compared to finding a "needle in a haystack."     - Logical errors, such as incorrect loop conditions or missing messages, are harder to isolate when the entire program is untested.
  • Case Study: Number Guessing Game Development Cycles:     - Cycle 2: A student writes code to check if a guess equals a hardcoded secret (e.g., 55). If the program prints nothing on a wrong guess, the student has forgotten the "Try again" feedback.     - Cycle 3: A loop is added, allowing the user to continue guessing until they are correct.     - Cycle 4: "Too high" and "Too low" messages are added for feedback. This cycle is considered "working perfectly" because all features (input, checking, looping, and feedback) are present and previously tested cycles were bug-free.
  • Real-Life Examples of Iteration:     - Writing an Essay: Writing a paragraph, reading it, fixing spelling, and then moving to the next.     - Cooking: Tasting soup after adding salt and adjusting as needed.

Software Testing Strategies and Data Types

  • Definition of Test Data: Any input provided to a program to determine if it behaves correctly.
  • The Three Types of Test Data:     - Normal Data: Typical, valid input that falls within the expected range (e.g., entering 22 for a pizza order app with a range of 141-4).     - Invalid Data: Input that is outside the expected range or of the wrong type (e.g., entering 55 or 1-1 for a 141-4 range).     - Boundary Data: Input at the extreme edges of the valid range (e.g., 11 and 44 for a 141-4 range).
  • Importance of Boundary Testing:     - Boundary data is critical for finding "off-by-one" errors.     - Example: If a programmer intends to accept scores from 00 to 100100, but writes the condition as mark<100\text{mark} < 100 instead of mark100\text{mark} \leq 100, a student with a score of 100100 would be incorrectly rejected.     - Example: If a pizza app accepts 00 despite a range of 141-4, it indicates an error like number0\text{number} \geq 0 instead of number1\text{number} \geq 1.
  • Test Plans: A test plan is a table used to organize tests systematically to ensure they are repeatable. A typical table includes:     - Test Data Type.     - Input.     - Expected Output (e.g., "Accepted" or "Rejected with error message").

Fundamentals of Computer Networking

  • Definition of a Computer Network: Two or more devices connected together for the purpose of sharing data.
  • PAN (Personal Area Network):     - Range: Typical range is up to 10metres10\,metres (within a room or on a person's body).     - Device Connectivity: Usually connects 22 to 55 devices owned by one person.     - Examples: Wireless earbuds, smartwatches, smartphones, Bluetooth mice, or printers connected via USB.     - Connection Methods: Primarily Bluetooth and USB.
  • LAN (Local Area Network):     - Geographical Scope: Confined to a single building or site, such as a home, school, or office.     - Hardware: Typically utilizes a central switch or a Wireless Access Point (WAP).     - Performance: High speed and low cost to run.
  • WAN (Wide Area Network):     - Geographical Scope: Spans large distances, including cities, countries, or continents.     - Performance: Generally slower than LANs because data must travel huge distances.     - Owner/Operator: ISPs (Internet Service Providers) own the infrastructure, such as long-distance cables, satellites, and undersea cables.     - Example: The Internet is the world's largest WAN.

Hardware and Connection Methods in Networking

  • Wired Connections:     - Advantages: Faster speeds, more secure (requires physical access to intercept data), and more stable (immune to interference).     - Fibre Optic Cables: Send data using pulses of light.
  • Wireless Connections:     - Advantages: Freedom of movement, easy addition of new devices, no cable installation requirements.     - Disadvantages: Slower than wired, less secure (signals can be intercepted), and subject to interference.     - Sources of Disruption: Walls, other Wi-Fi networks, and microwaves.
  • Comparative Analysis (Wired vs. Wireless):     - Technologies like 5G5G and Wi-Fi 6\text{Wi-Fi } 6 are improving wireless speeds.     - Wired remains superior for critical, high-performance applications (online exams, financial systems, hospital equipment).     - Conclusion: Wireless will not make wired obsolete; they will coexist, with wired used for performance and wireless for convenience.

Questions & Discussion

  • Q: Why is a LAN appropriate for a school with 500 computers across three buildings?
  • A: A LAN is ideal because the buildings are on a single campus. It can connect hundreds of devices at high speed and low cost using central switches or WAPs. A WAN would only be necessary if the school needed to connect to a different city/country or a distant sister school.
  • Q: Is a mixed network approach possible?
  • A: Yes. In a school scenario, desktop computers can be wired for speed and reliability, while tablets use Wi-Fi for mobility. The central switch for wired devices and WAPs for wireless devices work together.
  • Q: What are the dependencies in a Snake game?
  • A:     - One must display the snake before moving it.     - "Generate food" must be completed before "Check if food is eaten."     - "Increase score" depends on the "Check if food is eaten" sub-problem.     - "End the game" is impossible to test without "Detect collisions," "Display the snake," and "Move the snake" being complete, as these provide the triggers and visual feedback for the game-over state.