Linked Lists:
Deleting Nodes
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Linked Lists: Basic Operations
Operations Performed on Linked Lists
Several operations can be performed on linked
lists
Add a

Heaps &
Priority Queues
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Heaps
Building a Heap from scratch (a Max heap)
Given: an unsorted list of n values
54, 87, 27, 67, 19, 31, 29, 18, 32, 56

Binary Trees:
Deletion
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Trees: Deletion
Deletion From a Binary Search Tree
Deleting nodes from a BST requires some thought
There are 3 possible cas

Hash Tables
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Terminology
Table
An abstract data type that stores & retrieves
records according to their search key values
Record
Each individual row in t

Sorting:
2
O(n ) Algorithms
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Sorting: O(n2) Algorithms
Sorting Algorithms:
Fundamental problem in Computer Science
Sorting is done to make searching easie

Binary Trees:
Search & Insert
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Search Tree
Binary Search Trees
Ordering Property:
For each node N, all the values stored in the left subtree
of N ar

Binary Heaps &
Priority Queues
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Heaps
Heap:
A heap is an Abstract Data Type
So what is a heap?
More specifically, what does it do or how do they wor

More Recursion
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Recursion
What is Recursion? (reminder from last time)
From the programming perspective:
Recursion solves large problems by reducing
them

Binary Trees:
Practice Problems
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Trees: Practice Problems
Warmup Problem 1: Searching for a node
public boolean recursiveSearch(int data) cfw_
return

Recursion
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Recursion
What is Recursion?
Powerful, problem-solving strategy
yeah, that tells us a whole lot
</sacrasm_off>
In plain English:
Recursion: the

Graphs Intro.
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Northwest Airline Flight
Anchorage
Boston
Minneapolis
Seattle
Hartford
SF
Atlanta
Austin
Dr. Jonathan (Yahya) Cazalas
Sorting: Quick Sort
pag

Sorting:
Merge Sort
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Sorting: Merge Sort
Problem with Bubble/Insertion/Selection Sorts:
All of these sorts make a large number of
comparisons and swaps bet

Data Structure Intro &
Review of Arrays
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
What is Data?
Data
A collection of facts from which a conclusion
may be drawn
Example:
Temperature is 35 degrees

Algorithm
Analysis
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Order Analysis
Judging the Efficiency/Speed of an Algorithm
Thus far, weve looked at a few different
algorithms:
Max # of 1s
Linear Sea

Sorting:
Quick Sort
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Sorting: Quick Sort
Quick Sort
Most common sort used in practice
Why?
cuz it is usually the quickest in practice!
Quick Sort uses two

Binary Trees
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Outline
Tree Stuff
Trees
Binary Trees
Implementation of a Binary Tree
Tree Traversals Depth First
Preorder
Inorder
Postorder
Breadth F

And More
Recursion
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Binary Search A reminder
Array Search
We are given the following sorted array:
index
value
0
2
1
6
2
19
3
27
4
33
5
37
6
38
7
41
8
118

CPCS-204
Data
Structures-I
LAB 8: Stack
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use of stack data structure
in writing simple Java programs. Another aim is to teach the students how to
implement stack data structure

CPCS-204
Data
Structures-I
LAB 2: Linear Search VS Binary Search
Statement Purpose:
Purpose of this Lab is to familiarize the students with the code of linear search and
binary search. Another aim is to teach the students the difference between the
runnin

CPCS-204
Data
Structures-I
LAB 7: Algorithms Analysis
Statement Purpose:
Purpose of this lab is to introduce the concepts of Big-O running time of the
Algorithms to the students. The students are also familiarized with the time and space
complexity of alg

CPCS-204
Data
Structures-I
LAB 9: Queue
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use of queue data structure
in writing simple Java programs. Another aim is to teach the students how to
implement queue data structure

CPCS-204
Data
Structures-I
LAB 4: Linked List 2
Statement Purpose:
Purpose of this Lab is to familiarize the students with writing simple Java programs
using Linked List. The students are given small tasks related to Linked List which they
complete during

CPCS-204
Data
Structures-I
LAB 5: Recursion 1
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use and power of recursion
in Java. They will learn what types of problems can be solved using recursion. They
will also be taught

CPCS-204
Data
Structures-I
LAB 3: Linked List 1
Statement Purpose:
Purpose of this Lab is to familiarize the students with Linked List data structure.
Another aim is to teach the students the disadvantages of using arrays and
advantages of using linked li

CPCS-204
Data
Structures-I
LAB 6: Recursion 2
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use and power of recursion
in Java. They will learn what types of problems can be solved using recursion. They
will also be taught

CPCS-204
Data
Structures-I
LAB 1: Arrays
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use of elementary data
structure-Arrays. Another aim is to teach the students how to implement one
dimensional and two dimensional arra

CPCS-204
Data
Structures-I
LAB 10: Binary Search Trees
Statement Purpose:
Purpose of this Lab is to familiarize the students with the use of Binary Search Trees
data structure in writing simple Java programs. Another aim is to teach the students
how to im

More Algorithm
Analysis
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
More Algorithm Analysis
Examples of Analyzing Code:
We now go over many examples of code
fragments
Each of these methods will be

Stacks:
Implementation in
JAVA
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Stacks An Overview
Stacks:
Stacks are an Abstract Data Type
Meaning, they are a data type that we must build
(well, in JAV

Link Lists Gone Wild:
Circular and Doubly
Linked Lists
College of Computing & Information Technology
King Abdulaziz University
CPCS-204 Data Structures I
Double-Linked Lists
Limitations of a singly-linked list include:
Insertion at the front is O(1)
inse