Handout 21
Spring 2003 Yinglin Wang
CS112 Assignment 3A
Written by Nicholas Fang, updated by Justin Haugh
Due date : April 10 Problem 1: Big-O Notation a) What is the computational complexity of the following function:
b) What is the computational complex
AbstractDataTypesADT
YinglinWang CSDept.,SJTU
CS112Fundamentalsof ProgrammingAbstractions
Today we start on our next major themeAbstract Data Types (ADTs). The idea is to implement the behavior of a new data type in a way that hides the details from the c
Handout #52S May 22, 2002
CS106B Practice Final Solutions
Spring 2002 Robert Plummer
Problem 1: Recursion (25 points)
bool CanBeSeated(string guests[]) cfw_ int i; string table[NUM_GUESTS]; for (i = 0; i < NUM_GUESTS; i+) table[i] = "; return CanBeSeatedR
Handout #52 May 22, 2002
CS106B Practice Final
Spring 2002 Robert Plummer
Note: this practice exam is the actual exam from last quarter. A second practice exam will be available in electronic form from the class website some time later. We have removed so
Assignment
8A
Problem 1: Understanding graph algorithms Those of you who have played Clue will recognize the following undirected graph, which shows the connections between the various rooms on the game board:
The numbers on the various arcs show the dist
CS112 Assignment 7A
Problem 1: Substitution in Trees In mathematics, there are several common procedures that require you to replace all instances of a variable in a formula with some other variable. Working entirely at the client level of exp.h , write a
CS112 Assignment 6B Solitaire
Due: June 12 An object-oriented approach In this assignment, the implementation you will write moves you in the direction of "objectoriented" programming. Although C is not inherently an object-oriented language, we can use i
CS112 Assignment 6A
Iterators Problem 1: Implementing an Iterator In lecture, we mentioned that iterators are not unique to symbol tables, but in fact can be useful for other container ADTs. Consider the queue; one of the standard ways that we work with q
Recursive Procedures
Yinglin Wang CS Dept., SJTU
Contents of this lecture:
1. Review of Recursion definition 2. Review of The pitfalls you should avoid 3. The comparison of recursion and iteration 4. Recursive procedures
1. Several Definition of Recursion
Efficiency and ADTs-cont.
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
In the linked list representation, given a buffer variable, at any time you only directly know two positions: the start position of the buffer and the cur
Abstract Data Types cont.
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Lets consider the behavior of a stack Stack provides a storage for a collection of data values; these values form a sequence; The values can only be remov
Efficiency and ADTs
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Solution to chp8 exercise 1
Main() cfw_ stackADT integerStack; int integer; integerStack=NewStack(); printf( enter a list of integers, ending with 0: ); while(T
Abstract Data Types ADT
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Today we start on our next major theme Abstract Data Types (ADTs). The idea is to implement the behavior of a new data type in a way that hides the details
CS 112 Handout #15
Spring 2003 Yinglin Wang
CS112 Homework 2B (Boggle game)
Due Thursday, March 27. Electronic submission by 5:00pm
This assignment was originally developed by Todd Feldman and then enhanced by Julie Zelenski. Your mission is to write a pr
CS112 Handout #14
Spring 2003 Yinglin Wang
CS112 Homework 2A
Due Thursday, March 27.
Problem 1: Bracket Matching In the syntax of most programming languages, there are some characters that occur only in nested pairs, which are called bracketing operators.
Recursive Backtrackingcont.
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
1
Backtracking
Many problems can be thought of as a search through a space consisting of various nodes. Each node represents a state of the world. what
Recursive Backtracking
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
1
Contents of this lecture:
1. Review of the former lecture 2. Recursive Backtracking
CS112 Fundamentals of Programming Abstractions
2
1
1. Review: Tower of
Graphs
Yinglin WANG CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Bitwise operators
An important use of bitwise operators is to combine items from a set of constants, as in this example from a graphics package. Note that the values of the
Integer Sets
Yinglin WANG CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
About the final grade
It will be computed as follows: Programs 40% The first 2 Written home work 8% Your attendance and the test 2% Finals 50%
CS112 Fundamentals of Pr
Sets
Yinglin WANG CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Sets
A set is an unordered collection of distinct elements.
When we want to represent a collection of elements where the order is not important, the collection is what mathema
Sample of Practice Midterm
(It a sample of the midterm, you can practise it. Though solution is also given on this web site, s it is recommended that you do it yourself first) Name _ In all questions, you may use functions or definitions that have been us
Mapping Functions
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Review
Pointers to functions can be interpreted as data values in C
CS112 Fundamentals of Programming Abstractions
1
The printTable function
Call back functions i
Function pointers
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Main points
Pointers to functions can be interpreted as data values in C Use function pointers in the implementation of callback function
CS112 Fundamentals of Pr
Symbol Tables
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Main points of this lecture
Familiar with the concept of a symbol table and the design of its interface The technique of hashing and how it applies to symbol tables
C
Simulation using queues.
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Queue Basics
ordered group of homogeneous items Queues have two ends
Input at one end (tail) Remove from other end (head)
The element added first is also r
Queues-one of the linear structures.
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Main points:
Stacks can be implemented by linked lists. Stacks & queues are two important kinds of linear structures Implement queues by arrays
Efficiency and ADTs
Yinglin Wang CS Dept., SJTU
CS112 Fundamentals of Programming Abstractions
Our website moved to 202.120.1.155/wang-yl/index.htm ftp site remains 202.120.7.244
CS112 Fundamentals of Programming Abstractions
Solution to exercise 1
Main()