INF3110 Group 2 EXAM 2013 SOLUTIONS AND HINTS. But first, an example of compile-time and run-time type checking Imagine we have the following code. What.

Slides:



Advertisements
Similar presentations
Algorithm Analysis Input size Time I1 T1 I2 T2 …
Advertisements

Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
PRESENTED BY MATTHEW GRAF AND LEE MIROWITZ Linked Lists.
24-Aug-14 Abstract Classes and Interfaces. Java is “safer” than Python Python is very dynamic—classes and methods can be added, modified, and deleted.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
More about functions Plus a few random things. 2 Tail recursion A function is said to be tail recursive if the recursive call is the very last thing it.
Java Review Interface, Casting, Generics, Iterator.
Review of Exercises from Chapter 17 Statistics, Spring
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Recursion, pt. 2: Thinking it Through. What is Recursion? Recursion is the idea of solving a problem in terms of solving a smaller instance of the same.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Lecture 11: Polymorphism and Dynamic Binding Polymorphism Static (compile-time) binding Dynamic (run-time) binding.
Midterm Logistics Where? 2050 VLSB When? Monday, 4:10 to 5:40 What to do? –“Review problems” from Thursday/Friday in UCWise. –Two practice exams and solutions.
28-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Dec Abstract Classes and Interfaces. Eclipse trick CTRL + D will remove lines Organization Bookmarks TODOs – marking something as //TODO allows.
9-1 Solving 3 by 3 Systems Day 1. Umm… did she say 3 by 3?? Just like the 2 by 2 systems, we will solve the 3 by 3 systems. How many methods did we choose.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Exceptions Handling Exceptionally Sticky Problems.
CS/ENGRD 2110 FALL 2014 Lecture 6: Consequence of type, casting; function equals 1.
Problem of the Day  Why are manhole covers round?
Session 4: PREPARE FOR TESTS Year 7 Life Skills Student Wall Planner and Study Guide.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Everything you need to know to successfully use THE SCIENTIFIC METHOD.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
CSE 143 Lecture 23 Polymorphism; the Object class read slides created by Marty Stepp and Ethan Apter
More on Polymorphism. Ever have one of those days?
Variables, Primitives, and Objects A Visual Learner’s Guide.
Algorithm Analysis Data Structures and Algorithms (60-254)
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Abstract Classes and Interfaces 5-Dec-15. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
CS162 Week 1 Kyle Dewey. Overview Basic Introduction CS Accounts Scala survival guide.
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
M1G Introduction to Programming 2 5. Completing the program.
CSC 213 – Large Scale Programming Prof. Matthew Hertz WTC 207D /
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
CSE 143 Lecture 12 Inheritance slides created by Ethan Apter
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
BIT 143: Programming – Data Structures It is assumed that you will also be present for the slideshow for the first day of class. Between that slideshow.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
Using the Eclipse Debugger Extra Help Session (Christina Aiello)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Week91 APCS-A: Java Problem Solving November 2, 2005.
Introduction to Exceptions in Java CS201, SW Development Methods.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
By : Jack Kelenjian. Is a career in computers right for me? To determine if a career in computers is right for someone you need to identify what makes.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
课标人教实验版 高二 Module 6 Unit 3. Listening on workbook.
The Data Large Number of Workbooks Each Workbook has multiple worksheets Transaction worksheets have large (LARGE) number of lines (millions of records.
5 ONLINE DATING TIPS EVERY NEWBIE SHOULD KNOW. So you've finally given in to your friend's suggestion. You've created your own online dating account and.
CSE 143 Lecture 13 Inheritance slides created by Ethan Apter
Eighth Lecture Exception Handling in Java
Abstract Classes and Interfaces
Handling Exceptionally Sticky Problems
Last Class We Covered Data representation Binary numbers ASCII values
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Writing Methods AP Computer Science A.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Handling Exceptionally Sticky Problems
Arrays.
Presentation transcript:

INF3110 Group 2 EXAM 2013 SOLUTIONS AND HINTS

But first, an example of compile-time and run-time type checking Imagine we have the following code. What would be returned by «new B().me()»? An A object? A B object? So, static is compile-time and dynamic is run-time. In this example (Java) will try to figure out the types of all «elements», in an effort to prevent bad things from happening. The compiler only «sees» an A object being returned, but the object is actually a B object. Are there any potential problems with this? Since the compiler thinks it’s an A object, and B extends A, inheriting methods, this line is legal: new B().me().doA(); But it’s actually a B object, so: new B().me().doB(); should be legal too? But it’s not. The compiler can’t figure out that this should be legal. So we have to cast the object to a B object: ((B) new B().me().doB(); The compiler then «trusts» the programmer and lets it pass without it being able to verify that is actually is ok. Full example can be found at

So we’re to draw the run-time stack while executing reduction(address()) Yes, we did this exact exercise a couple of weeks ago So, how do we start?

So, we want to figure out if quality should be called with value or by reference

What would the different effects be? So in conclusion? By reference so the printLabel method has access to change the value in printQuality

A person does not define a «visitingAddress» method Can avoid the type error by casting p to VisitingPerson But is this actually safe? Why or why not?

So, we want to print the name as well when calling upon printLabel. At the same time we wish to preserve the call, so it should still be p.addr.printLabel(); The given hints here are what you may assume. So we have calls to superclasses using super.x() and we have support for anonymous classes. The solution given is this, but someone more awake than me pointed me to a problem with this solution So this would probably make more sense If you get something similar and you are completly stuck, work around the problem. It’s better to solve the problem is a «bad» way than do nothing. Any ideas on how to work around this problem?

So, we’re started of nice and easy once again. What does fold actually do? So fold is a curried function, recurses over a list, producing a value passed on as ‘y’ by calling a given function on the first element and the ‘y’ given. So the first result is (((0+1)+2)+3) = 6 The second expression is to mess with your heads. But ok, what is happening? So inside the paranthesis, we have an anonymous function that takes a function as a parameter and calls that function with the number 2. The function it’s given, returns a new anonymous function that takes a parameter y, and calculates 2 * y. I’ll have to draw this to make it into something more sensible probably. So the result of the second is 2 * 0 = 0

The b, c, d, e and f excersises are quite advanced, with a LOT of text and they are also quite tied together. To be able to go through the rest of the exam, I’ve decided to skip them. But they are a great way to challenge yourself when studing for the final exam, so highly recommended to try and understand them. Let’s do something scary and do it together, live. If you want the steps, you can find them on the solutions for 2013 in the course page for 2014.

So we want a predicate to convert a tree into a depth-first traversed list and we’re given a hint saying we can use the predicate append/3. So how should we solve problems like this? Let’s start with the base case, what is the base case in this scenario? So, having gotten the base case, what needs to happen in the other nodes?

Ok, we want to be able to remove ONE instance of a given value from a list. We should get multiple «hits» if the variable occurs multiple times in the list. So, let’s once again start with the base case. When do we want to «stop»? … considering we are using recursion, why can’t we have a base case something like: ‘del(_, [], []).’ ? For the non base case, when do we want to continue then? And that’s it, but…

So, for the last excersise we want to remove a given index in a list. They provide us a couple of hints, like if we get 0 as index, we shouldn’t remove anything, so maybe we need multiple base cases this time? So what would the base case(s) be? So what do we want to do if none of the base cases are true? Remember that we have to «force» prolog to calculate values. Yes, there is a paranthesis and a. missing in the solution ;)

Thanks for coming to the group lectures. I’ve learned a lot from all of you and have enjoyed spending this time with you. I hope you have learned something from these sessions, and wish you all the best of luck for the exam. Oh, and btw, I found the exam given last year, send me a mail at if you want me to send it to you. I can’t promise it’s relevant, and I also can’t provide a solution, but you can take a look if you want.