Data Structures

CSI33      D01 (45383)

Monday, Wednesday, 12:00 pm-1:50 pm, room CP 320

Date Class Materials HW assignment
Week 16

Here you can find your HW and quizzes grades (updated on May 14th):

Some interesting reads:
1) Pointers vs References:,
2) Unique pointers (std::unique_ptr):
05/15 Review
05/13 Sections 14.1 - 14.4

Lecture slides: CSI33-lecture27_part1.pdf, CSI33-lecture27_part2.pdf
Dikstra's example: DijkstrasExample.pdf
Breadth First Search implementation in C++: BFS.h, BFS.cpp, usingBFS.cpp, input1.txt

Breadth First Search Demonstration (you tube, ~9 mins):

Dijkstra algorithm Demonstration (you tude, ~9 mins):

A short (~2mins) but very nice video of depth first search algorithm application:

In-class Work: CSI33_Lecture27InClassWork.pdf
Solutions: CSI33_Lecture27InClassWorkSols.pdf
Week 15

Our Final Exam date is May 22nd, 12pm - 2pm at CP 320
05/08 Section 13.3 in C++

Quiz 9 (based on Chapters 12 and 13)

Lecture slides: CSI33-lecture26.pdf

programs (in C++): TreeNode.h, TreeNode.cpp, AVLTree.h, AVLTree.cpp, TestAVLTree.cpp
programs (from the book, in Python):,,

in-class work (with solutions):
Suggested exercises (for practice, not for grade):

1) Multiple-Choice questions: p. 481 / 10
2) Short-Answer Questions: p. 481 / 2
3) AVL trees (Short Answer questions): page 481 / 4-11,
Answers: Chapter13-AVL-answers.pdf
4) Look through the AVL code in Python and lecture slides - understand how the rotations are done. Finish up the code.
: you can use the following code for testing/seeing what is happenning(just add it to your program)
5) Look through the AVL code in C++ thoroughly
05/06 Section 7.5 in C++

Lecture slides: CSI33-Lecture25.pdf

programs (in C++):
TreeNode.h, TreeNode.cpp, usingTreeNode.cpp,
BST.h, BST.cpp, usingBST

Useful links:
BST delete node:
Insertion and deletion (6 mins video):
Comment: deletion procedure here follows a different strategy: right subtree, leftmost element.

In-class work: see lecture slides
Suggested exercise (for practice, not for grade):

1) define the delete operation for BSTs in our C++ code (use Python's code)

2) define the reverse operation for BSTs (in C++ and in Python implementations) that will reverse the structure of the BST, i.e. for every node, all nodes in the left subtree have values greater than the value of the node; and all nodes in the right subtree have values less than the value of the node.
Week 14

From now on there will be no graded HW assignments, although I highly recomment to work on them.
We had 17 homework assignments is total. 5 lowest scores will be dropped, 12 homeworks with best scores will be averaged.
05/01 Sections 13.3-13.5 in C++

Quiz 8 (based on Sections 10.4 - 11.4)

Lecture slides: CSI33-Lecture24.pdf

programs (in C++): Heap.h, Heap.template, testingHeap.cpp,
programs (from the book and not, in Python):,

C++ map reference:

In-class Work: see lecture slides, files to use:
Suggested exercises (for practice, not for grade):

0) Look through the hash examples in Section 13.5
1) True/False questions: p. 478 / 1, 2
2) Short-Answer Questions: pp. 479 - 480/ 1, 2, 4, 5, 8, 9
3) In-class work
Answers: Chapter13-answers.pdf

04/29 Sections 12.1-13.2

Lecture slides: CSI33-Lecture23.pdf
programs (from the book and not):
maximum.cpp, vec1.cpp, vec2.cpp, vec3.cpp(updated!);
Stack.h, Stack.template, test_Stack.cpp

Reference manual for Vector class template:

Algorithms library reference manual:

In-class Work:
1) Implement a template minimum function and test it on int and double type values.
Solution: minimumInClassWork.cpp

2) Implement a Queue using templates along with the code to test it. This is a suggested HW assignment.
: Queue.h, Queue.template, test_Queue.cpp
Suggested exercises (for practice, not for grade):

1) True-False questions: p. 440 / 1, 2, 5

2) Multiple-Choice questions: p. 440-441 / 1, 2, 4

3) Programming exercise: p. 442 / 2
Solution: Queue.h, Queue.template, test_Queue.cpp
Answers: Chapter12questionsAnswers.pdf

Week 13
Spring Recess

04/19 - 04/28

Week 12

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Here you can find your HW and quizzes gardes:

04/17 Sections 11.1 - 11.4

Quiz 7

Lecture slides: CSI33-Lecture22.pdf

programs (from the book and not): ListNode.h, LList.h, LList.cpp, testLList.cpp

In-class Work: see lecture slides.
2) ListNode2.h, LList2.h, LList2.cpp, testLList2.cpp
3) to be posted
HW19 (due date: Friday, 05/03)

1) Programming exercise: p. 424 / 2
    here is the code to check that your program works correctly: Chapter11-testLList2.cpp

Suggested exercises (for practice, not for grade):

1) True-False questions: p. 422 / 1, 2, 5

2) Multiple-Choice questions: p. 423 / 1, 2, 4

3) Short-Answer questions: p. 424 / 1, 2
Solutions: Chapter11questionsAnswers.pdf
04/15 Sections 10.4 - 10.5

Lecture slides: CSI33-Lecture21.pdf

programs (from the book): List.h, List.cpp, testList.cpp, testList1.cpp, testListp.cpp
Check out this one as well: unsigned.cpp

In-class work: see lecture slides
Solution (only for cin): List2.h, List2.cpp, testList2.cpp

HW18 (due date: Wednesday, 05/01)

Programming exercise: p. 400 / 4
see and use: mystring.h, mystring_draft.cpp, string_using.cpp

1) Start with definitions of constructor, destructor, operator+=(const char c), resize and cout functions.
2) Then add operator[], search/find, and reverse definitions.
3) Conclude with definitions of copy constructor, assignment operator= (both of these operators can use private method copy), and operator+=(const String& str)input method is already defined in the files provided.  

Week 11

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Here you can find your HW and quizzes gardes:

  Final Exam: Wednesday, May 22nd, 12pm - 1:50pm at CPH 320
04/10 Sections 10.1 - 10.3

Quiz 6

Lecture slides: CSI33-Lecture20.pdf
programs: Source.cpp
In-class work: see lecture slides

1) we do have a memory leak, see the picture
2) program: CSI33Lecture20InClassWork.cpp

More practice with pointers:
HW17 (due date: Friday, 04/19)

Short-Answer questions: p. 399 /5, 6

Suggested exercises (for practice, not for grade):
1) True-False questions: p. 396 / 3, 4,
2) Multiple-Choice questions: p. 397 / 1, 2, 3, 5
Solutions: Chapter10-questionsAnswers_part1.pdf
04/08 Sections 9.4 - 9.5

Lecture slides: CSI33-Lecture19.pdf

programs (from the book):
mainv1.cpp, Rationalv1.cpp, Rationalv1.h;
Rationalv2.h, Rationalv2.cpp, mainv2.cpp;
Rationalv3.h, Rationalv3.cpp, mainv3.cpp;
Card.h, Card.cpp, using_Card.cpp

in-class work solution: (with counter_ placed in the private section):
Card-InClassWork.h, Card-InClassWork.cpp, using_Card2.cpp
HW16 (due date: Wednesday, 04/17)

1) Programming Exercise: p. 352 / 3
Use this code to test your program: Rational_testing.cpp

Suggested exercises:

1) Short Answer questions: page 351/4
Answers to some of the True/False and Multiple Choice questions from Chapter 9: Chapter9-questionsAnswers.pdf
2) Define a Complex Number class using rectangular form of complex numbers, i.e. any complex number is r+mi, where r and m are real numbers and i is imaginary unit). Recall that i2 = -1.

The class should have +,-,and * binary operations defined.

Here are examples of operations:
(2+3i)+(9-7i) = 11-4i
(2+3i)-(9-7i) = -7+10i
(2+3i)*(9-7i) = 18-14i+27i-21i2 = 18+21+13i = 39 + 13i 
Week 10

  Final Exam: Wednesday, May 22nd, 12pm - 1:50pm at CPH 320
04/03 Sections 8.17, 9.1-9.3

Quiz 5, based on Chapter 8

Reference manual to C++ string class:

comparison of C-strings and C++ strings:

Lecture slides: CSI33-Lecture18.pdf

programs (from the book):
Rational.cpp, Rational.h, MainProg.cpp;
stringex.cpp, getline.cpp, readfile.cpp

HW14 (due date: Wednesday, 04/10)

1) Read sections 9.1-9.3, and go through the True/False questions 1-13, and multiple choice Questions 1-6 (not for submission),
2) Write a program that reads a collections of values (decimal numbers) from the input file and
- finds the smallest value,
- find the greatest value,
- finds the average of all values,
- finds the average of all positive values,
- finds the average of all negatice values,
- reports how many zeros,
- reports how many positive values are in the file,
- reports how many negative values are in the file,
- sorts them and stores the sorted collection of values in an output file.

All the information (except for the sorted collection) should be displayed on the screen. Each item above (finding smallest value,etc.) should be defined as a function.
04/01 Sections 8.12-8.17

Lecture slides: CSI33-Lecture17.pdf (starting from headers)

programs (from the book):
conversions.cpp, conversions.h, conversions2.h;
switchWithAssert.cpp, switch.cpp, switch2.cpp, switch3.cpp;

In-class work: CSI33_Day17_InClassWork.pdf
Solution: functions.h, inClassWork17.cpp
HW13 (due date: Monday, 04/08)
1) Read about macros on page 302 and see example (macro.cpp)

2) read sections 8.17.2 and 8.17.3

3) programming exercise: page 317/ 8-9 (do it in one program)
test code and header for your programs: searches.h, test_searches.cpp

Suggested exercises:
(for practice, not for grade):

1) Read chapter 8 and look through the True/False and Multiple choice questions of Chapter 8

2) Use our Python code ( and write the definition of Merge Sort. Use the following files to put Selection sort (selection.cpp) and Merge sort into: sort.h, sort.cpp, and then use these ones to test them: test_sort.cpp, test_sort2.cpp.

Week 9

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Here you can find your HW and quizzes gardes:
03/27 Sections 8.8-8.11

Quiz 4

Lecture slides:CSI33-lecture16.pdf,
CSI33-Lecture17.pdf (up to headers, excluding)

programs (from the book): grades.cpp, if1.cpp, if2.cpp, if3.cpp, typeConvs.cpp, loopExample1.cpp, buffer.cpp, str1.cpp

Here is a link to C-string vs C++ string:

In-class work: see the last slide of the lecture slides
Solution: CSI33-Day16-InClassWork2.cpp 
HW12 (due date: Wednesday, 04/03)
2) programming exercises: page 316/ 1, 2, 3, 4, 6

for programming exercise 2, here is the link to the slides that give the algorithm for it (starting from slide 53): CSI30-Ch3Section1part2.pdf

Instructions on how to work with Visual Studio:
1) Create a project:
    File -> New -> Project...
choose Visual C++ (on the left) Empty Project (on the right),
below: change the Name of the project and change the Location of the project.
it will take from few seconds to a couple of minutes to create a project ... wait
2) to add a file to you project:
find a panel on your right (called Solution Explorer) - you should see your project name there with a bunch of folders like Source Files, Resource Files, Header Files, ...
right click on the Source Files -> Add -> New Item
Choose Visual C++ (on the left) and C++ File (.cpp) (on the right),
don't foget to change the name of the file below (if you want it changed)
A window will open in the middle of the screen - you are ready to type the C++ code!
3) The following steps are to keep the console window open when you are running your program (otherwise it will be closed fast): In the Solution Explorer Panel (on your right): right click on your Project name (a menu will pop-up)
choose Properties (at the very bottom) -> then click on the triangle to the left of Linker -> then choose System -> then on the right, at the very top, click on the SubSystem and in the drop-down menu for this item choose Console (...). Click OK!

Congratulations! You are all set!

To compile and run your program / project hit Ctrl F5 or go to menu (on top) Debug -> Start Without Debugging.
03/25 C++ is coming to our classroom!

Sections 8.1-8.7

Lecture slides: CSI33-lecture15.pdf

programs (from the book): ctof.cpp, swap.cpp, increment.cpp, uninit.cpp

In-class work: see lecture slides
Solutions: FtoC.cpp, CSI33-Day15-InClassWork.cpp

1) We have Microsoft Visual Studio installed on all computers at CP 320.
Get Community Edition, package: Desktop development with C++ (free):

2) Code Blocks (for all platforms, free):

3) JetBrains CLion
It is free, but you will have to apply for it with your school e-mail. The confirmation will be sent to your e-mail immediately. Then you can proceede to the download page and get CLion.
Not for grade (due date: Wednesday, 03/27)
1) Install a C++ compiler on your home computer,
2) Read the beginning of Section 8.2 (pages 256-257),
3) Run all the programs from the lecture.

Week 8

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Here you can find your HW and quizzes gardes:

The Midterm Grade will be composed of:
HWs (6 best scores out of 9 are averaged): 60%,
Midterm Exam: 40%
03/20 Section 7.5

Quiz 4 is moved for next Wednesday

Lecture slides: CSI33-Lecture13.pdf

programs (from the book):,
other programs:

Useful links:
BST delete node:
Insertion and deletion (6 mins video):
Comment: deletion procedure here follows a different strategy: right subtree, leftmost element.

In-class work: see lecture slides
Solutions: CSI33Leture13InClassWorkSols.pdf,
HW11 (due date: Sunday, 03/31)
1) programming exercises:
p. 248 / 2, 3, 5
Test code you can use for these problems:

2) Write unit tests for class BST to test insert_rec and find method, by doing the following:
Insert the following elements, one by one into a tree: 7, 3, 8, 2, 5, 9, then by using BST's method asList compare the produced by that method list with list [2,3,5,7,8,9] - this is one unit test for insert_rec method.
To test the find method: create the same BST as above, and find 8, 2, 9, and 5; compare the result with the numbers themselves. Then try to find 11, 1, and 4 and compare the result of each search with None.

Suggested exercises (not for grade):
1) Short Answer questions: p. 248 / 2, 3, 4
Solutions: Chapter7-questionsAnswers.pdf
03/18 Sections 7.1-7.4

Lecture slides: CSI33-Lecture12.pdf

programs (from the book):

In-class work: CSI33_Day12_InClassWork.pdf
Answers: CSI33Lecture12pics.pdf
Suggested exercises (not for grade):
1) True-False questions: p. 245 / 1-5
2) Multiple-Choice questions: p. 246 / 2, 3
3) Short-Answer questions: p. 248 / 6

Solutions: Chapter7-questionsAnswers.pdf
Week 7

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Midterm Exam will be on Wednesday, March 13th

Here you can find your HW and quizzes gardes:
03/13 Midterm Exam

The Midterm Exam is open book and open notes and limited use of computer (only Python Interpreter and our web site).

You cannot use your laptop.
03/11 Preparation for the Midterm Exam

Library and Patron:,
In-class practice answers: CSI33MidtermExamInClassPracticeAnswersAndSolutions.pdf
Week 6

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Here you can find your HW and quizzes gardes:
03/06 Sections 6.1-6.3

Lecture slides: CSI33-Lecture10-11.pdf

You can watch a video on Merge Sort here:

programs (from the book):,,,,
programs (from the book):,,,

In-class work: see lecture slides
HW10 (due date: Friday, 03/15)

programming exercises: p. 215 / 1, 5

Suggested exercises:
(for practice, not for grade):
1) What list is returned by anagrams("word")?
2) True-False questions: p. 212 / 1, 2, 3, 6
3) Multiple-Choice questions: p. 213 / 1, 4, 5, 6
4) Trace recPower(4,8) and and figure out exactly how many multiplications it does.
5) Short Answer questions: p.214 / 1, 5

Solutions: Chapter6Answers_part1.pdf, Chapter6Answers_part2.pdf
03/04 All classes are cancelled due to inclement weather  
Week 5

Summarize the data structures we explored so far with the run-time efficiency of common operations!!!

Midterm Exam will be on Wednesday, March 13th
02/27 Quiz 3 (covers Chapters 3 and 4)

Sections 5.3-5.5

Lecture slides: CSI33-lecture09.pdf

programs (from the book):,

In-class work: see the lecture slides, CabCompany.pdf,

time-driven simulation:,
Event-driven simulation:,
HW9 (due date: Wednesday, 03/07)

programming exercise: p. 184 / 4
02/25 Sections 5.1-5.2

Lecture slides: CSI33-lecture08.pdf

programs (from the book):,

In-class assignment: see lectures slides.
Solutions/answers: In-classWorkAnswers.pdf,

Check out these useful videos:
Infix to Postifx:
Infix to Prefix:
HW8 (due date: Monday, 03/04)
programming exercise: p. 184 / 3 (use Stack to evaluate the post-fix expression as shown in lecuture slides)

Suggested exercises:
1) True-False questions: p. 181 / 1-4
2) Multiple-Choice questions: p. 182 / 1-5
3) Short-Answer questions: p. 183 / 1

Answers/Solutions: Chapter5-questionsAnswers-part1.pdf, Chapter5-questionsAnswers-part2.pdf
Week 4
Now you can see your class grades here:
Use the last 4 digits of your school ID to find your record  
02/20 Sections 4.4 - 4.5, 4.7

Lecture slides: CSI33-lecture07.pdf


In-class work: see the last slide in the lecture slides
Solutions: (work with LList),
Fibonacci numbers generator (2 versions):, Which version do you like better?
HW7 (due date: Wednesday, 02/27)
1) programming exercises: p. 152 / 1, 3 (do both in one file,

Suggested exercises:
1) True-False questions: p. 148 / 1, 2, 4, 5
2) Multiple-Choice questions: p. 149 / 1-4
3) take a look at two versions of __copy__ method for LList class's implementation on page 132.
Solutions/answers: Chapter4-questionsAnswersSuggestedProblems.pdf
Week 3

Note that on Tuesday, February 12th the college is closed - Lincoln's birthday
on Monday, February 18th the college is closed - President's day

02/13 Sections 4.2-4.3

Quiz 2 today

Lecture slides: CSI33-lecture06.pdf

For in-class work:,

In-class work: see lecture slides (the last two slides) and use this file: problems1-2
    problems 1-2:,;
    problems 3-4: In-classWorkProblems3_4.pdf
HW6 (due date: Wednesday, 02/20)

Programming assignment: Let's think about doubly-linked lists. Define a class ListNode2, with three attributes: item, leftL, and rightL.
Left link points to the previous node in the list, right link points to the next node in the list.
You can also add the display method to this class (like we did it in class for the ListNode class).
Then test your class.
For example, create a linked list of 5 values: 34, 1, 23, 7, and 10. Display it. Then insert new value, say 8 between 34 and 1 (this time you will have to take care of links pointing to the previous and next node), display the resulting list. Then delete an element, say 7, update the links and display the new list.
Use this draft:

Suggested exercises
(not for grade, but highly recommended):
1) Short-Answer questions: p. 151 / 2
Answers: Chapter4-questionsAnswers.pdf
02/11 Sections 3.5-3.6

Lecture slides: CSI33-lecture05.pdf

Here is a link to time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython:

Quiz 2 will be on Wednesday, February 13th and will be based on Chapters 2 and 3.
HW5 (due date: Wednesday, 02/20)
programming exercise: p. 104 / 9
See suggested specification with some code here:
a simple version (do not store the contents of each pile, only the top card):

Suggested exercises
(not for grade, but highly recommended):
1) True-False questions: p. 100 / 8, 12
2) Multiple choice questions: p. 101 / 1, 3, 4, 5, 6, 8
3) Short-answer questions: p.102 / 3

Solutions: Chapter3-questionsAnswers-part1.pdf, Chapter3-questionsAnswers-part2.pdf

Week 2
02/06 Sections 3.1-3.4

Quiz 1 today (based on Chapter 1)

Lecture slides: CSI33-lecture04.pdf
HW2 discussion: SelectionSortAnalysis

On this page you can find the link to the compressed file with all the codes from the book:

more programs (from the book):, (different from previous lecture meeting),,,,

If you want to find out how to play Bridge:
another video:

In-class work: see lecture slides (last few slides)
HW4 (due date: Wednesday, 02/13)

1) Finish implementing the program discussed in class (in-class work, second assignment).
comment: note that at this level you should define classes (for example, for player, for scoring and so forth) where appropriate, also don't forget documentation (both inner comments that start with # and docstrings)! The program must use the classes Card and Deck we defined in class.

2) Programming Exercises: p 103 / 1, 2, 3- all of these exercises should be implemented in one file
Test all the operations, send the tests with your HW submission!

Suggested exercises
(not for grade, but highly recommended):
1) True-False questions: p. 100 / 2, 3, 6
2) Short-answer questions: p.102 / 1, 2

Solutions: Chapter3-questionsAnswers-part1.pdf
02/04 Sections 2.1-2.3, and 2.6 from the book.

Lecture slides: CSI33-lecture03.pdf


In-class work: start working on the HW assignment
HW3 (due date: Monday, 02/11)

Write unit tests to test the methods suit, suitName and rankNameof Card class

See the

Week 1
01/30 Section 1.3 Algorithm Analysis

Lecture slides: CSI33-lecture02.pdf

Additional materials: BinarySearchIllustrated.pdf

Additional resources: Check out this simple explanation of big-O notation:

In-class work: lecture02InClassPractice.pdf
Solutions: lecture02InClassPracticeSols.pdf
HW2 (due date: Wednesday, 02/06):

1) True/False questions: p. 33 / 4-6, 9, 10 - not for grade
2) Multiple Choice questions: pp.34-35 / 1-6, 10 - not for grade

Solutions: Chapter1solsTFMConly.pdf

3) Short-answer questions: p. 36 / 8 - not for grade
Solution: Chapter1ShortAnswerQuestions.pdf

4) Write a program that has both Linear Search and Binary Search algorithms implemented defined as two seprate functions.
Run each of the algorithms on the list of integers from 0 to 999999 and time them on three different numbers to search for: 10, 499999, and 999999. At the end your program should print the results.
Here is a draft/skeleton of the program:

5) Programming Exercises: p. 37-38 / 3, 9
* Programming exercise 3 asks you to implement Selection Sort algorithm.
See my comments here: here and
video (about 10 mins) presenting visualization of Selection Sort:

* In programming exercise 9 you are not to use the built-in set type.

Reminder: don't forget to put specification for each of the functions you are defining as well as to use internal comments (that start with #)
01/28 Sections 1.1, 1.2

Lecture slides: CSI33-lecture01.pdf

In-class work: lecture01-handout.pdf
Solutions: lecture01-handoutSols.pdf

We watched a video about O, Ω, and Θ notations:

First two chapters of the book are available through e-reserves:
Choose CSI33 from the list
HW1 (due date: Sunday, 02/03):
1) read Sections 1.1-1.2

2) read about docstring conventions at

3) get the book