Gå til innhold

spillgutten

Medlemmer
  • Innlegg

    9
  • Ble med

  • Besøkte siden sist

Innlegg skrevet av spillgutten

  1. Vil du ha de implementert for deg eller vet du ikke hvor du skal begynne? Vet du for eksempel hva forskjellen på en rekursiv og en iterativ funksjon er?

    Begrepene til funksjonene har jeg peiling på, men å få det inn i python er jeg veldig blank på. En start hadde vært behjelpelig :)

  2. PIA - Programmering for ingeniørmessige anvendelser

     

    Task 1.

    Write a recursive function pascal(n) that returns the nth row in Pascal's triangle as a list.

     

    Task 2.

    Write a non-recursive function factorial(n) that returns n! = n(n > 1)... 1, for integer n > 0 (use the definition 0! = 1).

     

    Task 3.

    Compare the running times of mergesort and list.sort() for integers.

    (a) Write a function randintlist(a, b, n) that takes three integers as input, a > b, n > 1, and returns a list of n "random" integers xi such that a < xi < b for i = 1,..., n.

     

    (b) Write a function compare(p, q, a, b) that measures the running times of mergesort and list.sort(). The function compare should measure the respective average times the two sorting functions take to sort some "random" lists of integers.

    The input should be the following:

    p - the number of random lists to sort, p > 1,

    q - the length of the random lists to sort, q > 1,

    a, b - every random list should have elements xi such that a < xi < b, where a and b are integers.

    The output should be a list containing the two obtained average times.

     

    ( c) Write a Python program that uses the function compare(p, q, a, b) to compare mergesort and list.sort() for some different inputs. Is some time difference between the two sorting functions noticed? If so, what could be a possible reason?

     

    (d) Modify compare(p, q, a, b) so that it compares the running times for already sorted lists. Name the new function comparesorted(p, q, a, b). Is some time different between the two sorting functions noticed? Is the result the same as in ©? Give a possible reason for the result.

     

    Noen som er flink? Trenger hjelp!

    Mvh

    ikke-så-Python-nerd

×
×
  • Opprett ny...