0% found this document useful (0 votes)
47 views65 pages

Fundamentals of IT & Computers 25

Fundamentals of IT & Computers

Uploaded by

bens082023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views65 pages

Fundamentals of IT & Computers 25

Fundamentals of IT & Computers

Uploaded by

bens082023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 65

Fundamentals of IT & Computers

Basics of Computer and its Operations

Introduction :

A computer is an electronic device that can receive, store, process, and output data. It is a
machine that can perform a variety of tasks and operations, ranging from simple calculations
to complex simulations and artificial intelligence.

Computers consist of hardware components such as the central processing unit (CPU),
memory, storage devices, input/output devices, and peripherals, as well as software
components such as the operating system and applications.

The history of computers can be traced back to the 19th century when mechanical devices
such as the Analytical Engine and tabulating machines were developed. However, modern
computers as we know them today were developed in the mid-20th century with the invention
of the transistor and the development of integrated circuits.

Today, computers are widely used in various industries such as education, finance, healthcare,
and entertainment, and they have revolutionized the way we live, work, and communicate.
They have also given rise to a new era of technology such as the internet, cloud computing,
and mobile devices, which have further transformed our daily lives.

Computer is a device that transforms data into meaningful information. It processes the input
according to the set of instructions provided to it by the user and gives the desired output
quickly. A Computer can perform the following set of functions:

 Accept data
 Store data
 Process data as desired
 Retrieve the stored data as and when required
 Print the result in desired format.

Data and Information: Data: It is the term used for raw facts and figures fed into the
computer and along with the set of instructions which enables the computer to convert this
raw data into the refined and useful information. Information: Data represented in useful and
meaningful form is information.

Data and information are related concepts, but they have different meanings. Data refers to
raw facts and figures that are unorganized and have no meaning on their own. Information, on
the other hand, is data that has been processed, organized, and given context to make it
meaningful and useful.

Data can take many forms, such as numbers, words, images, or sounds. For example, a list of
sales figures for a company is data. However, this data by itself does not provide any useful
information. It needs to be processed and analyzed to be turned into information that can be
used for decision-making.

1
Information is data that has been processed and organized in a meaningful way to convey a
message or answer a question. For example, using the sales figures from the earlier example,
an analyst could create a graph or chart that shows the sales trends over time, providing
meaningful information about the company’s performance.

In summary, data is the raw, unorganized facts and figures, while information is data that has
been processed and given context to be meaningful and useful for decision-making.

Classification of Computers: Computers can be classified based on the technology being


used and the way they are designed to perform the various tasks. Computers can be
categorized into Digital, Analog and Hybrid based on their design and working:

1. Digital Computers : These are the modern computers which are capable of processing
information in discrete form. In digital technology data which can be in the form of letters,
symbols or numbers is represented in binary form i.e. 0s and 1s. The digital computers are
used in industrial, business and scientific applications. They are quite suitable for large
volume data processing.
2. Analog Computers : These computers are used to process data generated by ongoing
physical processes. A thermometer is an example of an analog computer since it measures
the change in mercury level continuously. Analog computers are well suited to simulating
systems. A simulator helps to conduct experiments repeatedly in real time environment.
Some of the common examples are simulations in aircrafts, nuclear power plants, hydraulic
and electronic networks.
3. Hybrid Computers : These use both analog and digital technology. It has the speed of analog
computer and the accuracy of a digital computer. It may accept digital or analog signals but
an extensive conversion of data from digital to analog and analog to digital has to be done.
Hybrid Computers are used as a cost effective means for complex simulations.
4. Supercomputers: These are the most powerful and expensive computers that are used for
complex scientific calculations, simulations, and research. They are used in fields such as
weather forecasting, cryptography, and nuclear research.
5. Mainframe Computers: These are large and powerful computers that are used by large
organizations such as banks, airlines, and government agencies to process massive amounts
of data and handle multiple users simultaneously.
6. Mini Computers: These are smaller and less powerful than mainframe computers, but they
are still capable of handling multiple users and processing large amounts of data. They are
commonly used by small to medium-sized businesses for accounting, inventory
management, and other data-intensive tasks.
7. Personal Computers: These are small and affordable computers that are designed for
individual users. They are commonly used for personal productivity, entertainment, and
communication.
8. Workstations: These are high-performance computers that are used by professionals such as
architects, engineers, and designers to run complex software applications for tasks such as
3D modeling, animation, and scientific visualization.
9. Embedded Systems: These are specialized computers that are built into other devices such
as cars, appliances, and medical equipment to control their operations and perform specific
functions.
10. Mobile Devices: These are small and portable computers that are designed for on-the-go
use, such as smartphones, tablets, and laptops

Classification of Digital Computers

2
1. Micro Computers :These are also known as Personal Computers. These type of digital
computer uses a microprocessor (a CPU on a single chip) and include both desktops and
laptops. These computers can work on small volume of data, are very versatile and can
handle variety of applications. These computers are being used as work stations, CAD,
multimedia and advertising applications. Example: portable computers such as PDAs
(Personal Digital Assistants) and tablets
2. Mini Computers :These computers can support multiple users working simultaneously on the
same machine. These are mainly used in an organization where computers installed in
various departments are interconnected. These computers are useful for small business
organizations.
3. Main Frames : These computers are large and very powerful computers with very high
memory capacity. These can process huge databases such as census at extremely fast rate.
They are suitable for big organizations, banks, industries etc. and can support hundreds of
users simultaneously on the network.
4. Super Computers : These are fastest and very expensive computers. They can execute
billions of instructions per second. These are multiprocessor, parallel systems suitable for
specialized complex scientific applications involving huge amounts of mathematical
applications such as weather forecasting.
5. Mainframe Computers: These are large and powerful computers that are used by large
organizations such as banks, airlines, and government agencies to process massive amounts
of data and handle multiple users simultaneously.
6. Minicomputers: These are smaller and less powerful than mainframe computers, but they
are still capable of handling multiple users and processing large amounts of data. They are
commonly used by small to medium-sized businesses for accounting, inventory
management, and other data-intensive tasks.
7. Microcomputers: These are the most common type of digital computers, also known as
personal computers or PCs. They are designed for individual users and are used for personal
productivity, entertainment, and communication.
8. Workstations: These are high-performance computers that are used by professionals such as
architects, engineers, and designers to run complex software applications for tasks such as
3D modeling, animation, and scientific visualization.
9. Supercomputers: These are the most powerful and expensive computers that are used for
complex scientific calculations, simulations, and research. They are used in fields such as
weather forecasting, cryptography, and nuclear research.
10. Embedded Systems: These are specialized computers that are built into other devices such
as cars, appliances, and medical equipment to control their operations and perform specific
functions.
11. Mobile Devices: These are small and portable computers that are designed for on-the-go
use, such as smartphones, tablets, and laptops.

Peripheral Devices

These devices are used for performing the specific functions and are connected to the
computer externally. These peripheral devices enable the computer to operate according to the
user requirements by feeding data in and out of the computer. Peripheral devices are as
follows:

 Keyboard
 Mouse
 Light Pen
 Optical/magnetic Scanner

3
 Touch Screen
 Microphone for voice as input
 Track Ball
 Monitor (Visual Display Unit)
 Printers
 Plotter
 Speaker

Difference between RAM and Hard-disk

RAM Hard Disk

RAM is an electronic device Hard-disk is an electromechanical device

Electro-mechanical device has speed slower than


Electronic device are faster in speed
Electronic device.

CPU is an electronic device,so it’s speed can Hard disk is an electro-mechanical


match with RAM.Therefore,CPU and RAM have device.Therefore,it’s speed cannot be match by CPU
connections and that connections is known as and hence there is no connection between hard-
buses disk and CPU.

RAM is much faster than a hard-disk. RAM is a Hard-disk is a type of non-volatile storage that is
type of volatile memory that can be accessed much slower than RAM. It is used for long-term
quickly by the CPU. This allows for fast data storage of data that needs to be preserved even
processing and multitasking. when the computer is turned off.

Hard-disk is non-volatile, meaning that its contents


RAM is volatile, meaning that its contents are are preserved even when the computer is turned
lost when the computer is turned off. off. This makes hard-disk an ideal choice for long-
term storage of data.

CPU process the data, and to process that data we need fast speed memory which is known as
RAM.

Types of Software

1. System Software : These are those software,without which our PC,laptop won’t run, i.e it is
must for a device to be operating. For Example: Linux,Unix,Windows,etc.
2. Application Software : These are those software,without which our PC,laptop can run, i.e
these software are not necessary for a device to be operating. For Example: Facebook,What’s
App,Games.

Difference between Hacker and Cracker

1. Hacker : They will just warn you something about malicious activity going around in your
computer.It will not steal your information.
2. Cracker : They will try to steal your Information without informing you.

4
Basic computer operation :

1. Booting up: This is the process of starting up the computer by loading the operating system
(OS) into memory. The computer runs a series of checks to ensure all hardware is working
correctly before loading the OS.
2. Logging in: After booting up, you will need to log in to access your user account. This requires
entering your username and password.
3. Running programs: Once you have logged in, you can run programs on your computer.
Programs can include web browsers, office applications, media players, and more.
4. Accessing data: You can access data stored on your computer or other connected devices,
such as external hard drives or cloud storage services. This can include files, documents,
photos, and other media.
5. Connecting to the internet: You can connect to the internet to access websites, download
files, and communicate with others online. This typically involves using a web browser to
access websites and other online services.
6. Communicating with other devices: You can communicate with other devices connected to
your computer, such as printers, scanners, or other peripherals. This allows you to print
documents, scan images, and perform other tasks.
7. Saving and backing up data: It’s important to save and back up your data regularly to avoid
data loss. You can save data to your local hard drive, external hard drives, or cloud storage
services.
8. Shutting down: When you’re finished using your computer, you should shut it down
properly. This involves closing all programs and files, saving any changes, and shutting down
the OS.
9. Troubleshooting: If you experience issues with your computer, you may need to
troubleshoot the problem. This can involve diagnosing hardware or software issues,
performing updates, or reinstalling drivers.
10. Security: It’s important to keep your computer secure by using antivirus software, firewalls,
and other security measures. This helps protect your data and prevent unauthorized access
to your system.

Issues of basic computers and computer operations :

some common issues that can arise with basic computers and computer operations:

1. Slow performance: Computers can become slow and unresponsive due to a variety of
factors, such as lack of storage space, outdated hardware, or malware.
2. Malware and viruses: Malware and viruses can infect computers and cause a range of
problems, including data loss, system crashes, and identity theft.
3. Hardware failures: Computer hardware components can fail over time, leading to issues like
system crashes, data loss, and display problems.
4. Software glitches: Software applications can sometimes malfunction or crash, leading to
issues like data loss or unresponsive programs.
5. Driver problems: Drivers are software components that enable hardware devices to
communicate with the operating system. If drivers become outdated or corrupted, it can
lead to issues like hardware failures or system crashes.
6. Compatibility issues: Sometimes software applications or hardware components may not be
compatible with each other, leading to issues like system crashes or display problems.
7. Internet connectivity issues: Problems with internet connectivity can lead to issues like slow
loading web pages, interrupted downloads, and difficulty accessing online services.

5
8. User error: Users can sometimes make mistakes or accidentally delete files or programs,
leading to issues like data loss or unresponsive programs.

Reference :

Some references for learning about basic computers and computer operations:

1. “Computer Basics” by GCFGlobal: This is a comprehensive guide to learning about


computers, including hardware components, software, and basic operations.
2. “Computer Science Basics” by Khan Academy: This course covers the fundamentals of
computer science, including how computers work, programming basics, and algorithms.
3. “Introduction to Computers” by Udemy: This course covers the basics of computer hardware,
software, and operations, including topics like file management, computer security, and
troubleshooting.
4. “Computer Operations” by Techopedia: This article provides an overview of computer
operations, including booting up, running programs, and saving and backing up data.
5. “How Computers Work” by HowStuffWorks: This website provides a detailed explanation of
how computers work, including the role of hardware components, operating systems, and
software applications.
6. “The Basics of Computer Operations” by The Tech Academy: This guide provides an overview
of basic computer operations, including starting up, running programs, and shutting down.
7. “Introduction to Computing” by Georgia Tech: This course provides an introduction to
computing, including basic computer operations, programming, and algorithms.

6
Characteristics of Computer System

A computer is a fast electronic device that processes raw data, performs arithmetic and logical
operations, and produces output. Nowadays, the computer has become a part of our life and
can be used in most fields. In a computer, there are various characteristics of computer
systems depending on their size, capacity, and specifications. But, the major characteristics of
the computer can be classified into Speed, Accuracy, Diligence, Versatility, Reliability,
Consistency, Memory, Storage Capacity, Remembrance Power, and Automation.

What is a Computer???
A computer system is a basic and functional computer that includes all the hardware and
software that are required to make it functional for the user. It is an electronic device that
accepts the data as input, processes the data in a pre-determined way and then communicates
the result as output on the screen. CPU which stands for Central Processing Unit is the brain
of the computer. It is an electronic circuit within a computer that executes instructions that
make up a computer program. Various blocks of CPU are-

 It carries out the operations of arithmetic and logical expressions.

 The timing and Control Unit controls the entire operation being performed on the computer
system.

 The register is a very small amount of very fast memory that is built into the CPU in order to
store the current data and instructions that are being performed by the CPU.

 unit is the storage unit of the computer system which is used to store the program statement
and data.

 Input and Output unit sends and receives data to display it to the user.

Characteristics of Computer System


Let’s go over the characteristics of computers.

1. Speed

Executing mathematical calculation, a computer works faster and more accurately than
human. Computers have the ability to process so many millions (1,000,000) of instructions
per second. Computer operations are performed in micro and nano seconds. A computer is a
time saving device. It performs several calculations and tasks in few seconds that we take
hours to solve. The speed of a computer is measure in terms of GigaHertz and MegaHertz.

2. Diligence

A human cannot work for several hours without resting, yet a computer never tires. A
computer can conduct millions of calculations per second with complete precision without
stopping. A computer can consistently and accurately do millions of jobs or calculations.

7
There is no weariness or lack of concentration. Its memory ability also places it ahead of
humans.

3. Reliability

A computer is reliable. The output results never differ unless the input varies. the output is
totally depend on the input. when an input is the same the output will also be the same. A
computer produces consistent results for similar sets of data, if we provide the same set of
input at any time we will get the same result.

4. Automation

The world is quickly moving toward AI (Artificial Intelligence)-based technology. A


computer may conduct tasks automatically after instructions are programmed. By executing
jobs automatically, this computer feature replaces thousands of workers. Automation in
computing is often achieved by the use of a program, a script, or batch processing.

5. Versatility

Versatility refers to a capacity of computer. Computer perform different types of tasks with
the same accuracy and efficiency. A computer can perform multiple tasks at the same time
this is known as versatility. For example, while listening to music, we may develop our
project using PowerPoint and Wordpad, or we can design a website.

6. Memory

A computer can store millions of records. these records may be accessed with complete
precision. Computer memory storage capacity is measured in Bytes, Kilobytes(KB),
Megabytes(MB), Gigabytes(GB), and Terabytes(TB). A computer has built-in memory
known as primary memory.

7. Accuracy

When a computer performs a computation or operation, the chances of errors occurring are
low. Errors in a computer are caused by human’s submitting incorrect data. A computer can
do a variety of operations and calculations fast and accurately.

Characteristics of Computer – FAQs


1. What do you mean by virtualization?

It is the technique of creating a virtual replica of a computer or operating system to run on


another hardware.

2. What is multitasking ability of a computer?

Computers can perform multiple tasks at the same time, allowing the user to work on multiple
programs at the same time is called multitasking ability. This characteristic of computer is
useful for applications such as data analysis, video editing, and so on.

8
3. What do you mean by data storage capacity of a computer?

data storage capacity means holding data in a memory. Computer data storage capacity is
increasing all the time, despite the fact that they can store multiple amounts of data. Modern
computers may store data in Terabytes, where a byte is a storage capacity word.

"GeeksforGeeks helped me ace the GATE exam! Whenever I had any doubt regarding any
topic, GFG always helped me and made my concepts quiet clear." - Anshika Modi | AIR 21

Choose GeeksforGeeks as your perfect GATE 2025 Preparation partner with these newly
launched programs
GATE CS & IT
GATE DS & AI
GATE Offline (Delhi/NCR)

Over 125,000+ students already trust us to be their GATE Exam guide. Join them & let us
help you in opening the GATE to top-tech IITs & NITs!

9
Types of Computers

Pre-Requisite: Basics of Computer

A computer is a device that transforms data into meaningful information. It processes the
input according to the set of instructions provided to it by the user and gives the desired
output. Computers are of various types and they can be categorized in two ways on the basis
of size and on the basis of data handling capabilities.

Computer

Types of Computer
There are two bases on which we can define the types of computers. We will discuss the type
of computers on the basis of size and data handling capabilities. We will discuss each type of
computer in detail. Let’s see first what are the types of computers.

 Super Computer
 Mainframe computer
 Mini Computer
 Workstation Computer
 Personal Computer (PC)
 Server Computer

10
 Analog Computer
 Digital Computer
 Hybrid Computer
 Tablets and Smartphone

Now, we are going to discuss each of them in detail.

Supercomputer

When we talk about speed, then the first name that comes to mind when thinking of
computers is supercomputers. They are the biggest and fastest computers (in terms of speed of
processing data). Supercomputers are designed such that they can process a huge amount of
data, like processing trillions of instructions or data just in a second. This is because of the
thousands of interconnected processors in supercomputers. It is basically used in scientific
and engineering applications such as weather forecasting, scientific simulations, and nuclear
energy research. It was first developed by Roger Cray in 1976.

Super Computers

Characteristics of Supercomputers

 Supercomputers are the computers that are the fastest and they are also very expensive.
 It can calculate up to ten trillion individual calculations per second, this is also the reason
which makes it even faster.
 It is used in the stock market or big organizations for managing the online currency world
such as Bitcoin etc.

11
 It is used in scientific research areas for analyzing data obtained from exploring the solar
system, satellites, etc.

Mainframe computer

Mainframe computers are designed in such a way that they can support hundreds or thousands
of users at the same time. It also supports multiple programs simultaneously. So, they can
execute different processes simultaneously. All these features make the mainframe computer
ideal for big organizations like banking, telecom sectors, etc., which process a high volume of
data in general.

Characteristics of Mainframe Computers

 It is also an expensive or costly computer.


 It has high storage capacity and great performance.
 It can process a huge amount of data (like data involved in the banking sector) very quickly.
 It runs smoothly for a long time and has a long life.

Minicomputer

Minicomputer is a medium size multiprocessing computer. In this type of computer, there are
two or more processors, and it supports 4 to 200 users at one time. Minicomputer is similar to
Microcontroller. Minicomputers are used in places like institutes or departments for different
work like billing, accounting, inventory management, etc. It is smaller than a mainframe
computer but larger in comparison to the microcomputer.

Characteristics of Minicomputer

 Its weight is low.


 Because of its low weight, it is easy to carry anywhere.
 less expensive than a mainframe computer.
 It is fast.

Workstation Computer

A workstation computer is designed for technical or scientific applications. It consists of a fast


microprocessor, with a large amount of RAM and a high-speed graphic adapter. It is a single-
user computer. It is generally used to perform a specific task with great accuracy.

Characteristics of Workstation Computer

 It is expensive or high in cost.


 They are exclusively made for complex work purposes.
 It provides large storage capacity, better graphics, and a more powerful CPU when compared
to a PC.
 It is also used to handle animation, data analysis, CAD, audio and video creation, and editing.

12
Personal Computer (PC)

Personal Computers is also known as a microcomputer. It is basically a general-purpose


computer designed for individual use. It consists of a microprocessor as a central processing
unit(CPU), memory, input unit, and output unit. This kind of computer is suitable for personal
work such as making an assignment, watching a movie, or at the office for office work, etc.
For example, Laptops and desktop computers.

Personal Computer

Characteristics of Personal Computer (PC)

 In this limited number of software can be used.


 It is the smallest in size.
 It is designed for personal use.

13
 It is easy to use.

Server Computer

Server Computers are computers that are combined data and programs. Electronic data and
applications are stored and shared in the server computer. The working of a server computer
is that it does not solve a bigger problem like a supercomputer but it solves many smaller
similar ones. Examples of server computer are like Wikipedia, as when users put a request for
any page, it finds what the user is looking for and sends it to the user.

Analog Computer

Analog Computers are particularly designed to process analog data. Continuous data that
changes continuously and cannot have discrete values are called analog data. So, an analog
computer is used where we don’t need exact values or need approximate values such as speed,
temperature, pressure, etc. It can directly accept the data from the measuring device without
first converting it into numbers and codes. It measures the continuous changes in physical
quantity. It gives output as a reading on a dial or scale. For example speedometer, mercury
thermometer, etc.

Digital Computer

Digital computers are designed in such a way that they can easily perform calculations and
logical operations at high speed. It takes raw data as input and processes it with programs
stored in its memory to produce the final output. It only understands the binary input 0 and 1,
so the raw input data is converted to 0 and 1 by the computer and then it is processed by the
computer to produce the result or final output. All modern computers, like laptops, desktops
including smartphones are digital computers.

Hybrid Computer

As the name suggests hybrid, which means made by combining two different things.
Similarly, the hybrid computer is a combination of both analog and digital computers. Hybrid
computers are fast like analog computers and have memory and accuracy like digital
computers. So, it has the ability to process both continuous and discrete data. For working
when it accepts analog signals as input then it converts them into digital form before
processing the input data. So, it is widely used in specialized applications where both analog
and digital data are required to be processed. A processor which is used in petrol pumps that
converts the measurements of fuel flow into quantity and price is an example of a hybrid
computer.

Tablet and Smartphones

Tablets and Smartphones are the types of computers that are pocket friendly and easy to carry
is these are handy. This is one of the best use of modern technology. These devices have
better hardware capabilities, extensive operating systems, and better multimedia functionality.
smartphones and tablets contain a number of sensors and are also able to provide wireless
communication protocols.

14
Tablet and Smartphones

We generally classify computers on the basis of size, functionality, and data handling
capabilities. For more, you can refer to Classification of Computers.

FAQ
1. Which computer can deal with analog data?

(A) Analogue Computer

(B) Digital Computer

(C) both a and b

(D) None of the above

Solution:

The correct option is A, i.e., Analogue computer

Analogue computer is particularly designed to process analogue data. A continuous data that
changes continuously and cannot have discrete values is called Analogue data.

2. __________ is also known as a Microcomputer.

(A) Supercomputer

15
(B) Minicomputer

(C) Workstation

(D) Personal computer

Solution:

The correct option is D, i.e., Personal computer.

3. Which type of computer has two or more processors and supports 4 to 200 users at
one time?

(A) Minicomputer

(B) Personal computer

(C) Analogue computer

(D) All of the above

Solution:

The correct option is A, i.e., Minicomputer

Minicomputer is a medium sized multiprocessing computer. In this type of computer, there


are two or more processors and it supports 4 to 200 users at one time.

4. All modern computers, like laptops, desktops including smartphones, are


______________computers.

(A) Hybrid

(B) Analogue

(C) Digital

(D) Supercomputer

Solution:

The correct option is C, i.e., digital.

Summer-time is here and so is the time to skill-up! More than 5,000 learners have now
completed their journey from basics of DSA to advanced level development programs such
as Full-Stack, Backend Development, Data Science.

And why go anywhere else when our DSA to Development: Coding Guide will help you

16
master all this in a few months! Apply now to our DSA to Development Program and our
counsellors will connect with you for further guidance & support.

17
Number System and Base Conversions

Electronic and Digital systems may use a variety of different number systems, (e.g. Decimal,
Hexadecimal, Octal, Binary), or even Duodecimal or less well known but better named
Uncial. All the other bases other than Decimal result from computer usage. Uncial (named
from Latin for 1/12 “uncia” the base twelve analogue of Decimal from the Latin word for
1/10 “decima”).

A number N in base or radix b can be written as:

(N)b = dn-1 dn-2 -- -- -- -- d1 d0 . d-1 d-2 -- -- -- -- d-m

In the above, dn-1 to d0 is the integer part, then follows a radix point, and then d-1 to d-m is the
fractional part.

dn-1 = Most significant bit (MSB)


d-m = Least significant bit (LSB)

How to convert a number from one base to another?

Follow the example illustrations:

1. Decimal to Binary
(10.25)10

18
Note: Keep multiplying the fractional part with 2 until decimal part 0.00 is obtained.
(0.25)10 = (0.01)2

Answer: (10.25)10 = (1010.01)2

2. Binary to Decimal
(1010.01)2
1x23 + 0x22 + 1x21+ 0x20 + 0x2 -1
+ 1x2 -2
= 8+0+2+0+0+0.25 = 10.25
(1010.01)2 = (10.25)10

3. Decimal to Octal
(10.25)10
(10)10 = (12)8
Fractional part:
0.25 x 8 = 2.00

Note: Keep multiplying the fractional part with 8 until decimal part .00 is obtained.
(.25)10 = (.2)8

Answer: (10.25)10 = (12.2)8

4. Octal to Decimal
(12.2)8
1 x 81 + 2 x 80 +2 x 8-1 = 8+2+0.25 = 10.25
(12.2)8 = (10.25)10

5. Hexadecimal to Binary
To convert from Hexadecimal to Binary, write the 4-bit binary equivalent of hexadecimal.

19
(3A)16 = (00111010)2

6. Binary to Hexadecimal
To convert from Binary to Hexadecimal, start grouping the bits in groups of 4 from the right-
end and write the equivalent hexadecimal for the 4-bit binary. Add extra 0’s on the left to
adjust the groups.

1111011011
0011 1101 1011
(001111011011 )2 = (3DB)16

7. Binary to Octal
To convert from binary to octal, start grouping the bits in groups of 3 from the right end and
write the equivalent octal for the 3-bit

binary. Add 0’s on the left to adjust the groups.

Example:

111101101

111 101 101

(111101101)2 = (755)8

20
"GeeksforGeeks helped me ace the GATE exam! Whenever I had any doubt regarding any
topic, GFG always helped me and made my concepts quiet clear." - Anshika Modi | AIR 21

Choose GeeksforGeeks as your perfect GATE 2025 Preparation partner with these newly
launched programs
GATE CS & IT
GATE DS & AI
GATE Offline (Delhi/NCR)

Over 125,000+ students already trust us to be their GATE Exam guide. Join them & let us
help you in opening the GATE to top-tech IITs & NITs!

21
1’s and 2’s complement of a Binary Number
Last Updated : 15 Dec, 2022



Given a Binary Number as a string, print its 1’s and 2’s complements.

1’s complement of a binary number is another binary number obtained by toggling all bits in
it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.In the 1’s complement format , the positive
numbers remain unchanged . The negative numbers are obtained by taking the 1’s
complement of positive counterparts.

for example +9 will be represented as 00001001 in eight-bit notation and -9 will be


represented as 11110110, which is the 1’s complement of 00001001.

Examples:

1's complement of "0111" is "1000"


1's complement of "1100" is "0011"

2’s complement of a binary number is 1, added to the 1’s complement of the binary number.
In the 2’s complement representation of binary numbers, the MSB represents the sign with a
‘0’ used for plus sign and a ‘1’ used for a minus sign. the remaining bits are used for
representing magnitude. positive magnitudes are represented in the same way as in the case of
sign-bit or 1’s complement representation. Negative magnitudes are represented by the 2’s
complement of their positive counterparts.

Examples:

2's complement of "0111" is "1001"


2's complement of "1100" is "0100"

Another trick to finding two’s complement:

Step 1: Start from the Least Significant Bit and traverse left until you find a 1. Until you find
1, the bits stay the same

Step 2: Once you have found 1, let the 1 as it is, and now

Step 3: Flip all the bits left into the 1.

Illustration

Suppose we need to find 2s Complement of 100100

Step 1: Traverse and let the bit stay the same until you find 1. Here x is not known yet.
Answer = xxxx00 –

22
Step 2: You found 1. Let it stay the same. Answer = xxx100

Step 3: Flip all the bits left into the 1. Answer = 011100.

Hence, the 2s complement of 100100 is 011100.

Recommended Practice

1’s Complement

Try It!

For one’s complement, we simply need to flip all bits.


For 2’s complement, we first find one’s complement. We traverse the one’s complement
starting from LSB (least significant bit), and look for 0. We flip all 1’s (change to 0) until we
find a 0. Finally, we flip the found 0. For example, 2’s complement of “01000” is “11000”
(Note that we first find one’s complement of 01000 as 10111). If there are all 1’s (in one’s
complement), we add an extra 1 in the string. For example, 2’s complement of “000” is
“1000” (1’s complement of “000” is “111”).

Below is the implementation.

// C++ program to print 1's and 2's complement of

// a binary number

#include <bits/stdc++.h>

using namespace std;

// Returns '0' for '1' and '1' for '0'

char flip(char c) {return (c == '0')? '1': '0';}

// Print 1's and 2's complement of binary number

// represented by "bin"

void printOneAndTwosComplement(string bin)

int n = bin.length();

int i;

string ones, twos;

ones = twos = "";

23
// for ones complement flip every bit

for (i = 0; i < n; i++)

ones += flip(bin[i]);

// for two's complement go from right to left in

// ones complement and if we get 1 make, we make

// them 0 and keep going left when we get first

// 0, make that 1 and go out of loop

twos = ones;

for (i = n - 1; i >= 0; i--)

if (ones[i] == '1')

twos[i] = '0';

else

twos[i] = '1';

break;

// If No break : all are 1 as in 111 or 11111;

// in such case, add extra 1 at beginning

if (i == -1)

twos = '1' + twos;

cout << "1's complement: " << ones << endl;

cout << "2's complement: " << twos << endl;

24
// Driver program

int main()

string bin = "1100";

printOneAndTwosComplement(bin);

return 0;

Output:

1's complement: 0011


2's complement: 0100

Time Complexity: O(n)

Auxiliary Space: O(1)

Below is the implementation.

// Java program to print 1's and 2's complement of


// a binary number

class GFG
{

// Returns '0' for '1' and '1' for '0'


static char flip(char c)
{
return (c == '0') ? '1' : '0';
}

// Print 1's and 2's complement of binary number


// represented by "bin"
static void printOneAndTwosComplement(String bin)
{
int n = bin.length();
int i;

String ones = "", twos = "";


ones = twos = "";

// for ones complement flip every bit


for (i = 0; i < n; i++)
{
ones += flip(bin.charAt(i));
}

25
// for two's complement go from right to left in
// ones complement and if we get 1 make, we make
// them 0 and keep going left when we get first
// 0, make that 1 and go out of loop
twos = ones;
for (i = n - 1; i >= 0; i--)
{
if (ones.charAt(i) == '1')
{
twos = twos.substring(0, i) + '0' + twos.substring(i + 1);
}
else
{
twos = twos.substring(0, i) + '1' + twos.substring(i + 1);
break;
}
}

// If No break : all are 1 as in 111 or 11111;


// in such case, add extra 1 at beginning
if (i == -1)
{
twos = '1' + twos;
}

System.out.println("1's complement: " + ones);;


System.out.println("2's complement: " + twos);
}

// Driver code
public static void main(String[] args)
{
String bin = "1100";
printOneAndTwosComplement(bin);
}
}

// This code contributed by Rajput-Ji

Output:

1's complement: 0011


2's complement: 0100

Time Complexity: O(n)

Auxiliary Space: O(1)

Below is the implementation.

# Python3 program to print 1's and 2's


# complement of a binary number

# Returns '0' for '1' and '1' for '0'

26
def flip(c):
return '1' if (c == '0') else '0'

# Print 1's and 2's complement of


# binary number represented by "bin"
def printOneAndTwosComplement(bin):

n = len(bin)
ones = ""
twos = ""

# for ones complement flip every bit


for i in range(n):
ones += flip(bin[i])

# for two's complement go from right


# to left in ones complement and if
# we get 1 make, we make them 0 and
# keep going left when we get first
# 0, make that 1 and go out of loop
ones = list(ones.strip(""))
twos = list(ones)
for i in range(n - 1, -1, -1):

if (ones[i] == '1'):
twos[i] = '0'
else:
twos[i] = '1'
break

i -= 1
# If No break : all are 1 as in 111 or 11111
# in such case, add extra 1 at beginning
if (i == -1):
twos.insert(0, '1')

print("1's complement: ", *ones, sep = "")


print("2's complement: ", *twos, sep = "")

# Driver Code
if __name__ == '__main__':
bin = "1100"
printOneAndTwosComplement(bin.strip(""))

# This code is contributed


# by SHUBHAMSINGH10

Output:

1's complement: 0011


2's complement: 0100

Time Complexity: O(n)

Auxiliary Space: O(1)

27
Below is the implementation.

// C# program to print 1's and 2's complement of


// a binary number
using System;

class GFG
{

28
// Returns '0' for '1' and '1' for '0'
static char flip(char c)
{
return (c == '0') ? '1' : '0';
}

// Print 1's and 2's complement of binary number


// represented by "bin"
static void printOneAndTwosComplement(String bin)
{
int n = bin.Length;
int i;

String ones = "", twos = "";


ones = twos = "";

// for ones complement flip every bit


for (i = 0; i < n; i++)
{
ones += flip(bin[i]);
}

// for two's complement go from right to left in


// ones complement and if we get 1 make, we make
// them 0 and keep going left when we get first
// 0, make that 1 and go out of loop
twos = ones;
for (i = n - 1; i >= 0; i--)
{
if (ones[i] == '1')
{
twos = twos.Substring(0, i) + '0' +
twos.Substring(i + 1,twos.Length-(i+1));
}
else
{
twos = twos.Substring(0, i) + '1' +
twos.Substring(i + 1,twos.Length-(i+1));
break;
}
}

// If No break : all are 1 as in 111 or 11111;


// in such case, add extra 1 at beginning
if (i == -1)
{
twos = '1' + twos;
}

Console.WriteLine("1's complement: " + ones);;


Console.WriteLine("2's complement: " + twos);
}

// Driver code
public static void Main(String[] args)
{
String bin = "1100";
printOneAndTwosComplement(bin);
}
}

29
// This code has been contributed by 29AjayKumar

Output:

1's complement: 0011


2's complement: 0100

Time Complexity: O(n)

Auxiliary Space: O(1)

Below is the implementation.

// Javascript program to print 1's and 2's complement of


// a binary number

// Returns '0' for '1' and '1' for '0'


function flip (c) {return (c == '0')? '1': '0';}

// Print 1's and 2's complement of binary number


// represented by "bin"

30
function printOneAndTwosComplement(bin)
{
var n = bin.length;
var i;

var ones, twos;


ones = twos = "";

// for ones complement flip every bit


for (i = 0; i < n; i++)
ones += flip(bin[i]);

// for two's complement go from right to left in


// ones complement and if we get 1 make, we make
// them 0 and keep going left when we get first
// 0, make that 1 and go out of loop
twos = ones;
twos = twos.split('')
for (i = n - 1; i >= 0; i--)
{
if (ones[i] == '1')
twos[i] = '0';
else
{
twos[i] = '1';
break;
}
}
twos = twos.join('')
// If No break : all are 1 as in 111 or 11111;
// in such case, add extra 1 at beginning
if (i == -1)
twos = '1' + twos;

document.write( "1's complement: " + ones + "<br>");


document.write( "2's complement: " + twos + "<br>");
}

// Driver program
var bin = "1100";
printOneAndTwosComplement(bin);

Output:

1's complement: 0011


2's complement: 0100

Time Complexity: O(n)

Auxiliary Space: O(1)

Thanks to Utkarsh Trivedi for the above solution.


As a side note, signed numbers generally use 2’s complement representation. Positive values
are stored as it is and negative values are stored in their 2’s complement form. One extra bit is

31
required to indicate whether the number is positive or negative. For example, char is 8 bits in
C. If 2’s complement representation is used for char, then 127 is stored as it is, i.e., 01111111,
where first 0 indicates positive. But -127 is stored as 10000001.
Related Post :
Efficient method for 2’s complement of a binary string

References:
http://qa.geeksforgeeks.org/6439/write-program-calculate-ones-and-twos-complement-of-
number
https://www.geeksforgeeks.org/difference-between-1s-complement-representation-and-2s-
complement-representation-technique/

BCD or Binary Coded Decimal

Binary Coded Decimal, or BCD, is another process for converting decimal numbers into
their binary equivalents.

 It is a form of binary encoding where each digit in a decimal number is represented in the
form of bits.

32
 This encoding can be done in either 4-bit or 8-bit (usually 4-bit is preferred).
 It is a fast and efficient system that converts the decimal numbers into binary numbers as
compared to the existing binary system.
 These are generally used in digital displays where is the manipulation of data is quite a task.
 Thus BCD plays an important role here because the manipulation is done treating each digit
as a separate single sub-circuit.

The BCD equivalent of a decimal number is written by replacing each decimal digit in the
integer and fractional parts with its four bit binary equivalent.the BCD code is more precisely
known as 8421 BCD code , with 8,4,2 and 1 representing the weights of different bits in the
four-bit groups, Starting from MSB and proceeding towards LSB. This feature makes it a
weighted code , which means that each bit in the four bit group representing a given decimal
digit has an assigned weight.
Many decimal values, have an infinite place-value representation in binary but have a finite
place-value in binary-coded decimal. For example, 0.2 in binary is .001100… and in BCD is
0.0010. It avoids fractional errors and is also used in huge financial calculations.

Consider the following truth table and focus on how are these represented.

Truth Table for Binary Coded Decimal

DECIMAL NUMBER BCD

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

In the BCD numbering system, the given decimal number is segregated into chunks of four
bits for each decimal digit within the number. Each decimal digit is converted into its direct
binary form (usually represented in 4-bits).

For example:

33
1. Convert (123)10 in BCD

From the truth table above,


1 -> 0001
2 -> 0010
3 -> 0011
thus, BCD becomes -> 0001 0010 0011

2. Convert (324)10 in BCD

(324)10 -> 0011 0010 0100 (BCD)

Again from the truth table above,


3 -> 0011
2 -> 0010
4 -> 0100
thus, BCD becomes -> 0011 0010 0100

This is how decimal numbers are converted to their equivalent BCDs.

 It is noticeable that the BCD is nothing more than a binary representation of each digit of a
decimal number.
 It cannot be ignored that the BCD representation of the given decimal number uses extra
bits, which makes it heavy-weighted.

Related articles:

1. Program to Convert BCD number into Decimal number

2. BCD Adder in Digital Logic

3. BCD to 7 Segment Decoder

"The DSA course helped me a lot in clearing the interview rounds. It was really very helpful
in setting a strong foundation for my problem-solving skills. Really a great investment, the
passion Sandeep sir has towards DSA/teaching is what made the huge difference." - Gaurav |
Placed at Amazon

Before you move on to the world of development, master the fundamentals of DSA on
which every advanced algorithm is built upon. Choose your preferred language and start
learning today:

34
DSA In JAVA/C++
DSA In Python
DSA In JavaScript
Trusted by Millions, Taught by One- Join the best DSA Course Today!

Error Detection Codes: Parity Bit Method

Error Detection Codes : The binary information is transferred from one location to another
location through some communication medium. The external noise can change bits from 1 to
0 or 0 to 1.This changes in values changes the meaning of actual message and is called error.
For efficient data transfer, there should be an error detection and correction codes. An error
detection code is a binary code that detects digital errors during transmission. To detect error
in the received message, we add some extra bits to the actual data.

Without addition of redundant bits, it is not possible to detect errors in the received message.
There are 3 ways in which we can detect errors in the received message :

35
1. Parity Bit

2. CheckSum

3. Cyclic Redundancy Check (CRC)

We’ll be understanding the parity bit method in this article in depth :-

Parity Bit Method : A parity bit is an extra bit included in binary message to make total
number of 1’s either odd or even. Parity word denotes number of 1’s in a binary string. There
are two parity system – even and odd parity checks.

1. Even Parity Check: Total number of 1’s in the given data bit should be even. So if the
total number of 1’s in the data bit is odd then a single 1 will be appended to make total
number of 1’s even else 0 will be appended(if total number of 1’s are already even). Hence, if
any error occurs, the parity check circuit will detect it at the receiver’s end. Let’s understand
this with example, see the below diagram :

Even Parity Check (fig – 1.1)

In the above image, as we can see the data bits are ‘1011000’ and since this is even parity
check that we’re talking about, 1 will be appended as the parity bit (highlighted in red) to
make total count of 1’s even in the data sent. So here, our parity bit is 1. If the total count of 1
in the given data bits were already even, then 0 would’ve been appended.

36
2. Odd Parity Check: In odd parity system, if the total number of 1’s in the given binary
string (or data bits) are even then 1 is appended to make the total count of 1’s as odd else 0 is
appended. The receiver knows that whether sender is an odd parity generator or even parity
generator. Suppose if sender is an odd parity generator then there must be an odd number of
1’s in received binary string. If an error occurs to a single bit that is either bit is changed to 1
to 0 or 0 to 1, received binary bit will have an even number of 1’s which will indicate an
error.

Take reference from fig(1.1) and rather than appending the 1 as parity bit, append 0 because
total number of 1’s are already odd.

37
Some more examples :-

Message (XYZ) P(Odd) P(Even)

000 1 0

001 0 1

010 0 1

011 1 0

100 0 1

101 1 0

110 1 0

111 0 1

38
Fi
gure – Error Detection with Odd Parity Bit

Limitations :

1. The limitation of this method is that only error in a single bit would be identified and we
also cannot determine the exact location of error in the data bit.

2. If the number of bits in even parity check increase or decrease (data changed) but remained
to be even then it won’t be able to detect error as the number of bits are still even and same
goes for odd parity check.

See the below image for more details :

Can’t detect error (Even Parity Check)

In the above example, the the data bits has been changed but as we can see the total count of
1’s remain to be even, the error can’t be detected even though the message’s meaning has
been changed. You can visualize the same for odd parity check the number of 1’s will remain

39
odd, even if the data bits have been changed and the odd parity check won’t be able to detect
error.

Points to Remember :

 In 1’s complement of signed number +0 and -0 has two different representation.


 The range of signed magnitude representation of an 8-bit number in which 1-bit is used as a
signed bit as follows -27 to +27.
 Floating point number is said to be normalized if most significant digit of mantissa is one. For
example, 6-bit binary number 001101 is normalized because of two leading 0’s.
 Booth algorithm that uses two n bit numbers for multiplication gives results in 2n bits.
 The booth algorithm uses 2’s complement representation of numbers and work for both
positive and negative numbers.
 If k-bits are used to represent exponent then bits number = (2k-1) and range of exponent = –
(2k-1 -1) to (2k-1).

"GeeksforGeeks helped me ace the GATE exam! Whenever I had any doubt regarding any
topic, GFG always helped me and made my concepts quiet clear." - Anshika Modi | AIR 21

Choose GeeksforGeeks as your perfect GATE 2025 Preparation partner with these newly
launched programs
GATE CS & IT
GATE DS & AI
GATE Offline (Delhi/NCR)

Over 125,000+ students already trust us to be their GATE Exam guide. Join them & let us
help you in opening the GATE to top-tech IITs & NITs!

40
What is Algorithm | Introduction to Algorithms

Definition of Algorithm
The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
Or
” A procedure for solving a mathematical problem in a finite number of steps that frequently
involves recursive operations”.

Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.

Use of the Algorithms:


Algorithms play a crucial role in various fields and have many applications. Some of the key
areas where algorithms are used include:

1. Computer Science: Algorithms form the basis of computer programming and are used to
solve problems ranging from simple sorting and searching to complex tasks such as artificial
intelligence and machine learning.

2. Mathematics: Algorithms are used to solve mathematical problems, such as finding the
optimal solution to a system of linear equations or finding the shortest path in a graph.

3. Operations Research: Algorithms are used to optimize and make decisions in fields such as
transportation, logistics, and resource allocation.

41
4. Artificial Intelligence: Algorithms are the foundation of artificial intelligence and machine
learning, and are used to develop intelligent systems that can perform tasks such as image
recognition, natural language processing, and decision-making.

5. Data Science: Algorithms are used to analyze, process, and extract insights from large
amounts of data in fields such as marketing, finance, and healthcare.

These are just a few examples of the many applications of algorithms. The use of algorithms
is continually expanding as new technologies and fields emerge, making it a vital component
of modern society.

Algorithms can be simple and complex depending on what you want to achieve.

It can be understood by taking the example of cooking a new recipe. To cook a new recipe,
one reads the instructions and steps and executes them one by one, in the given sequence. The
result thus obtained is the new dish is cooked perfectly. Every time you use your phone,
computer, laptop, or calculator you are using Algorithms. Similarly, algorithms help to do a
task in programming to get the expected output.

The Algorithm designed are language-independent, i.e. they are just plain instructions that can
be implemented in any language, and yet the output will be the same, as expected.

What is the need for algorithms?


1. Algorithms are necessary for solving complex problems efficiently and effectively.

2. They help to automate processes and make them more reliable, faster, and easier to
perform.

3. Algorithms also enable computers to perform tasks that would be difficult or impossible for
humans to do manually.

4. They are used in various fields such as mathematics, computer science, engineering, finance,
and many others to optimize processes, analyze data, make predictions, and provide
solutions to problems.

What are the Characteristics of an Algorithm?

42
As one would not follow any written instructions to cook the recipe, but only the standard
one. Similarly, not all written instructions for programming are an algorithm. For some
instructions to be an algorithm, it must have the following characteristics:

 Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps should be
clear in all aspects and must lead to only one meaning.

 Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs. It


may or may not take input.

 Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it
should be well-defined as well. It should produce at least 1 output.

 Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.

 Feasible: The algorithm must be simple, generic, and practical, such that it can be executed
with the available resources. It must not contain some future technology or anything.

 Language Independent: The Algorithm designed must be language-independent, i.e. it must


be just plain instructions that can be implemented in any language, and yet the output will
be the same, as expected.

 Input: An algorithm has zero or more inputs. Each that contains a fundamental operator
must accept zero or more inputs.

 Output: An algorithm produces at least one output. Every instruction that contains a
fundamental operator must accept zero or more inputs.

 Definiteness: All instructions in an algorithm must be unambiguous, precise, and easy to


interpret. By referring to any of the instructions in an algorithm one can clearly understand

43
what is to be done. Every fundamental operator in instruction must be defined without any
ambiguity.

 Finiteness: An algorithm must terminate after a finite number of steps in all test cases. Every
instruction which contains a fundamental operator must be terminated within a finite
amount of time. Infinite loops or recursive functions without base conditions do not possess
finiteness.

 Effectiveness: An algorithm must be developed by using very basic, simple, and feasible
operations so that one can trace it out by using just paper and pencil.

Properties of Algorithm:
 It should terminate after a finite time.

 It should produce at least one output.

 It should take zero or more input.

 It should be deterministic means giving the same output for the same input case.

 Every step in the algorithm must be effective i.e. every step should do some work.

Types of Algorithms:
There are several types of algorithms available. Some important algorithms are:

1. Brute Force Algorithm:

It is the simplest approach to a problem. A brute force algorithm is the first approach that
comes to finding when we see a problem.

2. Recursive Algorithm:

A recursive algorithm is based on recursion. In this case, a problem is broken into several sub-
parts and called the same function again and again.

3. Backtracking Algorithm:

The backtracking algorithm builds the solution by searching among all possible solutions.
Using this algorithm, we keep on building the solution following criteria. Whenever a solution
fails we trace back to the failure point build on the next solution and continue this process till
we find the solution or all possible solutions are looked after.

4. Searching Algorithm:

Searching algorithms are the ones that are used for searching elements or groups of elements
from a particular data structure. They can be of different types based on their approach or the
data structure in which the element should be found.

44
5. Sorting Algorithm:

Sorting is arranging a group of data in a particular manner according to the requirement. The
algorithms which help in performing this function are called sorting algorithms. Generally
sorting algorithms are used to sort groups of data in an increasing or decreasing manner.

6. Hashing Algorithm:

Hashing algorithms work similarly to the searching algorithm. But they contain an index with
a key ID. In hashing, a key is assigned to specific data.

7. Divide and Conquer Algorithm:

This algorithm breaks a problem into sub-problems, solves a single sub-problem, and merges
the solutions to get the final solution. It consists of the following three steps:

 Divide

 Solve

 Combine

8. Greedy Algorithm:

In this type of algorithm, the solution is built part by part. The solution for the next part is
built based on the immediate benefit of the next part. The one solution that gives the most
benefit will be chosen as the solution for the next part.

9. Dynamic Programming Algorithm:

This algorithm uses the concept of using the already found solution to avoid repetitive
calculation of the same part of the problem. It divides the problem into smaller overlapping
subproblems and solves them.

10. Randomized Algorithm:

In the randomized algorithm, we use a random number so it gives immediate benefit. The
random number helps in deciding the expected outcome.

To learn more about the types of algorithms refer to the article about “Types of Algorithms“.

Advantages of Algorithms:
 It is easy to understand.

 An algorithm is a step-wise representation of a solution to a given problem.

 In an Algorithm the problem is broken down into smaller pieces or steps hence, it is easier
for the programmer to convert it into an actual program.

45
Disadvantages of Algorithms:
 Writing an algorithm takes a long time so it is time-consuming.

 Understanding complex logic through algorithms can be very difficult.

 Branching and Looping statements are difficult to show in Algorithms(imp).

How to Design an Algorithm?


To write an algorithm, the following things are needed as a pre-requisite:

1. The problem that is to be solved by this algorithm i.e. clear problem definition.

2. The constraints of the problem must be considered while solving the problem.

3. The input to be taken to solve the problem.

4. The output is to be expected when the problem is solved.

5. The solution to this problem is within the given constraints.

Then the algorithm is written with the help of the above parameters such that it solves the
problem.

Example: Consider the example to add three numbers and print the sum.

Step 1: Fulfilling the pre-requisites

As discussed above, to write an algorithm, its prerequisites must be fulfilled.

1. The problem that is to be solved by this algorithm: Add 3 numbers and print their sum.

2. The constraints of the problem that must be considered while solving the problem: The
numbers must contain only digits and no other characters.

3. The input to be taken to solve the problem: The three numbers to be added.

4. The output to be expected when the problem is solved: The sum of the three numbers
taken as the input i.e. a single integer value.

5. The solution to this problem, in the given constraints: The solution consists of adding the 3
numbers. It can be done with the help of the ‘+’ operator, or bit-wise, or any other method.

Step 2: Designing the algorithm

Now let’s design the algorithm with the help of the above pre-requisites:

Algorithm to add 3 numbers and print their sum:

46
1. START

2. Declare 3 integer variables num1, num2, and num3.

3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3
respectively.

4. Declare an integer variable sum to store the resultant sum of the 3 numbers.

5. Add the 3 numbers and store the result in the variable sum.

6. Print the value of the variable sum

7. END

Step 3: Testing the algorithm by implementing it.

To test the algorithm, let’s implement it in C language.

Program:

// C++ program to add three numbers

// with the help of above designed

// algorithm

#include <bits/stdc++.h>

using namespace std;

int main()

// Variables to take the input of

// the 3 numbers

int num1, num2, num3;

// Variable to store the resultant sum

int sum;

// Take the 3 numbers as input

47
cout << "Enter the 1st number: ";

cin >> num1;

cout << " " << num1 << endl;

cout << "Enter the 2nd number: ";

cin >> num2;

cout << " " << num2 << endl;

cout << "Enter the 3rd number: ";

cin >> num3;

cout << " " << num3;

// Calculate the sum using + operator

// and store it in variable sum

sum = num1 + num2 + num3;

// Print the sum

cout << "\nSum of the 3 numbers is: "

<< sum;

return 0;

// This code is contributed by shivanisinghss2110

Output

Enter the 1st number: 0


Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

48
Program:

// C program to add three numbers


// with the help of above designed algorithm

#include <stdio.h>

int main()
{

// Variables to take the input of the 3 numbers


int num1, num2, num3;

// Variable to store the resultant sum


int sum;

// Take the 3 numbers as input


printf("Enter the 1st number: ");
scanf("%d", &num1);
printf("%d\n", num1);

printf("Enter the 2nd number: ");


scanf("%d", &num2);
printf("%d\n", num2);

printf("Enter the 3rd number: ");


scanf("%d", &num3);
printf("%d\n", num3);

// Calculate the sum using + operator


// and store it in variable sum
sum = num1 + num2 + num3;

// Print the sum


printf("\nSum of the 3 numbers is: %d", sum);

return 0;
}

Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

49
Program:

// Java program to add the three numbers


// with the help of above designed
// algorithm
import java.util.*;

class GFG {
public static void main(String[] args)
{

// Variable to store the resultant sum


int sum = 0;

// Declare the object and initialize with


// predefined standard input object
Scanner sc
= new Scanner(System.in); // Scanner definition

// Variables to take the input of


// the 3 numbers
System.out.println("Enter the 1st number: ");
int num1 = sc.nextInt();

// input is an Integer
// read by nextInt() function
System.out.println(" " + num1);
System.out.println("Enter the 2nd number: ");
int num2 = sc.nextInt();
System.out.println(" " + num2);
System.out.println("Enter the 3rd number: ");
int num3 = sc.nextInt();
System.out.println(" " + num3);

// Calculate the sum using + operator


// and store it in variable sum
sum = num1 + num2 + num3;
System.out.println("Sum of the 3 numbers is = "
+ sum);
}
}

/*This code is contributed by Rishab Dugar*/

Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

Program:

50
# Python3 program to add three numbers
# with the help of above designed
# algorithm

if __name__ == "__main__":

# Variables to take the input of


# the 3 numbers
num1 = num2 = num3 = 0

# Variable to store the resultant sum


sum = 0

# Take the 3 numbers as input


num1 = int(input("Enter the 1st number: "))

num2 = int(input("Enter the 2nd number: "))

num3 = int(input("Enter the 3rd number: "))

# Calculate the sum using + operator


# and store it in variable sum
sum = num1 + num2 + num3

# Print the sum


print("\nSum of the 3 numbers is:", sum)

Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

Program:

51
// C# program to add the three numbers
// with the help of above designed
// algorithm
using System;

class GFG {
static public void Main ()
{

// Variable to store the resultant sum


int sum = 0;

// Variables to take the input of


// the 3 numbers
Console.Write("Enter the 1st number: ");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine(" " + num1);
Console.Write("Enter the 2nd number: ");
int num2 = int.Parse(Console.ReadLine());
Console.WriteLine(" " + num2);
Console.Write("Enter the 3rd number: ");
int num3 = int.Parse(Console.ReadLine());
Console.WriteLine(" " + num3);

// Calculate the sum using + operator


// and store it in variable sum
sum = num1 + num2 + num3;
Console.WriteLine("Sum of the 3 numbers is = "
+ sum);
}
}

/*This code is contributed by Pushpesh Raj*/

Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

Program:

52
// Javascript program to add three numbers
// with the help of above designed
// algorithm

// Variables to take the input of


// the 3 numbers
let num1 = 0, num2 = 0, num3 = 0;

// Variable to store the resultant sum


let sum = 0;

// Take the 3 numbers as input


console.log("Enter the 1st number: ");
num1 = parseInt(prompt());
console.log(" " + num1 + "<br>");

console.log("Enter the 2nd number: ");


num2=parseInt(prompt());
console.log(" " + num2 + "<br>");

console.log("Enter the 3rd number: ");


num3=parseInt(prompt());
console.log(" " + num3);

// Calculate the sum using + operator


// and store it in variable sum
sum = num1 + num2 + num3;

// Print the sum


console.log("<br>Sum of the 3 numbers is: " + sum);

// This code is contributed by Aman Kumar

Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152

Here is the step-by-step algorithm of the code:

53
1. Declare three variables num1, num2, and num3 to store the three numbers to be added.

2. Declare a variable sum to store the sum of the three numbers.

3. Use the cout statement to prompt the user to enter the first number.

4. Use the cin statement to read the first number and store it in num1.

5. Use the cout statement to prompt the user to enter the second number.

6. Use the cin statement to read the second number and store it in num2.

7. Use the cout statement to prompt the user to enter the third number.

8. Use the cin statement to read and store the third number in num3.

9. Calculate the sum of the three numbers using the + operator and store it in the sum variable.

10. Use the cout statement to print the sum of the three numbers.

11. The main function returns 0, which indicates the successful execution of the program.

Time complexity: O(1)


Auxiliary Space: O(1)

One problem, many solutions: The solution to an algorithm can be or cannot be more than
one. It means that while implementing the algorithm, there can be more than one method to
implement it. For example, in the above problem of adding 3 numbers, the sum can be
calculated in many ways:

 + operator

 Bit-wise operators

 . . etc

How to analyze an Algorithm?


For a standard algorithm to be good, it must be efficient. Hence the efficiency of an algorithm
must be checked and maintained. It can be in two stages:

1. Priori Analysis:

“Priori” means “before”. Hence Priori analysis means checking the algorithm before its
implementation. In this, the algorithm is checked when it is written in the form of theoretical
steps. This Efficiency of an algorithm is measured by assuming that all other factors, for
example, processor speed, are constant and have no effect on the implementation. This is done
usually by the algorithm designer. This analysis is independent of the type of hardware and
language of the compiler. It gives the approximate answers for the complexity of the program.

54
2. Posterior Analysis:

“Posterior” means “after”. Hence Posterior analysis means checking the algorithm after its
implementation. In this, the algorithm is checked by implementing it in any programming
language and executing it. This analysis helps to get the actual and real analysis report about
correctness(for every possible input/s if it shows/returns correct output or not), space required,
time consumed, etc. That is, it is dependent on the language of the compiler and the type of
hardware used.

What is Algorithm complexity and how to find it?


An algorithm is defined as complex based on the amount of Space and Time it consumes.
Hence the Complexity of an algorithm refers to the measure of the time that it will need to
execute and get the expected output, and the Space it will need to store all the data (input,
temporary data, and output). Hence these two factors define the efficiency of an algorithm.
The two factors of Algorithm Complexity are:

 Time Factor: Time is measured by counting the number of key operations such as
comparisons in the sorting algorithm.

 Space Factor: Space is measured by counting the maximum memory space required by the
algorithm to run/execute.

Therefore the complexity of an algorithm can be divided into two types:

1. Space Complexity: The space complexity of an algorithm refers to the amount of memory
required by the algorithm to store the variables and get the result. This can be for inputs,
temporary operations, or outputs.

How to calculate Space Complexity?


The space complexity of an algorithm is calculated by determining the following 2
components:

 Fixed Part: This refers to the space that is required by the algorithm. For example, input
variables, output variables, program size, etc.

 Variable Part: This refers to the space that can be different based on the implementation of
the algorithm. For example, temporary variables, dynamic memory allocation, recursion
stack space, etc.
Therefore Space complexity S(P) of any algorithm P is S(P) = C + SP(I), where C is the fixed
part and S(I) is the variable part of the algorithm, which depends on instance characteristic I.

Example: Consider the below algorithm for Linear Search

Step 1: START
Step 2: Get n elements of the array in arr and the number to be searched in x
Step 3: Start from the leftmost element of arr[] and one by one compare x with each element
of arr[]
Step 4: If x matches with an element, Print True.

55
Step 5: If x doesn’t match with any of the elements, Print False.
Step 6: END
Here, There are 2 variables arr[], and x, where the arr[] is the variable part of n elements and x
is the fixed part. Hence S(P) = 1+n. So, the space complexity depends on n(number of
elements). Now, space depends on data types of given variables and constant types and it will
be multiplied accordingly.

2. Time Complexity: The time complexity of an algorithm refers to the amount of time
required by the algorithm to execute and get the result. This can be for normal operations,
conditional if-else statements, loop statements, etc.

How to Calculate, Time Complexity?


The time complexity of an algorithm is also calculated by determining the following 2
components:

 Constant time part: Any instruction that is executed just once comes in this part. For
example, input, output, if-else, switch, arithmetic operations, etc.

 Variable Time Part: Any instruction that is executed more than once, say n times, comes in
this part. For example, loops, recursion, etc.

Therefore Time complexity of any algorithm P is T(P) = C + TP(I), where C is the


constant time part and TP(I) is the variable part of the algorithm, which depends on the
instance characteristic I.

Example: In the algorithm of Linear Search above, the time complexity is calculated as
follows:

Step 1: –Constant Time


Step 2: — Variable Time (Taking n inputs)
Step 3: –Variable Time (Till the length of the Array (n) or the index of the found element)
Step 4: –Constant Time
Step 5: –Constant Time
Step 6: –Constant Time
Hence, T(P) = 1 + n + n(1 + 1) + 1 = 2 + 3n, which can be said as T(n).

How to express an Algorithm?


1. Natural Language:- Here we express the Algorithm in the natural English language. It is too
hard to understand the algorithm from it.

2. Flow Chart:- Here we express the Algorithm by making a graphical/pictorial representation of


it. It is easier to understand than Natural Language.

3. Pseudo Code:- Here we express the Algorithm in the form of annotations and informative
text written in plain English which is very much similar to the real code but as it has no syntax
like any of the programming languages, it can’t be compiled or interpreted by the computer.
It is the best way to express an algorithm because it can be understood by even a layman
with some school-level knowledge.

56
"The DSA course helped me a lot in clearing the interview rounds. It was really very helpful
in setting a strong foundation for my problem-solving skills. Really a great investment, the
passion Sandeep sir has towards DSA/teaching is what made the huge difference." - Gaurav |
Placed at Amazon

Before you move on to the world of development, master the fundamentals of DSA on
which every advanced algorithm is built upon. Choose your preferred language and start
learning today:

DSA In JAVA/C++
DSA In Python
DSA In JavaScript
Trusted by Millions, Taught by One- Join the best DSA Course Today!

57
Definition, Types, Complexity and Examples of 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.

Or we can say that an algorithm is said to be accurate if and only if it stops with the proper
output for each input instance.

NEED OF THE ALGORITHMS :

Algorithms are used to solve problems or automate tasks in a systematic and efficient manner.
They are a set of instructions or rules that guide the computer or software in performing a
particular task or solving a problem.

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.

Overall, algorithms are an essential tool for solving problems in a variety of fields, including
computer science, engineering, data analysis, finance, and many others.

Example:

Consider a box where no one can see what’s happening inside, we say a black box.

We give input to the box and it gives us the output we need but the procedure that we might
need to know behind the conversion of input to desired output is an ALGORITHM.

An algorithm is independent of the language used. It tells the programmer the logic used to
solve the problem. So, it is a logical step-by-step procedure that acts as a blueprint to
programmers.

Real-life examples that define the use of algorithms:


 Consider a clock. We know the clock is ticking but how does the manufacturer set those nuts
and bolts so that it keeps on moving every 60 seconds, the min hand should move and every
60 mins, the hour hand should move? So to solve this problem, there must be an algorithm
behind it.
 Seen someone cooking your favorite food for you? Is the recipe necessary for it? Yes, it is
necessary as a recipe is a sequential procedure that turns a raw potato into a chilly potato.
This is what an algorithm is: following a procedure to get the desired output. Is the sequence

58
necessary to be followed? Yes, the sequence is the most important thing that has to be
followed to get what we want.

Types of Algorithms:
 Sorting algorithms: Bubble Sort, insertion sort, and many more. These algorithms are used to
sort the data in a particular format.
 Searching algorithms: Linear search, binary search, etc. These algorithms are used in finding
a value or record that the user demands.
 Graph Algorithms: It is used to find solutions to problems like finding the shortest path
between cities, and real-life problems like traveling salesman problems.

Sorting algorithms are algorithms that take a collection of elements and rearrange them in
a specified order (e.g. ascending or descending). There are many different sorting
algorithms, each with its own strengths and weaknesses. Some of the most commonly used
sorting algorithms include:

Bubble sort: A simple sorting algorithm that repeatedly steps through the list, compares
adjacent elements and swaps them if they are in the wrong order.

Insertion sort: A simple sorting algorithm that builds up the final sorted array one item at a
time, by comparing each new item to the items that have already been sorted and inserting it
in the correct position.

Selection sort: A simple sorting algorithm that repeatedly selects the minimum element from
the unsorted part of the array and moves it to the end of the sorted part.

Merge sort: A divide-and-conquer sorting algorithm that works by dividing the unsorted list
into n sub-lists, sorting each sub-list, and then merging them back into a single sorted list.

Quick sort: A divide-and-conquer sorting algorithm that works by selecting a “pivot”


element from the array and partitioning the other elements into two sub-arrays, according to
whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively.

Each of these algorithms has different time and space complexities, making some more
suitable for certain use cases than others.

Searching algorithms are algorithms that search for a particular element or value in a data
structure (such as an array or a linked list). Some of the most commonly used searching
algorithms include:

Linear search: A simple searching algorithm that iterates through every element of a list
until it finds a match.

Binary search: A searching algorithm that works by dividing a sorted list in half repeatedly,
until the desired element is found or it can be determined that the element is not present.

59
Jump search: A searching algorithm that works by jumping ahead by fixed steps in the list,
until a suitable candidate is found, and then performing a linear search in the surrounding
elements.

Interpolation search: A searching algorithm that works by using information about the range
of values in the list to estimate the position of the desired element and then verifying that it is
indeed present.

Hash table search: A searching algorithm that uses a hash function to map elements to
indices in an array, and then performs constant-time lookups in the array to find the desired
element.

Each of these algorithms has different time and space complexities, making some more
suitable for certain use cases than others. The choice of which algorithm to use depends on the
specific requirements of the problem, such as the size of the data structure, the distribution of
values, and the desired time complexity.

Graph algorithms are a set of algorithms that are used to process, analyze and understand
graph data structures. Graphs are mathematical structures used to model relationships
between objects, where the objects are represented as vertices (or nodes) and the
relationships between them are represented as edges. Graph algorithms are used in a
variety of applications such as network analysis, social network analysis, recommendation
systems, and in many other areas where understanding the relationships between objects is
important. Some of the common graph algorithms include:

Shortest Path algorithms (e.g. Dijkstra’s, Bellman-Ford, A*)


Minimum Spanning Tree algorithms (e.g. Kruskal, Prim)
Maximum Flow algorithms (e.g. Ford-Fulkerson, Edmonds-Karp)
Network Flow algorithms (e.g. Bipartite Matching)
Connectivity algorithms (e.g. Depth-first Search, Breadth-first Search)

Why do we use algorithms?


Consider two kids, Aman and Rohan, solving the Rubik’s Cube. Aman knows how to solve it
in a definite number of steps. On the other hand, Rohan knows that he will do it but is not
aware of the procedure. Aman solves the cube within 2 minutes whereas Rohan is still stuck
and by the end of the day, he somehow managed to solve it (might have cheated as the
procedure is necessary).

So the time required to solve with a procedure/algorithm is much more effective than that
without any procedure. Hence the need for an algorithm is a must.

In terms of designing a solution to an IT problem, computers are fast but not infinitely fast.
The memory may be inexpensive but not free. So, computing time is therefore a bounded
resource and so is the space in memory. So we should use these resources wisely and
algorithms that are efficient in terms of time and space will help you do so.

Creating an Algorithm:

60
Since the algorithm is language-independent, we write the steps to demonstrate the logic
behind the solution to be used for solving a problem. But before writing an algorithm, keep
the following points in mind:

 The algorithm should be clear and unambiguous.


 There should be 0 or more well-defined inputs in an algorithm.
 An algorithm must produce one or more well-defined outputs that are equivalent to the
desired output. After a specific number of steps, algorithms must ground to a halt.
 Algorithms must stop or end after a finite number of steps.
 In an algorithm, step-by-step instructions should be supplied, and they should be
independent of any computer code.

Example: algorithm to multiply 2 numbers and print the result:

Step 1: Start

Step 2: Get the knowledge of input. Here we need 3 variables; a and b will be the user input
and c will hold the result.

Step 3: Declare a, b, c variables.

Step 4: Take input for a and b variable from the user.

Step 5: Know the problem and find the solution using operators, data structures and logic

We need to multiply a and b variables so we use * operator and assign the result to c.
That is c <- a * b

Step 6: Check how to give output, Here we need to print the output. So write print c

Step 7: End

Example 1: Write an algorithm to find the maximum of all the elements present in the array.
Follow the algorithm approach as below:

Step 1: Start the Program

Step 2: Declare a variable max with the value of the first element of the array.

Step 3: Compare max with other elements using loop.

Step 4: If max < array element value, change max to new max.

Step 5: If no element is left, return or print max otherwise goto step 3.

Step 6: End of Solution

Example 2: Write an algorithm to find the average of 3 subjects.


Follow the algorithm approach as below:

61
Step 1: Start the Program

Step 2: Declare and Read 3 Subject, let’s say S1, S2, S3

Step 3: Calculate the sum of all the 3 Subject values and store result in Sum variable (Sum =
S1+S2+S3)

Step 4: Divide Sum by 3 and assign it to Average variable. (Average = Sum/3)

Step 5: Print the value of Average of 3 Subjects

Step 6: End of Solution

Know about Algorithm Complexity:


Complexity in algorithms refers to the amount of resources (such as time or memory) required
to solve a problem or perform a task. The most common measure of complexity is time
complexity, which refers to the amount of time an algorithm takes to produce a result as a
function of the size of the input. Memory complexity refers to the amount of memory used by
an algorithm. Algorithm designers strive to develop algorithms with the lowest possible time
and memory complexities, since this makes them more efficient and scalable.

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.

Usually there are natural units for the domain and range of this function.

An algorithm is analyzed using Time Complexity and Space Complexity. Writing an efficient
algorithm help to consume the minimum amount of time for processing the logic. For
algorithm A, it is judged on the basis of two parameters for an input of size n :

 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.
 “Time” can mean the number of memory accesses performed, the number of comparisons
between integers, the number of times some inner loop is executed, or some other natural
unit related to the amount of real time the algorithm will take.
 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. For example, if we use a hash table (a kind of data structure), we need
an array to store values so
 this is an extra space occupied, hence will count towards the space complexity of the
algorithm. This extra space is known as Auxiliary Space.
 Space complexity is a function describing the amount of memory(space)an algorithm takes in
terms of the amount of input to the algorithm.
 Space complexity is sometimes ignored because the space used is minimal and/ or obvious,
but sometimes it becomes an issue as time.

.The time complexity of the operations:

62
 The choice of data structure should be based on the time complexity of the operations that
will be performed.
 Time complexity is defined in terms of how many times it takes to run a given algorithm,
based on the length of the input.
 The time complexity of an algorithm is the amount of time it takes for each statement to
complete. It is highly dependent on the size of the processed data.
 For example, if you need to perform searches frequently, you should use a binary search
tree.

.The space complexity of the operations:

 The choice of data structure should be based on the space complexity of the operations that
will be performed.
 The amount of memory used by a program to execute it is represented by its space
complexity.
 Because a program requires memory to store input data and temporal values while running ,
the space complexity is auxiliary and input space.
 For example, if you need to store a lot of data, you should use an array.

cases in complexities:
There are two commonly studied cases of complexity in algorithms:

1.Best case complexity: The best-case scenario for an algorithm is the scenario in which the
algorithm performs the minimum amount of work (e.g. takes the shortest amount of time, uses
the least amount of memory, etc.).

2.Worst case complexity: The worst-case scenario for an algorithm is the scenario in which
the algorithm performs the maximum amount of work (e.g. takes the longest amount of time,
uses the most amount of memory, etc.).

In analyzing the complexity of an algorithm, it is often more informative to study the worst-
case scenario, as this gives a guaranteed upper bound on the performance of the algorithm.
Best-case scenario analysis is sometimes performed, but is generally less important as it
provides a lower bound that is often trivial to achieve.

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

63
 Creating efficient algorithms is time-consuming and requires good logical skills.
 Nasty to show branching and looping in algorithms.

Summer-time is here and so is the time to skill-up! More than 5,000 learners have now
completed their journey from basics of DSA to advanced level development programs such
as Full-Stack, Backend Development, Data Science.

And why go anywhere else when our DSA to Development: Coding Guide will help you
master all this in a few months! Apply now to our DSA to Development Program and our
counsellors will connect with you for further guidance & support.

64
https://www.geeksforgeeks.org/error-detection-codes-parity-bit-method/?ref=lbp

https://www.geeksforgeeks.org/error-detection-codes-parity-bit-method/?ref=lbp

65

You might also like