0% found this document useful (0 votes)
5 views

Problem Solving

Uploaded by

saeediraza10
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Problem Solving

Uploaded by

saeediraza10
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Problem solving

Programming fundamentals
Problem-solving
• Problem-solving is at the core of programming.
• It's the skill that allows programmers to break down a problem, think
logically, and design a solution that the computer can execute.
1. Understanding the Problem

The first step in problem-solving is to understand the problem. This


involves:
• Reading the problem carefully and identifying what’s being asked.
• Clarifying requirements: What inputs will the program have? What should
the output be?
• Breaking down the problem into smaller parts if it’s complex.
Example: "Write a program to calculate the average of three numbers."
Here, you need to understand that you’ll be given three numbers as
inputs, and the output should be their average.
2. Plan the Solution

Once you understand the problem, plan how to solve it. This phase
involves:
• Listing steps to solve the problem (this is called an algorithm).
• Choosing the right approach and considering alternative solutions if available.
• Deciding on necessary data structures or functions to use.
Example: To calculate the average of three numbers, the steps could be:
• Get three numbers as input.
• Add the three numbers.
• Divide the sum by three to get the average.
• Display the average.
3. Writing the Algorithm

An algorithm is a step-by-step sequence of instructions to solve a


problem. You can use pseudocode or flowcharts to represent it.
Algorithms make it easier to translate your plan into actual code.
Example Pseudocode for calculating an average:
4. Implementing the Solution
(Coding)
• After creating the algorithm, it’s time to write the code.
• Choose a programming language (like Python, C++, or Java) and
translate each step into code.
• Be sure to follow coding standards and best practices for readability
and efficiency.
5. Testing and Debugging

• Once you have a working solution, you need to test it with different
inputs to make sure it behaves as expected.
• Debugging involves identifying and fixing any errors or bugs in the
code. Testing helps to verify that the solution meets all requirements.
6. Documentation and
Maintenance
• Good documentation explains how the code works and is especially
important in large projects or team environments.
• Write comments in your code to explain complex sections and provide
details about inputs and outputs.
• Maintenance refers to updating and improving the solution over time
as requirements change or if you find ways to optimize it.
Why Problem-Solving is Important in
Programming

• Programming isn’t just about writing code; it’s about finding


solutions. Strong problem-solving skills help you think clearly, break
down complex issues, and apply logical solutions. These skills will not
only help in coding but also make you a better thinker and innovator
in any technical field.
Von-neumann
architecture
Introduction of Von Neumann
architecture
• The Von Neumann architecture is a computer architecture model that
forms the basis of most modern computers.
• It was proposed by mathematician and physicist John von Neumann
in 1945, it outlines a design where the program instructions and data
are stored in the same memory space, allowing the computer to
access and process them efficiently.
Architecture
Introduction
It is also known as ISA (Instruction set architecture) computer and is
having three basic units:
• The Central Processing Unit (CPU)
• The Main Memory Unit
• The Input/Output Device
Key Components of Von Neumann Architecture
• Memory (RAM): Stores both data Performs all arithmetic and logical
and instructions. The single storage operations, such as addition,
location for both instructions and subtraction, and comparisons,
data makes this architecture required by program instructions.
straightforward but limits • Input/Output (I/O): Handles data
simultaneous access. exchange between the computer and
• Control Unit (CU): Manages and external devices, such as keyboards,
coordinates all operations of the monitors, and storage drives.
computer by fetching instructions • Registers: Small, fast storage
from memory, interpreting them, locations within the CPU that
and directing other parts of the temporarily hold data and
system to execute them. instructions during processing.
• Arithmetic Logic Unit (ALU):
Registers
There are different types of registers used in architecture
• Accumulator: Stores the results of calculations made by ALU. It holds the intermediate
of arithmetic and logical operatoins. it acts as a temporary storage location or device.
• Program Counter (PC): Keeps track of the memory location of the next instructions to
be dealt with. The PC then passes this next address to the Memory Address Register
(MAR).
• Memory Address Register (MAR): It stores the memory locations of instructions that
need to be fetched from memory or stored in memory.
• Memory Data Register (MDR): It stores instructions fetched from memory or any data
that is to be transferred to, and stored in, memory.
• Current Instruction Register (CIR): It stores the most recently fetched instructions
while it is waiting to be coded and executed.
• Instruction Buffer Register (IBR): The instruction that is not to be executed
immediately is placed in the instruction buffer register IBR.
Buses
Data is transmitted from one part of a computer to another, connecting
all major internal components to the CPU and memory, by the means
of Buses.
Types:
• Data Bus: It carries data among the memory unit, the I/O devices, and the
processor.
• Address Bus: It carries the address of data (not the actual data) between
memory and processor.
• Control Bus: It carries control commands from the CPU (and status signals
from other devices) in order to control and coordinate all the activities within
the computer.
How It Works?
How It Works?

The Von Neumann architecture operates in a fetch-decode-execute


cycle:
• Fetch: The control unit retrieves an instruction from memory.
• Decode: The control unit decodes the instruction to understand what
action is needed.
• Execute: The ALU performs the required operation, and the result is
stored back in memory or a register.
Advantages

• Simplicity: Having a single memory for instructions and data simplifies


the design and manufacturing of computers.
• Flexibility: Allows for easier modifications of instructions and re-
programmability, making it versatile for various computing tasks.
Limitations

Von Neumann Bottleneck:


• The CPU and memory share the same data bus, so instructions and
data cannot be fetched simultaneously.
• This limits the system’s speed, as the CPU may have to wait for data
access, creating a bottleneck.

You might also like