Algorithm Analysis
CENG 213 Data Structures 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 algorithm can be implemented usi

#include <cstdlib>/ This library is added for the NULL keyword
class StackException/ Throw this exception class when invalid stack operation is performed
cfw_
public:
StackException() : message( "Stack is Empty ! Invalid Operation !" ) cfw_
const ch

Recursion
CENG 707
1
Recursion
Recursion is a technique that solves a problem by solving
a smaller problem of the same type.
A recursive function is a function invoking itself, either
directly or indirectly.
Recursion can be used as an alternative to i

The Abstract Data Type Queue
A queue is a list from which items are deleted from one end ( front)
and into which items are inserted at the other end ( rear, or back)
It is like line of people waiting to purchase tickets:
Queue is referred to as a first

Linked Lists
1
Linked List Basics
Linked lists and arrays are similar since they both
store collections of data.
The array's features all follow from its strategy of
allocating the memory for all its elements in one
block of memory.
Linked lists use an

Intoduction to C+
1
Programming in C+
C+
Improves on many of C's features
Has object-oriented capabilities
Increases software quality and reusability
Developed by Bjarne Stroustrup at Bell Labs
Called "C with classes"
C+ (increment operator) - enha

Priority Queues
(Heaps)
1
Priority Queues
Many applications require that we process records
with keys in order, but not necessarily in full sorted
order.
Often we collect a set of items and process the one
with the current minimum value.
e.g. jobs sent

Hashing
1
Hash Tables
Well discuss the hash table ADT which supports only
a subset of the operations allowed by binary search
trees.
The implementation of hash tables is called hashing.
Hashing is a technique used for performing insertions,
deletions a

AVL
Trees
1
AVL Trees
An AVL tree is a binary search tree with a balance condition.
AVL is named for its inventors: Adelson-Velskii and Landis
AVL tree approximates the ideal tree (completely balanced tree).
AVL Tree maintains a height close to the minimu

Sorting Algorithms
Sorting
Sorting is a process that organizes a collection of data into either ascending or
descending order.
An internal sort requires that the collection of data fit entirely in the
computers main memory.
We can use an external sort whe

Abstract Data Types (ADTs)
An abstract data type (ADT) is an abstraction of a data structure
An ADT specifies:
Data stored
Operations on the data
Error conditions associated with operations
01/17/13
1
The Stack ADT
The Stack ADT stores arbitrary obj

#include <vector>
#include <string>
using namespace std;
class Recipe
cfw_
public:
struct Ingredient/ Ingredients of the recipe
cfw_
string name;/ name of the ingredient
int cost;/ cost of the ingredient
;
private:
typedef LinkedAndXOrBinaryTree

#include <cstdlib>/ This library is added for the NULL keyword
#include <string>
using namespace std;
class LinkedAndXOrBinaryTreeException/ Throw this exception class when invalid tree operation is performed
cfw_
public:
LinkedAndXOrBinaryTreeExceptio

!MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS
CNG213 C Programming Programming Assignment 3!
Date handed out:
11 December 2015, Friday
Date submission due: 24 December 2015, Thursday
Telephone System Simulator
In this assignment, you will writ

!MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS
CNG213 C Programming Programming Assignment 2!
Date handed out:
Sunday 22 November 2015
Date submission due: Monday 7 December 2015
Path Finder
This assignment aims to help you practice linked list

MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS
CNG213 C Programming Programming Assignment 1
Date handed out:
Wednesday 04 November 2015
Date submission due: Monday 16 November 2015
Introduction
This assignment aims to help you

!MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS
CNG213 C Programming Programming Assignment 4!
Date handed out:
Sunday 27 December 2015
Date submission due: Friday 08 January 2016
Indexing Tweets!
This assignment aims to help you practice binary

Trees
1
Preliminaries (continued)
A path from node n1 to nk is defined as a sequence of
nodes n1, n2, , nk such that ni is parent of ni+1 (1 i < k)
The length of a path is the number of edges on that
path.
There is a path of length zero from every node

AVL Search Trees
Inserting in an AVL tree
Insertion implementation
Deleting from an AVL tree
Insertion
Insert using a BST insertion algorithm.
Rebalance the tree if an imbalance occurs.
An imbalance occurs if a node's balance factor changes from -1 to -2

CSCE3110
DataStructures&
AlgorithmAnalysis
RadaMihalcea
http:/www.cs.unt.edu/~rada/CSCE3110
Trees.BinaryTrees.
Reading:Chap.4(4.14.2)Weiss
TheBritishConstitution
Crown
Church of
England
House of
Council
Lords
Court
Minister
s
County
Rural
District
Supreme

CSCE3110
DataStructures&
AlgorithmAnalysis
RadaMihalcea
http:/www.cs.unt.edu/~rada/CSCE3110
Trees.BinaryTrees.
Reading:Chap.4(4.14.2)Weiss
TheBritishConstitution
Crown
Church of
England
House of
Council
Lords
Court
Minister
s
County
Rural
District
Supreme

Trees
Chapter 15
Chapter Contents
Tree Concepts
Traversals of a Tree
Hierarchical
Organizations
Tree Terminology
Traversals of a Binary
Tree
Traversals of a General
Tree
Java Interfaces for
Trees
Examples of Binary
Trees
Interfaces for All Trees
Interface

Binary Trees
Page: 1
Binary Trees
by Nick Parlante This article introduces the basic concepts of binary trees, and then works through a series of practice problems with solution code in C/C+ and Java. Binary trees have an elegant recursive pointer structu

Deletion from an AVL Tree
First we will do a normal binary search tree delete. Note that structurally speaking, all deletes from a binary search tree delete nodes with zero or one child. For deleted leaf nodes, clearly the heights of the children of the n