Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ICS 3 1 1 : Algorithms Spring 2 0 2 4 Problem Set 1 Prof. Nodari Sitchinava Due: Friday, January 1 2 , 2 0
ICS : Algorithms Spring
Problem Set
Prof. Nodari Sitchinava Due: Friday, January at pm
You may discuss the problems with your classmates, however you must write up the solutions on your
own and list the names of every person with whom you discussed each problem.
Start every problem on a separate page, with the exception that Problems can start on the same page
as Problem Peer credit assignment
Peer Credit Assignment point extra credit for replying
Please list the names of the other members of your peer group for this week and the number of extra credit
points you think they deserve for their participation in group work.
You have a total of points to allocate across all of your peers.
You can distribute the points equally, give them all to one person, or do something in between.
You need not allocate all the points available to you.
You cannot allocate any points to yourself Points allocated to yourself will not be recorded.
Catenable Stack pts
In this problem you will design a data structure that implements Stack ADT using singlylinked list instead
of an array. In addition your stack will have the following additional operation:
public catenateStack s; appends the contents of Stack s to the current stack
The new operation will have the following properties:
Let n ssize m ssize Then executing scatenates results in the following:
The new size of s is the sum of the size of s and the original size of s ie the following evaluates
to true: ssize n m
Top n elements of s after the call scatenates are the same as the elements of s before the call.
The bottom m elements of s after the call scatenates are the same as the elements of s before
the call.
a The implementation described in the book, lecture notes and screencasts uses an array to implement
Stack ADT. Can you implement catenateStack s operation that runs in O time for such imple
mentation? If yes, write down the algorithm that achieves that and demonstrate that it runs in O
time. If not, describe what goes wrong.
b Write down algorithms that implement the original Stack ADT using a singlylinked list instead of
the array. That is write down pseudocode for implementing each operation of Stack ADT: Stack
pushObject o pop size isEmpty top Make sure that each of the above opera
tions takes at most O time in your implementation.
c Design an algorithm that implements catenateStack s operation in O time. Write down the
algorithm and demonstrate that it runs in O time.
Relative Growth Rates of Functions pts
Continuing in the style of inclass exercises, ll in the table for these pairs of functions with Yes" or No in
each empty box. Then for each row, justify your choice, preferably by showing mathematical relationships
eg transforming one expression into another, or into expressions that are more easily compared
f n gn O oOmega omega Theta
elog n log n
fn ncos n
gnlog n
Fun with Induction pts
Prove the following statements using strong induction:
a pts n
i
ri rn
r for every nonnegative integer n and every real number r
b pts Suppose that a store oers gift certicates in denominations of $ and $ Then any item
priced at an integer number of dollars of value at least $ can be paid for with these gift certicates
without a need to use any other form of currency. For example, an item priced $ can be paid with
two $ gift certicates and two $ gift certicates.
Fun with Logarithms OPTIONAL pts
a Prove the following identity:
n
log n
b Simplify the following expressions. Show your work.
nlog
nlog
n log n
nlog n
c Order the expressions in part b according to their asymptotic growth, from the lowest to the highest.
Justify your answers.
Tiling with Lshaped Tiles OPTIONAL pts
A construction company is given a contract to tile bathrooms in a new apartment building in Kakaako.
However, because of the customer's demands, the company is a bit stumped and hired you as a consultant
to help them out.
The oor of every bathroom to be tiled is squareshaped, but bathrooms in dierent apartments are of
dierent sizes. All you know is that each bathroom is of size n times n inches for various integers n For
example, one bathroom might be of size times inches, another one might be times inches, and so on
The whole bathroom oor must be tiled, except for a squareshaped drain on the oor of size times inches.
However, due to the unique design of the apartments, dierent bathrooms have the drain in dierent loca
tions on the oor: some have them in a corner, others in the center, yet others a few inches away from the
wall. All you know is that in each case, the drain will be some integer inches away from the walls. Moreover,
the construction company must tile the oor using special tiles. Ea
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started