Algorithms. Intro2CS week 5
|
|
- Bernard McKenzie
- 5 years ago
- Views:
Transcription
1 Algorithms Intro2CS week 5 1
2 Computational problems A computational problem specifies an inputoutput relationship What does the input look like? What should the output be for each input? Example: Input: an integer number N Output: Is the number prime? Example: Input: A list of names of people Output: The same list sorted alphabetically
3 Algorithms An algorithm is an exact specification of how to solve a computational problem An algorithm must specify every step completely, so a computer can implement it without any further understanding An algorithm must work for all possible inputs of the problem. Algorithms must be: Correct: For each input produce an appropriate output Efficient: run as quickly as possible, and use as little memory as possible more about this later There can be many different algorithms for each computational problem.
4 Describing Algorithms Algorithms can be implemented in any programming language Usually we use pseudo-code to describe algorithms Testing whether input N is prime: For j = 2.. N-1 Math notation: j divides N If j N Output N is composite and halt Output N is prime In this course we will describe algorithms in Python
5 Greatest Common Divisor מחלק משותף מקסימאלי Definition: The GCD of two natural numbers x, y is the largest integer j that divides both (without remainder). I.e. j x, j y and j is the largest integer with this property. The GCD Problem: Input: natural numbers x, y Output: GCD(x,y) their GCD
6 Simple GCD algorithm 6
7 Proof of Correctness משפט: לכל שני מספרים טבעיים,x y אלגוריתם זה מחזיר את.gcd(x,y) הוכחה: שום מספר גדול מ (x,y) min לא יכול לחלק את שניהם ולכן ה- gcd חייב להיות מספר שלם בין 1 ל-( x,y ) min )כולל(, וזהו התחום שהלולאה עוברת עליו. הפונקציה מחזירה את המחלק המשותף )כלומר ה- i כך ש i x וגם ) i y האחרון שמצאה, ומכיוון שהיא עוברת על הערכים מקטן לגדול, זהו גם המחלק המשותף הגדול ביותר. 7
8 Need for speed Conclusion: On my PC, the loop in the gcd function runs about 10 Million times per second. Conclusion: gcd( , ) will require about seconds > 300 years 8
9 Euclid s Algorithm Considered first algorithm Invented. Idea: Assume x >> y: gcd(x,y) = gcd(x-y, y) = = gcd(x-2y, y) = = = gcd(x%y, y) 9
10 Euclid s algorithm in python Example run: gcd(250, 72) x y
11 Proof of Correctness משפט: לכל שני מספרים טבעיים,x y אלגוריתם זה מחזיר את.gcd(x,y) הוכחה: נראה )בשקף הבא( שלאורך כל התוכנית, הערכים של,x y שומרים על אותו gcd כמו של ה,x y המקוריים. נראה )אחר כך( שהפונקציה תמיד מסיימת את הלולאה זה קורה כאשר 0=y וברור ש gcd(x,0) הינו באמת x )שכן x x וגם 0 x וברור ששום מספר גדול יותר לא מחלק את x( וזה מה שאנו מחזירים. מכיון שה- gcd לא השתנה זה גם ה- gcd של ה-,x y המקוריים. 11
12 Proof of Loop invariant סימון: x i, y i יסמנו את הערכים של המשתנים,x y לאחר i פעמים שהלולאה רצה. בפרט x 0, y 0 הינם הערכים המקוריים של,x y gcd(x i, y i )=gcd(x 0, y 0 ) לכל למה: 0 i מתקיים ש: הוכחה: באינדוקציה על i. עבור 0=i זה טריוויאלית נכון. נניח לגבי i נוכיח לגבי 1+i:, y i לפי קוד התוכנית 1+i = x הבאה מתקיים ש: ו- i+1.)x i % y i (= y ולכן לפי הלמה המתמטית gcd(x i+1, y i+1 ) = gcd(y i, x i %y i ) = gcd(x i %y i, y i ) = gcd(x i, y i ) = gcd(x 0, y 0 ) gcd(a,b) = gcd(a%b, b) למה מתמטית: לכל שני שלמים a,b מתקיים ש 12
13 Proof of Mathematical Lemma למה מתמטית: a,b מתקיים (b gcd(a,b)=gcd(a%b, לכל ולכן הוכחה: מספיק להראות ש ) i b וגם i (a%b) ( אםם ) i b וגם i a ( מכיון ש i b קיים שלם m כך ש.b=mi תהי n המנה השלמה בחלוקת a לb אזי.a%b = a-nb = a-nmi ) ( i a משמעותו שקיים k כך ש ki=a ולכן: i (a%b) ולכן a%b = a-nmi = ki-nmi = (k-nm)i a%b=a-nmi=li כך ש l משמעותו שקיים i (a%b) ) ( i a ולכן a = li+nmi = (l+nm)i 13
14 Proof of Termination משפט: לכל שני מספרים אי-שליליים,x y הפונקציה מסיימת את הריצה. הוכחה: לפי קוד התוכנית, כל עוד לא סיימנו אנו מעדכנים i+1 )x i % y i (= y ולכן. y i+1 >y i כלומר הערך של המשתנה השלם y קטן ממש כל סבב של הלולאה ולכן מספר הסבבים הוא לכל היותר הערך המקורי של y. 14
15 How fast does it run? 15
16 Square Roots The problem we want to address is to compute the square root of a real number. When working with real numbers, we can not have complete precision. The inputs will be given in finite precision The outputs should only be computed approximately The square root problem: Input: a positive real number x, and a precision requirement Output: a real number r such that r- x
17 Binary Search Algorithm idea The square root of x is somewhere between L=0 and H=max(1,x). If we take a middle point M=(L+H)/2 we can tell whether it is too high or too low by testing whether M 2 > x or M 2 < x, after that we can continue searching in the correct half. 17
18 Square Root via Binary Search in Python round l h m
19 Proof of correctness משפט: לכל קלט אי-שלילי x ערך r כך ש:. r- x וערך >0 התוכנית מחזירה למה: לאורך כל ריצת התוכנית מתקיימת האינווריאנטה ש:.l x h )הוכחה בשקף הבא( l הוכחת המשפט: לפי הקוד, הערך של h-l קטן פי 2 כל סבב של הלולאה, והלולאה מסתיימת כאשר ערך זה קטן מ- ולכן הלולאה עוצרת אחרי מספר סופי של צעדים )כי תמיד יש k כך ש.)(h-l)/2 k < אז מתקיים ש: xוכמו - l h-l כן 0 l, x - ולכן החזרת הערך כמו שעושה הקוד מקיימת את הנדרש. 19
20 Proof of Invariant למה: לאורך כל ריצת התוכנית מתקיימת האינווריאנטה ש:.l x h הוכחה: רצה. באינדוקציה על מספר הפעמים i שהלולאה בסיס האינדוקציה: h=max(1,x) l=0 x )כי עבור <1(. x מתקיים x<1 עבור ואילו x x 1 xמתקיים צעד האינדוקציה: אנו משנים את הערך של h להיות m רק אם באמת m 2 x< ולכן (הערך החדש של ; x > h) אנו משנים את הערך של l להיות m רק אם m 2 x ולכן (הערך החדש של. x l) 20
21 In General This type of binary search can be used to find the roots of any continuous function f. Mean Value Theorem: if f(low)<0 and f(high)>0 then for some low<x<high, f(x)=0. In our case, to find 2, 2 we solved f ( x) x 2 0
22 Run time Analysis 22
23 How fast will your program run? The running time of your program will depend upon: The algorithm The input Your implementation of the algorithm in a programming language The compiler/interpreter you use The OS on your computer Your computer hardware Maybe other things: temperature outside; other programs on your computer; Our Motivation: analyze the running time of an algorithm as a function of only simple parameters of the input.
24 Some timings on my old office PC 24
25 Comparing with old timings in Java System Empty loop Float division PII, 333MHz, Interpreted (1998) PIII, 500MHz, compiled (2000) River, compiled (2011) ~2010 PC, Python, interpreted (2015)
26 Basic idea: counting operations Each algorithm performs a sequence of basic operations: Arithmetic: (low + high)/2 Comparison: if x > 0: Assignment: temp = x Branching: while y>0: Idea: count the number of basic operations performed on the input. Difficulties: Which operations are basic? Not all operations take the same amount of time. Operations take different times with different hardware or compilers
27 Difficulties do not matter so much Operation counts are only problematic in terms of constant factors. The general form of the function describing the running time is invariant over hardware, languages or compilers! for i in range(n): for j in range(n): x = x + i*j Running time is about n 2. We use Big-O notation, and say that the running time is O(n 2 )
28 Asymptotic behavior of functions
29 Mathematical Formalization Definition: Let f and g be functions from the natural numbers to the natural numbers. We write f=o(g) if there exists a constant c such that for all n: f(n) cg(n). f=o(g) c n: f(n) cg(n) This is a mathematically formal way of ignoring constant factors, and looking only at the shape of the function. f=o(g) should be considered as saying that f is at most g, up to constant factors. We usually will have f be the running time of an algorithm and g a nicely written function. E.g. The running time of the previous algorithm was O(n 2 ).
30 Asymptotic analysis of algorithms We usually embark on an asymptotic worst case analysis of the running time of the algorithm. Asymptotic: Formal, exact, depends only on the algorithm Ignores constants Applicable mostly for large input sizes Worst Case: Bounds on running time must hold for all inputs. Thus the analysis considers the worst-case input. Sometimes the average performance can be much better Real-life inputs are rarely average in any formal sense
31 Let s time some functions 31
32 ??-- time 32
33 Linear O(n) -- time 33
34 ??- time 34
35 Quadratic O(n 2 ) - time 35
36 ?? - time 36
37 Logarithmic - O(log n) - time 37
38 Exponential O(2 n ) running time 38
39 Running time of simple GCD algorithm Theorem: The simple GCD algorithm runs in time O(min(x,y)) 39
40 Running time of Euclid s GCD Algorithm How fast does Euclid s algorithm terminate? From the first iteration onward we have that x > y. In an iteration where x 2y then x%y < y x/2. In an iteration where x < 2y then x%y = x-y < x/2. Thus, the value of xy decreases by a factor of at least 2 each iteration (except, maybe, the first one).
41 Run time analysis of Euclid s Algorithm Theorem: Euclid s GCD algorithm runs in time O(log2x + log2y) Proof: As we have seen, in every iteration of the loop (except maybe the first) the value of xy decreases by a factor of at least 2. Thus after k+1 iterations the value of xy is at most 2 -k times the original value. Since the algorithm terminates when xy=0 and since it is an integer, the algorithm must terminate at the latest when k satisfies: 2 -k xy < 1 (for the original values of x, y). Thus the algorithm runs for at most 1+log 2 (xy) iterations. Each iteration has only a constant number of operations, thus the total running time is O(log 2 (xy)) = O(log x + log y).
42 Run time comparison Simple GCD Euclid GCD asymptotic O(min(x,y)) O(log(x)+log(y)) 2 digit numbers 100 Fraction of a second 9 digit numbers a minute 18 digit numbers Hundreds of years log 2 (100) 7 Fraction of a second log 2 (10 9 ) 30 Fraction of a second log 2 (10 18 ) 60 Fraction of a second Actual run times assume that python does around 10,000,000 simple loops per second 42
43 Binary search Square root algorithm h-l goes down by a factor of 2 each iteration. Starts at max(1, x), finishes when reaching Run time is O(log 2 (x/ )) = O(log x + log (1/ ))
44 Algorithms on Arrays 44
45 Array access operations O(1) 45
46 Random Access Memory a a[3] To access a[i], take start location of a, and add i to it to get the address in RAM 46
47 Array Append O(1) Implementation Logic: If (out of space) Then (copy to a new place that has twice the space) 47
48 Array Search O(n) 48
49 Dictionary Access and Search O(1) 49
50 Hash Tables key value hagar 123 david 456 noah 789 hash( hagar ) = 7 hash( david ) = 2 hash( noah ) =
51 Input: An array The sorting problem Output: The same array, with the elements reordered from smallest to largest. [53, 12, 77, 23, 50] [12, 23, 50, 53, 77] [ yossi, david, anat, gila ] [ anat, david, gila, yossi ] 51
52 Comparison in Python 52
53 Selection Sort 53
54 Selection Sort i
55 Proof of Correctness: Argmin Theorem: argmin returns the index of the smallest element in a[start:] Invariant: When the iteration with value i ends, index holds the location of the smallest element in a[start:i+1] 55
56 Proof of Correctness: sort Theorem: When sort terminates, the array a holds the original elements, but in sorted order. Invariants: a always holds the same multi-set of elements After the i th iteration, a[:i+1] holds the smallest i+1 elements of a in sorted order 56
57 Selection Sort O(n 2 ) Runtime O(n) O(n) times argmin 57
58 Binary Search Sample Run [10,20,30,40,50] Find(20) l h m
59 Binary Search Sample Run [10,20,30,40,50] Find(25) l h m
60 Binary Search O(log n) Runtime Invariant: a[l-1] < x < a[h] (where we consider a[-1]=-, a[len(a)]= 60
Programming for Engineers in Python
Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the
More informationProgramming for Engineers in Python
Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the
More information1 Elementary number theory
Math 215 - Introduction to Advanced Mathematics Spring 2019 1 Elementary number theory We assume the existence of the natural numbers and the integers N = {1, 2, 3,...} Z = {..., 3, 2, 1, 0, 1, 2, 3,...},
More informationChapter 4. Number Theory. 4.1 Factors and multiples
Chapter 4 Number Theory We ve now covered most of the basic techniques for writing proofs. So we re going to start applying them to specific topics in mathematics, starting with number theory. Number theory
More informationAlgorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48
Algorithm Analysis (Algorithm Analysis ) Data Structures and Programming Spring 2018 1 / 48 What is an Algorithm? An algorithm is a clearly specified set of instructions to be followed to solve a problem
More informationPractical Session 2 Constants Don t Matter!!!
Practical Sessio 2 Costats Do t Matter!!! Algorithm Aalysis f() = O(g()) Big O f() = Ω(g()) Big Omega There exist c > 0 ad 0 > 0 such that: 0 f() cg() for each 0 There exist c > 0 ad 0 > 0 such that: 0
More informationEuclid's Algorithm. MA/CSSE 473 Day 06. Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm
MA/CSSE 473 Day 06 Euclid's Algorithm MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm 1 Quick look at review topics in textbook REVIEW
More informationCS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims Lecture 10: Asymptotic Complexity and What Makes a Good Algorithm? Suppose you have two possible algorithms or
More informationתרגילים ופתרונות בשפת - C הסתעפויות
תרגילים ופתרונות בשפת - C הסתעפויות כתב וערך: שייקה בילו תרגיל - 1 כתוב תוכנית שתקבל מהמשתמש שלושה מספרים, ותציג את הגדול מביניהם על המסך. #include void main() int mis1, mis2, mis3, max; printf("please
More informationקורס תכנות שיעור שני: שימוש במשתנים,
קורס תכנות שיעור שני: שימוש במשתנים, בקרת זרימה, לולאות 1 נושאי השיעור היום משתנים )variables( טיפוסי משתנים בשפת C הגדרת משתנים השמה למשתנים פעולות על משתנים קליטת ערכים מהמשתמש הדפסה משתנים בקרת זרימה
More informationסכום (סדרת ערכים) אחרת - דוגמא: סכום-ספרות (num) אם < 10 num החזר 1 או אם = 0 = num החזר 0 public static int numofdigits (int num)
1 תבנית צבירה תבניות אלגוריתמיות לפעולות רקורסיביות תבנית צבירה לסדרת ערכים: סכום (סדרת ערכים) החזר את ערך הקצה + סכום (סדרת הערכים ללא ערך הקצה) דוגמא: פעולה המחזירה את סכום הספרות שבמספר שלם לא שלילי
More informationמבוא לתכנות ב- JAVA מעבדה 2
מבוא לתכנות ב- JAVA מעבדה 2 מה בתרגול טיפוסים פרימיטיביים המרות טיפוסים אופרטורים יחסיים ולוגיים משפט if-else בתרגול הקודם טיפוסים פרימיטביים לייצוג מספרים שלמים וממשיים ואופרטורים לפעולות בין מספרים.1
More informationמצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }
שאלה : (4 נקודות) א. ב. ג. (5 נקודות) הגדירו את המונח race-condition במדוייק לא להשמיט פרטים. ספקו דוגמא. (5 נקודות) מהו? Monitor נא לספק הגדרה מלאה. ( נקודות) ( נקודות) ציינו כמה תהליכים יווצרו בקוד הבא
More informationמבוא לתכנות בשפת C. Tzachi (Isaac) Rosen
מבוא לתכנות בשפת C מצביעים והקצאה דינאמית כתובות של משתנים לכל משתנה כתובת של המקום שלו בזיכרון כבר ראינו: שם של מערך הוא למעשה הכתובת של התא הראשון )באינדקס 0( של המערך להזכירכם: תא של מערך הינו משתנה
More informationLecture 10: Recursion vs Iteration
cs2010: algorithms and data structures Lecture 10: Recursion vs Iteration Vasileios Koutavas School of Computer Science and Statistics Trinity College Dublin how methods execute Call stack: is a stack
More informationCSE 373 APRIL 3 RD ALGORITHM ANALYSIS
CSE 373 APRIL 3 RD ALGORITHM ANALYSIS ASSORTED MINUTIAE HW1P1 due tonight at midnight HW1P2 due Friday at midnight HW2 out tonight Second Java review session: Friday 10:30 ARC 147 TODAY S SCHEDULE Algorithm
More informationAmortized Analysis, Union-Find,
Practical Session No. 13 Amortized Analysis, Union-Find, AMORTIZED ANALYSIS Refers to finding the average running time per operation, over a worst-case sequence of operations. Amortized analysis differs
More informationCS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK
CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Page 1 UNIT I INTRODUCTION 2 marks 1. Why is the need of studying algorithms? From a practical standpoint, a standard set of algorithms from different
More informationCSC236 Week 5. Larry Zhang
CSC236 Week 5 Larry Zhang 1 Logistics Test 1 after lecture Location : IB110 (Last names A-S), IB 150 (Last names T-Z) Length of test: 50 minutes If you do really well... 2 Recap We learned two types of
More informationפתרון מוצע לבחינת מה"ט ב_שפת c מועד אביב תשע"ח, פברואר 8102 מחבר: מר שייקה בילו, מכללת אורט רחובות
פתרון מוצע לבחינת מה"ט ב_שפת c מועד אביב תשע"ח, פברואר 8102 מחבר: מר שייקה בילו, מכללת אורט רחובות שאלה מספר 1 התוכנית מגדירה חמישה משתנים שלמים: השלושה הראשונים הם שלושה מצביעים - *s *t,i. j ושלושה נוספים
More informationANALYSIS OF ALGORITHMS
ANALYSIS OF ALGORITHMS Running Time Pseudo-Code Asymptotic Notation Asymptotic Analysis Mathematical facts T(n) n = 4 Input Algorithm Output 1 Average Case vs. Worst Case Running Time of an Algorithm An
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationElementary maths for GMT. Algorithm analysis Part I
Elementary maths for GMT Algorithm analysis Part I Algorithms An algorithm is a step-by-step procedure for solving a problem in a finite amount of time Most algorithms transform input objects into output
More informationModule 2: Classical Algorithm Design Techniques
Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module
More informationCOE428 Lecture Notes Week 1 (Week of January 9, 2017)
COE428 Lecture Notes: Week 1 1 of 10 COE428 Lecture Notes Week 1 (Week of January 9, 2017) Table of Contents COE428 Lecture Notes Week 1 (Week of January 9, 2017)...1 Announcements...1 Topics...1 Informal
More informationתרגול 4 פונקציות. מבנה של פונקציה: public static <return value type> <function name> (<arg1 type> <arg1>, <arg2 type> <arg2>, ) { <function body> }
נושאי התרגול: מה הן פונקציות הגדרת פונקציה,קריאה לפונקציה העברת ארגומנטים,החזרת ערך או void העברת משתנים פרימיטיביים ומערכים לפונקציה העמסה של פונקציות תרגול 4 פונקציות מוטיבציה לעיתים,אנו נזקקים לבצע
More informationהנכות 1 םוכיס לוגרת 14 1
תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers
More informationPractical Session - Heap
Practical Session - Heap Heap Heap Maximum-Heap Minimum-Heap Heap-Array A binary heap can be considered as a complete binary tree, (the last level is full from the left to a certain point). For each node
More informationLecture 7 Number Theory Euiseong Seo
Lecture 7 Number Theory Euiseong Seo (euiseong@skku.edu) 1 Number Theory God created the integers. All else is the work of man Leopold Kronecker Study of the property of the integers Specifically, integer
More informationPractical Session No. 14 Topological sort,amortized Analysis
Practical Session No. 14 Topological sort,amortized Analysis Topological- Sort Topological sort Ordering of vertices in a directed acyclic graph (DAG) G=(V,E) such that if there is a path from v to u in
More informationData Structures and Algorithms
Asymptotic Analysis Data Structures and Algorithms Algorithm: Outline, the essence of a computational procedure, step-by-step instructions Program: an implementation of an algorithm in some programming
More informationModule 1: Asymptotic Time Complexity and Intro to Abstract Data Types
Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationתוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב
תוכנה 1 בשפת Java נושאים שונים בהורשה רובי בוים ומתי שמרת בית הספר למדעי המחשב אוניברסיטת תל אביב Today Static vs. Dynamic binding Equals / hashcode String Immutability (maybe) 2 Static versus run-time
More informationMath Introduction to Advanced Mathematics
Math 215 - Introduction to Advanced Mathematics Number Theory Fall 2017 The following introductory guide to number theory is borrowed from Drew Shulman and is used in a couple of other Math 215 classes.
More informationcsci 210: Data Structures Program Analysis
csci 210: Data Structures Program Analysis Summary Summary analysis of algorithms asymptotic analysis and notation big-o big-omega big-theta commonly used functions discrete math refresher Analysis of
More informationמשתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1
משתנים שעור מס. 2 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 תפקיד המשתנים הצהרה על משתנה השמת ערך במשתנה int a, b, c; a = 1234; b = 99; c = a + b; משתנים מאפשרים לנו לשמור
More informationLECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes.
LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes. Input Algorithm Output An algorithm is a step-by-step procedure for
More informationGraph Database, think different!
Graph Database, think different! Written by Roni Licher Winter 2014-2015 236363 - Database Systems - Technion Nodes Edges (directed or not) Properties Neo4j and Cypher 4j Graph database (Like SQL server
More informationCommunication Networks ( ) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University. Allon Wagner
Communication Networks (0368-3030) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University Allon Wagner Kurose & Ross, Chapter 3.5.5, 3.7 (5 th ed.) Many slides adapted from: J. Kurose
More informationOutline and Reading. Analysis of Algorithms 1
Outline and Reading Algorithms Running time ( 3.1) Pseudo-code ( 3.2) Counting primitive operations ( 3.4) Asymptotic notation ( 3.4.1) Asymptotic analysis ( 3.4.2) Case study ( 3.4.3) Analysis of Algorithms
More informationOrganisation. Assessment
Week 1 s s Getting Started 1 3 4 5 - - Lecturer Dr Lectures Tuesday 1-13 Fulton House Lecture room Tuesday 15-16 Fulton House Lecture room Thursday 11-1 Fulton House Lecture room Friday 10-11 Glyndwr C
More informationPlotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1
CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done
More informationRUNNING TIME ANALYSIS. Problem Solving with Computers-II
RUNNING TIME ANALYSIS Problem Solving with Computers-II Performance questions 4 How efficient is a particular algorithm? CPU time usage (Running time complexity) Memory usage Disk usage Network usage Why
More informationמערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1
מערכים שעור מס. 4 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 למה מערכים? ברצוננו לאחסן בתוכנית ציוני בחינה כדי לחשב את ממוצע הציונים וסטיית התקן. נניח ש 30 סטודנטים לקחו
More informationCSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session
CSE 146 Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session Comparing Algorithms Rough Estimate Ignores Details Or really: independent of details What are some details
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationAgenda. The worst algorithm in the history of humanity. Asymptotic notations: Big-O, Big-Omega, Theta. An iterative solution
Agenda The worst algorithm in the history of humanity 1 Asymptotic notations: Big-O, Big-Omega, Theta An iterative solution A better iterative solution The repeated squaring trick Fibonacci sequence 2
More informationCOMPSCI 230 Discrete Math Prime Numbers January 24, / 15
COMPSCI 230 Discrete Math January 24, 2017 COMPSCI 230 Discrete Math Prime Numbers January 24, 2017 1 / 15 Outline 1 Prime Numbers The Sieve of Eratosthenes Python Implementations GCD and Co-Primes COMPSCI
More informationCS:3330 (22c:31) Algorithms
What s an Algorithm? CS:3330 (22c:31) Algorithms Introduction Computer Science is about problem solving using computers. Software is a solution to some problems. Algorithm is a design inside a software.
More informationClosed Book Examination. One and a half hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Wednesday 20 th January 2010
Closed Book Examination COMP20010 One and a half hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE Algorithms and Imperative Programming Date: Wednesday 20 th January 2010 Time: 14.00 15.30 Please
More informationData Structures Lecture 8
Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 8 Recap What should you have learned? Basic java programming skills Object-oriented
More informationAlgorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.
Algorithms Analysis Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc. Algorithms analysis tends to focus on time: Techniques for measuring
More informationUNIT 1 ANALYSIS OF ALGORITHMS
UNIT 1 ANALYSIS OF ALGORITHMS Analysis of Algorithms Structure Page Nos. 1.0 Introduction 7 1.1 Objectives 7 1.2 Mathematical Background 8 1.3 Process of Analysis 12 1.4 Calculation of Storage Complexity
More informationMultiple-choice (35 pt.)
CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need
More informationשאלה 1 מהו הפלט של התוכנית הבאה:
תרגול חזרה שאלה 1 מהו הפלט של התוכנית הבאה: public sttic int wht(int n) { int i; int sum=0; if(n == 0) return 1; for (i=0; i
More information(Refer Slide Time: 1:27)
Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data
More informationRecursion Chapter 8. What is recursion? How can a function call itself? How can a function call itself?
Recursion Chapter 8 CS 3358 Summer I 2012 Jill Seaman What is recursion? Generally, when something contains a reference to itself Math: defining a function in terms of itself Computer science: when a function
More informationCSCE 411 Design and Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms Set 4: Transform and Conquer Slides by Prof. Jennifer Welch Spring 2014 CSCE 411, Spring 2014: Set 4 1 General Idea of Transform & Conquer 1. Transform the original
More informationSolutions to the Second Midterm Exam
CS/Math 240: Intro to Discrete Math 3/27/2011 Instructor: Dieter van Melkebeek Solutions to the Second Midterm Exam Problem 1 This question deals with the following implementation of binary search. Function
More informationLecture Notes, CSE 232, Fall 2014 Semester
Lecture Notes, CSE 232, Fall 2014 Semester Dr. Brett Olsen Week 11 - Number Theory Number theory is the study of the integers. The most basic concept in number theory is divisibility. We say that b divides
More informationOutline. runtime of programs algorithm efficiency Big-O notation List interface Array lists
Outline runtime of programs algorithm efficiency Big-O notation List interface Array lists Runtime of Programs compare the following two program fragments: int result = 1; int result = 1; for (int i=2;
More informationLecture 3 Algorithms with numbers (cont.)
Advanced Algorithms Floriano Zini Free University of Bozen-Bolzano Faculty of Computer Science Academic Year 2013-2014 Lecture 3 Algorithms with numbers (cont.) 1 Modular arithmetic For cryptography it
More information3. Logical Values. Boolean Functions; the Type bool; logical and relational operators; shortcut evaluation
140 3. Logical Values Boolean Functions; the Type bool; logical and relational operators; shortcut evaluation Our Goal 141 int a; std::cin >> a; if (a % 2 == 0) std::cout
More information6. Asymptotics: The Big-O and Other Notations
Chapter 7 SEARCHING 1. Introduction, Notation 2. Sequential Search 3. Binary Search 4. Comparison Trees 5. Lower Bounds 6. Asymptotics: The Big-O and Other Notations Outline Transp. 1, Chapter 7, Searching
More informationAssertions & Verification & Example Loop Invariants Example Exam Questions
2014 November 27 1. Assertions & Verification & Example Loop Invariants Example Exam Questions 2. A B C Give a general template for refining an operation into a sequence and state what questions a designer
More informationCSCA48 Winter 2018 Week 10:Algorithm Analysis. Marzieh Ahmadzadeh, Nick Cheng University of Toronto Scarborough
CSCA48 Winter 2018 Week 10:Algorithm Analysis Marzieh Ahmadzadeh, Nick Cheng University of Toronto Scarborough Algorithm Definition: Solving a problem step-by-step in finite amount of time. Analysis: How
More information10/5/2016. Comparing Algorithms. Analyzing Code ( worst case ) Example. Analyzing Code. Binary Search. Linear Search
10/5/2016 CSE373: Data Structures and Algorithms Asymptotic Analysis (Big O,, and ) Steve Tanimoto Autumn 2016 This lecture material represents the work of multiple instructors at the University of Washington.
More informationAlgorithm Analysis. Applied Algorithmics COMP526. Algorithm Analysis. Algorithm Analysis via experiments
Applied Algorithmics COMP526 Lecturer: Leszek Gąsieniec, 321 (Ashton Bldg), L.A.Gasieniec@liverpool.ac.uk Lectures: Mondays 4pm (BROD-107), and Tuesdays 3+4pm (BROD-305a) Office hours: TBA, 321 (Ashton)
More informationData structure and algorithm in Python
Data structure and algorithm in Python Algorithm Analysis Xiaoping Zhang School of Mathematics and Statistics, Wuhan University Table of contents 1. Experimental studies 2. The Seven Functions used in
More informationתוכנה 1 תרגול מספר 13
1 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 2 ו- HASHCODE EQUALS 3 תזכורת: המחלקה Object package
More informationתוכנה 1 תרגול מספר 13
1 2 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( ו- HASHCODE EQUALS חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 3 4 package java.lang; תזכורת: המחלקה
More informationAssertions & Verification Example Exam Questions
2009 November 23 Assertions & Verification Example Exam Questions 1. 2. A B C Give a general template for refining an operation into a sequence and state what questions a designer must answer to verify
More informationChoice of C++ as Language
EECS 281: Data Structures and Algorithms Principles of Algorithm Analysis Choice of C++ as Language All algorithms implemented in this book are in C++, but principles are language independent That is,
More informationAsymptotic Analysis of Algorithms
Asymptotic Analysis of Algorithms EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG Algorithm and Data Structure A data structure is: A systematic way to store and organize data
More informationJava How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Searching data involves determining whether a value (referred to as the search key) is present in the data
More informationAlgorithm. Algorithm Analysis. Algorithm. Algorithm. Analyzing Sorting Algorithms (Insertion Sort) Analyzing Algorithms 8/31/2017
8/3/07 Analysis Introduction to Analysis Model of Analysis Mathematical Preliminaries for Analysis Set Notation Asymptotic Analysis What is an algorithm? An algorithm is any well-defined computational
More informationמבוא למדעי המחשב תרגול 13: עצים בינאריים
מבוא למדעי המחשב תרגול 13: עצים בינאריים עצים בינאריים - הגדרה הגדרה: עץ בינארי הוא עץ ריק (בלי צמתים) או עץ המורכב משורש ושני תתי-עצים, הוא עץ בינארי. ימני ושמאלי, שכל אחד מהם תרגיל 1 עץ בינארי מסודר
More informationWhat is an algorithm?
Reminders CS 142 Lecture 3 Analysis, ADTs & Objects Program 1 was assigned - Due on 1/27 by 11:55pm 2 Abstraction Measuring Algorithm Efficiency When you utilize the mylist.index(item) function you are
More informationASP.Net Web API.
ASP.Net Web API 1 מה זה? Web API View בלבד ולא Data אותו מממש השרת והוא מחזיר לקליינט API הוא Web API הבקשה והתשובה הן בפרוטוקול Http\Https הקליינטים של Web API יכולים להיות רבים : אפשר להשתמש גם בMVC
More informationIntroduction to the Analysis of Algorithms. Algorithm
Introduction to the Analysis of Algorithms Based on the notes from David Fernandez-Baca Bryn Mawr College CS206 Intro to Data Structures Algorithm An algorithm is a strategy (well-defined computational
More information$ gcc check.c. $ a.out. $ gcc check.c -o check. $ check. $ gcc -Wall check.c -o check. #include <stdio.h>
תכנות בסיסי בשפת C תוכנית ראשונה תוכנית ב - C מורכבת מאוסף פונקציות והגדרות טיפוסים. C איננה שפה object oriented כך שאין בה מושגים של מחלקה ואובייקט. נתחיל בתוכנית הראשונה המסורתית, זו המדפיסה הודעה יחידה
More informationDepartment of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I
MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency
More informationבמידה ולסעיף ניתנה תשובה ובנוסף נרשם לגבי הסעיף לא יודע/ת אזי הניקוד שיינתן
פקולטה: מדעי הטבע מחלקה: מדעי המחשב שם הקורס: מבוא למחשבים ושפת C קוד הקורס: 2-7028510 תאריך בחינה: שאלות חזרה למבחן. חשוב: אין להסיק ששאלות אחרות לא יכולות להישאל במבחן, אין להסיק כי נושאים מסויימים בסיליבוס
More informationCS1 Lecture 22 Mar. 6, 2019
CS1 Lecture 22 Mar. 6, 2019 HW 5 due Friday Questions? In discussion exams next week Last time Ch 12. Zip, lambda, etc Default/keyword function parameters Ch 19 conditional expresssions, list comprehensions
More information0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)
0.1 Welcome http://cs161.stanford.edu My contact info: Jessica Su, jtysu at stanford dot edu, office hours Monday 3-5 pm in Huang basement TA office hours: Monday, Tuesday, Wednesday 7-9 pm in Huang basement
More informationLecture Notes on Contracts
Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,
More informationLecture Notes on Sorting
Lecture Notes on Sorting 15-122: Principles of Imperative Computation Frank Pfenning Lecture 4 September 2, 2010 1 Introduction Algorithms and data structures can be evaluated along a number of dimensions,
More informationCMPSCI 187: Programming With Data Structures. Lecture 5: Analysis of Algorithms Overview 16 September 2011
CMPSCI 187: Programming With Data Structures Lecture 5: Analysis of Algorithms Overview 16 September 2011 Analysis of Algorithms Overview What is Analysis of Algorithms? L&C s Dishwashing Example Being
More informationAlgorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang
Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Last class Review some algorithms learned in previous classes idea => pseudocode => implementation Correctness? Three sorting algorithms:
More informationData Structures and Algorithms
Berner Fachhochschule - Technik und Informatik Data Structures and Algorithms Topic 1: Algorithm Analysis Philipp Locher FS 2018 Outline Course and Textbook Overview Analysis of Algorithm Pseudo-Code and
More informationUCT Algorithm Circle: Number Theory
UCT Algorithm Circle: 7 April 2011 Outline Primes and Prime Factorisation 1 Primes and Prime Factorisation 2 3 4 Some revision (hopefully) What is a prime number? An integer greater than 1 whose only factors
More informationRecursion Chapter 8. What is recursion? How can a function call itself? How can a function call itself? contains a reference to itself.
Recursion Chapter 8 CS 3358 Summer II 2013 Jill Seaman What is recursion?! Generally, when something contains a reference to itself! Math: defining a function in terms of itself! Computer science: when
More information3. Logical Values. Our Goal. Boolean Values in Mathematics. The Type bool in C++
Our Goal 3. Logical Values Boolean Functions; the Type bool; logical and relational operators; shortcut evaluation int a; std::cin >> a; if (a % 2 == 0) std::cout
More information3. Logical Values. Our Goal. Boolean Values in Mathematics. The Type bool in C++
148 Our Goal 149 3. Logical Values Boolean Functions; the Type bool; logical and relational operators; shortcut evaluation int a; std::cin >> a; if (a % 2 == 0) std::cout
More informationמבוא לתכנות ב- JAVA תרגול 7
מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה
More informationמדעי המחשב 2 יחידות לימוד פתרון בחינת הבגרות פרק א. I x > a. פתרון 2: משפט switch
1 מדעי המחשב 2 יחידות לימוד פתרון בחינת הבגרות שאלה פרק א :1 m a b k k b x I x > a II x < b פלט I && II 0 8 12 8 4 1 9 11 2 10 11 9 8 2 12 35 13 העמודות המסומנות בכחול אינן עמודות חובה בפתרון. שאלה 2:
More informationWeek - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 Euclid's Algorithm
More informationCS221: Algorithms and Data Structures. Asymptotic Analysis. Alan J. Hu (Borrowing slides from Steve Wolfman)
CS221: Algorithms and Data Structures Asymptotic Analysis Alan J. Hu (Borrowing slides from Steve Wolfman) 1 Learning Goals By the end of this unit, you will be able to Define which program operations
More informationרשימות דילוגים Skip Lists
Lecture6 of Geiger & Itai s slide brochure www.cs.technion.ac.il/~dang/courseds רשימות דילוגים Skip Lists Skip lists: A probabilistic Alternative to Balanced Trees, William Pugh, Communications of the
More informationAlgorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs
Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to
More information