Informatik I (D-BAUG)

Ähnliche Dokumente
Informatik I D-ITET Self-Assessment II,

Informatik D-MATH/D-PHYS Self-Assessment II,

Das folgende Kleingedruckte finden Sie auch auf einer "scharfen" Prüfung. 1. Dauer der Prüfung: 20 Minuten. Exam duration: 20 minutes.

Das folgende Kleingedruckte finden Sie auch auf einer "scharfen" Prüfung. 1. Dauer der Prüfung: 15 Minuten. Exam duration: 15 minutes.

Informatik D-MATH/D-PHYS Self-Assessment IV,

Informatik D-MATH/D-PHYS Self-Assessment III,

Informatik Prüfung Lösung B. Gärtner

Informatik 1 Kurzprüfung 2 LÖSUNG

Level 2 German, 2016

Informatik Prüfung Lösung B. Gärtner

Level 2 German, 2015

Level 1 German, 2016

Übersetzen des Quelltexts in ausführbaren Maschinen-Code Translation of source code into executable machine code

Level 2 German, 2013

Magic Figures. We note that in the example magic square the numbers 1 9 are used. All three rows (columns) have equal sum, called the magic number.

Level 1 German, 2014

SAMPLE EXAMINATION BOOKLET

Informatik Prüfung Lösung B. Gärtner

Informatik Prüfung B. Gärtner

Level 1 German, 2011

16. Dynamische Datenstrukturen

DIBELS TM. German Translations of Administration Directions

Informatik - Übungsstunde

Level 1 German, 2012

Basispruefung Herbst 2016/ Einführung in die Programmierung

Weather forecast in Accra

D-BAUG Informatik I. Exercise session: week 1 HS 2018

Level 1 German, 2013

Informatik I Prüfung B. Gärtner

Was heißt Denken?: Vorlesung Wintersemester 1951/52. [Was bedeutet das alles?] (Reclams Universal-Bibliothek) (German Edition)

13. Dynamische Datenstrukturen

Accelerating Information Technology Innovation

Informatik für Mathematiker und Physiker Woche 2. David Sommer

Informatik Prüfung Lösung B. Gärtner

GERMAN LANGUAGE Tania Hinderberger-Burton, Ph.D American University

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL USER GUIDE June 2016

Level 1 German, 2012

Paper Reference. Paper Reference(s) 1231/4H Edexcel GCSE German Paper 4H Writing Higher Tier Tuesday 12 June 2007 Afternoon Time: 1 hour

Algorithms & Datastructures Midterm Test 1

Java Tools JDK. IDEs. Downloads. Eclipse. IntelliJ. NetBeans. Java SE 8 Java SE 8 Documentation

Future plans. Exercise 1: Read the text below.

Where are we now? The administration building M 3. Voransicht

Kursbuch Naturheilverfahren: Curriculum der Weiterbildung zur Erlangung der Zusatzbezeichnung Naturheilverfahren (German Edition)

Finite Difference Method (FDM)

Im Fluss der Zeit: Gedanken beim Älterwerden (HERDER spektrum) (German Edition)

Funktion der Mindestreserve im Bezug auf die Schlüsselzinssätze der EZB (German Edition)

VORANSICHT. Halloween zählt zu den beliebtesten. A spooky and special holiday Eine Lerntheke zu Halloween auf zwei Niveaus (Klassen 8/9)

Informatik I D-ITET Prüfung F. Friedrich

Max und Moritz: Eine Bubengeschichte in Sieben Streichen (German Edition)

Handbuch der therapeutischen Seelsorge: Die Seelsorge-Praxis / Gesprächsführung in der Seelsorge (German Edition)

Wie man heute die Liebe fürs Leben findet

Paper Reference. Paper Reference(s) 4375/01 London Examinations IGCSE German Paper 1: Listening

German translation: technology

Mercedes OM 636: Handbuch und Ersatzteilkatalog (German Edition)

Duell auf offener Straße: Wenn sich Hunde an der Leine aggressiv verhalten (Cadmos Hundebuch) (German Edition)

Level 2 German, 2011

Organische Chemie IV: Organische Photochemie

Cambridge International Examinations Cambridge International Advanced Subsidiary Level

Übungsstunde: Informatik 1 D-MAVT

Level 1 German, 2015

Registration of residence at Citizens Office (Bürgerbüro)

Zu + Infinitiv Constructions

Wer bin ich - und wenn ja wie viele?: Eine philosophische Reise. Click here if your download doesn"t start automatically

Cambridge International Examinations Cambridge International Advanced Subsidiary Level

Die Intrige: Historischer Roman (German Edition)

Mock Exam Behavioral Finance

Informatik I (D-ITET)

VGM. VGM information. HAMBURG SÜD VGM WEB PORTAL - USER GUIDE June 2016

Modern Foreign Languages

Englisch-Grundwortschatz

Brandbook. How to use our logo, our icon and the QR-Codes Wie verwendet Sie unser Logo, Icon und die QR-Codes. Version 1.0.1

Ein Stern in dunkler Nacht Die schoensten Weihnachtsgeschichten. Click here if your download doesn"t start automatically

Cambridge International Examinations Cambridge International Advanced Subsidiary Level

Die einfachste Diät der Welt: Das Plus-Minus- Prinzip (GU Reihe Einzeltitel)

KTdCW Artificial Intelligence 2016/17 Practical Exercises - PART A

Arbeitsblatt Nein, Mann!

Sagen und Geschichten aus dem oberen Flöhatal im Erzgebirge: Pfaffroda - Neuhausen - Olbernhau - Seiffen (German Edition)

Paper Reference. German Paper 1F Listening and Responding Foundation Tier Friday 22 May 2009 Morning Time: 30 minutes (+5 minutes reading time)

Die Bedeutung neurowissenschaftlicher Erkenntnisse für die Werbung (German Edition)

Paper Reference. Paper Reference(s) 4375/01 London Examinations IGCSE German Paper 1: Listening

Prüfung A Informatik D-MATH/D-PHYS :15 14:55

FIRST LANGUAGE GERMAN

Harry gefangen in der Zeit Begleitmaterialien

CNC ZUR STEUERUNG VON WERKZEUGMASCHINEN (GERMAN EDITION) BY TIM ROHR

Martin Luther. Click here if your download doesn"t start automatically

Level 2 German, 2013

Offenes Lernen 1: Pflichtaufgaben

Fachübersetzen - Ein Lehrbuch für Theorie und Praxis

C++ kurz & gut (German Edition)

Jägersprache, Wildkunde und Begriffe aus der Jagd: Schwerpunkt Jägerprüfung Rotwild, Rehwild, Gamswild, Steinwild, Muffelwild (German Edition)

Tote Hose: Worüber Männer schweigen. Ein Tagebuch (German Edition)

Informatik II D-BAUG Prüfung F. Friedrich

Transkript:

Self Assessment II (Lösung) Informatik I (D-BAUG) Felix Friedrich, Hermann Lehner ETH Zürich, 11.2017. Name, Vorname:.................................................................. Legi-Nummer:.................................................................. Diese Selbsteinschätzung dient Ihrer und unserer Orientierung. Sie wird eingesammelt, korrigiert und vertraulich behandelt. Sie hat aber keinen Einfluss auf eine spätere Leistungsbewertung. Sie haben 20 Minuten Zeit. Das folgende Kleingedruckte finden Sie auch auf einer scharfen Prüfung. Allgemeine Richtlinien: General guidelines: 1. Dauer der Prüfung: 20 Minuten. Exam duration: 20 minutes. 2. Erlaubte Unterlagen: Wörterbuch (für gesprochene Sprachen). 4 A4 Seiten handgeschrieben oder 11pt Schriftgrösse. Permitted examination aids: dictionary (for spoken languages). 4 A4 pages hand written or 11pt font size 3. Benützen Sie einen Kugelschreiber (blau oder schwarz) und keinen Bleistift. Bitte schreiben Sie leserlich. Nur lesbare Resultate werden bewertet. 4. Lösungen sind direkt auf das Aufgabenblatt in die dafür vorgesehenen Boxen zu schreiben (und direkt darunter, falls mehr Platz benötigt wird). Ungültige Lösungen sind deutlich durchzustreichen! Korrekturen bei Multiple-Choice Aufgaben bitte unmissverständlich anbringen! Use a pen (black or blue), not a pencil. Please write legibly. We will only consider solutions that we can read. Solutions must be written directly onto the exam sheets in the provided boxes (and directly below, if more space is needed). Invalid solutions need to be crossed out clearly. Provide corrections to answers of multiple choice questions without any ambiguity! 5. Es gibt keine Negativpunkte für falsche Antworten. There are no negative points for false answers. 6. Störungen durch irgendjemanden oder irgendetwas melden Sie bitte sofort der Aufsichtsperson. 7. Wir sammeln die Prüfung zum Schluss ein. Wichtig: stellen Sie unbedingt selbst sicher, dass Ihre Prüfung von einem Assistenten eingezogen wird. Stecken Sie keine Prüfung ein und lassen Sie Ihre Prüfung nicht einfach am Platz liegen. Dasselbe gilt, wenn Sie früher abgeben wollen: bitte melden Sie sich lautlos, und wir holen die Prüfung ab. Vorzeitige Abgaben sind nur bis 15 Minuten vor Prüfungsende möglich. 8. Wenn Sie zur Toilette müssen, melden Sie dies einer Aufsichtsperson durch Handzeichen. 9. Wir beantworten keine inhaltlichen Fragen während der Prüfung. Kommentare zur Aufgabe schreiben Sie bitte auf das Aufgabenblatt. If you feel disturbed by anyone or anything, let the supervisor of the exam know immediately. We collect the exams at the end. Important: you must ensure that your exam has been collected by an assistant. Do not take any exam with you and do not leave your exam behind on your desk. The same applies when you want to finish early: please contact us silently and we will collect the exam. Handing in your exam ahead of time is only possible until 15 minutes before the exam ends. If you need to go to the toilet, raise your hand and wait for a supervisor. We will not answer any content-related questions during the exam. Please write comments referring to the tasks on the exam sheets. Question: 1 2 3 4 Total Points: 6 4 6 4 20 Score:

Informatik I 2/8 Self Assessment II 11.2017 Aufgabe 1: Code Lesen (6P) Beschreiben Sie in den folgenden Boxen jeweils in Worten, was die darunter stehende Methode macht. Beschreiben Sie nicht die einzelnen Schritte sondern die Bedeutung. Provide in the following boxes what the methodes are doing. Do not describe the single steps but rather the meaning. /2P (a) Gibt zurück, ob b in a enthalten ist. // pre: non-null array a static boolean p(int[] a, int b){ int r = a.length; while (r > 0){ if (a[--r] == b) {return true; return false; (b) /2P Teilersumme von n // pre: n >= 0 static int q(int n){ int r = 0; for (int i = 1; i<=n; ++i){ if (n % i == 0){ r += i; return r; (c) /2P Rückgabe von a b // pre: a,b > 0 static int r(int a, int b){ if (b == 0){ return 1; return a * r(a,b-1); 2 points each, zero points for description line by line

Informatik I 3/8 Self Assessment II 11.2017 Aufgabe 2: Code Schreiben (4P) /4P Vervollständigen Sie folgende Methode mindist so, dass Sie die minimale absolute Differenz x y zweier unterschiedlicher Werte x und y aus dem Array a zurückgibt. Complement the following method mindist such that it returns the minimal absolute difference x y of two different points x and y from the array a. // pre: a!= null, a.length >= 2 // post: return minimum distance Math.abs(a[i]-a[j]) of all pairs i!= j public static int mindist(int a[]){ int dist = Math.abs(a[0]-a[1]); for (int i = 0; i<a.length; ++i){ for ( int j = i+1; j<a.length; ++j ){ int d = Math.abs(a[i]-a[j]); if (d < dist){ dist = d; return dist; 2 points for correct for loop, 2 points for correct if statement. 1p deduction for out of bounds, 1p deduction for other semantic errors. 2 points deduction if pseudo-code is used instead of Java. No deductions for missing semicolons or other superficial mistakes.

Informatik I 4/8 Self Assessment II 11.2017 Aufgabe 3: Listen (6P) Sei für diese Aufgabe folgende Listknoten- Klasse gegeben: Let for this task be the following list-node class be given: class ListNode{ ListNode next; int value; ListNode (int v, ListNode n){ value = v; next = n; Es sei eine verkettete Liste von Knoten gegeben. Das Ende der Liste ist durch einen Null- Knoten gegeben. Beispiel: Assume a linked list of node elements. The end of the linked ist is provided by a nullnode. Example: n 1 2 3 4 null Die folgende rekursive Funktion gibt die Werte der Knoten aus, startend beim gegebenen Knoten n bis zum Ende der verketteten Liste. The following recursive function outputs the node s values, starting from the given node element n and traversing to the end of the linked list. void output(listnode n){ if (n!= null){ Out.println(n.value); output(n.next); Ausgabe Beispiel 1 2 3 4 Example Output: (a) /2P Vervollständigen Sie den folgenden Code so, dass die Werte in umgekehrter Reihenfolge ausgegeben werden. Verwenden Sie Rekursion! Complement the following Code such that the values in the list are output in reversed order. Use recursion!

Informatik I 5/8 Self Assessment II 11.2017 void outputr(listnode n){ if (n!= null){ outputr(n.next); Out.println(n.value); Ausgabe Beispiel 4 3 2 1 Example Output: 2 points for correct recursion (basically code from l.h.s. with swapped line), 1 point for correct (!) inversion of the list. Do not deduce points for call of output instead of outputr if the rest is correct (then it is only a superficial mistake). (b) Auf der nächsten Seite sehen Sie eine (korrekte) Implementation einer Listenklasse, mit Operationen out, empty und append. Jemand behauptet, dass die Implementation mancher Operationen einfacher wird, wenn die Liste am Anfang immer mit einem nicht-leeren (Wächter-) Element beginnt und schlägt daher die danach folgende SentinelListe vor. Vervollständigen Sie also die Methoden der SentinelListe so, dass die beiden Klassen List und SentinelList dieselbe Semantik aufweisen. Die Liste, welche auf der linken Seite dargestellt ist, sähe mit Wächterelement wie folgt aus. On the following page you see a (correct) implementation of a list class with operations out, empty and append. Someone claims that the implementation of some operations becomes simpler when the list always starts with a non-empty (sentinel) element. Therefore he proposes the following SentinelList. Complement the methods of the SentinelList such that both classes List and SentinelList provide the same semantics. The list displayed on the left hand side would look like the following with a sentinel. /4P Wächter n (0) 1 2 3 4 null Sentinel

Informatik I 6/8 Self Assessment II 11.2017 Vervollständigen Sie die Methoden der SentinelListe auf der rechten Seite so, dass die beiden Klassen List und SentinelList dieselbe Semantik aufweisen. Das heist, der von Aussen beobachtbare Effekt des ausgeführten Codes ist identisch. Complement the methods of the SentinelList on the right page such that both classes List and SentinelList provide the same semantics. That is, the effect observable from outside is identical. class List{ ListNode head; List(){ head = null; // post: outputs the list content (first in, first out) public void out(){ ListNode n = head; while (n!= null){ Out.print(n.value + " "); n = n.next; // post: returns if the list is empty public boolean empty(){ return head == null; // post: appends a new node with value at the end of the list public void append(int value){ if (head == null){ head = new ListNode(value, null); return; ListNode p = head; while (p.next!= null){ p = p.next; p.next = new ListNode(value,null);

Informatik I 7/8 Self Assessment II 11.2017 class SentinelList{ ListNode head; SentinelList(){ head = new ListNode(0, null); // head = sentinel // post: outputs the list content (first in, first out) public void out(){ ListNode n = head.next; while (n!= null){ Out.print(n.value + " "); n = n.next; // post: returns if the list is empty // (a list with sentinel is called empty when it contains no element but the sent public boolean empty(){ return head.next == null; // post: appends a new node with value at the end of the list public void append(int value){ ListNode p = head; while (p.next!= null){ p = p.next; p.next = new ListNode(value,null); 1 point for correct implementation of empty(), 3 points for append. Deduce 2 points if the left hand side is reproduced one-to-one, deduce 2 points when end of list is lost in iterations (when iterating and not storing the prev pointer implicitly)

Informatik I 8/8 Self Assessment II 11.2017 /4P Aufgabe 4: Fehlersuche (4P) Im nachfolgenden Codebeispiel steckt ein Fehler. Das Beispiel kompiliert vollständig. Die vorhandenen Fehler werden vom Compiler also nicht bemerkt. Erklären jeweils kurz den Fehler und geben Sie ganz kurz eine mögliche Behebung in den Boxen unter den Codestücken an. In dieser Aufgabe betrachten wir Code dann als fehlerfrei, wenn er korrekt terminiert und unter der Vorbedingung die Nachbedingung erfüllt. // swap integers a and b static void swap(int a, int b){ int temp = a; a = b; b = temp; The following code example has a bug. It compiles successfully. That means the bug is not identified by the compiler. Please explain the bug and a possible resolution in the boxes below the code pieces. Within this task we consider code bug-free if it terminates correctly and if it fulfills the post-condition under the pre-condition. // pre: unsorted array a!= null // post: a sorted static void bubblesort(int a[]){ for (int i = 0; i<a.length; ++i) for (int j = i; j<a.length; ++j) if (a[i] > a[j]) swap(a[i],a[j]); Problem / Problem: Array wird nicht korrekt sortiert. Die Swap-Methode ist wirkungslos Behebung / Resolution: Neue Methode swap(int a[], int s, int t) oder swapping inline 2 points for correct problem description (swap method problem explained), 2 points for resolution