U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM

Size: px
Start display at page:

Download "U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM"

Transcription

1 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 PRACTICE EXAM Time Allowed: TWO HOURS ******** WITH SOLUTIONS ********** CLOSED BOOK Permitted materials: Silent n-programmable calculators or silent programmable calculators with their memories cleared are permitted in this examination. Instructions: October 24, 2018 Questions: Printed foreign language English dictionaries are permitted. No other material is permitted. Attempt ALL Questions. The real examination is out of 120 marks; BUT, The marks on this practice exam DON T ADD UP RIGHT!. Brief Documentation is at the end of the examination script Collection Types [16] Lists, Maps, and Sorting [31] Complexity, Big-O costs [20] Simulation with Collections [23] Traversing General Trees [20] Traversing Graphs [10] COMP 103 Page 1 of 16

2 Question 1. Collection Types [16 marks] (a) [4 marks] What is the key difference between Stacks and Queues? Stacks are LIFO, add and remove from same end Queues are FIFO, add and remove from opposite ends (b) [4 marks] Suppose you are writing a program to keep track of all the words that an ESL student has already learned and the words that they still get wrong. What collection type(s) would you use? Justify your choice. Set(s) because need to add and access words easily, but there is order required (c) [4 marks] Suppose you are writing a program to manage the keystroke signals from a keyboard. What Collection type should you use, and why? Queue - the signals need to be processed in the order they were received - FIFO (Question 1 continued on next page) COMP 103 Page 2 of 16

3 (Question 1 continued) (d) [4 marks] A Set has the same operations as a Collection. but it behaves differently. How is a Set different from a Collection? When would you use a Collection that isn t a Set? Set doesn t allow duplicates. When we need to allow duplicates. COMP 103 Page 3 of 16

4 Question 2. Concordances [31 marks] A Concordance is an index of words in a document. It should have an entry for each distinct word, and for each word, it should identify all the positions in the document where the word occurs. Suppose you are writing a program that creates concordances. Assume that the program can read a document into a List of words: private List <String> allwords; (a) [3 marks] Assume the positions of the words should be the index of the word in allwords (ie, the number of the word in the document). Typically, a concordance should be printed out in alphabetical order of the words. Define an appropriate Map type for the concordance field and initialise it. private Map <String, List <Integer>> concordance = new TreeMap<String, List<Integer>>();. (b) [11 marks] Complete the following makeconcordance method which should process the words in allwords to produce a concordance in the concordance field. public void makeconcordance(){ for ( int pos = 0; pos<allwords.size (); pos++){ String word = allwords.get(pos); if (!concordance.containskey(word)){ concordance.put(word, new ArrayList<Integer>()); concordance.get(word).add(pos); (Question 2 continued on next page) COMP 103 Page 4 of 16

5 (Question 2 continued) (c) [7 marks] Complete the following printalphabetically method to print out the concordance, in alphabetic order of the words, listing each word on a new line, followed by the positions of the word. E.g. afraid: [10, 49, 84, 143, 243, 589, 745] all: [53, 205, 301, 372, 632, 746] : Note: you can print all the values in a List or Collection with UI.print(myData). public void printalphabetically (){ for ( String word : concordance.keyset()){ UI. println (word+": "+concordance.get(word)); (Question 2 continued on next page) COMP 103 Page 5 of 16

6 (Question 2 continued) (d) [10 marks] [Hard and rather nasty!] It is sometimes useful to print a concordance in order of the frequency of the words. Complete the following printbyfrequency method to print out all the words in the concordance, in order of frequency. Each word should be on a new line, followed by the frequency. E.g. the: 89 of: 74 and: 68 : Hint: Copy the words and their frequencies to a different collection and sort them before printing them out. public void printbyfrequency (){ List <Map.Entry<String, Collection<Integer>>> list = new ArrayList<Map.Entry<String, Collection<Integer>>>(concordance.entrySet()); Collections. sort ( list, (Map.Entry<String, Collection<Integer>> me1, Map.Entry<String, Collection<Integer>> me2) > { if (me1.getvalue(). size ()>me2.getvalue().size ()) {return 1; if (me1.getvalue(). size ()<me2.getvalue().size ()) {return 1; return 0; ); for (Map.Entry<String, Collection<Integer>> me : list){ UI. println (me.getkey()+": "+me.getvalue().size()); COMP 103 Page 6 of 16

7 Question 3. Complexity: Big-O costs [20 marks] (a) [12 marks] What are the Big-O costs of the fragments of code below. Assume the size of the list is n. for ( int k = 0; k < list. size (); k++) { list.add( list.remove(0)); // cost= O( n ) times= // Total Cost = O( nˆ2 ) n for ( int k = 0; k < list. size (); k++) { for ( int j = 0; j < k; j++) { [or n(n 1)/2] if ( list.get(k). equals( list.get(j ))){ // cost= O( 1 ) times= nˆ2, UI. println ( list.get(k )); // cost= O( 1 ) times= 0.. nˆ2 // Total Cost = O( nˆ2 ) Map<String, Integer> mydata = new TreeMap<String, Integer>(); for ( String word : list ){ if (mydata.containskey(word)){ // cost = O( log(n) ) times= n mydata.put(word, mydata.get(word) 2); // cost = O( log(n) ) times= 0.. n 1 else { mydata.put(word, 1); // cost = O( log(n) ) times= 1.. n int max = 0; for ( String word : mydata.keyset()){ if (mydata.get(word) > max){ // cost = O( log(n) ) times= 1.. n max = mydata.get(word); // cost = O( log(n) ) times= 1.. n UI. println (max); // Total Cost = O( n log(n) ) (Question 3 continued on next page) COMP 103 Page 7 of 16

8 (Question 3 continued) (b) [4 marks] A program uses an ArrayList to store all the words in a document, and then searches for duplicate words by comparing each word in the list with every other word. When the List has 1000 words, the program takes 50 milliseconds to check for duplicates. If the List had 10,000 words, how long would you expect the program to take to check for duplicates? Explain why. 5000mS = 5 seconds. The algorithm is O(n 2 ). If you multiply the size of the list by 10, you will multiply the cost by 10 2 = 100 Therefore cost is 50 x 100 = 5000 (c) [4 marks] A better program uses a HashSet to check for duplicates by stepping through the list of words, checking the word is already in the HashSet, and then adding it to the HashSet if it is t present. When the document has 1,000 words, the program takes 10 milliseconds to check for duplicates If the document had 10,000 words, how long would you expect the program to take to check for duplicates? Explain why. 100 ms. The algorithm is O(n) - check costs O(1), do it n times If you multiply the size of the list by 10, you will multiply the cost by 10) Therefore cost is 10 x 10 = 100 COMP 103 Page 8 of 16

9 Question 4. Simulation with Collections [23 marks] Suppose you are writing a program to simulate a minibus service at an airport where minibuses take groups of passengers to lots of different suburbs. There is a separate queue for passengers for each destination Each time tick, a passenger may arrive at the minibus stop and joins the queue for their destination. If there is queue for their destination, then the passenger starts a new queue. Each time tick, if a minibus is ready, it is allocated to the destination with the longest queue, loads as many passengers as it can from the queue, and departs. If a queue is empty, it is removed. You are to write the passengerarrive and loadbus methods. The Passenger class has the following constructor and methods: Passenger class : public Passenger(); // make a new passenger (with a destination ) public String getdestination (); // removes 1 tick from remaining screening time The Bus class has the following constructor and methods: Bus class: public Bus(); // make a new bus public void loadpassenger(passenger p) // load a passenger onto the bus public boolean hasspace() // if space on bus for ather passenger public void depart() // make bus depart The MiniBusSimulation class has the following field, constructor and run method. public class MiniBusSimulation{ private Map<String, Queue<Passenger>> station; // map of queues for each destination public MiniBusSimulation(){ station = new HashMap<String, Queue<Passenger>>(); public void run (){ int time = 0; while (true){ time++; if (Math.random()<0.2) { passengerarrive(new Passenger()); if (Math.random()<0.01) { loadbus(new Bus()); // subquestion (a) // subquestion (b) Hint: sketch a diagram of the content of station. (Question 4 continued on next page) COMP 103 Page 9 of 16

10 (Question 4 continued) (a) [11 marks] Complete the following passengerarrive method which should add the passenger to the queue for their destination, creating the queue if there isn t one already. public void passengerarrive (Passenger p){ String dest = p.getdestination (); if ( station. get(dest)==null){ station. put(dest, new ArrayDeque<Passenger>()); station. get(dest ). offer (p); (b) [12 marks] Complete the following loadbus method which should choose the largest queue load passengers from the queue (up to the CAPACITY of the bus) remove the queue if it is empty make the bus depart public void loadbus(bus b){ Queue<Passenger> maxq = new ArrayDeque<Passenger>(); for ( String dest : station. keyset()){ if ( station. get(dest ). size ()> maxq.size()){ maxq = station.get(dest); while (!maxq.isempty() && b.hasspace()){ b.loadpassenger(maxq.poll()); b.depart (); COMP 103 Page 10 of 16

11 Question 5. Traversing Trees [20 marks] This question uses GTNodes in a program to record a tree of the evolutionary history of plant species. Each GTNode contains a Plant object, which contains information about a particular plant species. The children of a de are the plants that were direct descendents of the plant in the de. class GTNode<E> implements Iterable<GTNode<E>>{ public GTNode(E item); // constructor public E getitem(); // return item in the de public void addchild(gtnode<e>); // add a new child public void removechild(gtnode<e>); // remove a child public Iterator <GTNode<E>> iterator(); // enables the for (E child : de ){... class Plant public Plant( String name, boolean flowers ); // constructor public String getname(); public boolean hasflowers (); public String getleafshape(); (a) [9 marks] Complete the following hasplant, method which will return true if any plant in the subtree starting at de has the given name. To do this, it will need to traverse the tree under de. public boolean hasplant(gtnode<plant> de, String name){ if (de.getitem(). getname().equals(name)){ return true; for (GTNode<Plant> child : de){ if (hasplant( child, name)){ return true; return false ; (Question 5 continued on next page) COMP 103 Page 11 of 16

12 (Question 5 continued) (b) [11 marks] It is uncommon for a plant without flowers to have several descendent plants with flowers. In some cases, this indicates there is a missing plant in the evolutionary history. Complete the following fixtree method which should find any plant in the tree which does t have flowers, has at least one child without flowers, and at least two children with flowers. For each such plant, it should insert a new unkwn plant (name:?? ) with flowers as a child of the de and as parent of the children with flowers. For example: AA AA BB CC FF BB CC FF DD EE KK GG DD?? GG HH LL EE KK HH LL (Each de in the figure contains the name of a plant and whether it has flowers.) public void fixtree (GTNode<Plant> tree){ if (! tree.getitem (). hasflowers()){ int numflowerchildren = 0; int numnoflowerchildren = 0; for (GTNode<Plant> child : tree){ if ( child. getitem (). hasflowers()) {numflowerchildren++; else {numnoflowerchildren++; if (numflowerchildren>=2 && numnoflowerchildren>=1){ GTNode<Plant> unkwn = new GTNode<Plant>(new Plant("??", true)); for (GTNode<Plant> child : tree){ if ( child. getitem (). hasflowers()) {unkwn.addchild(child); for (GTNode<Plant> child : unkwn){tree.removechild(child); tree. addchild(unkwn); for (GTNode<Plant> child : tree){ fixtree ( child ); COMP 103 Page 12 of 16

13 Question 6. Traversing Graphs [10 marks] You are writing a program to analyse social networks. Your program stores information about all the people in the network in a Collection of Person objects. private Collection <Person> socialnetwork; Each Person object contains a Collection of the person s friends. class Person public String getname(); public Collection <Person> getfriends(); (a) [5 marks] Complete the following isconnected method which should return true if two Persons are connected via a sequence of friend relations in the network. Hints: Use a visited set. You will need an additional recursive method. public boolean isconnected(person p1, Person p2){ Set<Person> visited = new HashSet<Person>(); return isconnected(p1, p2, visited ); public boolean isconnected(person p1, Person p2, Set<Person> visited){ if ( visited. contains(p1)) { return false ; if (p1. equals(p2)) { return true; visited. add(p1); for (Person friend : p1. getfriends ()){ if (isconnected( friend, p2, visited ) ) { return true; return false ; (Question 6 continued on next page) COMP 103 Page 13 of 16

14 (Question 6 continued) (b) [5 marks] A more interesting question is whether two people are connected over at most n links, where n is a small integer like 4 or 5. Complete a new version of isconnected that returns true if two Persons are connected over at most n links: public boolean isconnected(person p1, Person p2, int n){ return isconnected(p1, p2, n, visited ); public boolean isconnected(person p1, Person p2, int n, Set<Person> visited){ if (n < 0) { return false ; if ( visited. contains(p1)) { return false ; if (p1. equals(p2)) { return true; visited. add(p1); for (Person friend : p1. getfriends ()){ if (isconnected( friend, p2, n 1, visited ) ) { return true; visited. remove(p1); return false ; * * * * * * * * * * * * * * * COMP 103 Page 14 of 16

15 Documentation for COMP 103 Exam Brief, simplified specifications of some relevant Java collection types and classes. Note: E stands for the type of the item in the collection. interface Collection <E> public boolean isempty() // cost : O(1) for standard collection classes public int size () // cost : O(1) for standard collection classes public void clear () public boolean add(e item) public boolean contains(object item) public boolean remove(object element) interface List <E> extends Collection<E> // Implementations: ArrayList public boolean isempty() public int size () public void clear () public E get( int index) public E set( int index, E element) public boolean contains(object item) public void add(int index, E element) public E remove(int index) public boolean remove(object element) // cost : O(1) // cost : O(1) // cost : O(n) // cost : O(n) ( unless index close to end.) // cost : O(n) ( unless index close to end.) // cost : O(n) interface Set extends Collection<E> // Implementations: HashSet, TreeSet public boolean isempty() public int size () public void clear () public boolean add(e item) // cost : O(1) for HashSet, // O(log(n)) for TreeSet public boolean contains(object item) // cost : O(1) for HashSet, // O(log(n)) for TreeSet public boolean remove(object element) // cost : O(1) for HashSet, // O(log(n)) for TreeSet interface Map<K, V> // Implementations: HashMap, TreeMap public V get(k key) // cost : O(1) for HashMap, O(log(n)) for TreeMap public V put(k key, V value) // cost : O(1) for HashMap, O(log(n)) for TreeMap public V remove(k key) // cost : O(1) for HashMap, O(log(n)) for TreeMap public boolean containskey(k key) // cost : O(1) for HashMap, O(log(n)) for TreeMap public Set<K> keyset() // cost : O(1) public Collection <V> values() // cost : O(1) public Set<Map.Entry<K,V>> entryset() // returns set of key value pairs // ( get returns null if the key is t present ) // (put and remove return the old value, if any)

16 interface Queue<E> extends Collection<E> // Implementations: ArrayDeque, LinkedList, PriorityQueue public boolean isempty() public int size () public void clear () public E peek () // cost : O(1) for ArrayDeque, LinkedList, // O(1) for PriorityQueue public E poll () // cost : O(1) for ArrayDeque, LinkedList, // O(log(n)) for PriorityQueue public boolean offer (E element) // cost : O(1) for ArrayDeque, LinkedList, // O(log(n)) for PriorityQueue // (peek and poll return null if the queue is empty) class Stack<E> implements Collection<E> public boolean isempty() public int size () public void clear () public E peek () // cost : O(1) public E pop () // cost : O(1) public E push (E element) // cost : O(1) // (peek and pop return null if the queue is empty) class Collections public void sort ( List <E> list); // cost = O(n log(n)) in general // O(n) almost sorted public void sort ( List <E> list, (E e1, E e2) >{..);// cost = O(n log(n)) in general // O(n) almost sorted public void swap(list<e> list, int i, int j ); // cost = O(1) public void reverse ( List <E> list); // cost = O(n) public void shuffle ( List <E> list); // cost = O(n) interface Comparable<E> // Items can be compared for sorting or a priority queue. public int compareto(e other); // Comparable objects must have a compareto method: // returns ve if this comes before other ; // +ve if this comes after other, // 0 if this and other are the same interface Iterable <E> // can use a foreach loop on these items public Iterator <E> iterator() ; // returns an Iterator object Integer and Double constants: Integer. MAX VALUE; Integer.MIN VALUE; Double.MAX VALUE; Double.NaN; Double.POSITIVE INFINITY; Double.NEGATIVE INFINITY;

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

COMP 103 : Test. 2018, Sept 12//(Corrected)

COMP 103 : Test. 2018, Sept 12//(Corrected) Family Name:.............................. Other Names:............................. Student ID:................................ Signature.................................. COMP 103 : Test 2018, Sept 12//(Corrected)

More information

COMP 103 : Test. 2019, Jan 9 ** WITH SOLUTIONS **

COMP 103 : Test. 2019, Jan 9 ** WITH SOLUTIONS ** Family Name:.............................. Other Names:...................................... Signature.................................. COMP 103 : Test 2019, Jan 9 ** WITH SOLUTIONS ** Instructions Time

More information

COMP 103 : Test. 2018, Sept 12//(Corrected) ** WITH SOLUTIONS

COMP 103 : Test. 2018, Sept 12//(Corrected) ** WITH SOLUTIONS Family Name:.............................. Other Names:............................. Student ID:................................ Signature.................................. COMP 103 : Test 2018, Sept 12//(Corrected)

More information

EXAMINATIONS 2016 TRIMESTER 2

EXAMINATIONS 2016 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

EXAMINATIONS 2017 TRIMESTER 2

EXAMINATIONS 2017 TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2017 TRIMESTER 2 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

More information

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION

More information

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction

More information

EXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 Trimester 1, MID-TERM TEST COMP103 Introduction

More information

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 103: Test

More information

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 MID YEAR COMP103 Introduction to Data

More information

Model Solutions. COMP 103: Test April, 2013

Model Solutions. COMP 103: Test April, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 40 minutes

More information

Model Solutions. COMP 103: Mid-term Test. 21st of August, 2014

Model Solutions. COMP 103: Mid-term Test. 21st of August, 2014 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 50 minutes

More information

Model Solutions. COMP 103: Test May, 2013

Model Solutions. COMP 103: Test May, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 45 minutes

More information

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2007 SUMMER TRIMESTER COMP103 Introduction

More information

Model Solutions. COMP 103: Mid-term Test. 19th of August, 2016

Model Solutions. COMP 103: Mid-term Test. 19th of August, 2016 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 45 minutes

More information

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 MID YEAR COMP103 Introduction to Data

More information

****** NOTE!! THIS CONTAINS SOLUTIONS ***** TRIMESTER 2

****** NOTE!! THIS CONTAINS SOLUTIONS ***** TRIMESTER 2 T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N ****** NOTE!! THIS CONTAINS SOLUTIONS *****

More information

COMP103 Test. 5 Sept, 2007

COMP103 Test. 5 Sept, 2007 Family Name:.......................... Other Names:.......................... ID Number:............................ COMP103 Test 5 Sept, 2007 Instructions Time: 90 minutes. Answer all the questions. There

More information

EXAMINATIONS 2010 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2010 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 MID YEAR COMP103 Introduction to Data

More information

CONTAINS SOLUTIONS!!!

CONTAINS SOLUTIONS!!! T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2007 END YEAR COMP103 Introduction to Data

More information

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2010 END YEAR COMP103 Introduction to Data

More information

COMP 103 Introduction to Data Structures and Algorithms

COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data

More information

EXAMINATIONS 2006 SUMMER TRIMESTER. COMP103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2006 SUMMER TRIMESTER. COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2006 SUMMER TRIMESTER COMP103 Introduction to Data Structures and Algorithms

More information

EXAMINATIONS 2013 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2013 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2013 TRIMESTER 1 COMP 103 INTRODUCTION

More information

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:

More information

EXAMINATIONS 2011 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2011 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 END YEAR COMP103 Introduction to Data

More information

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2016 CSC 321: Data Structures Fall 2016 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:

More information

CSC 321: Data Structures. Fall 2017

CSC 321: Data Structures. Fall 2017 CSC 321: Data Structures Fall 2017 Balanced and other trees balanced BSTs: AVL trees, red-black trees TreeSet & TreeMap implementations heaps priority queue implementation heap sort 1 Balancing trees recall:

More information

EXAMINATIONS 2012 END-OF-YEAR COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2012 END-OF-YEAR COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 END-OF-YEAR COMP 103 INTRODUCTION TO

More information

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018

Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018 CS 61B Abstract Data Types Spring 2018 Exam Prep 5: February 12, 2018 1 Assorted ADTs A list is an ordered collection, or sequence. 1 interface List { 2 boolean add(e element); 3 void add(int index,

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net Sorting Tree Balancing A sorted tree is balanced iff for each node holds: Math.abs(size(node.left)

More information

PIC 20A Collections and Data Structures

PIC 20A Collections and Data Structures PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write

More information

17. Java Collections. Organizing Data. Generic List in Java: java.util.list. Type Parameters ( Parameteric Polymorphism ) Data Structures that we know

17. Java Collections. Organizing Data. Generic List in Java: java.util.list. Type Parameters ( Parameteric Polymorphism ) Data Structures that we know Organizing Data Data Structures that we know 17 Java Collections Generic Types, Iterators, Java Collections, Iterators Today: Arrays Fixed-size sequences Strings Sequences of characters Linked Lists (up

More information

CSE 2123: Collections: Priority Queues. Jeremy Morris

CSE 2123: Collections: Priority Queues. Jeremy Morris CSE 2123: Collections: Priority Queues Jeremy Morris 1 Collections Priority Queue Recall: A queue is a specific type of collection Keeps elements in a particular order We ve seen two examples FIFO queues

More information

Topic 10: The Java Collections Framework (and Iterators)

Topic 10: The Java Collections Framework (and Iterators) Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of

More information

Java Collections Framework. 24 April 2013 OSU CSE 1

Java Collections Framework. 24 April 2013 OSU CSE 1 Java Collections Framework 24 April 2013 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Points off Total off Net Score. CS 314 Final Exam Spring 2016 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1 Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing

More information

Java Map and Set collections

Java Map and Set collections Java Map and Set collections Java Set container idea interface Java Map container idea interface iterator concordance example Java maps and sets [Bono] 1 Announcements This week s lab based on an example

More information

Collections Questions

Collections Questions Collections Questions https://www.journaldev.com/1330/java-collections-interview-questions-and-answers https://www.baeldung.com/java-collections-interview-questions https://www.javatpoint.com/java-collections-interview-questions

More information

Class 32: The Java Collections Framework

Class 32: The Java Collections Framework Introduction to Computation and Problem Solving Class 32: The Java Collections Framework Prof. Steven R. Lerman and Dr. V. Judson Harward Goals To introduce you to the data structure classes that come

More information

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods Adam Blank Lecture 5 Winter 2019 CS 2 Introduction to Programming Methods CS 2: Introduction to Programming Methods Java Collections Abstract Data Types (ADT) 1 Abstract Data Type An abstract data type

More information

CS61BL: Data Structures & Programming Methodology Summer 2014

CS61BL: Data Structures & Programming Methodology Summer 2014 CS61BL: Data Structures & Programming Methodology Summer 2014 Instructor: Edwin Liao Midterm 2 July 30, 2014 Name: Student ID Number: Section Time: TA: Course Login: cs61bl-?? Person on Left: Possibly

More information

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of

More information

CS 314 Exam 2 Spring 2018

CS 314 Exam 2 Spring 2018 Points off 1 2 3 4 5 Total off CS 314 Exam 2 Spring 2018 Your Name Your UTEID Circle your TA's Name: Aish Anthony Chris Dayanny Hailey Ivan Jacob Joseph Lucas Shelby Instructions: 1. There are 5 questions

More information

HEAPS & PRIORITY QUEUES

HEAPS & PRIORITY QUEUES HEAPS & PRIORITY QUEUES Lecture 13 CS2110 Spring 2018 Announcements 2 A4 goes out today! Prelim 1: regrades are open a few rubrics have changed No Recitations next week (Fall Break Mon & Tue) We ll spend

More information

Outline. runtime of programs algorithm efficiency Big-O notation List interface Array lists

Outline. runtime of programs algorithm efficiency Big-O notation List interface Array lists Outline runtime of programs algorithm efficiency Big-O notation List interface Array lists Runtime of Programs compare the following two program fragments: int result = 1; int result = 1; for (int i=2;

More information

Abstract Data Types Data Structure Grand Tour Java Collections.

Abstract Data Types Data Structure Grand Tour Java Collections. Abstract Data Types Data Structure Grand Tour Java Collections http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Stacks and Queues Hopefully you have met with your partner

More information

Collections (Java) Collections Framework

Collections (Java) Collections Framework Collections (Java) https://docs.oracle.com/javase/tutorial/collections/index.html Collection an object that groups multiple elements into a single unit. o store o retrieve o manipulate o communicate o

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net MULTIVARIATE TREES 2 Multivariate Trees general class of trees nodes can have any number of children

More information

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number: CSE143 Midterm Summer 2017 Name of Student: Section (e.g., AA): Student Number: The exam is divided into six questions with the following points: # Problem Area Points Score ---------------------------------------------

More information

Generics Collection Framework

Generics Collection Framework Generics Collection Framework Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Generics

More information

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

27/04/2012. Objectives. Collection. Collections Framework. Collection Interface. Collection algorithm. Legacy collection Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"

More information

Name CPTR246 Spring '17 (100 total points) Exam 3

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

Abstract Data Types Data Structure Grand Tour Java Collections.

Abstract Data Types Data Structure Grand Tour Java Collections. Abstract Data Types Data Structure Grand Tour Java Collections http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png } Stacks and Queues Ideally, you have met with your partner

More information

CSE 143 Au03 Final Exam Page 1 of 15

CSE 143 Au03 Final Exam Page 1 of 15 CSE 143 Au03 Final Exam Page 1 of 15 Reference information about many standard Java classes appears at the end of the test. You might want to tear off those pages to make them easier to refer to while

More information

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so. CSE 143 Sp04 Midterm 2 Page 1 of 10 Reference information about some standard Java library classes appears on the last pages of the test. You can tear off these pages for easier reference during the exam

More information

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering

Java Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering Readings and References Java Collections References» "Collections", Java tutorial» http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Winter 2003 Software Engineering http://www.cs.washington.edu/education/courses/403/03wi/

More information

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

NAME: c. (true or false) The median is always stored at the root of a binary search tree. EE 322C Spring 2009 (Chase) Exam 2: READ THIS FIRST. Please use the back side of each page for scratch paper. For some of the questions you may need to think quite a bit before you write down an answer.

More information

Tables and Priority Queues

Tables and Priority Queues Chapter 12 Tables and Priority Queues 2011 Pearson Addison-Wesley. All rights reserved 12 A-1 The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that

More information

SUMMARY INTRODUCTION COLLECTIONS FRAMEWORK. Introduction Collections and iterators Linked list Array list Hash set Tree set Maps Collections framework

SUMMARY INTRODUCTION COLLECTIONS FRAMEWORK. Introduction Collections and iterators Linked list Array list Hash set Tree set Maps Collections framework SUMMARY COLLECTIONS FRAMEWORK PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 2016 Introduction Collections and

More information

infix expressions (review)

infix expressions (review) Outline infix, prefix, and postfix expressions queues queue interface queue applications queue implementation: array queue queue implementation: linked queue application of queues and stacks: data structure

More information

Java Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering

Java Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering Readings and References Java Collections "Collections", Java tutorial http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Spring 2004 Software Engineering http://www.cs.washington.edu/education/courses/403/04sp/

More information

COMP 250. Lecture 29. interfaces. Nov. 18, 2016

COMP 250. Lecture 29. interfaces. Nov. 18, 2016 COMP 250 Lecture 29 interfaces Nov. 18, 2016 1 ADT (abstract data type) ADT s specify a set of operations, and allow us to ignore implementation details. Examples: list stack queue binary search tree priority

More information

Tables and Priority Queues!

Tables and Priority Queues! Chapter 12! Tables and Priority Queues! 2011 Pearson Addison-Wesley. All rights reserved 12 A-1 2015-11-30 21:52:31 1/49 Chapter-12.pdf (#14) The ADT Table The ADT table, or dictionary! Uses a search key

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces Taking Stock IE170: Algorithms in Systems Engineering: Lecture 7 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University January 29, 2007 Last Time Practice Some Sorting Algs

More information

Abstract Data Types Data Structure Grand Tour Java Collections.

Abstract Data Types Data Structure Grand Tour Java Collections. Abstract Data Types Data Structure Grand Tour Java Collections http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png } Stacks and Queues Ideally, you have met with your partner

More information

Software 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface

Software 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface Java Collections Framework Collection: a group of elements Based Design: Software 1 with Java Java Collections Framework s s Algorithms Recitation No. 6 (Collections) 2 Collection s Online Resources Collection

More information

Ū P O K O O T E I K A A M Ā U I U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1 *** WITH SOLUTIONS ***

Ū P O K O O T E I K A A M Ā U I U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1 *** WITH SOLUTIONS *** T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1 *** WITH SOLUTIONS

More information

CMSC 202H. Containers and Iterators

CMSC 202H. Containers and Iterators CMSC 202H Containers and Iterators Container Definition A container is a data structure whose purpose is to hold objects. Most languages support several ways to hold objects Arrays are compiler-supported

More information

CS61BL Summer 2013 Midterm 2

CS61BL Summer 2013 Midterm 2 CS61BL Summer 2013 Midterm 2 Sample Solutions + Common Mistakes Question 0: Each of the following cost you.5 on this problem: you earned some credit on a problem and did not put your five digit on the

More information

Collections Framework: Part 2

Collections Framework: Part 2 Collections Framework: Part 2 Computer Science and Engineering College of Engineering The Ohio State University Lecture 18 Collection Implementations Java SDK provides several implementations of Collection

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources

More information

CS2110: Software Development Methods. Maps and Sets in Java

CS2110: Software Development Methods. Maps and Sets in Java CS2110: Software Development Methods Maps and Sets in Java These slides are to help with the lab, Finding Your Way with Maps This lab uses Maps, and Sets too (but just a little). Readings from textbook:

More information

CONTAİNERS COLLECTİONS

CONTAİNERS COLLECTİONS CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping

More information

University of Maryland College Park Dept of Computer Science

University of Maryland College Park Dept of Computer Science University of Maryland College Park Dept of Computer Science CMSC132H Fall 2009 Midterm First Name (PRINT): Last Name (PRINT): University ID: I pledge on my honor that I have not given or received any

More information

Announcements. Container structures so far. IntSet ADT interface. Sets. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am

Announcements. Container structures so far. IntSet ADT interface. Sets. Today s topic: Hashing (Ch. 10) Next topic: Graphs. Break around 11:45am Announcements Today s topic: Hashing (Ch. 10) Next topic: Graphs Break around 11:45am Container structures so far Array lists O(1) access O(n) insertion/deletion (average case), better at end Linked lists

More information

CS 314 Midterm 2 Fall 2012

CS 314 Midterm 2 Fall 2012 Points off 1 2 3 4 5 Total off Net Score CS 314 Midterm 2 Fall 2012 Your Name_ Your UTEID Circle yours TA s name: John Zihao Instructions: 1. There are 5 questions on this test. 2. You have 2 hours to

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

An Interface with Generics

An Interface with Generics Generics CSC207 Software Design Generics An Interface with Generics Generics class foo introduces a class with a type parameter T. introduces a type parameter that is required to be

More information

Lecture 13: AVL Trees and Binary Heaps

Lecture 13: AVL Trees and Binary Heaps Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 4: Generic Type and Collections Stéphane Airiau Université Paris-Dauphine Lesson 4: Generic Type and Collections (Stéphane Airiau) Java 1 Linked List 1 public class Node

More information

182 review 1. Course Goals

182 review 1. Course Goals Course Goals 182 review 1 More experience solving problems w/ algorithms and programs minimize static methods use: main( ) use and overload constructors multiple class designs and programming solutions

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps Lecture 12 1 Review: Data Structure A data structure is a collection of data organized in some fashion The structure not only stores data but also supports operations for accessing/manipulating the data

More information

PRIORITY QUEUES AND HEAPS

PRIORITY QUEUES AND HEAPS PRIORITY QUEUES AND HEAPS Lecture 17 CS2110 Spring 201 Readings and Homework 2 Read Chapter 2 A Heap Implementation to learn about heaps Exercise: Salespeople often make matrices that show all the great

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 3 Online Resources

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ ABSTRACT DATATYPES 2 Abstract Datatype (ADT)

More information

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures

Announcements HEAPS & PRIORITY QUEUES. Abstract vs concrete data structures. Concrete data structures. Abstract data structures Announcements A due TOMORROW. Late deadline is Sunday. A5 released. Due next Thursday. Deadline for Prelim 1 regrade requests is tomorrow. Remember to complete your TA evaluations by tonight. HEAPS & PRIORITY

More information

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 36. Collections Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Arrays Class Interface Collection and Class Collections ArrayList Class Generics LinkedList Class Collections Algorithms

More information

Type Parameters: E - the type of elements returned by this iterator Methods Modifier and Type Method and Description

Type Parameters: E - the type of elements returned by this iterator Methods Modifier and Type Method and Description java.lang Interface Iterable Type Parameters: T - the type of elements returned by the iterator Iterator iterator() Returns an iterator over a set of elements of type T. java.util Interface Iterator

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

Today's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps

Today's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps Today's Agenda > To give a practical introduction to data structures > To look specifically at Lists, Sets, and Maps > To talk briefly about Generics in Java > To talk about interfaces in Java Data Structures

More information

CS314 Exam 2 - Spring Suggested Solution and Criteria 1

CS314 Exam 2 - Spring Suggested Solution and Criteria 1 CS314 Spring 2016 Exam 2 Solution and Grading Criteria. Grading acronyms: AIOBE - Array Index out of Bounds Exception may occur BOD - Benefit of the Doubt. Not certain code works, but, can't prove otherwise

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No

More information