Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture # 2 Algorithms and Programs. Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples.

Similar presentations


Presentation on theme: "Lecture # 2 Algorithms and Programs. Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples."— Presentation transcript:

1 Lecture # 2 Algorithms and Programs

2 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

3 Review of Homework # 1 Groups share Sorting Algorithms What is the Key Idea of the Algorithm? What makes an algorithm efficient? What is the best Sorting Algorithm?

4 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

5 Algorithms What is an Algorithm? A precise, repeatable method or finite sequence of steps to solve a problem or accomplish a task What are some examples of algorithms? - In everyday life? - In Science? - In Computing? - In the workplace?

6 Algorithms What is an Algorithm? A precise, repeatable method or finite sequence of steps to solve a problem or accomplish a task What are some examples of algorithms? - In everyday life? Recipes – Dressing - Driving - In Science? Temperature Conversion - Adding - In Computing? Searching – Network Traffic - In the workplace? Purchasing – Food Preparation

7 Algorithms Example 1 To Die-For Pot Roast: Ingredients: 1 (4 -5 lb) beef roast, any kind 1 (1 1/4 ounce) package brown gravy mix, dry 1 (1 1/4 ounce) package dried Italian salad dressing mix 1 (1 1/4 ounce) package ranch dressing mix, dry 1/2 cup water

8 Algorithms Example 1 (cont.) To Die-For Pot Roast: Directions: Step 1: Place beef roast in crock pot. Step 2: Mix the dried mixes together in a bowl and sprinkle over the roast. Step 3: Pour the water around the roast. Step 4: Cook on low for 7-9 hours.

9 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own.

10 Algorithm Exercise Algorithm for Getting to School – write it on your laptop so you can share it Step 1: Unsleep (must be specific – when?) Step 2: Step 3: Step 4: Step 5: Step 6: Step 7:

11 What’s in Your Algorithm? WPbasic – on screen Share and Evaluate

12 Algorithm Efficiency What makes an algorithm efficient? - Is it the time that it takes? - Is it the number of steps required? - Is it the complexity?

13 Algorithm Efficiency What has been the decrease in the mile run over the past 5 decades? What has been the decrease in the amount of time required by a computer to add two numbers over the past 5 decades? Has the algorithm for addition changed?

14 What are the Essential Ingredients of an Algorithm? Input: Define type, format of input data Output: Define output/result Steps: Specific sequence of steps or instructions Computable: steps can be performed, validated Halts: The algorithm will halt in finite time

15 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

16 Exercise Determine the inputs, outputs, steps and stopping condition for your favorite recipe Determine the inputs, outputs, steps and stopping conditions for other everyday tasks How can you increase the efficiency of some of these tasks?

17 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

18 Programs Computer Programs are simply algorithms that are implemented in a particular programming language like java, javascript, HTML, C, python, etc. These Languages use a sequence of steps, named variables, assignment statements, and data types and data structures to implement the algorithm.

19 Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1;

20 Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1;

21 Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A + 13 75 + 13 = 88

22 Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A-B+3 75 - 88 + 3 = -10

23 Program A sequence of things to do A = 75; B = A+13; A = A-B+3; C = A/2 + 1; A / 2 + 1 -10 / 2 + 1 = -4

24 Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples of Algorithms 4.Practice: You will create an Algorithm 5.Evaluate: We will share and evaluate our Algorithms 6.Re-practice: Analyze your favorite recipe as an Algorithm We will look at a classical sorting Algorithm together You will look at a Program on your own

25 Exercise: Write a Sorting Algorithm Create an algorithm to sort (alphabetize) a list of names. How will you represent the names? How will you solve this problem? What will be the key idea of the algorithm? - now that you are an expert (of “Sorts”)

26 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AJim BBill Alice Nancy Bob

27 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AJim BBill Alice Nancy Bob

28 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill BJim Alice Nancy Bob

29 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill BJim Alice Nancy Bob

30 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill Jim BAlice Nancy Bob

31 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name ABill Jim BAlice Nancy Bob

32 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim BBill Nancy Bob

33 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim BBill Nancy Bob

34 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

35 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

36 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill BNancy Bob

37 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

38 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

39 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

40 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name AAlice Jim Bill Nancy BBob

41 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim Bill Nancy BBob

42 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

43 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

44 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice AJim BBill Nancy Bob

45 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill BJim Nancy Bob

46 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill BJim Nancy Bob

47 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

48 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

49 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim BNancy Bob

50 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

51 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

52 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

53 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice ABill Jim Nancy BBob

54 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

55 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

56 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

57 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

58 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

59 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim BNancy Bob

60 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

61 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill AJim Nancy BBob

62 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

63 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

64 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill ABob Nancy BJim

65 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

66 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

67 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob ANancy BJim

68 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

69 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

70 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

71 A Sort Algorithm Input: An unordered list of names Output:An ordered list of names Steps:1 Refer to the first two names as index A and B respectively 2If Name[A] > Name [B] swap Name[A] with Name [B] 3If B does not point to the last name on the list move B to the next name and go back to Step 2 4If there are 2 or more names after A move A to the next name move B to the name following A Go back to Step 2 Stop Name Alice Bill Bob AJim BNancy

72 Algorithm Analysis What is the Key Idea? - It makes use of an Exchange Sort - It compares 2 items and swaps them if they are out of order - This continues until we sweep through all of the names

73 Algorithm Analysis How efficient is this algorithm? - How many compares/swaps? - How many times do we “visit” each name on the list? - How can we characterize the “speed” or efficiency of this algorithm?

74 Algorithm Analysis How can we measure algorithm efficiency? - If there are n items in the list … - and we “visit” each item n times … - Then the algorithm is

75 Algorithm Analysis How can we measure algorithm efficiency? - If there are n items in the list … - and we “visit” each item n times … - Then the algorithm is ~n 2 complexity

76 Algorithm Analysis Can we do better than ~n 2 complexity? - Can we do ~n complexity? - Can we do ~2n complexity? - The most efficient algorithms are ~n log n


Download ppt "Lecture # 2 Algorithms and Programs. Today Questions: From Homework #1 1.Introduce: What is an Algorithm? 2.Explain: Algorithm defined 3.Demo: Examples."

Similar presentations


Ads by Google