Assignment #1: Answer Keys
1. The algorithm is :
f (0) = 0
f (N ) = f (N/2) + N mod 2
2. We use induction on N to prove the result.
The equation that was given to us was :
N 2
fi = fN 1
(1)
i=0
Base Case: N = 2
The LHS of (1) is f0 = 0
The RHS of (1) is
University of Arizona
CSc345 (Fall 2011; B. Moon)
CSc 345 Homework Assignment #1
Problems
1. (20 pts) Write a recursive algorithm that returns the number of 1s in the binary representation of an
input integer N . Use the fact that this is equal to the num
Mergesort and Quicksort
Know the high-level strategy behind each
algorithm, as a divide-and-conquer solutions.
Be able to derive the best-case time
complexity of each.
Be able to write the merge() function.
Be able to describe the operation of partition()
Topic 02: Structural Induction
Slides are by courtesy of Russell Lewis.
1
Structural Induction
Many of the discrete structures we use can be
recursively characterized or recursively defined.
That is good, because a recursive definition lets us
prove impor
Algorithm Analysis 1: Step Counting
Objectives: Students should be able to . . .
identify constant-time operations from simple
pseudocode (using standard assumptions),
count the number of time steps for simple looping
procedures, such as sorting algorithm
Introduction and Proofs
10/20/14 8:34 AM
Definition of algorithm: method for solving problems suitable for computer
implementation
Definition of data structure: Most algorithms involve methods of organizing
the data involved in the computation. Object cre
Linear Hashing
This document discusses hashing keys into and splitting hash entries under the Linear Hashing
scheme. Although an array may not be an ideal data structure for Linear Hashing, an array is
easier to use for an example, and the basic concepts
Data Structures
10/20/14 8:34 AM
Review of basic data structures
Abstract Data Type (ADT)
o Mathematical model for a class of data structures that have
similar behavior, like adding, sorting
o Examples:
! List
! Queue
! Stack (can use a linked list or an
16 June 11 : sorting
10/20/14 8:34 AM
Sorting:
There is no best sorting algorithm, you must decide based on the
input, each has pros and cons
o For example, if the list is almost sorted, you could use
selection sort, which has a good best case run time
10/20/14 8:34 AM
Graphs:
Definition:
o A graph G=(V,E) consists of a collection V of vertices (nodes),
and a collection E of edges, each of which join two verticies.
Two kinds of graphs:
o Undirected
! An edge e in E is a pair of nodes in V
e = cfw_u, v
Run time: Big O
Definition of Big-O
We will use this for tight upper bounds
let f(n) and g(n) be functions that map positive
integers to positive real numbers. We say that f(n)
O( g(n) ) if there exists a contstant c > 0 and integer constant
n 0 0 such t
Homework 2 (CS 345, Fall 2016). Due at the start of class on October 5.
Solutions should be clear and neat, whether handwritten or typeset. Show your work, write clear
sentences, and include clear diagrams if necessary.
1. (15 points.) Use the definitions
Homework 1 (CS 345, Fall 2016). Due at the start of class (1 PM) on 12 September.
Turn in a single document with your solutions, either as a paper document (in class) or electronic
document (to D2L dropbox). Solutions should be clear and neat, whether han
Using Asymptotic Time Complexity
Constant-time operations: cost (1).
Calls to methods: compute the time cost of the
method
Loops: # iterations, times cost of loop-body.
Conditions: costs of test, plus chosen code.
Series of operations: use the sum rule.
S
University of Arizona
CSc345 (Fall 2011; B. Moon)
CSc 345 Homework Assignment #3
Problems
1. (10 pts) Exercise 9.14 in page 337. [Closed hashing/linear probing]
2. (10 pts) Show the result of inserting 3, 1, 4, 6, 9, 2, 5, 7 into an initially empty max-he
University of Arizona
CSc345 (Fall 2011; B. Moon)
CSc 345 Programming Assignment #1
ADT for Polynomials
Problem Statement
For this programming assignment, we dene an abstract data type (ADT) for single-variable polynomials. A polynomial has zero or more t
University of Arizona
CSc345 (Fall 2011; B. Moon)
CSc 345 Programming Assignment #2
Static Hashing vs. Dynamic Hashing
Problem Statement
For this assignment, we design an electronic dictionary with spelling checker. In order to practice building different
University of Arizona
CSc345 (Fall 2011; B. Moon)
CSc 345 Programming Assignment #3
Airline Travel Scheduler
Problem Statement
There are numerous application domains where problems and tasks are formulated by graphs. The purpose
of this programming assign
Asymptotic Notation
Objectives: you should be able to
Recall the definitions big-O, big-Theta, and bigOmega asymptotic bounds on time costs,
Sort big-Theta bounds in order of increasing growth
rate,
Determine whether a given polynomial function is
contain
Begging The Question is a bad thing.
The phrase beg the question means to build an argument for something, using that something as
supporting evidence. It means using circular reasoning, or committing a kind of logical fallacy. (The
term is also used to m
Topic 01: Review
Propositions, Predicates, and Operators
Quantifiers
Sets
Sums
Proofs (especially induction)
Trees
Slides courtesy of Russell Lewis
1
Propositions
Proposition:
A statement that is either true or false (often with
respect to an associated c
Abstract Data Type
Authors mildly disagree over the following definitions, but we
will go with Shaffer's version (read 1.2).
In CS, a data type is a collection of values . . .
(Standard) integer, real number, string of characters, reference.
(Custom, aggr
22 June 11
10/20/14 8:34 AM
Radix Sort:
Sorting data with integer keys by splitting its key into individual
digits and comparing individual digits sharing the same significant
position
Least significant digit:
o For numbers
Most significant digit:
o Re