PROBLEM SOLVING USING (CH-1)
PROBLEM SOLVING USING (CH-1)
CHAPTER 1
Programming is the process of creating a set of instructions that a computer can follow to perform
a specific task. These instructions are written in a language that the computer can understand,
known as a programming language.
Key Components of a Computer
1. Hardware: The physical components of a computer, such as the CPU, RAM, storage
devices, and input/output devices.
2. Software: The programs and applications that run on a computer, including the operating
system, software applications, and programming languages.
Types of Programming Languages
1. Low-level languages: These languages are closer to the machine level and require a deep
understanding of computer architecture. Examples include assembly language.
2. High-level languages: These languages are more human-readable and easier to learn. They
are often used for general-purpose programming. Examples include Python, Java, C++,
and JavaScript.
The Programming Process
4. Testing: Test the code to ensure it works as expected and identify and fix any errors.
6. Maintenance: Update and maintain the code over time to address new requirements or fix
bugs.
1. Input Units:
• Function: These devices allow users to enter data and instructions into the
computer.
Examples:
• Registers: Temporary storage locations within the CPU for holding data and
instructions during processing.
3. Memory:
• Function: Stores data and instructions temporarily or permanently.
Types:
• RAM (Random Access Memory): Volatile memory used for temporary storage of
data and programs currently in use.
4. Output Units:
• Function: Display the results of the computer's processing.
5. Storage Devices:
• Function: Store data and programs permanently.
• Examples: Hard disk drives (HDDs), solid-state drives (SSDs), optical drives (CD/DVD),
USB drives.
1. Input: This is the process of receiving data from the outside world. It involves devices like
keyboards, mice, scanners, microphones, and cameras, which translate information into a
format the computer can understand.
2. Processing: This is where the computer takes the input data and manipulates it according
to a set of instructions (a program). The Central Processing Unit (CPU) is the brain of the
computer, responsible for executing these instructions and performing calculations.
These four functions work together in a continuous cycle, allowing computers to perform a vast
array of tasks, from simple calculations to complex simulations and artificial intelligence.
The following diagram shows an example of these functions.
Computer Hardware
Hardware refers to the physical components of a computer. Computer Hardware is any part of the
computer that we can touch these parts. These are the primary electronic devices used to build up
the computer. Examples of hardware in a computer are the Processor, Memory Devices, Monitor,
Printer, Keyboard, Mouse, and Central Processing Unit.
• Input Devices: Input Devices are those devices through which a user enters data and
information into the computer or simply, User interacts with the Computer. Examples of
Input Devices are Keyboard, Mouse, Scanner, etc.
• Output Devices: Output Devices are devices that are used to show the result of the task
performed by the user. Examples of Output Devices are Monitors, Printers, Speakers, etc.
• Storage Devices: Storage Devices are devices that are used for storing data and they are
also known as Secondary Storage Data. Examples of Storage Devices are CDs, DVDs,
Hard Disks, etc.
Computer Software
Software is a collection of instructions, procedures, and documentation that performs different
tasks on a computer system. We can say also Computer Software is a programming code executed
on a computer processor. The code can be machine-level code or code written for an operating
system.
Examples of software are MS- Word, Excel, PowerPoint, Google Chrome, Photoshop, MySQL,
etc.
Different Types of Computer Software
• Application Software: Application Software is the software that works the basic
operations of the computer. It performs a specific task for users. Application Software
includes Word Processors, Spreadsheets, etc. Types of Application software include
General Purpose Software, Customized Software, etc.
Types of software
Software
In a computer system, the software is basically a set of instructions or commands that tell a
computer what to do. In other words, the software is a computer program that provides a set of
instructions to execute a user’s commands and tell the computer what to do. For example
like MS-Word, MS-Excel, PowerPoint, etc.
Types of Software
It is a collection of data that is given to the computer to complete a particular task. The chart
below describes the types of software:
Above is the diagram of types of software. Now we will briefly describe each type and its subtypes:
1. System Software
• Operating System
• Language Processor
• Device Driver
2. Application Software
• General Purpose Software
• Customize Software
• Utility Software
System Software
System software is software that directly operates the computer hardware and provides the basic
functionality to the users as well as to the other software to operate smoothly. Or in other words,
system software basically controls a computer’s internal functioning and also controls hardware
devices such as monitors, printers, and storage devices, etc. It is like an interface between hardware
and user applications, it helps them to communicate with each other because hardware understands
machine language(i.e. 1 or 0) whereas user applications are work in human-readable languages
like English, Hindi, German, etc. so system software converts the human-readable language into
machine language and vice versa.
Types of System Software
It has two subtypes which are:
1. Operating System: It is the main program of a computer system. When the computer
system ON it is the first software that loads into the computer’s memory. Basically, it
manages all the resources such as computer memory, CPU, printer, hard disk, etc., and
provides an interface to the user, which helps the user to interact with the computer system.
It also provides various services to other computer software. Examples of operating
systems are Linux, Apple macOS, Microsoft Windows, etc.
3. Device Driver: A device driver is a program or software that controls a device and helps
that device to perform its functions. Every device like a printer, mouse, modem, etc. needs
a driver to connect with the computer system eternally. So, when you connect a new device
with your computer system, first you need to install the driver of that device so that your
operating system knows how to control or manage that device.
Application Software
Software that performs special functions or provides functions that are much more than the basic
operation of the computer is known as application software. Or in other words, application
software is designed to perform a specific task for end-users. It is a product or a program that is
designed only to fulfill end-users’ requirements. It includes word processors, spreadsheets,
database management, inventory, payroll programs, etc.
1. General Purpose Software: This type of application software is used for a variety of tasks and
it is not limited to performing a specific task only. For example, MS-Word, MS-Excel,
PowerPoint, etc.
2. Customized Software: This type of application software is used or designed to perform specific
tasks or functions or designed for specific organizations. For example, railway reservation
system, airline reservation system, invoice management system, etc.
3. Utility Software: This type of application software is used to support the computer
infrastructure. It is designed to analyze, configure, optimize and maintains the system, and take
care of its requirements as well. For example, antivirus, disk fragmenter, memory tester, disk
repair, disk cleaners, registry cleaners, disk space analyzer, etc.
Compiler and Interpreter
Compilers and Interpreters: The Translators of Code
In the world of programming, computers can't directly understand the code we write. They need it
to be translated into machine code, a low-level language of 0s and 1s. This is where compilers and
interpreters come into play.
Compiler
Definition: A compiler is like a translator that translates the entire source code (the code
written by the programmer) into machine code in one go, before the program is executed.
Process:
1. Source Code: The programmer writes the code in a high-level language (like C,
C++, Java).
2. Compilation: The compiler analyzes the entire source code, checks for errors, and
translates it into machine code (also known as object code or executable file).
Compiler process
Advantages:
• Faster Execution: Compiled programs generally execute much faster than interpreted
ones because the translation process is completed beforehand.
• Better Performance: Compilers can perform optimizations on the code during the
compilation process, resulting in more efficient machine code.
• Platform Independence (to some extent): Compiled code can sometimes be made to run
on different platforms with minimal modifications.
Disadvantages:
• Slower Development Cycle: The entire program needs to be recompiled after every code
change, which can be time-consuming.
• Difficult Debugging: Identifying and fixing errors can be more challenging as the
compiler might report errors after the entire program has been translated.
• Platform Dependence: While some level of portability is possible, compiled code is often
tied to a specific processor architecture.
Interpreter
Definition: An interpreter, on the other hand, translates and executes the code line by line.
It doesn't create a separate machine code file.
Process:
1. Source Code: The programmer writes the code in a high-level language (like
Python, JavaScript, Ruby).
2. Interpretation: The interpreter reads the code line by line, translates it into
machine code, and executes it immediately.
3. Execution: If there's an error in a line, the interpreter stops and reports the error.
Interpreter process
Examples
• Faster Development: Changes to the code can be tested immediately without the need for
a lengthy compilation process.
• Easier Debugging: Errors are identified and reported line by line, making it easier to
pinpoint the source of the problem.
• Platform Independence: Interpreted code is generally more portable across different
operating systems.
Disadvantages:
• Slower Execution: Interpreted programs typically run slower than compiled ones due to
the overhead of translation during execution.
• Less Efficient: Interpreters generally cannot optimize code to the same extent as
compilers, leading to less efficient execution.
• Requires Interpreter: The interpreter program must be present on the machine to run the
interpreted code.
Machine language is a low-level programming language that consists of binary bits i.e. only 0 and
1. The data present in binary form is the reason for its fast execution. In Machine language,
instructions are directly executed by the CPU. Machine language is also known as object code or
machine code. Machine language is binary language.
Machine language
• Assemblers: Special programs called assemblers translate assembly language code into
machine code.
As a human, we write code in high level language. The programming language which we use to
write codes such as C, C++ and java are high level languages. High level language is not
understood by computer directly so it is converted into low level machine language to understand
the meaning of code and perform execution. Computers compile the code written by us and
translate into machine code and then execute it. Computers are only able to understand machine
language.
• It is nearly impossible to learn machine language for humans because it requires a lot of
memorization.
1. Operand(s)
The operand(s) represents the data that the operation must be performed on. This data can
take various forms, depending on the processor's architecture. This can be a register
containing a value, a memory address pointing to a location in memory where the data is
stored, or a constant value embedded within the instruction itself.
2. Opcode
The opcode (Operation code) represents the operation that the processor must perform.
This indicates that the instruction is an arithmetic operation such as addition, subtraction,
multiplication, or division.
• Machine languages are faster in execution because they are in binary form.
• Machine language does not need to be translated , because it is already present in simple
binary form.
• The evolution of the computer system and operating system over the time period is due to
machine language.
• Machine languages are used in developing a high-grade computer system.
Assembly Language:
Assembly language is a low-level programming language that provides a way for humans to
communicate directly with computer hardware. It's a step above machine code, which is the raw
binary instructions that the computer's processor understands.
• Low-level language: It's closer to machine code, the raw instructions understood by the
computer's processor.
• Direct hardware control: Provides fine-grained control over hardware resources like
memory and registers.
Examples: x86 assembly, ARM assembly
Advantages
Disadvantages
• More Complex
• More time consuming
• Lack of Portability
High-Level Language:
• Human-readable: Uses English-like syntax and constructs, making them easier to write
and understand.
• Platform-independent (mostly): Programs written in high-level languages can often be
compiled to run on different types of computers.
• Abstraction: Hides low-level details of the hardware, allowing programmers to focus on
the problem at hand.
• Increase Readability
• Portability
• Faster Development
Disadvantages
• Slower Execution
• Memory Usage
• Less Control Over Hardware
Key Differences
Flowcharts and algorithms
Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that define
step-by-step how a work is to be executed in order to get the expected results. Let’s take a look at
an example for a better understanding. As programmers, we are all aware of the Linear Search
program
Key Characteristics:
• Finiteness: An algorithm must eventually terminate after a finite number of steps.
• Definiteness: Each step in the algorithm must be precisely defined and unambiguous.
• Input: An algorithm may or may not take input.
Flowcharts
A flowchart is a diagrammatic representation of an algorithm. It uses various shapes to
depict different types of operations and arrows to indicate the flow of control between
them.
Common Symbols:
Algorithm:
1. Read three numbers: num1, num2, and num3.
▪ Largest = num1
Else:
▪ Largest = num3
3. Else:
If num2 is greater than num3:
▪ Largest = num2
Else:
▪ Largest = num3