אלגוריתמים, WINDOWS והחיים. מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיוןsort.

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Sorting, Sets, and Selecting - Ed. 2. and 3.: Chapter 10 - Ed. 4.: Chapter 11.
מבוא למדעי המחשב לתעשייה וניהול דוגמאות ותרגול נוסף במערך חד ממדי הרצאה 12.
COPYRIGHT 2003: Dr. David Scanlan, CSUS OBJECTIVES: Explain the need for arrays. Coding an array. Basic algorithms: Largest, Smallest, Sum, Standard Deviation,
Computation for Physics 計算物理概論 Algorithm. An algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing,
מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s =
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
Match-and-Stop Search Will find FIRST match Use Boolean variable to denote whether a match has been found or not Found initially False If a match is found,
סוגי מידע / משתנים ד " ר אבי רוזנפלד. סוגאורךטווח Boolean1 Bit0,1 Byte1 byte0-255 Char 2 bytes תו Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335.
Problem Solving #6: Search & Sort ICS Outline Review of Key Topics Review of Key Topics Problem 1: Recursive Binary Search … Problem 1: Recursive.
מבוא למדעי המחשב © אריק פרידמן 1 מצביעים כמערכים דוגמה.
מבני בקרה מבוא לתכנות למנע " ס - שבוע מספר 3 - מאיר קומר - סמסטר ב ' - תשס " ו הסתעפות “ אם השמאל ואימנה ואם הימין ואשמאילה ”
1 Lecture 23:Applications of Arrays Introduction to Computer Science Spring 2006.
פתרון תרגיל 10. שאלה #1 Module Module1 Sub Main() Dim maarach(9), zoogy(4), ezoogy(5) As Integer Dim i, counter, j As Integer For i = 0 To 9 Console.WriteLine("please.
פתרון תרגיל 11. שאלה #1 Module Module1 Sub Main() Dim x(10, 10) As Integer Dim i, j As Integer For i = 1 To 10 For j = 1 To 10 x(i, j) = i * j Console.Write("
מערכים מבוא לתכנות למנע"ס - שבוע מספר 8 - מאיר קומר - סמסטר ב' - תשס"ו והנה בעיה כתוב תוכנית אשר תקלוט 36 מספרים ותדפיס כמה מתוכם גדולים יותר מהממוצע.
מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
פתרון תרגילים #9. דוגמה פשוטה #1 Module Module1 Sub Main() Dim x As String x = Console.ReadLine For i = 1 To x.Length() - 1 Step 2 Console.WriteLine(x(i))
מערכים דו ממדי ו STRUCTS פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length()
פונקציות. פונקציות מוכרות Imports System.Math Module Module1 Sub Main() Dim x As Decimal = Math.Abs(-10.4) Dim y As Decimal Console.WriteLine("I will.
1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.
1 מבוא למדעי המחשב רקורסיה. 2 רקורסיה היא שיטה לפתרון בעיות המבוססת על העיקרון העומד ביסוד אינדוקציה מתמטית: אם ידועה הדרך לפתור בעיה עבור המקרים הבסיסיים.
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8: Searching and Sorting Arrays.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
Lecture 5 Searching and Sorting Richard Gesick. The focus Searching - examining the contents of the array to see if an element exists within the array.
VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.
Computer Science Searching & Sorting.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 8: Searching and Sorting Arrays.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.
Sorting: Optimising Bubblesort Damian Gordon. Sorting: Bubble Sort If we look at the bubble sort algorithm again:
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
מבוא למדעי המחשב הרצאה 9: תכנות רקורסיבי 2 1. חישוב עצרת: רקורסיית זנב public static int fact (int n){ return factacc(n,1); } public static int factacc.
Bubble Sort.
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Searching When we maintain a collection of data,
מבוא למדעי המחשב לתעשייה וניהול הרצאה 12. ספריות.
Bubble Sort Notes David Beard CIS220. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
1 מבוא למדעי המחשב הרצאה 5: פונקציות. 2 מבוא לפונקציות חלוקה של אלגוריתם לתת משימות: משימה - פונקציה: דוגמאות מציאת המקסימלי מבין שני איברים האינדקס של.
Sorting Algorithms. Sorting Sorting is a process that organizes a collection of data into either ascending or descending order. public interface ISort.
אלגוריתמי חיפוש. Brute Force Module Module1 Function BruteForce(ByRef x() As Integer, ByRef item As Integer) As Integer Dim i As Integer For i = 0 To.
COM148X1 Interactive Programming Lecture 4. Topics Today DateTime Functions Using Module Using Procedure Using Function Pass by Value and Pass by Reference.
Searching and Sorting Searching algorithms with simple arrays
Searching and Sorting Arrays
The Bubble Sort Mr. Dave Clausen La Cañada High School
Pseudo-code 1 Running time of algorithm is O(n)
מבוא למדעי המחשב לתעשייה וניהול
Sorting Algorithms.
Section 2.6: Searching and Sorting
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2017 Lecture 39: searching.
البرمجة بلغة الفيجول بيسك ستوديو
كلية المجتمع الخرج البرمجة - المستوى الثاني
And now for something completely different . . .
searching Concept: Linear search Binary search
Searching and Sorting Arrays
Lesson Objectives Aims Key Words
Searching and Sorting Arrays
Module 8 – Searching & Sorting Algorithms
Sorting Algorithms.
Presentation transcript:

אלגוריתמים, WINDOWS והחיים

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיוןsort

מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מעבר ראשון הסתיים מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מעבר שני הסתיים מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מעבר שלישי הסתיים מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר מעבר רביעי הסתיים מיון מיון בועות

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר המערך ממוין מיון מיון בועות

BubbleSort Module Module1 Sub Swap(ByRef x As Integer, ByRef y As Integer) Dim temp As Integer = x x = y y = temp End Sub Sub BubblesortUp(ByRef x() As Integer) Dim i, pass As Integer For pass = 1 To x.Length() - 1 For i = 0 To x.Length() - 2 If (x(i) > x(i + 1)) Then Swap(x(i), x(i + 1)) End If Next End Sub

Main Sub Print(ByVal x() As Integer) Dim i As Integer For i = 0 To x.Length() - 1 Console.WriteLine("In position {0} I have {1} ", i, x(i)) Next End Sub Sub Main() Dim x() As Integer = {1, 2, 53, 3, 1, 23} BubblesortUp(x) Print(x) End Sub End Module

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 מיון בועות משופר מיון Sub BubblesortUp(ByRef x() As Integer) Dim i, pass As Integer Dim flag As Boolean = True While (flag) flag = False For pass = 1 To x.Length() - 1 For i = 0 To x.Length() - 2 If (x(i) > x(i + 1)) Then Swap(x(i), x(i + 1)) flag = True End If Next End While End Sub

Selection Sort מאת:

הפונקציה Sub SelectionSort(ByRef x() As Integer) Dim i, j As Integer For i = 0 To x.Length() - 1 Dim min As Integer = i For j = i + 1 To x.Length() - 1 If (x(j) < x(min)) Then min = j ' The position of the smallest End If Next Swap(x(i), x(min)) Next End Sub

רקורסיה - Recursion Module Module1 Function Atzeret(ByVal x As Integer) As Integer If (x = 1) Then Return 1 Else Return x * Atzeret (x - 1) End If End Function Sub Main() Dim x As Integer = 6 Console.WriteLine("Atzeret x " & Atzeret (x)) End Sub End Module

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר ? 12 חיפוש חיפוש בינרי

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 חיפוש חיפוש בינארי Sub Main() Dim x() As Integer = {1, 2, 4, -2, 3, 0, 55} BubblesortUp(x) Dim item As Integer = 13 Dim result As Integer = -1 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 ElseIf item > x(Mid) Then low = Mid + 1 Else high = Mid - 1 End If End While End Sub End Module אבל איך יודעים אם מצאתי? יופי, אבל איפה?

מבוא למדעי המחשב - מאיר קומר - סמסטר א '- תשס " ט - שיעור מספר 7 סיכום חיפוש סידרתי - sequential בינארי - binary מיון בועות - bubble בחירה – selection