Tutorial 4 Algorithms and Data Structures

Similar documents
CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

Final Exam in Algorithms and Data Structures 1 (1DL210)

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

Fundamental Algorithms

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

INSTITUTE OF AERONAUTICAL ENGINEERING

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Graph Search Methods. Graph Search Methods

Graph Search Methods. Graph Search Methods

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

CS301 - Data Structures Glossary By

DESIGN AND ANALYSIS OF ALGORITHMS

CS171 Final Practice Exam

III Data Structures. Dynamic sets

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

CS171 Final Practice Exam

HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015

Chapter 22 Elementary Graph Algorithms

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

Final Exam in Algorithms and Data Structures 1 (1DL210)

Standard ADTs. Lecture 19 CS2110 Summer 2009

TIE Graph algorithms

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

Some major graph problems

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CISC-235* Test #3 March 19, 2018

Inf 2B: Graphs, BFS, DFS

CS2 Algorithms and Data Structures Note 9

I A graph is a mathematical structure consisting of a set of. I Formally: G =(V, E), where V is a set and E V V.

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

CSC2100-Data Structures

a) State the need of data structure. Write the operations performed using data structures.

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Final Examination CSE 100 UCSD (Practice)

CS 206 Introduction to Computer Science II

Algorithms: Lecture 10. Chalmers University of Technology

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

CS 310 Advanced Data Structures and Algorithms

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

Lecture 9 Graph Traversal

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

ECE250: Algorithms and Data Structures Midterm Review

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

csci 210: Data Structures Graph Traversals

Lecture 3: Graphs and flows

Module 11: Additional Topics Graph Theory and Applications

VALLIAMMAI ENGINEERING COLLEGE

Lecture 18. Collision Resolution

TIE Graph algorithms

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

Course Review. Cpt S 223 Fall 2009

Hash Tables. Gunnar Gotshalks. Maps 1

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Lecture 16 More on Hashing Collision Resolution

You must include this cover sheet. Either type up the assignment using theory5.tex, or print out this PDF.

Outline. Graphs. Divide and Conquer.

22.3 Depth First Search

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Lecture 10 Graph algorithms: testing graph properties

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

Lesson 1 Introduction to Path Planning Graph Searches: BFS and DFS

Graph Search. Adnan Aziz

CSI 604 Elementary Graph Algorithms

DATA STRUCTURES AND ALGORITHMS

Chapter 10. Fundamental Network Algorithms. M. E. J. Newman. May 6, M. E. J. Newman Chapter 10 May 6, / 33

Teach A level Compu/ng: Algorithms and Data Structures

More on Hashing: Collisions. See Chapter 20 of the text.

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

Data Structure and Algorithm, Spring 2017 Final Examination

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Homework Assignment #3 Graph

How to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

Old final Exam Question Answer true or false and justify your answer: Since it takes at least n-1 key comparisons to find the min of n data items and

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Language-based Protection: Solution

Logic, Algorithms and Data Structures ADT:s & Hash tables. By: Jonas Öberg, Lars Pareto

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Closed Book Examination. One and a half hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Wednesday 20 th January 2010

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Basic Graph Algorithms (CLRS B.4-B.5, )

Computational Optimization ISE 407. Lecture 19. Dr. Ted Ralphs

CS8391-DATA STRUCTURES

CS 8391 DATA STRUCTURES

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Topic 1 Uninformed Search

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

Transcription:

Tutorial 4 Algorithms and Data Structures Jonathan Cederberg <jonathan.cederberg@it.uu.se> Monday, October 11 th, 2010

Outline Example 1 Example 2 3 AD 10 Dept. of Information Technology - 2 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Outline Example 1 Example 2 3 AD 10 Dept. of Information Technology - 3 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Problem (15p) Assume that we a set of four digit numbers that we want to store in a hash table: 1066 1789 1945 1600 1915 2005 1000 Consider two hash functions hashcode 1 (x) = x mod 10 and x (x mod 1000) hashcode 2 (x) = 1000. Assume numbers arrive from left to right. a) Draw the resulting hash table if we use hashcode 1 and linear probing to resolve collisions. b) Draw the resulting hash table if we use hashcode 2 and chaining to resolve collisions. AD 10 Dept. of Information Technology - 4 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Problem (15p) Assume that we a set of four digit numbers that we want to store in a hash table: 1066 1789 1945 1600 1915 2005 1000 Consider two hash functions hashcode 1 (x) = x mod 10 and x (x mod 1000) hashcode 2 (x) = 1000. Assume numbers arrive from left to right. a) Draw the resulting hash table if we use hashcode 1 and linear probing to resolve collisions. b) Draw the resulting hash table if we use hashcode 2 and chaining to resolve collisions. c) With the additional knowledge that the input numbers are all years, which of the two hashfunctions would be the better choice for arbitrary input? AD 10 Dept. of Information Technology - 4 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Outline Example 1 Example 2 3 AD 10 Dept. of Information Technology - 5 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Graphs - what are they good for? Provide a good representation of... Data structures (linked lists, tables, trees) The internet DNA A road net A sewer system The circulation of the blood in the body... Google uses graphs! AD 10 Dept. of Information Technology - 6 - Jonathan Cederberg jonathan.cederberg@it.uu.se

And then? With the representation, we can isolate interesting properties of the graph, and thus discover interesting properties of the underlying system. Example: A road system is abstracted as a directed graph in the natural way. What information would computing the strongly connected components of this graph give us? AD 10 Dept. of Information Technology - 7 - Jonathan Cederberg jonathan.cederberg@it.uu.se

AD 10 Dept. of Information Technology - 8 - Jonathan Cederberg jonathan.cederberg@it.uu.se

AD 10 Dept. of Information Technology - 9 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Whether there is a path from every junction to all other junctions. AD 10 Dept. of Information Technology - 9 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Fundamentals: DFS and BFS We look a vertex at a time, examining it and discovering its neighbours (moving the frontier). The difference lies in how when the neighbours are examined! AD 10 Dept. of Information Technology - 10 - Jonathan Cederberg jonathan.cederberg@it.uu.se

DFS When examining a node, just tag it as discovered and examine all not yet discovered neighbours first. So we examine the nodes using a LIFO policy. AD 10 Dept. of Information Technology - 11 - Jonathan Cederberg jonathan.cederberg@it.uu.se

BFS When examining a node, put all not yet discovered neighbours on hold and let them wait for their turn. So we examine the nodes using a FIFO policy. AD 10 Dept. of Information Technology - 12 - Jonathan Cederberg jonathan.cederberg@it.uu.se

The essence DFS uses LIFO, BFS uses FIFO. This means they are essentially the same, except that DFS uses a stack and BFS uses a queue. Note that this glosses over a lot of important points, read the book for more detailed explanation. AD 10 Dept. of Information Technology - 13 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Outline Example 1 Example 2 3 AD 10 Dept. of Information Technology - 14 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Implementation of graphs Implement some representation of directed graphs. You are advised to use adjacency list representation if you do not definitely prefer to use adjacency matrix. (4 pts) AD 10 Dept. of Information Technology - 15 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Implementation of graphs Implement some representation of directed graphs. You are advised to use adjacency list representation if you do not definitely prefer to use adjacency matrix. (4 pts) Implement the possibility of doing a BFS search on your graph, starting at a user-specified vertex. The program should print (to standard out) the order in which the vertices are discovered. (3 pts) AD 10 Dept. of Information Technology - 15 - Jonathan Cederberg jonathan.cederberg@it.uu.se

Implementation of graphs Implement some representation of directed graphs. You are advised to use adjacency list representation if you do not definitely prefer to use adjacency matrix. (4 pts) Implement the possibility of doing a BFS search on your graph, starting at a user-specified vertex. The program should print (to standard out) the order in which the vertices are discovered. (3 pts) Implement the possibility of doing a DFS search on your graph, starting at a user-specified vertex. The program should print (to standard out) the order in which the vertices are discovered. (3 pts) Deadline: 27/10 AD 10 Dept. of Information Technology - 15 - Jonathan Cederberg jonathan.cederberg@it.uu.se