id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

david.white@denison.edu cs109fall2014 > fun631
prev  |  next  |  chance

Do exercise 6.3.1 parts (a)-(m) on pen and paper. Each answer should be in Big Oh notation. If the algorithm is linear then the answer is "O(n)", if quadratic then "O(n*n)", if constant time then "O(1)". Take your results and put them into a list called L, which is a list of strings starting with the answer for part (a) and ending with the answer for part (m). For instance, if you got the following answers (say for the first three parts):

(a) O(1)
(b) O(n*n)
(c) O(n)
then you'd type a list of the form ["O(1)","O(n*n)","O(n)",...] where the dots are for your answers to parts (d)-(m). Once you've typed your answers into a list named L, copy and paste the following code:
def fun631(k):
  L = [...]
  if k < 15:
    return list2string([k])
  else:
    return list2string(L)

def list2string(L):
    s = ""
    for val in L:
      s += str(val) + ' '
    return s
All you have to do is to fill in the list L with your answers to parts (a)-(m), remembering that you have to type it in the form L=["O(1)","O(n*n)","O(n)",...] but perhaps with different answers for parts (a)-(c). Part g is constant time, so every one of you should have a list of the form L = [-,-,-,-,-,-,"O(1)",-,-,-,-,-,-] where you've filled in the blanks with either "O(1)", "O(n)", or "O(n*n)". For Part k, observe that the string called name could have a very large length, but the string 'hello' will always have length 5. Think about the specific steps your code unravels to.

fun631(1) → '1 '
fun631(2) → '2 '
fun631(3) → '3 '

...Save, Compile, Run (ctrl-enter)

def fun631(k):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy