Fundamentals of IT & Computers 25
Fundamentals of IT & Computers 25
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.
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
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
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.
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.
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.
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:
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-
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.
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
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.
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
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
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.
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
Workstation Computer
12
Personal Computer (PC)
Personal Computer
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.
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?
Solution:
Analogue computer is particularly designed to process analogue data. A continuous data that
changes continuously and cannot have discrete values is called Analogue data.
(A) Supercomputer
15
(B) Minicomputer
(C) Workstation
Solution:
3. Which type of computer has two or more processors and supports 4 to 200 users at
one time?
(A) Minicomputer
Solution:
(A) Hybrid
(B) Analogue
(C) Digital
(D) Supercomputer
Solution:
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”).
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.
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
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
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
Example:
111101101
(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.
Examples:
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:
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
Illustration
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.
Recommended Practice
1’s Complement
Try It!
// a binary number
#include <bits/stdc++.h>
// represented by "bin"
int n = bin.length();
int i;
23
// for ones complement flip every bit
ones += flip(bin[i]);
twos = ones;
if (ones[i] == '1')
twos[i] = '0';
else
twos[i] = '1';
break;
if (i == -1)
24
// Driver program
int main()
printOneAndTwosComplement(bin);
return 0;
Output:
class GFG
{
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;
}
}
// Driver code
public static void main(String[] args)
{
String bin = "1100";
printOneAndTwosComplement(bin);
}
}
Output:
26
def flip(c):
return '1' if (c == '0') else '0'
n = len(bin)
ones = ""
twos = ""
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')
# Driver Code
if __name__ == '__main__':
bin = "1100"
printOneAndTwosComplement(bin.strip(""))
Output:
27
Below is the implementation.
class GFG
{
28
// Returns '0' for '1' and '1' for '0'
static char flip(char c)
{
return (c == '0') ? '1' : '0';
}
// Driver code
public static void Main(String[] args)
{
String bin = "1100";
printOneAndTwosComplement(bin);
}
}
29
// This code has been contributed by 29AjayKumar
Output:
30
function printOneAndTwosComplement(bin)
{
var n = bin.length;
var i;
// Driver program
var bin = "1100";
printOneAndTwosComplement(bin);
Output:
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/
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.
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
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:
"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 : 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
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 :
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 :-
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.
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 :
"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”.
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.
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.
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 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.
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.
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 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:
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.
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.
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.
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.
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.
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.
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.
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.
Now let’s design the algorithm with the help of the above pre-requisites:
46
1. START
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.
7. END
Program:
// algorithm
#include <bits/stdc++.h>
int main()
// the 3 numbers
int sum;
47
cout << "Enter the 1st number: ";
<< sum;
return 0;
Output
48
Program:
#include <stdio.h>
int main()
{
return 0;
}
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152
49
Program:
class GFG {
public static void main(String[] args)
{
// 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);
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152
Program:
50
# Python3 program to add three numbers
# with the help of above designed
# algorithm
if __name__ == "__main__":
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -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 ()
{
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152
Program:
52
// Javascript program to add three numbers
// with the help of above designed
// algorithm
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152
53
1. Declare three variables num1, num2, and num3 to store the three numbers to be added.
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.
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
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.
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.
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.
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.
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.
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.
Example: In the algorithm of Linear Search above, the time complexity is calculated as
follows:
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
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.
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.
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.
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.
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:
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:
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 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 2: Declare a variable max with the value of the first element of the array.
Step 4: If max < array element value, change max to new max.
61
Step 1: Start the Program
Step 3: Calculate the sum of all the 3 Subject values and store result in Sum variable (Sum =
S1+S2+S3)
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.
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 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