This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Similar documents
1. O(log n), because at worst you will only need to downheap the height of the heap.

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

Total Score /1 /20 /41 /15 /23 Grader

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

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

Exam 3 Practice Problems

Total Score /15 /20 /30 /10 /5 /20 Grader

Total Score /15 /20 /30 /10 /5 /20 Grader

Data Structure. IBPS SO (IT- Officer) Exam 2017

CS521 \ Notes for the Final Exam

CSE 373 Spring Midterm. Friday April 21st

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

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

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

Data Structures Brett Bernstein

Programming II (CS300)

Homework Assignment #3 Graph

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

ext Total Score /20 /20 /15 /20 /25 /5 Grader

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

CS 350 Final Algorithms and Complexity. It is recommended that you read through the exam before you begin. Answer all questions in the space provided.

Computer Science E-22 Practice Final Exam

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

CS302 Data Structures using C++

Practice Problems for the Final

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

CSE 373 Final Exam 3/14/06 Sample Solution

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Introduction to Algorithms April 21, 2004 Massachusetts Institute of Technology. Quiz 2 Solutions

12 Abstract Data Types

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Math 15 - Spring Homework 5.2 Solutions

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

Chapter 9 Graph Algorithms

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

Problem Pts Score Grader Problem Pts Score Grader

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

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

Sample Question Paper

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

CS171 Midterm Exam. October 29, Name:

Computer Science Spring 2005 Final Examination, May 12, 2005

COS 226 Algorithms and Data Structures Fall Midterm

CS 4349 Lecture October 18th, 2017

CS 161 Fall 2015 Final Exam

Student Number: Lab day:

CS171 Final Practice Exam

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

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

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

UNIVERSITY REGULATIONS

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINAL EXAM SOLUTIONS

) $ f ( n) " %( g( n)

Data Structures Question Bank Multiple Choice

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

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

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

Basic Data Structures (Version 7) Name:

Minimum Spanning Trees

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

6.1 Minimum Spanning Trees

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Total Points: 60. Duration: 1hr

Lecture Summary CSC 263H. August 5, 2016

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

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

CSci 231 Final Review

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

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

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

CSC 172 Data Structures and Algorithms. Lecture 24 Fall 2017

DATA STRUCTURES AND ALGORITHMS

Problem Score Maximum MC 34 (25/17) = 50 Total 100

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

CS 170 Spring 2000 Solutions and grading standards for exam 1 Clancy

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Balanced Binary Search Trees. Victor Gao

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview

Solutions to relevant spring 2000 exam problems

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Transcription:

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have encountered on homeworks, the midterm, and on this practice sheet. Since you will not hand in solutions to these practice problems, you are welcome to work together on them, although we advise that you go ahead and write up solutions as a way of making certain that you really understand the answers found during discussion. Keep in mind that you are responsible for understanding the concepts behind any of the mentioned algorithms. Note : This practice exam is longer than the actual exam would be so you should not worry if it takes you longer than three hours to attempt. CS16 Introduction to Algorithms and Data Structures Spring 2017

Problem 1 For each of the following, give a worst-case runtime, and a brief explanation (a sentence or two). In cases where the algorithm isn t specified, use the best one you can think of. 1. Removing the minimum element from a heap that contains n items 2. Constructing a minimum spanning tree for a connected graph with n nodes and n 2 edges using Kruskal s algorithm 3. Determining whether an item occurs in an unsorted singly-linked list 4. Sorting n integers, all between 0 and 9, where n is much greater than 100. 5. Finding a spanning tree (not necessarily a minimum-weight spanning tree) for a connected graph of n nodes and n log n edges. 6. Doing a pre-order traversal for a binary tree with n nodes. CS16 Introduction to Algorithms and Data Structures Spring 2017 2

Problem 2 In a binary search tree, T, in-order traversal will visit the nodes in increasing-key order, thus providing a linear-time mechanism for extracting all keys in order. Suppose that you have some range of keys, say k1 k k2, and you d like to extract all keys in T that lie within this range, and you d like to get the results, as before, in increasing-key order. (Note that neither k1 nor k2 needs to actually be a key in the BST, and that the returned list of keys might well be empty!) Once again, inorder traversal with a test for in-range-ness will solve the problem in worst case O(n) time, where n is the number of keys in the tree. You are to describe how to solve the problem in time O(h + s), where h is the height of the tree T, and s is the number of keys returned. Give a brief description of your approach to this problem. Write pseudocode for your algorithm. Explain briefly why your algorithm is O(h + s). CS16 Introduction to Algorithms and Data Structures Spring 2017 3

Problem 3 By now you should know how to construct a minimum spanning tree from a graph. However, sometimes we don t want a minimum spanning tree perhaps we want to force our spanning tree to contain specific edges, regardless of whether or not those edges are optimal. Suppose you are given an undirected graph G = (V, E) with edge weights w e, and an acyclic set of edges F, where F is a subset of E. (You may assume the edges are decorated such that inf(e) will return either true if e is one of the edges in F, or false otherwise.) Develop an algorithm that runs in O( E log E ) and returns the lightest spanning tree T such that the edges of F are all contained in T. Give a brief description of your approach to this problem. Write pseudocode for your algorithm. Explain briefly why your algorithm is O( E log E ). CS16 Introduction to Algorithms and Data Structures Spring 2017 4

Problem 4 Describe an efficient algorithm for finding the length of the longest path from a vertex s to a vertex t in a directed acyclic graph G = (V, E) with edge-weights w e. (If there s no path from s to t, return.) Also write pseudocode for your algorithm. CS16 Introduction to Algorithms and Data Structures Spring 2017 5

Problem 5 Consider the following two algorithms, each of which takes an input graph, G = (V, E) with edge lengths l(u, v). Algorithm A: This algorithm picks a random node s, runs Dijsktras algorithm on it to find distances from s to all nodes, and retains the V /2 nodes that are closest to s [in the case of a tie, it chooses randomly.]. It then recursively calls itself on the graph consisting of these nearby nodes and all edges in E that join such nearby nodes. For a graph with a single vertex, the algorithm returns that node. This particular implementation of Dijkstra uses an array to represent the priority queue. Algorithm B: The second algorithm sorts the edges by length, and returns the length of the median edge. What are the runtimes of each algorithm? For what kinds of graphs would Algorithm A be faster? Algorithm B? Briefly explain your answers. CS16 Introduction to Algorithms and Data Structures Spring 2017 6

Problem 6 You are given a knapsack which can hold a maximum weight of C (an integer). You also have an endless supply (i.e. you can use any number of each item) of n items with positive integer weights w 0...w n 1 and values v 0...v n 1. Develop an algorithm that returns the maximum value your knapsack can have by filling it with your items. You can use the same item as many times as you need. Your algorithm should run in O(C n), where n is the number of items Write pseudocode for your algorithm. (Hint: recall the change-making problem from section) CS16 Introduction to Algorithms and Data Structures Spring 2017 7

Problem 7 Write pseudocode for a method reverselist(head) that takes in the head of a singly linked-list and reverses the list. Note that a singly linked-list is simply a linked list in which every node has a pointer to its next element in the list and the last node s next pointer points to null. Example: Given a linked lista B C D with head A the method turns it into the list: D C B A with head D. Explain the runtime of your solution. CS16 Introduction to Algorithms and Data Structures Spring 2017 8

Problem 8 You are given a non-empty stack S of integers. Write pseudocode for a method that sorts the stack in ascending order from the bottom-up (i.e. the bottom element is the smallest integer). You are allowed to use the push(), pop(), peek(), isempty() methods of a stack, but you may not use other data structures in your solution. Hint : You can accomplish this by creating one more stack in your method, and transfer elements into the new stack each time checking that the transfer doesn t violate the sort order. Example : Here s a stack S 5 2 3 1 4 Your method should return a stack that looks like this: 5 4 3 2 1 CS16 Introduction to Algorithms and Data Structures Spring 2017 9

Problem 9 1. What data structure is used to do autocomplete? Describe how it works in a few sentences. 2. Name two defining aspects of the functional paradigm and describe them in a few sentences. 3. Are there graphs where Dijkstra s will fail? If so, explain why. 4. Describe one difference between problems in the sets P and NP. 5. What is the difference between online algorithms and offline algorithms? Give an example of a time that we have used each in class. CS16 Introduction to Algorithms and Data Structures Spring 2017 10