Computer Science: Problem Solving Techniques

Introduction to Programming

  • Programming is a skill for computer professionals that enables the computer to perform tasks.
  • Computer programming involves writing sequences of instructions using a Programming Language.
    • Programming Language: A set of written symbols that instructs computer hardware for specified operations.
    • A Program: Sequence of instructions written in a programming language to execute a specific task.

Reasons to Study Programming

  • Enhances ability to express ideas and understand different programming languages.
  • Improves background knowledge to select appropriate programming languages for tasks.
  • Develops the capability to design new languages and contribute to computing advancements.

Overview of Computer Organization

  • Computer is divided into six logical units:
    1. Input Unit
    2. Output Unit
    3. Memory Unit
    4. Central Processing Unit (CPU)
    5. Arithmetic and Logic Unit
    6. Secondary Storage Device

Types of Programming Languages

Desktop and Web Applications

  • Desktop Application: Runs locally on computers.
  • Web Application: Stored on a server and accessed via a browser.

Web Programming Languages

  • HTML (Hyper Text Markup Language): Defines structure and layout of web pages, but has static content.
  • XML (Extensible Markup Language): Allows custom tags for data transmission between applications.
  • JavaScript: Adds dynamic content to web pages, enabling interactivity.
  • PHP: Server-side scripting language for dynamic websites with database access.

Software Programming Languages

  • C: Developed in the 1970s for application development.
  • C++: Object-oriented successor of C, widely used for graphical applications.
  • Visual Basic: Developed by Microsoft for creating Windows applications.
  • Java: General-purpose language for various applications, including web and mobile.

Programming Paradigms

  • Approaches to problem-solving using programming languages.

Key Paradigms

  1. Procedural Paradigm: Uses a list of instructions for sequential execution.
    • Examples: FORTRAN, COBOL, C
  2. Functional Paradigm: Treats all subprograms as mathematical functions.
    • Examples: Lisp, Haskell
  3. Object-oriented Paradigm: Models real-world problems using objects.
    • Examples: Java, C++, Python

Problem-Solving Techniques

  1. Understanding the Problem: Clearly defining the issue to be solved.
  2. Analyzing the Problem: Exploring different methods and evaluating solutions.
  3. Developing the Solution: Creating a detailed sequence of operations.
  4. Coding and Implementation: Translating the algorithm into a computer language.

Algorithms

  • An algorithm is a step-by-step procedure for solving a problem.

Properties of Algorithms

  • Finiteness: Must complete in a finite number of steps.
  • Definiteness: Each step should be clearly defined.
  • Sequence: Each step has a unique preceding and succeeding step.
  • Correctness: Must compute the correct answer for all inputs.
  • Completeness: Should completely solve the problem.
  • Efficiency: Should use minimal resources.
  • Input/Output: Specified input values and expected results.

Example Algorithm

  • To find the average of three numbers:
    1. Start
    2. Read values of x, y, z
    3. s = x + y + z
    4. A = s/3
    5. Write value of A
    6. Stop

Pseudocode and Flowcharts

  • Pseudocode: A way to write algorithms in simple English, focusing on logic without language syntax distractions.

Rules for Writing Pseudocode

  1. Write one statement per line.
  2. Capitalize initial keywords (e.g., READ, WRITE).
  3. Indent to show hierarchy.
  4. End multiline structures properly.
  5. Keep statements programming language independent.
  • Flowchart: A graphical representation of an algorithm using symbols for different actions.

Common Flowchart Symbols

  • Flowline: Connects symbols and indicates logic flow.
  • Terminal: Start/End of a task.
  • Input/Output: Used for reading and displaying data.
  • Processing: Arithmetic and manipulation instructions.
  • Decision: Logic or comparison operations with two exit paths.

Designing Flowcharts

  1. All boxes connected with arrows.
  2. Exit points generally at the bottom of symbols.
  3. Flow typically goes top to bottom, with upward flows limited to three symbols.
  4. Use connectors for mapping breaks.

Advantages of Flowcharts

  • Enhance communication and understanding of system logic.
  • Effective analysis and documentation of programs.
  • Facilitate easier program maintenance.
  • Aid the coding phase of program development.

Example Structures in Pseudocode

  • Selection Structure:
    • IF amount < 1000 THEN interestRate = .06 ELSE interestRate = .10
  • Nesting IF Statements:
    • Display menu and activate game based on user selection.
  • Looping Structures:
    • WHILE loop for counting structures.
    • REPEAT loop example.

Conclusion

  • Understanding problem-solving techniques, algorithms, pseudocode, and flowcharts is essential for successful programming.
  • These concepts form the foundation for designing effective computer programs and systems.