Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION TO COMPUTERS 2nd exam solution. Question 1 Suppose that you are given a group of non-negative numbers and you are asked to arrange them in.

Similar presentations


Presentation on theme: "INTRODUCTION TO COMPUTERS 2nd exam solution. Question 1 Suppose that you are given a group of non-negative numbers and you are asked to arrange them in."— Presentation transcript:

1 INTRODUCTION TO COMPUTERS 2nd exam solution

2 Question 1 Suppose that you are given a group of non-negative numbers and you are asked to arrange them in sequence from largest to smallest. You may organize a line that begins with the largest person and continues in descending order according to magnitude. Describe an algorithm for completing this task.

3 Solution of Q1 比較型的 Sorting Buble Sort Selection Sort Merge Sort Insertion Sort……

4 Question 2 Suppose you need to look up a specific number from a sequence of N numbers using sequential search. A.How many checks would be required, in the worst case, to find the number? B.How many checks would be required, in the best case, to find the number?

5 Solution of Q2 A.N B.1

6 Question 3 Consider the list of numbers shown below: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85] A.Which number in the list is the "easiest" to find using binary search? That is, which number could be located in the fewest number of checks? Please explain.

7 Question 3 B.Which number in the list is the "hardest" to find using binary search? That is, which number would require the largest number of checks? Please explain.

8 Solution of Q3 A.45 ,因為它為整個數列的中位數。 B.35 、 40 、 80 、 85 ,因為這幾個數都需要花 費 4 次比對。

9 Question 4 Recall that Newton’s algorithm uses the following expression to refine the square root of a positive number N: newApproximation = (oldApproximation + N/oldApproximation)/2

10 Question 4 Imagine that, while you are using Newton's algorithm, the approximations converge on the actual square root of N. Would the value change if you tried to further refine the square root? Why or why not?

11 Solution of Q4 不會,因為已經收斂了。 newApproximation=(oldApproximation+N/oldAp proximation)/2=oldApproximation

12 Question 5 Please answer the following questions: A.Show the page before the user pushes the button. B.Show the page after the user types 45 in the tempBox text box, types 12 in the windBox text box, and pushes the button.

13 Question 5

14

15 Solution of Q5-A

16 Solution of Q5-B

17 Question 6 Please answer the following questions: A.Show the page if the user pushes the button without typing anything in the inputBox text box. B.Show the page after the user types in “I am sad.” and pushes the button.

18 Question 6

19

20 Solution of Q6-A

21 Solution of Q6-B

22 Question 7 Please answer the following questions: A.Show the page after the user types 25 in the redDot text box, types 30 in the blueDot text box, and pushes the button. B.Show the page after the user types 5 in the len text box, types 4 in the redDot text box, types 4 in the blueDot text box, and pushes the button.

23 Question 7

24

25 Solution of Q7-A

26 Solution of Q7-B

27 Question 8 Create a Web page that reads in an intgeger number entered by the user and then determines whether that number is even positive, odd positive, negative, or zero. The page should contain a text box in which the user can enter the number and a button for initiating the analysis.

28 Question 8 When the user inputs the desired number and clicks the button, a function should be called to identify the number’s type and display the result in an alert box.

29 Solution of Q8

30

31

32 Question 9 Create a Web page that prompts the user to enter a specific number of years and then displays the corresponding time in seconds. Assume that all years consist of exactly 365 days.

33 Question 9 Your page should include the definition of a function named YearsToSeconds that requires one input a value corresponding to a number of years--and returns the equivalent time in seconds, and another definition of a function named DoConversion that reads the number of years from a text box, calls the function YearsToSeconds, and displays the number of seconds in another text box after the user enters the number and pushes the button.

34 Solution of Q9

35

36

37 Question 10 A.Consider the following code segment Given x=23 and y=7, what the output would the above code produce?

38 Question 10 if (x >= y) { if (x*10 ");} else{document.write("TWO ");} } else{document.write("THREE ");}

39 Solution of Q10-A TWO

40 Question 10 B.Consider the following code segment: What ranges in which temperature and windSpeed are located in order to show a window with message “Good 5!”?

41 Question 10 if (temperature <= 50){ if (windSpeed < 7) {alert(“Good 1!”);} else{ if (windSpeed >= 15) {alert(“Good 2!”);} else{alert(“Good 3!”);} }} ………. ……… else{ if (windSpeed > 10) {alert(“Good 4!”);} else{ if (windSpeed < 5) {alert(“Good 5!”);} else{alert(“Good 6!”);} }}

42 Solution of Q10-B Temperature > 50 windSpeed < 5


Download ppt "INTRODUCTION TO COMPUTERS 2nd exam solution. Question 1 Suppose that you are given a group of non-negative numbers and you are asked to arrange them in."

Similar presentations


Ads by Google