SlideServe
Menu
Préférences
© SlideServe · v2026

אלגוריתמי חיפוש

tola avatar
13 diapositives · 265 Views · Sep 04, 2014

אלגוריתמי חיפוש. Brute Force. Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To x.Length() - 1 If (x(i) = item) Then Return i End If Next

אלגוריתמי חיפוש - slide 1
01 / 13אלגוריתמי חיפוש
1 / 17

Télécharger la présentation

אלגוריתמי חיפוש
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. אלגוריתמיחיפוש

  2. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To x.Length() - 1 If (x(i) = item) Then Return i End If Next Return -1 'Not found! End Function Sub Main() Dim numbers() As Integer = {1, 2, 3, 4, 10, 10, 71, 101} Dim key As Integer key = Console.ReadLine() Console.WriteLine(BruteForce(numbers, key)) End Sub End Module

  3. BubbleSearch Function BubbleSearch(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To x.Length() - 1 If (x(i) = item) Then If i > 0 Then Swap(x(i), x(i - 1)) End If Return i End If Next Return -1 'Not found! End Function Sub Main() Dim numbers() As Integer = {1, 2, 3, 4, 10, 10, 71, 101} Dim key As Integer key = Console.ReadLine() Console.WriteLine(BubbleSearch(numbers, key)) Console.WriteLine(BubbleSearch(numbers, key)) End Sub

  4. ? 12 חיפוש חיפושבינרי 2 5 8 11 23 24 28 34 38 41 44 45 52 60 70 מבוא למדעי המחשב - מאיר קומר - סמסטר א'- תשס"ט - שיעור מספר 7

  5. חיפושבינארי אבל איך יודעים אם מצאתי? יופי, אבל איפה? חיפוש Function BinarySearch(ByRef x() As Integer, ByRef item As Integer) As Integer Dim Mid As Integer Dim low As Integer = 0 Dim high As Integer = x.Length() - 1 While (low <= high) Console.WriteLine("high is " & high) Console.WriteLine("low is " & low) Mid = (low + high) \ 2 If (item = x(Mid)) Then Console.WriteLine("I found it!!") Return Mid 'Found here! ElseIf item > x(Mid) Then low = Mid + 1 Else high = Mid - 1 End If End While Return -1 'Not found! End Function מבוא למדעי המחשב - מאיר קומר - סמסטר א'- תשס"ט - שיעור מספר 7

  6. Main דוגמא של Sub Main() Dim numbers() As Integer = {1, 2, 3, 4, 10, 10, 71, 101} Dim key As Integer key = Console.ReadLine() Console.WriteLine(BinarySearch(numbers, key)) End Sub

  7. חיפושבינארי ריכורסיבית Sub RBinarySearch(ByRef x() As Integer, ByRef item As Integer, ByVal low As Integer, ByVal high As Integer) Dim Mid As Integer If (low > high) Then Console.WriteLine("Item not found") Else Mid = (low + high) / 2 If item > x(Mid) Then RBinarySearch(x, item, Mid + 1, high) ElseIf item < x(Mid) Then RBinarySearch(x, item, low, Mid - 1) Else Console.WriteLine("I found it in position " & Mid) End If End If End Sub

  8. Main דוגמא של Sub Main() Dim numbers() As Integer = {1, 2, 3, 4, 10, 10, 71, 101} Dim key As Integer key = Console.ReadLine() RBinarySearch(numbers, key, 0, numbers.Length() - 1) End Sub

  9. Boyer and Moore Algorithm

  10. Right to Left (like in Hebrew) • Matching the pattern from right to left • For a pattern abc: ↓ T:bbacdcbaabcddcdaddaaabcbcb P:abc • Worst case is still O(n m)

  11. Boyer-Moore Example T: P:

  12. חיפוש פשוט לטקסטים Module Module1 Sub Main() Dim t As String = "my name is avi, not aviya, or aviva, avihu, aviv or david!" Console.WriteLine(t.IndexOf("avi")) Console.WriteLine(t.LastIndexOf("avi")) End Sub End Module

  13. Text Matching in VB Imports System.Text.RegularExpressions Module Module1 Sub Main() Dim myMatches As MatchCollection Dim t As String = "my name is avi, not aviya, or aviva, avihu, aviv or david!" Dim myRegex As New Regex("avi") myMatches = myRegex.Matches(t) Dim successfulMatch As Match For Each successfulMatch In myMatches Console.WriteLine(successfulMatch.Index) Next End Sub End Module