CS202 Fundamental Structures of Computer Science II
Quiz 1
Name
: _
ID
: _
1-a
20
1-b
20
1-c
20
2
40
Total
100
Section : 1
Important: Every incorrect answer will end up with -10 points. So, don't answer unless you are sure.
1.
(60 pts) What is the running

Graphs
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2015
CS202 - Fundamental Structures of Computer Science II
1
Graphs
Graphs are one of the unifying themes of computer science.
A graph G = (V, E) is de

Analysis of Algorithms
Fall 2015
CS202 - Fundamentals of Computer Science II
1
Algorithm
An algorithm is a set of instructions to be followed to solve a problem.
There can be more than one solution (more than one algorithm) to solve a given problem.
An

Sorting and Searching
Fall 2015
CS202 - Fundamentals of Computer Science II
1
Problem of the Day
Fall 2015
CS202 - Fundamentals of Computer Science II
2
Sequential Search
int sequentialSearch( const int a[], int item, int n)cfw_
for (int i = 0; i < n & a[

Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Fall 2015
CS202 - Fundamentals of Computer Science II
1
What is a Tree?
T is a tree if either
r
T has no nodes, or
T is of the form:
T1
T2
Tk
where r is a nod

CS 202: Fundamental Structures of Computer
Sciences II
Assignment 1
Due: 23:59, March 10 (Monday), 2014
Part 1
In this assignment, your aim is to implement the following sorting algorithms
for integer arrays, and to empirically evaluate them. Moreover, yo

CS 202: Fundamental Structures of Computer
Sciences II
Assignment 2
Due: 23:59, April 3 (Thursday), 2014
In this assignment, you will get familiar with an important programming
concept, i.e., algebraic expression tree and dierent expression notations such

CS 202 Fundamental Structures of Computer Sciences II
Assignment 3 Heap, Priority Queue
Due: 23:59, May 5 (Monday), 2014
In this programming assignment, you are asked to find a software solution to the scheduling problem of
Bilkent Bank. The banks manager

CS 202 Fundamental Structures of Computer Science II
Assignment 3 Heaps and AVL Trees
Date Assigned: November 6, 2015
Due Date: November 21 23:55 (sharp), 2015
1) Question Part (40 points)
a) (10 points) Show the result of inserting 13, 8, 5, 9, 4, 6, 12,

CS 202 Fundamental Structures of Computer Science II
Assignment 4
Date Assigned: November 23, 2015
Due Date: December 9, 2015 - 23:55 (sharp)
1) Question Part (40 points)
Assume that we have the following balanced-searched tree implementations:
a) AVL tre

Hashing
Fall 2015
CS202 - Fundamental Structures of Computer Science II
1
Hashing
Using balanced search trees (2-3, 2-3-4, red-black,
and AVL trees), we implement table operations in O
(logN) time
retrieval, insertion, and deletion
Can we find a data s

Balanced Search Trees: AVL Trees
The height of a binary search tree is sensitive to the order of
insertions and deletions.
The height of a binary search tree is between log2(N+1) and N.
So, the worst case behavior of some BST operations are O(N).
Ther

2-3 Trees, 2-3-4 Trees
Red-Black Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Fall 2015
CS202 - Fundamental Structures of Computer Science II
1
2-3 Trees
Definition:
A 2-3 tree is a tree in which each inter

Binary Trees
Array-based implementation of
Binary Tree
After a couple insertions/deletions
Index
Data
Left
Child
Right
Child
0
75
5
1
1
90
-1
-1
2
92
0
-1
3
18
-1
-1
4
100
7
2
5
27
-1
-1
6
7
9
20
-1
3
8
6
9
10
Root=100
free=8
Inserting a New Node
New Tabl

Tables
Appropriate for problems that must manage data by value.
Some important operations of tables:
An ordinary table of cities
Inserting a data item containing the value x.
Delete a data item containing the value x.
Retrieve a data item containing

2-3 Trees & Red-Black Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2015
CS202 - Fundamental Structures of Computer Science II
1
2-3 Trees
Definition:
A 2-3 tree is a tree in which each internal
node

CS202
Section 1
Quiz No. 1: Quiz for Fun
September 11, 2015
Solutions
Q-1)
Given three integers a, b, and c. Please write an algorithm /function that outputs maximum of these
three integers. Several different solutions are possible.
A-1)
Q-2)
Please guess

CS202
Section 1
Quiz No. 2: Recurrence Equation & Insertion Sort
September 29, 2015
Solutions
Q-1)
Complexity of a recursive algorithm is given as follows:
Find the solution in asymptotic notation.
A-1)
1
Q-2)
As an input an unsorted array is given as fol

CS202
Section 1
Quiz No. 3: Quicksort
October 9, 2015
Solutions
Q-1) Sort in ascending order, use last element as the pivot (see the algorithm on the last page).
a) 8 / 7 / 15 / 3 / 42 / 1
b) 42 / 8 / 15 / 3 / 1 / 7
c) 1 / 3 / 7 / 8 / 15 / 42
A-1)
a) Firs

CS202
Section 1
Quiz No. 4: Binary Tree
October 20, 2015
Solutions
Q-1) For a binary tree the following preorder and inorder traversal results are given. Construct the
corresponding binary tree.
Preorder: ABDEHICFG
Inorder: DBHEIAFCG
Solution:
From preord

CS 202 Fundamental Structures of Computer Science II
Assignment 1 Algorithm Efficiency and Sorting
Assigned on: 2 October 2015 (Friday)
Due Date: 16 October 2015 (Friday)
Question-1: Tracing(20 points)
Trace the following sorting algorithms to sort the ar

CS 202 Fundamental Structures of Computer Science II
Assignment 2 Trees
Date : 19 October 2015
Due Date: 3 November 2015 - 23:59 (Tuesday)
4 November 2015 - 00:05 (12:05 AM) Wed. 1
Q1) [10 pts]
Give the prefix, infix, and postfix expressions obtained by p

Worksheet for Trees
Worksheet for Midterm 2
CS200: Algorithms and Data Structures
1. Given the binary tree operations, what tree or trees does the following sequence of
statements produce?
Public void Ex11()cfw_
BinaryTree<Integer> t1 = new

Analysis of Algorithms
Spring 2015
CS202 - Fundamentals of Computer Science II
1
Algorithm
An algorithm is a set of instructions to be followed to solve a problem.
There can be more than one solution (more than one algorithm) to solve a given problem.

Sorting and Searching
Spring 2015
CS202 - Fundamentals of Computer Science II
1
Problem of the Day
Spring 2015
CS202 - Fundamentals of Computer Science II
2
Sequential Search
int sequentialSearch( const int a[], int item, int n)cfw_
for (int i = 0; i < n

Hashing
Spring 2015
CS202 - Fundamental Structures of Computer Science II
1
Hashing
Using balanced search trees (2-3, 2-3-4, red-black,
and AVL trees), we implement table operations in O
(logN) time
retrieval, insertion, and deletion
Can we find a data

Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2015
CS202 - Fundamentals of Computer Science II
1
What is a Tree?
T is a tree if either
r
T has no nodes, or
T is of the form:
T1
T2
Tk
where r is a n

Balanced Search Trees
The height of a binary search tree is sensitive to the order of
insertions and deletions.
The height of a binary search tree is between log2(N+1) and N.
So, the worst case behavior of some BST operations are O(N).
There are vario

Graphs
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Fall 2015
CS202 - Fundamental Structures of Computer Science II
1
Graphs
Graphs are one of the unifying themes of computer science.
A graph G = (V, E) is defi