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:
- Input Unit
- Output Unit
- Memory Unit
- Central Processing Unit (CPU)
- Arithmetic and Logic Unit
- 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
- Procedural Paradigm: Uses a list of instructions for sequential execution.
- Examples: FORTRAN, COBOL, C
- Functional Paradigm: Treats all subprograms as mathematical functions.
- Object-oriented Paradigm: Models real-world problems using objects.
- Examples: Java, C++, Python
Problem-Solving Techniques
- Understanding the Problem: Clearly defining the issue to be solved.
- Analyzing the Problem: Exploring different methods and evaluating solutions.
- Developing the Solution: Creating a detailed sequence of operations.
- 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:
- Start
- Read values of x, y, z
- s = x + y + z
- A = s/3
- Write value of A
- Stop
Pseudocode and Flowcharts
- Pseudocode: A way to write algorithms in simple English, focusing on logic without language syntax distractions.
Rules for Writing Pseudocode
- Write one statement per line.
- Capitalize initial keywords (e.g., READ, WRITE).
- Indent to show hierarchy.
- End multiline structures properly.
- 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
- All boxes connected with arrows.
- Exit points generally at the bottom of symbols.
- Flow typically goes top to bottom, with upward flows limited to three symbols.
- 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.