100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Searching Algorithms Basics

Rating
-
Sold
-
Pages
6
Uploaded on
08-11-2024
Written in
2024/2025

These are well-crafted notes with simple colors to make the important points such as the algorithms stand out. Simple colors are used to not make the document overwhelming and to allow enough white space for future annotation if/when printed. These are a mix of example algorithms with simple and easy-to-understand explanations.

Show more Read less
Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
November 8, 2024
Number of pages
6
Written in
2024/2025
Type
Class notes
Professor(s)
Gokhool
Contains
All classes

Subjects

Content preview

Lecture 3: Algorithms Analysis

Algorithm Complexity
Examples of Operations
Purely computational Operations :
1) Basic operations
• Arithmetic operations
• Comparison operations
• Assignment operations
2) Non-basic operations
• Searching within a database that fits in RAM for a given value
• Running a regular expression pattern match on a string


Code to retrieve the maximum element in an array
int max = arr[0];
for (int i = 1; i < n; i++ ) {
if ( arr[i] >= max ) {
max = arr[i];
}
}
Assuming processor can execute the following operations as one instruction each:
—Assigning a value to a variable
—Looking up the value of a particular element in an array
—Comparing two values
—Incrementing a value
—Basic arithmetic operations such as addition and multiplication


1) No of instructions = 2 →Look-up and Assignment
The algorithm always requires these two instructions, regardless of the value of n.

, 2) The for loop initialization code has to always run
No of instructions = 2 →Assignment and Comparison
These will run before the first for-loop iteration.
3) After each for-loop iteration, we need 2 more instructions to run
No of instructions = 2 →Increment
➔ Comparison


4) Looking at the for body, we have 2 instructions that happen always
→ Lookup and Comparison
If it happens to be so that arr[ i ] >= max, then we'll run these 2 additional
instructions →Lookup and Assignment.


If we ignore the loop body, the number of instructions this algorithm needs is 4 +
2n.
int max = arr[0];
for (int i = 1; i < n; i++ ) {


}
➔ 4 instructions at the start
➔ 2instructions for each of the n iterations
Mathematical function f(n) gives us the number of instructions the algorithm needs
➔ f(n) = 4 + 2n




We can't define an f(n) as easily, because our number of instructions doesn't depend
solely on n but also on our input.
$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
Elitish

Get to know the seller

Seller avatar
Elitish university of mauritius
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
0
Documents
3
Last sold
-
Elitish's Summary notes

Summary notes on all topics related to Computer Science/Software Engineering. Simple, no overwhelming colors and examples. These can help refresh your memory or serve as the base for your learning.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions