1: Infix to Postfix and Evaluation
1: Infix to Postfix and Evaluation
Part 1:
Translate from infix to postfix
Initialize a Queue
Initialize a Stack
Read in one expression in infix format; e.g.
(a+b)*c
In the following algorithm, assume Next is
what the pr
Structure, Array, and Pointer
Objectives
Structures
Arrays of Structures
Structures as Function Arguments
Dynamic Data Structure Allocation
Problem Solving
Common Programming Errors
270 Struct, Array, Pointers
1
Structures
Historical holdovers from
5: Binary Trees
5: Binary Trees
In computer science, a binary tree is a tree data structure in which
each node has at most two children Typically the first node is
each node has at most two children. Typically the first node is
known as the parent and the
Graph
Graph
Graph Structure and Codes
directed graph: digraph
A directed graph or digraph is a pair G= (V, A) of: a set
V, whose elements are called vertices or nodes, a set
A of ordered pairs of vertices, called arcs, directed
edges, or arrows (and somet
Class and Abstraction
Meaning of an Abstract Data Type
Declaring and Using a class Data Type
Using Separate Specification and
Implementation Files
Invoking class Member Functions in Client
Code
C+ class Constructors
1
Abstraction
Abstraction is the separ
Pointers
C+ uses an asterisk * to denote a pointer.
If Item is then a pointer to such an Item object has the type
Item
Item *item_ptr;
declares item_ptr as a pointer variable to an Item object.
For example:
int *pa;
1
Pointer: Creating dynamic objects
pa
15: Graph algorithms: others
Bellman-Ford algorithm
1. For some weighted digraphs with negative weights
2. Still a shortest path algorithm
3. Computes the shortest path weights d(s, v) from
vertex s V, to all other vertices v V.
4. Or report all negative
Graph
Graph
Graph Structure
A graph is a mathematical abstraction :
a set of vertices (nodes), and a set of edges (arcs),
where an edge connects two vertices in the graph
A graph is a pair (V,E), where V is a finite set and E is a
binary relation on V.
V
Sorting
Selection Sort
Insert Sort
Merge Sort
Selection Sort
It is a in-place sort method.
A comparison sort
Complexity O ( n2 )
Not efficient when data set is large
2
Selection Sort: Algorithm
Find the minimum value in the list
Swap it with the value
Heapsort
Heapsort is an internal sorting method which
sorts an array of n records in place in
O(n log n) time.
It is a in-place sort method.
1
Heapsort
Heapsort is always O(n log n)
Quicksort is usually O(n log n) but in the worst
case slows to O(n2)
Q
Graph
Graph
Graph algorithms
Weighted Graph:
In a weighted graph, or network, it is frequently
desired to find the shortest path between two
nodes, a and b
Shortest Path:
A path from a to b such that the sum of the weights
on the path is minimized.
A Shor
More on Trees
Other considerations in access time
AVL may not be adequate for some computing and
data access time limit
B-trees: m-way trees
1
Disk access time vs CPU time
We have assumed that all instructions are created
equally in our analysis. What if
Binary Tree and AVL Tree
1
Insertion into a Binary Search Tree
2
Height Balanced Tree:
AVL Tree (Adelson-Velskii and Landis)
A balanced binary search tree where the height
of the two subtrees (children) of a node differs
by at most one. Look-up, insertio
5: Recursive Functions
5: Recursive Functions
Recursive Definition:
A function is defined by itself.
1
Factorials
Factorials
Formal definition:
Factorial (2)
int factorial(int n)
/* Pre: n is a nonnegative integer.
Post: Return the value of the factorial
4: Linked Lists
4: Linked Lists
Pointers: An object, often a variable, that stores the location (that
is the machine address) of some other object typically of
is the machine address) of some other object, typically of a
structure containing data that we
Sorting
Bubble Sort
Radix Sort
Quicksort
Heapsort
1
Bubble Sort
2
Bubble Sort
1. Index goes through entire array
Swap adjacent items according to the rule of
ascending or descending
The max or min is pushed to the end of the
array
2. Starting the new ro
ECE370
Assigned
Due
Programming Assignment 3
2/14/17
3/6/17
Winter2017
LinkedLists
Thisprogramistoimplementanumberoffunctionsonalinkedlist.
1. Insertion of a node to a linked list, by given criteria
2. Deletion of a node on a linked list, by given criteri