0% found this document useful (0 votes)
25 views4 pages

CS300 Sample Final Quest Ons PDF

Uploaded by

slymn13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

CS300 Sample Final Quest Ons PDF

Uploaded by

slymn13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

// Notes: Question 2 will not be solved in recitation

CS300 SAMPLE FINAL QUESTIONS


1) Given the input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function
h(x) = x mod 10, show the resulting:

a. separate chaining hash table

b. hash table using linear probing

c. hash table using quadratic probing

d. hash table with second hash function h2(x) = 7 − (x mod 7)

2. Longest Consecutive Subsequence

Given an array of integers, find the length of the longest subsequence such that elements in
the subsequence are consecutive integers, the consecutive numbers can be in any order.
Examples:

Input: arr[] = {1, 9, 3, 10, 4, 20, 2};


Output: 4
The subsequence 1, 3, 4, 2 is the longest subsequence of consecutive elements
Input: arr[] = {36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42 , 1 , 2}
Output: 5
The subsequence 36, 35, 33, 34, 32 is the longest subsequence of consecutive elements.

3)
a) Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, and 2, one at a
time, into an initially empty binary heap.
b) Show the result of using the linear-time algorithm to build a binary heap using the
same input.
c) Show the result of performing three deleteMin operations in the heap of the
previous exercise.

This study source was downloaded by 100000770618860 from CourseHero.com on 01-08-2023 14:02:06 GMT -06:00

https://www.coursehero.com/file/175543102/CS300-SAMPLE-FINAL-QUEST%C4%B0ONSpdf/
4) Prove that for binary heaps, buildHeap does at most 2N−2 comparisons between
elements.

5) Show the result of the following sequence of union instructions on trees


representing disjoint sets: union(1,2), union(3,4), union(3,5), union(1,6),
union(3,7), union(8,9), union(1,8), union(3,10), union (3,11), union(3,12),
union(3,13), union(14,15), union(16,0), union(14,16), union (1,3), union(1,
14) when the unions are:
a. performed arbitrarily
b. performed by height
c. performed by size

6) Sort the sequence 3, 1, 4, 1, 5, 9, 2, 6, 5 using insertion sort. Show each step.

7) Show how heapsort processes the input 142, 543, 123, 65, 453, 879, 572, 434,111, 242,
811, 102.

8) Sort { 3, 1, 4, 1, 5, 9, 2, 6 } using merge sort. Show each step.

9) Sort 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 using quicksort with median-of-three partitioning and a


cutoff of 3.

10) Construct a permutation of 20 elements that is as bad as possible for quicksort using
median-of-three partitioning and a cutoff of 3.

This study source was downloaded by 100000770618860 from CourseHero.com on 01-08-2023 14:02:06 GMT -06:00

https://www.coursehero.com/file/175543102/CS300-SAMPLE-FINAL-QUEST%C4%B0ONSpdf/
11) Find a topological ordering for the graph below:

a. Use a queue and assume that vertices appear on an adjacency list alphabetically.

b. Use a stack and assume that vertices appear on an adjacency list alphabetically.

12) Find the shortest path from A to all other vertices for the graph below, show your
steps:

This study source was downloaded by 100000770618860 from CourseHero.com on 01-08-2023 14:02:06 GMT -06:00

https://www.coursehero.com/file/175543102/CS300-SAMPLE-FINAL-QUEST%C4%B0ONSpdf/
13) Find a minimum spanning tree for the graph below using Prim’s algorithm.
Is this minimum spanning tree unique? Why?

This study source was downloaded by 100000770618860 from CourseHero.com on 01-08-2023 14:02:06 GMT -06:00

https://www.coursehero.com/file/175543102/CS300-SAMPLE-FINAL-QUEST%C4%B0ONSpdf/
Powered by TCPDF (www.tcpdf.org)

You might also like