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
Tentamen (uitwerkingen)

Dsa Module 5- String Matching Algorithms & Naive Method Analysis

Beoordeling
-
Verkocht
-
Pagina's
17
Cijfer
A+
Geüpload op
25-02-2026
Geschreven in
2025/2026

Dsa Module 5- String Matching Algorithms & Naive Method Analysis

Instelling
Vak

Voorbeeld van de inhoud

lOMoARcPSD|44613495




Dsa Module - 5 notes


Data Structure and Algorithms for Problem solving (Visvesvaraya Technological
University)




Scan to open on Studocu




Studocu is not sponsored or endorsed by any college or university
Downloaded by Samuel Wachira ndiang'ui ()

, lOMoARcPSD|44613495




Module – 5
String - Matching Algorithms




1. The Naive String-Matching Algorithm

The naive algorithm finds all valid shifts using a loop that checks the condition
P (1.. m) = T (s + 1… s + m) for each of the n - m + 1 possible values of s.



NAIVE-STRING-MATCHER (T, P)

1 n = T.length

2 m = P.length

3 for s = 0 to n - m

4 if P [1..m] == T [s + 1 … s + m]

5 print “Pattern occurs with shift” s


Show the comparisons the naive string matcher makes for the pattern P = 0001 in the text
T = 000010001010001.

Text (T): 000010001010001

Pattern (P): 0001 (length m = 4)

Text length: n = 15

Number of shifts: n - m + 1 = 12



We try shifts from s = 0 to 11, comparing substrings T[s:s+4] with P.




Downloaded by Samuel Wachira ndiang'ui ()

, lOMoARcPSD|44613495




Shift s T substring T[s:s+4] Compare with P Match? Comparisons

0 0000 0001 ✗ 4 (mismatch at 4th)

1 0000 0001 ✗ 4

2 0001 0001 ✓ 4

3 0010 0001 ✗ 1

4 0100 0001 ✗ 1

5 1000 0001 ✗ 1

6 0001 0001 ✓ 4

7 0010 0001 ✗ 1

8 0101 0001 ✗ 1

9 1010 0001 ✗ 1

10 0100 0001 ✗ 1

11 1001 0001 ✗ 1

Matches found at shifts: s = 2 and s = 6
Total comparisons: 4+4+4+1+1+1+4+1+1+1+1+1 = 24



Suppose that all characters in the pattern P are different. Show how to accelerate NAIVE-
STRING-MATCHER to run in time O(n).

If all characters in P are distinct:

• When a mismatch is found at position j, we can safely shift P by j positions instead of
just 1.

• Since no prefix of P is a suffix, there's no point in checking intermediate shifts.

This results in skipping comparisons and advances faster, which leads to O(n) time in the best
and average cases.

You can modify the loop:

s=0
while s <= n - m:




Downloaded by Samuel Wachira ndiang'ui ()

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
25 februari 2026
Aantal pagina's
17
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

€21,29
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
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
Writewise Chamberlain College Of Nursing
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
52
Lid sinds
1 jaar
Aantal volgers
5
Documenten
1826
Laatst verkocht
1 dag geleden
Writewise - Stuvia US

Writewise - Stuvia US Certified tutor, offering accurate, reliable, and current study materials to support students in their exam preparation and assignments. Aiming to provide the best resources, such as summaries, nursing exam test. Up-to-date exams and assignments, Detailed test banks with verified questions and answers, Elaborate exam solutions, Case studies and discussions Customized package deals tailored to your needs. I’m committed to providing only high-quality documents to ensure the best outcomes. Get instant access to expertly prepared materials designed to help you excel in your academic journey. Reach out today and take a step closer to achieving your goals! Always be Encouraged to leave a review after sale, all complements and comments, positive &amp; Negative are appreciated to guide for better changes.

Lees meer Lees minder
3,0

4 beoordelingen

5
1
4
0
3
2
2
0
1
1

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