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
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
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
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
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
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
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
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
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 #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 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
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