Question

In: Computer Science

2. A general medical practitioner (GP) has compiled an electronic computer file of patient information. Among...

2. A general medical practitioner (GP) has compiled an electronic computer file of patient information. Among the information contained in the file are details of the height of each patient. The GP has developed a simple algorithm showing how the file can be read [until the end of the file (EOF) is reached] to find and write the height of the tallest patient. The pseudocode for the algorithm is:

start tall = 0

do until EOF

read height

If tall < height

tall = height

end If

end do

a) (*) Draw a flowchart (following the conventions used in class) that represents the pseudo code. [6 marks]

b) (*) What is the likely complexity of your program using big-O notation? Clearly point out what the primary parameters are and define your terms. [2 marks]

c) Your colleague is working on two algorithms, X and Y, that determines whether two people are a certain distance apart. They use a number of different inputs, n. They are seeking your advice. If they tell you that algorithm X has a worst-case runtime complexity of O(n) and algorithm Y has a worst-case runtime complexity of O(n2 ), which algorithm would you recommend and why? [2 marks]

d)Your colleague then adds that the average-case time complexity for X is Ɵ(logn) and for Y is Ɵ(n). Does this change your advice at all, and why? [2 marks] Your answers should be no longer than a sentence or two.

e) Write a recursive function sum_factor(n), using the pseudocode principles covered in the lecture, to sum up the numbers i between 1 and n where i is a factor of n, (that is i completely divides n). You need to write a function is_factor(n,i) that returns 1 if i is a factor of n and 0 otherwise. You need to invoke/call this function from sum_factor(n) algorithm. You may assume that n will be greater than 0 – error checking is not needed. [8 marks] Please note: Submission of actual code (e.g., in Ruby or Python or any other programming language) will be awarded zero marks – we are seeking pseudocode. Answers using iteration will be marked on pseudocode alone and cannot receive full marks.

write tall

end

Solutions

Expert Solution

Hey There,

- I understood your question and I have given the answer to the best of my knowledge.

- Here as mentioned in the question I have given direct answers with explanation.

- If you need further explanation then do let me know in the comments box I will be more than happy to help.

Answer:

a). Flowchart:

  

b). Complexity

- To end the program user needs to enter a value that is less than the tall variable. So we don't know how much time it will happen. So the worst-case complexity will be  O(n).

- However in the best case the complexity can be O(1). If the user enters a smaller value in the first attempt then our program will end.

c). X has the worst-case runtime complexity of O(n) while Y has the worst-case time complexity is O(). So we can clearly see that X's algorithm will perform much better as it will take less time to run the code.

- We know that O(n) is efficient than O() so I will definitely recommend the X's algorithm as it will be more efficient and It will take less time.

d). The average complexity of X is Ɵ(long) while for Y it is Ɵ(n). We know that "logn" is better than "n".

- So this will not change my advice at all.

e) Recursive function:

-

1. Program starts
2. Declare a global variable sum = 0
3. define is_factor(int n, int i) function:
    if n mod i equals to 0 then:
        return 1
    else
        return -1
4. Start sum_factor(n, 1) function:
    if i <= n then:
        call is_factor(n, i) function
        store the output in result variable
        if result equals 1 then:
            sum = sum + i;
        else:
            call sum_factor(n, i+1)
    end the function
5. Start main function:
    Call sum_factor with given number value
    sum_factor(n, 1);
    display the value of sum variable
    end of main
  

Hope it helps:)


Related Solutions

A study in Batu Pahat General Hospital's on patient account division has compiled data on the...
A study in Batu Pahat General Hospital's on patient account division has compiled data on the age of accounts receivables. The data collected indicates that the age of the accounts follows a normal distribution with mean 28 days and a standard deviation of 8 days. Ahmad would like to know the probability of the accounts between 20 and 40 days old and the probability of the accounts which less than 30 days old. Shows the calculation of both problems.
1. How is evolution important to current/furture medical practive (for practitioner and patient, with examples) 2....
1. How is evolution important to current/furture medical practive (for practitioner and patient, with examples) 2. Describe how evolutionary theory allows for a better knowledge about human behavior and how does this impact the understanding of various human behaviors that are diverse (with examples) 3. how does this have value to life. (with examples)
The electronic medical record allows for an elevate level of treatment for a patient now that...
The electronic medical record allows for an elevate level of treatment for a patient now that their medical history is now accessible to their treating healthcare provider with a click of the mouse. Although this technology can lead to a quicker diagnosis and cross-collaboration of providers, there remain some potential pitfalls. For this week's written assignment, in a 1-2 page paper, research potential issues with the use of electronic medical records? Discuss the issues and define the problems. Provide applicable...
Information Management Systems: Benefits of Electronic Medical Records
Information Management Systems: Benefits of Electronic Medical Records
Integrative Urinary Case Study While working as a general practitioner, your patient Lamar comes to your...
Integrative Urinary Case Study While working as a general practitioner, your patient Lamar comes to your office for a standard checkup. Because Lamar is 60 years old and has type II diabetes, you frequently subject him to lab tests to evaluate kidney function, as you know that kidney function can be compromised in diabetics. Urinary Case Study.01 One type of damage that you are worried about detecting is damage to the endothelial cells of the kidney glomeruli and the podocytes...
Webster Company Ltd has compiled the following information.
Webster Company Ltd has compiled the following information. Source of capital Book value Market Value After tax Cost Long-term debt $ 4,000,000 $3,840,000 6.0% Preference share capital 40,000 60,000 13% Ordinary share equity 1,060,000 3,000,000 17% Totals $5,100,000 6,900,000   Calculate the WACC (to the nearest two decimal places) using book value weights.              Calculate the WACC (to the nearest two decimal places) using market value weights.                                      ...
Among the computer chips produced at a computer facility, 2% are mildly defective and an additional...
Among the computer chips produced at a computer facility, 2% are mildly defective and an additional 3% are highly defective. The remaining chips are OK. Different chips are independent in terms of status. If a chips is mildly defective, it costs $20 to repair it to proper condition. For highly defective chips, the cost is $60. There is no repair cost for OK chips. Suppose that 40 chips produced at this facility are examined for defects: 1. What is the...
The owner of the Information contained in the Medical Records is: The Physician The Patient The...
The owner of the Information contained in the Medical Records is: The Physician The Patient The Medical Facility The Health Insurance Company
Why has the U.S. seen more focus on the specialist versus the general practitioner?
Why has the U.S. seen more focus on the specialist versus the general practitioner?
1.Explain the importance of patient medical records. 2.Identify the documents that constitute a patient medical record....
1.Explain the importance of patient medical records. 2.Identify the documents that constitute a patient medical record. 3.Recall the 6 Cs of charting. 4.Describe the need for neatness, timeliness, accurate, and professional tone in patient records. 5.Describe the steps in responding to a written request for release of medical records.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT