0% found this document useful (0 votes)
16 views14 pages

Lect 2

The document discusses algorithms, their definition, analysis, and complexity. It defines algorithms and their key properties. It then discusses analyzing algorithms through measuring their space and time complexity, and defines different time complexities including constant, linear, logarithmic, quadratic, and exponential time complexities. It also discusses how to measure an algorithm's time complexity and factors that determine an algorithm's quality.

Uploaded by

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

Lect 2

The document discusses algorithms, their definition, analysis, and complexity. It defines algorithms and their key properties. It then discusses analyzing algorithms through measuring their space and time complexity, and defines different time complexities including constant, linear, logarithmic, quadratic, and exponential time complexities. It also discusses how to measure an algorithm's time complexity and factors that determine an algorithm's quality.

Uploaded by

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

Data Structures and Algorithms

Algorithms
Dr.Associate Professor
/Abdualmajed Al-Khulaidi
Algorithm Definition
An algorithm is a specific set of instructions that
perform a specific function.
It must fulfill the following conditions:
1-(Input)
2-(Output)
3-(Definiteness)
4-(Finiteness )
5-(effectiveness)
(Algorithm Analysis )
Algorithm analysis:
It is the determination of the efficiency of the algorithm and then its
improvement, as there are two measures that are directly related to
the achievement of the algorithm, namely:
1- (Space Complexity) It is the amount of memory required to run the
program until its completion, as this type depends on two parts:
A- Fixed part: or independent from the input and output
characteristics, as this part includes the instruction space, the space
assigned to the variables, whether simple or complex variables of fixed
size in addition to the space of the constants, ... etc.
B- A variable part: It consists of the space required by the program
with the complex variables, the size of which depends on the example
of the problem to be solved.
(Algorithm Analysis )
2-Time Complexity:
Time complexity: The amount of time the code
or algorithm takes to process or accomplish the
task.
Types of time complications

You can express time complexity with (Big O Notation). Big O notation expresses the running time of the
algorithm in terms of how fast it grows in relation to the input (this input is called "n").
Time Constant Complexity: O (1)

When time complexity is constant. Denoted as


O (1), the size of the input n does not matter.
Algorithms of constant time complexity take a
constant amount of time to run, regardless of
the size of n.
Linear Time Complexity: O (n)

When the time complexity grows in direct


proportion to the size of the input, you face
linear time complexity, or O (n) algorithms with
this time complexity will process the input (n) in
the n number of operations. This means that as
the input grows, the algorithm takes longer to
complete.
Logarithmic time complexity: O (log n)

Algorithms of this complexity make the


computation incredibly fast. The algorithm is
said to operate in logarithmic time if the
execution of time is proportional to the
logarithm of the input size. This means that
instead of increasing the time taken to perform
each subsequent step, the time is reduced by an
amount inversely proportional to the n input.
ime-squared complexity: O (n²)

In this type of algorithm, the time taken to run


grows proportional to the square of the input
size (like linear, but square). In most scenarios
and especially for large data sets, algorithms
with quadratic complexity take a long time to
implement and should be avoided.
Exponential Time Complexity: O (2 ^
n)
n exponential time algorithms, the growth rate
doubles with each addition to the input (n), and
often iterates across all subsets of the input
items. Anytime the input unit increases by 1,
this doubles the number of operations
performed.
How to measure time complexity?
In general, we saw that the fewer operations in
an algorithm, the faster it is.
Benchmarks to compare algorithms
-The amount of computer time needed to
implement them.
-The amount of computer memory needed by the
algorithm
-The clarity and simplicity of the algorithm
Factors that determine the quality of
the algori
• Computer speed
• The amount of data
• Programmer
• The language in which the algorithm is written
Data & Information
Data :The term data is simply defined as “facts and
figures”. Each piece of data is a little fact that doesn’t
mean much on its own. The word data can be used for a
singular fact or a collection of facts.
Information :
information is defined simply as “news or knowledge
received or given”. It is what results when you have
processed, interpreted, and organized facts. The word
comes from the Latin word īnfōrmātiō, meaning
“formation or conception.”

You might also like