Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
YouTube Security VideosAndroid Police: Samsung is smashing records! #shorts #tech #phones(21.09.2026 um 13:55 Uhr)
YouTube Security Videosheise & c't: Bundesnetzagentur wollte diesen Futterautomaten verbieten(21.09.2026 um 13:53 Uhr)
YouTube Security VideosNeil Patel: Your Google Traffic Isn't An Asset It's A Loan #shorts(21.09.2026 um 14:05 Uhr)
Windows Tipps & SecurityF-14 A Tomcat Top Gun endlich als Revell Klemmbausteinmodell erhältlich(21.09.2026 um 14:27 Uhr)
Sichere ProgrammierungShow the Hand-Back Sample Before Approving an Agent Score(21.09.2026 um 14:15 Uhr)
Sichere ProgrammierungHybrid retrieval in one Postgres query: RRF over tsvector + pgvector(21.09.2026 um 14:15 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

TOP 25 ALGORITMOS | Knuth-Morris-Pratt (KMP) Array

Este algoritmo é um algoritmo de busca de strings que é usado para encontrar um padrão dentro de textos grandes de forma eficiente. Ao contrário do algoritmo de busca de padrões ingênuos que começa do início do padrão após cada incompati…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Este algoritmo é um algoritmo de busca de strings que é usado para encontrar um padrão dentro de textos grandes de forma eficiente. Ao contrário do algoritmo de busca de padrões ingênuos que começa do início do padrão após cada incompatibilidade, o KMP usa a estrutura do padrão para evitar comparações redundantes. Ele pré-processa a string do padrão e cria uma matriz chamada matriz Longest Prefix Suffix (lps) que indica quanto do padrão pode ser reutilizado após uma incompatibilidade.



📁 | Resumo









🤖 | Código




function constructLps(pat, lps) {

// len armazena o comprimento do prefixo mais longo que também é um sufixo para o índice anterior
let len = 0;


// lps[0] é sempre 0
lps[0] = 0;


let i = 1;
while (i < pat.length) {

// Se os caracteres corresponderem, incremente o tamanho de lps
if (pat[i] === pat[len]) {
len++;
lps[i] = len;
i++;
}

// Se houver uma incompatibilidade
else {
if (len !== 0) {

// Atualiza len para o valor lps anterior para evitar comparações redundantes
len = lps[len - 1];
} else {

// Se nenhum prefixo correspondente for encontrado, defina lps[i] como 0
lps[i] = 0;
i++;
}
}
}
}


function search(pat, txt) {
const n = txt.length;
const m = pat.length;


const lps = new Array(m);
const res = [];


constructLps(pat, lps);


// Ponteiros i e j, para percorrer o texto e o padrão
let i = 0;
let j = 0;


while (i < n) {

// Se os caracteres corresponderem, mova ambos os ponteiros para frente
if (txt[i] === pat[j]) {
i++;
j++;


// Se o padrão inteiro for correspondido armazena o índice inicial no resultado
if (j === m) {
res.push(i - j);

// Utiliza o LPS do índice anterior para pula comparações desnecessárias
j = lps[j - 1];
}
}

// Se houver uma incompatibilidade
else {

// Use o valor lps do índice anterior para evitar comparações redundantes
if (j !== 0)
j = lps[j - 1];
else
i++;
}
}
return res;
}






🕰️ | Complexidade de Tempo

Como N é o comprimento do texto e M é o comprimento do padrão. Isso ocorre porque criar o array LPS (Longest Prefix Suffix) leva tempo O(M), e a busca pelo texto leva tempo O(N). Logo, a complexidade de tempo será O(N + M).



📦 | Complexidade de Espaço

Como há necessidade de espaço temporário auxiliar, a complexidade de espaço será O(M).



✔️ | Vantagens

✦ Eficiente;



❌ | Desvantagens

✦ Nada intuitivo e nada fácil de implementar;

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten TOP 25 ALGORITMOS | Knuth-Morris-Pratt (KMP) Array

Thematisch verwandte Begriffe: ALGORITMOS, KnuthMorrisPratt, Array · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94097 | A vulnerability was determined in Netcore NBR200V2 1.3.241127.071246. Th…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick