{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Homework 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Your Name: " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Big-$O$ Notation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 1 (3 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is $2^{n+1}=O(2^n)$? Justify your answer using [Definition 3.1](https://6001-majhi.datasci.land/notes/big-o.html#def-o)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 2 (3 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is $2^{2n}=O(2^n)$? Justify your answer using [Definition 3.1](https://6001-majhi.datasci.land/notes/big-o.html#def-o)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 3 (3 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using [Definition 3.1](https://6001-majhi.datasci.land/notes/big-o.html#def-o), show that the function $100n\\lg{n}$ is $O(n^2-1)$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 4 (1+1 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Describe the difference between an upper bound and a tight upper bound? Explain using an example.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 5 (1+1 points)\n", "Provide an example of an $O(1)$ and $O(n)$ algorithm.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 6 (🏅 Bonus)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If $f(n)=O(g(n))$, then $2^{f(n)} = O(2^{g(n)})$. True or false? Justify your answer.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Powerset Generation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 7 (5 points)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a Python code to generate all the subsets of a given list.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def powerset(A):\n", " # input: a list\n", " # output: a list of lists\n", " # implement me\n", " pass\n", "\n", "powerset(['a', 'c', 'b'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 8 (2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If the input list has $n$ elements, describe the time complexity of your code. A thorough explanation is required.\n" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }