M180: Data Structures & Algorithms in Java
Trees & Binary Trees
Arab Open University
Trees
A tree is a nonlinear data structure used to represent
entities that are in some hierarchical relationship
Examples in real life:
Family tree
Table of contents

M180: Data Structures & Algorithms in Java
Graphs
Arab Open University
Topics
Graphs
Undirected graphs
Directed graphs
Graph Traversals
Depth-first
Breadth-first
4/30/16
AOU - Lebanon - M180
2
Graph Definitions
Nodes and links between them:
May be linked

M180: Data Structures & Algorithms in Java
Recursion
Arab Open University
Recursive thinking
Recursion: a programming technique in which a method can call
itself to solve a problem
Recursive definition: one which uses the concept being defined
in the defi

M180: Data Structures & Algorithms in Java
Linked Lists
Arab Open University
Outline
Linked list nodes
Linked list operations
Insertion
Append
Deletion
Other types of linked lists
Doubly-linked
Circular
4/30/16
AOU- M180
2
Limitation of Arrays
An arr

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package binarytree;
/*
* Java Program to Implement Binary Search Tree
*/
import java.util.Scanner;
/* Class BSTNode */
class BSTNode
cfw_
BSTNode left, right;

M180: Data Structures & Algorithms in Java
Two-Dimensional Arrays
Arab Open University
Two-Dimensional
Arrays
4/30/16
AOU- M180
2
Two-Dimensional Arrays
In Java a two-dimensional array is an array of arrays.
A two-dimensional array is declared by specifyi

M180: Data Structures & Algorithms in Java
Part1 - Overview
Part 2 - Arrays in Java
Arab Open University
Introduction to Data
Structures and Algorithms
4/30/16
AOU- M180
2
Overview
o A data structure is a scheme for organizing data in the memory
of a comp

M180: Data Structures & Algorithms in Java
Queues
Arab Open University
The Queue Definition and ADT
Queue: is a data structure that can simulate a list of stream of data.
In this structure, new elements are inserted at one end, rear, and
exiting (retrieve

package javaapplication7;
import java.io.*;
import java.util.*;
/ for Stack class
/
class Node cfw_
public int data;
public Node left;
public Node right;
/ data item (key)
/ this node's left child
/ this node's right child
public Node(int d)cfw_
data=d;
l

M180: Data Structures & Algorithms in Java
Text Processing in Java
Arab Open University
Strings
Java string is a sequence of characters. They are objects of type
String.
Strings are Immutable: Once a String object is created it
cannot be changed.
To get c

M180: Data Structures & Algorithms in Java
Sorting Algorithms
Arab Open University
Sorting
A fundamental application for computers.
Done to make finding data (searching) faster.
Many different algorithms for sorting.
One of the difficulties with sorting i

public class MergeSort cfw_
public static int[] mergeSort(int [] list) cfw_
if (list.length <= 1) cfw_
return list;
/ Split the array in half
int[] first = new int[list.length / 2];
int[] second = new int[list.length - first.length];
System.arraycopy(lis

M180: Data Structures & Algorithms in Java
Algorithm Analysis
Arab Open University
Program design
The analysis of algorithm is
a basic step in the program
design
2
What is analysis of algorithms?
There are often many approaches (algorithms) to solve a pr

M180: Data Structures & Algorithms in Java
Stacks
Arab Open University
4/30/16
1
Abstract Data Types (ADTs)
o ADT: A specification of a collection of data & the operations that
can be performed on it.
o Stack: Retrieves elements in the reverse of the orde

public class Queue cfw_
private int [ ] theArray;
private int
front;
private int
back;
private int
count;
private static final int DEFAULT_CAPACITY = 10;
/constructor
public Queue( ) cfw_
theArray = new int[ DEFAULT_CAPACITY ];
makeEmpty( );
/*
* Test if

public class Stack cfw_
private Object [ ] theArray;
private int
top;
private static final int DEFAULT_CAPACITY = 10;
/constructor
public Stack( ) cfw_
theArray = new Object[ DEFAULT_CAPACITY ];
top = -1;
/*
* Test if the stack is logically empty.
* and