BPC Unit-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

What is a Computer?

A computer is an electronic device that accepts data from the user, processes it,
produces results, displays them to the users, and stores the results for future usage.
Data is a collection of unorganized facts & figures and does not provide any
further information regarding patterns, context, etc. Hence data means
"unstructured facts and figures".
Information is a structured data i.e. organized meaningful and processed data. To
process the data and convert into information, a computer is used.
Functions of Computers
A computer performs the following functions −
Receiving Input
Data is fed into computer through various input devices like keyboard, mouse,
digital pens, etc. Input can also be fed through devices like CD-ROM, pen drive,
scanner, etc.
Processing the information
Operations on the input data are carried out based on the instructions provided in
the programs.
Storing the information
After processing, the information gets stored in the primary or secondary storage
area.
Producing output
The processed information and other details are communicated to the outside world
through output devices like monitor, printer, etc.
Functional Components of a Computer
 Input Unit :The input unit consists of input devices that are attached to the
computer. These devices take input and convert it into binary language that
the computer understands. Some of the common input devices are keyboard,
mouse, joystick, scanner etc.
Central Processing Unit (CPU)

The CPU is called the brain of the computer since no action can take place without
its permission and execution is the main processing unit. It communicates with all
the other components of the computer and has 3 components that help in the
smooth functioning of the CPU. The components of the CPU are:

Memory Unit
The information entered through the input devices is saved in the memory of the
CPU and then passed on to the other parts. Similarly, when the output is ready it is
saved in the memory before the result is given to the user.

Control Unit
This unit controls the functioning component of the computer. It collects the data
entered, leads it on for processing after the processing is done, receives the output,
and provides it to the user. So getting instructions, decoding them, signaling the
execution, and receiving the output is done by the control center and hence it is
called the center of all processing actions that happen in the computer.

Arithmetic and Logical Unit


This unit does mathematical calculations, arithmetic operations, comparison of
data, and decision-making. It has circuits that are built for addition, subtraction,
multiplication, division, and other calculations.

Random Access Memory (RAM)

RAM is the most commonly referred to a component in a computer. The RAM is


also known as the volatile memory since it gets erased every time the computer
restarts. It stores the data regarding the programs which are frequently accessed
programs and processed. It helps programs to start up and close quickly

Storage Unit

The computers need to store all their data and they have either a Hard Disk Drive
(HDD) or a Solid State Drive (SDD) for this purpose. Hard disk drives are disks
that store data and this data is read by a mechanical arm. Solid-State drives are like
SIM cards in mobile phones. They have no moving parts and are faster than hard
drives. There is no need for a mechanical arm to find data on a physical location on
the drive and therefore this takes no time at all.
 Output Unit : The output unit consists of output devices that are attached
with the computer. It converts the binary data coming from CPU to human
understandable form. The common output devices are monitor, printer,
plotter etc.
Computing Environments : When a problem is solved by the computer, during
that computer uses many devices, arranged in different ways and which work
together to solve problems. This constitutes a computing environment where
various number of computer devices arranged in different ways to solve different
types of problems in different ways. In different computing environments
computer devices are arranged in different ways and they exchange information
in between them to process and solve problem. One computing environment
consists of many computers other computational devices, software and networks
that to support processing and sharing information and solving task. Based on
the organization of different computer devices and communication processes
there exists multiple types of computing environments. Types of Computing
Environments : There are the various types of computing environments. They
are :
Computing Environments Types

1. Personal Computing Environment : In personal computing environment


there is a stand-alone machine. Complete program resides on computer and
executed there. Different stand-alone machines that constitute a personal
computing environment are laptops, mobiles, printers, computer systems,
scanners etc. That we use at our homes and offices.

2.
3. Time-Sharing Computing Environment : In Time Sharing Computing
Environment multiple users share system simultaneously. Different users
(different processes) are allotted different time slice and processor switches
rapidly among users according to it. For example, student listening to music
while coding something in an IDE. Windows 95 and later versions, Unix,
IOS, Linux operating systems are the examples of this time sharing
computing environment.

4.
5. Client Server Computing Environment : In client server computing
environment two machines are involved i.e., client machine and server
machine, sometime same machine also serve as client and server. In this
computing environment client requests resource/service and server provides
that respective resource/service. A server can provide service to multiple
clients at a time and here mainly communication happens through computer
network.

6.
7. Distributed Computing Environment : In a distributed computing
environment multiple nodes are connected together using network but
physically they are separated. A single task is performed by different
functional units of different nodes of distributed unit. Here different
programs of an application run simultaneously on different nodes, and
communication happens in between different nodes of this system over
network to solve task.

8.
9. Grid Computing Environment : In grid computing environment, multiple
computers from different locations works on single problem. In this system
set of computer nodes running in cluster jointly perform a given task by
applying resources of multiple computers/nodes. It is network of computing
environment where several scattered resources provide running environment
for single task.
10.Cloud Computing Environment : In cloud computing environment on
demand availability of computer system resources like processing and
storage are availed. Here computing is not done in individual technology or
computer rather it is computed in cloud of computers where all required
resources are provided by cloud vendor. This environment primarily
comprised of three services i.e software-as-a-service (SaaS), infrastructure-
as-a-service (IaaS), and platform-as-a-service (PaaS).
11.
12.Cluster Computing Environment : In cluster computing environment
cluster performs task where cluster is a set of loosely or tightly connected
computers that work together. It is viewed as single system and performs task
parallelly that’s why also it is similar to parallel computing environment.
Cluster aware applications are especially used in cluster computing
environment.

Advantages of different computing environments:

1. Mainframe: High reliability, security, and scalability, making it suitable for


mission-critical applications.
2. Client-Server: Easy to deploy, manage and maintain, and provides a
centralized point of control.
3. Cloud Computing: Cost-effective and scalable, with easy access to a wide
range of resources and services.
4. Mobile Computing: Allows users to access information and applications from
anywhere, at any time.
5. Grid Computing: Provides a way to harness the power of multiple computers
for large-scale computations.
6. Embedded Systems: Enable the integration of software into devices and
products, making them smarter and more functional.

Disadvantages of different computing environments:

1. Mainframe: High cost and complexity, with a significant learning curve for
developers.
2. Client-Server: Dependence on network connectivity, and potential security
risks from centralized data storage.
3. Cloud Computing: Dependence on network connectivity, and potential
security and privacy concerns.
4. Mobile Computing: Limited processing power and memory compared to
other computing environments, and potential security risks.
5. Grid Computing: Complexity in setting up and managing the grid
infrastructure.
6. Embedded Systems: Limited processing power and memory, and the need for
specialized skills for software development

Algorithm

An algorithm is a well-defined sequential computational technique that accepts a


value or a collection of values as input and produces the output(s) needed to
solve a problem.

NEED OF THE ALGORITHMS :

There are several reasons why we use algorithms:


 Efficiency: Algorithms can perform tasks quickly and accurately, making
them an essential tool for tasks that require a lot of calculations or data
processing.
 Consistency: Algorithms are repeatable and produce consistent results every
time they are executed. This is important when dealing with large amounts of
data or complex processes.
 Scalability: Algorithms can be scaled up to handle large datasets or complex
problems, which makes them useful for applications that require processing
large volumes of data.
 Automation: Algorithms can automate repetitive tasks, reducing the need for
human intervention and freeing up time for other tasks.
 Standardization: Algorithms can be standardized and shared among
different teams or organizations, making it easier for people to collaborate
and share knowledge.

Characteristics of an Algorithm
Well-defined Inputs
 The expected inputs of an algorithm must be well-defined to ensure its
correctness, predictability, and repeatability.

 Well-defined inputs ensure that the algorithm's behavior is deterministic,


which means, that the same input will always produce the same output.

 Unambiguous inputs help prevent incorrect implementations and


misunderstanding of the algorithm's requirements.


With well-defined inputs, it is easier to optimize the algorithm based on the
characteristics of the input.
Well-defined Outputs
 The outputs of an algorithm should be well-defined to ensure that the
algorithm produces the intended and accurate result for a given set of inputs.

 It avoids ambiguity and guarantees that the algorithm solves the problem
correctly.

 It is also easy to verify the correctness of the algorithm's implementation.


Well-defined outputs allow you to optimize the algorithm further to achieve
the results more efficiently.
Unambiguity
 Ambiguity in the algorithm's description can lead to incorrect
implementations and unreliable results. That is why it is important for an
algorithm to be unambiguous.

 It allows the algorithm to be predictable, i.e., the same input produces the
same output, which makes debugging an implementation easier.

 It is also easier for unambiguous to be standardized and used widely for


different applications.
 While implementing unambiguous algorithms, you can focus more on
optimizations rather than handling unexpected errors and edge cases.

Finiteness
 The algorithm should end after a finite amount of time, and it should have a
limited number of instructions.

 A finite algorithm ensures that it will eventually stop executing and produce a
result.

 An infinite algorithm would never reach a conclusion, which is impractical in


real-world scenarios where computation cannot be performed infinitely.

 The time and space complexity can be analyzed in the case of a finite
algorithm which is important for performing further optimizations.
Language Independent
 A language-independent algorithm can be easily ported to different
programming languages and platforms, making it more adaptable and usable
across various environments.

 Being language-independent also makes an algorithm future-proof which


means it can be implemented easily using newer programming languages.

 It is important for algorithms to be language-independent in educational


settings where students are exposed to different programming languages.

 It also makes it easier to compare the algorithm's performance using different


programming languages.
Effectiveness and Feasibility
 An algorithm should be feasible because feasibility indicates that it is practical
and capable of being executed within reasonable constraints and resources.

 It also avoids excessive execution times, which can make an algorithm


unusable in real-world scenarios.

 Feasible algorithms can be easily implemented using existing hardware


infrastructure without using specialized resources.

 They are adopted easily for usage across different fields due to its practical
hardware requirements.
Complexity in algorithms refers to the amount of resources (such as time or
memory) required to solve a problem or perform a task.

The complexity of an algorithm is a function describing the efficiency of the


algorithm in terms of the amount of data the algorithm must process.

An algorithm is analyzed using Time Complexity and Space Complexity.

 Time Complexity: Time taken by the algorithm to solve the problem. It is


measured by calculating the iteration of loops, number of comparisons etc.
 Time complexity is a function describing the amount of time an algorithm
takes in terms of the amount of input to the algorithm.
Space Complexity: Space taken by the algorithm to solve the problem. It
includes space used by necessary input variables and any extra space (excluding
the space taken by inputs) that is used by the algorithm.

Advantages of Algorithms
 Easy to understand: Since it is a stepwise representation of a solution to a
given problem, it is easy to understand.
 Language Independent: It is not dependent on any programming language,
so it can easily be understood by anyone.
 Debug / Error Finding: Every step is independent / in a flow so it will be
easy to spot and fix the error.
 Sub-Problems: It is written in a flow so now the programmer can divide the
tasks which makes them easier to code.
Disadvantages of Algorithms
 Creating efficient algorithms is time-consuming and requires good logical
skills.
 Nasty to show branching and looping in algorithms.
What is a Flowchart
Flowcharts are nothing but the graphical representation of the data or the
algorithm for a better understanding of the code visually. It displays step-by-step
solutions to a problem, algorithm, or process.

A flowchart is a picture of boxes that indicates the process flow sequentially.

Flowchart symbols
Different types of boxes are used to make flowcharts flowchart Symbols
The terminator symbol represents the starting or ending point of the system.

Process
A box indicates some particular operation.

Document
This represents a printout, such as a document or a report.

Decision
A diamond represents a decision or branching point. Lines coming out from the
diamond indicates different possible situations, leading to different sub-
processes.

Data
It represents information entering or leaving the system. An input might be an
order from a customer. Output can be a product to be delivered.

On-Page Reference
This symbol would contain a letter inside. It indicates that the flow continues on
a matching symbol containing the same letter somewhere else on the same page.

Off-Page Reference
This symbol would contain a letter inside. It indicates that the flow continues on
a matching symbol containing the same letter somewhere else on a different
page.

Delay or Bottleneck
Identifies a delay or a bottleneck.

Flow
Lines represent the flow of the sequence and direction of a process.

Flowchart Example – Simple Algorithms


Flowchart Example – Calculate Profit and Loss
What is 'Pseudocode'

Definition: Pseudocode is an informal way of programming description that does


not require any strict programming language syntax or underlying technology
considerations. It is used for creating an outline or a rough draft of a program.
Description: Pseudocode is not an actual programming language. So it cannot be
compiled into an executable program. It uses short terms or simple English
language syntaxes to write code for programs before it is actually converted into a
specific programming language.

Advantages of Pseudocode
 Improves the readability of any approach. It’s one of the best approaches to
start implementation of an algorithm.
 Acts as a bridge between the program and the algorithm or flowchart. Also
works as a rough documentation, so the program of one developer can be
understood easily when a pseudo code is written out. In industries, the
approach of documentation is essential. And that’s where a pseudo-code
proves vital.
 The main goal of a pseudo code is to explain what exactly each line of a
program should do, hence making the code construction phase easier for the
programmer.
 Pseudocode is understood by the programmers of all types.
 It cannot be compiled into an executable program.

Generations of programming language


1. First-Generation Language :
The first-generation languages are also called machine languages/ 1G language.
This language is machine-dependent. The machine language statements are
written in binary code (0/1 form) because the computer can understand only
binary language.
Advantages :
1. Fast & efficient as statements are directly written in binary language.
2. No translator is required.
Disadvantages :
1. Difficult to learn binary codes.
2. Difficult to understand – both programs & where the error occurred.
2. Second Generation Language :
The second-generation languages are also called assembler languages/ 2G
languages. Assembly language contains human-readable notations that can be
further converted to machine language using an assembler.
Assembler – converts assembly level instructions to machine-level instructions.
Programmers can write the code using symbolic instruction codes that are
meaningful abbreviations of mnemonics. It is also known as low-level language.
Advantages :
1. It is easier to understand if compared to machine language.
2. Modifications are easy.
3. Correction & location of errors are easy.
Disadvantages :
1. Assembler is required.
2. This language is architecture /machine-dependent, with a different instruction
set for different machines.
3. Third-Generation Language :
The third generation is also called procedural language /3 GL. It consists of the
use of a series of English-like words that humans can understand easily, to write
instructions. It’s also called High-Level Programming Language. For execution,
a program in this language needs to be translated into machine language using a
Compiler/ Interpreter.
Examples: FORTRAN, ALGOL, COBOL, C++, CAdvantages :
1. Use of English-like words makes it a human-understandable language.
2. Lesser number of lines of code as compared to the above 2 languages.
3. Same code can be copied to another machine & executed on that machine by
using compiler-specific to that machine.
Disadvantages :
1. Compiler/ interpreter is needed.
2. Different compilers are needed for different machines.
4. Fourth Generation Language :
The fourth-generation language is also called a non – procedural language/ 4GL.
It enables users to access the database. Examples: SQL, Foxpro, Focus, etc.
These languages are also human-friendly to understand.
Advantages :
1. Easy to understand & learn.
2. Less time is required for application creation.
3. It is less prone to errors.
Disadvantages :
1. Memory consumption is high.
2. Has poor control over Hardware.
3. Less flexible.
5. Fifth Generation Language :
The fifth-generation languages are also called 5GL. It is based on the concept of
artificial intelligence. It uses the concept that rather than solving a problem
algorithmically, an application can be built to solve it based on some constraints,
i.e., we make computers learn to solve any problem. Parallel Processing &
superconductors are used for this type of language to make real artificial
intelligence.
Examples: mercury, prolog, OPS5 etc.
Advantages :
1. Machines can make decisions.
2. Programmer effort reduces to solve a problem.
3. Easier than 3GL or 4GL to learn and use.
Disadvantages :
1. Complex and long code.
2. More resources are required & they are expensive too.

Compiler

 A Compiler is a program that translates source code from a high-level


programming language to a lower level language computer understandable
language(e.g. assembly language, object code, or machine code) to create an
executable program
 It is more intelligent than interpreter because it goes through the entire code
at once
 It can tell the possible errors and limits and ranges.
 But this makes it’s operating time a little slower
 It is platform-dependent
 It help to detect error and get displayed after reading the entire code by
compiler.
 In other words we can say that, “Compilers turns the high level language to
binary language or machine code at only time once”, it is known as
Compiler.

Interpreter

 An interpreter is also a program like a compiler that converts assembly


language into Machine Code
 But an interpreter goes through one line of code at a time and executes it and
then goes on to the next line of the code and then the next and keeps going
on until there is an error in the line or the code has completed.
 It is 5 to 25 times faster than a compiler but it stops at the line where error
occurs and then again if the next line has an error too.
 Where as a compiler gives all the errors in the code at once.
 Also, a compiler saves the machine codes for future use permanently but an
interpreter doesn’t, but an interpreter occupies less memory.

Assembler
 An assembler translates assembly language programs into machine code.The
output of an assembler is called an object file, which contains a combination
of machine instructions as well as the data required to place these
instructions in memory.

Linker

For a code to run we need to include a header file or a file saved from the library
which are pre-defined if they are not included in the beginning of the program then
after execution the compiler will generate errors, and the code will not work.
Linker is a program that holds one or more object files which is created by
compiler, combines them into one executable file.Linking is implemented at both
time,load time and compile time. Compile time is when high level language is
turns to machine code and load time is when the code is loaded into the memory by
loader.

Linker is of two types:

1.Dynamic Linker:-

 It is implemented during run time.


 It requires less memory.
 In dynamic linking there are many chances of error and failure chances.
 Linking stored the program in virtual memory to save RAM,So we have
need to shared library

2.Static Linker:-

 It is implemented during compilation of source program.


 It requires more memory.
 Linking is implemented before execution in static linking.
 It is faster and portable.
 In static linking there are less chances to error and No chances to failure.

Loader

A loader is a program that loads the machine codes of a program into the system
memory. \It is part of the OS of the computer that is responsible for loading the
program. It is the bare beginning of the execution of a program. Loading a program
involves reading the contents of an executable file into memory. Only after the
program is loaded on operating system starts the program by passing control to the
loaded program code. All the OS that supports loading have loader and many have
loaders permanently in their memory.
C Program Execution Process

1) C program (source code) is sent to preprocessor first. The preprocessor is


responsible to convert preprocessor directives into their respective values. The
preprocessor generates an expanded source code.

2) Expanded source code is sent to compiler which compiles the code and converts
it into assembly code.

3) The assembly code is sent to assembler which assembles the code and converts
it into object code. Now a simple.obj file is generated.

4) The object code is sent to linker which links it to the library such as header files.
Then it is converted into executable code. A simple.exe file is generated.

5) The executable code is sent to loader which loads it into memory and then it is
executed. After execution, output is sent to console.

You might also like