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 algorithm can be implemented using different programming languages on differen
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
Hashing
Spring 2016
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
Graphs
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2016
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
2-3 Trees & Red-Black Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2016
CS202 - Fundamental Structures of Computer Science II
1
2-3 Trees
Definition:
A 2-3 tree is a tree in which each internal
node
Trees
Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
Spring 2016
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
What is a (General) Tree?
A (general) tree is a set of nodes with the following properties:
The set can be empty.
Otherwise, the set is partitioned into k+1 disjoint subsets:
a tree consists of a distinguished node r, called root, and
zero or more non
Trees
03/27/14
CS202 - Fundamentals of Computer Science II
1
What is a Tree?
T is a tree if either
T has no nodes, or
r
T is of the form:
T1
T2
Tk
where r is a node and T1, T2, ., Tk are trees.
03/27/14
CS202 - Fundamentals of Computer Science II
2
Tre
Balanced Search Trees
05/04/16
CS202 - Fundamental Structures of Computer Science II
1
AVL Trees
05/04/16
CS202 - Fundamental Structures of Computer Science II
2
AVL Trees
Definition:
An AVL tree is a binary search tree such that
for any node in the tree,
Analysis of Algorithms
Spring 2016
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 2016
CS202 - Fundamentals of Computer Science II
1
Problem of the Day
Spring 2016
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
What is a (General) Tree?
A (general) tree is a set of nodes with the following properties:
The set can be empty.
Otherwise, the set is partitioned into k+1 disjoint subsets:
a tree consists of a distinguished node r, called root, and
zero or more non
Trace the following sorting algorithm for sorting the array 7 1 9 2 3 5 into ascending order.
Use the array implementation as described in the textbook/lectures.
Insertion sort
719235
179235
179235
127935
123795
123579
Selection sort
719235|
71523|9
3152|
CS 202 Fundamental Structures of Computer Science II
Assignment 1 Algorithm Analysis, Sorting and Searching
Due Date: June 21, 2010 (Monday)
Question-1 (30 points)
Trace the following sorting algorithm for sorting the array: 7 1 9 2 3 5 into ascending
ord
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
Sorting Examples
CS 202
Department of Computer Engineering
Bilkent University
Slides adapted from Aybar Acar
Spring 2015
Spring 2015
c
2015,
CS 202 (Bilkent University)
1 / 14
Playing Cards
Spring 2015
c
2015,
CS 202 (Bilkent University)
2 / 14
Insertion
CS 202 - Fundamental Structures of Computer Science II
Spring 2003, Section 1
Quiz #1 Solution
Question: The following items are given: 80, 60, 70, 90, 85, 50, 55, 58, 57, 56.
a. Insert them into a binary search tree in the given order. Draw the tree afte
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
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 algorithm can be implemented using different programming languages on differen