Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

Searching Algorithms Basics

Beoordeling
-
Verkocht
-
Pagina's
6
Geüpload op
08-11-2024
Geschreven 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.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

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.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
8 november 2024
Aantal pagina's
6
Geschreven in
2024/2025
Type
College aantekeningen
Docent(en)
Gokhool
Bevat
Alle colleges

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
Elitish

Maak kennis met de verkoper

Seller avatar
Elitish university of mauritius
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
0
Documenten
3
Laatst verkocht
-
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 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen