Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  33 -4 8 10 127 5 operations:

Similar presentations


Presentation on theme: "Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  33 -4 8 10 127 5 operations:"— Presentation transcript:

1 Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  33 -4 8 10 127 5 operations: push (insert) pop (remove) topAndPop Oct 17, 2001 CSE 373, Autumn 2001

2 Stack Applications calculators: postfix or reverse Polish notation.
example: * Function calls stack frame or activation record func4 return var locals vars arguments func2 func1 func1() { func2(); func3(); } func2() { func4(); } Oct 17, 2001 CSE 373, Autumn 2001

3 Queues A list where circular array (modular arithmetic)
inserts happens at the end removes happen at the beginning circular array (modular arithmetic) Applications: graph algs, operating systems, web servers, etc. 5 3 7 ^^ front back -5 4 8 2 1 ^^ back front Oct 17, 2001 CSE 373, Autumn 2001

4 Trees Motivation: O(N) time to access arrays or linked lists.
Goal: O(log N) time for all operations. A tree is a collection of nodes. The collection may be empty. If it isn’t empty, then the tree consists of a distinguished node r, called a root and zero or more non-empty distinct (sub)trees T1, … , Tk, each of whose root are connected by a directed edge from r. Oct 17, 2001 CSE 373, Autumn 2001

5 Visualizing Trees root of each subtree is a child of r.
r is the parent of each subtree root. r T2 T3 T1 Oct 17, 2001 CSE 373, Autumn 2001

6 Tree terminology A leaf has no children.
Siblings have the same parent. grandparent, grandchild A path is a sequence of nodes n1, n2, … , nk such that ni is the parent of ni+1 for 1  i < k. The length of a path is the number of edges in the path. The depth of a node is the length of the path from the root to the node. The height of a tree: length of the longest path from root to a leaf. Oct 17, 2001 CSE 373, Autumn 2001

7 Tree example C:\ MyMail D101 cse373 school pers hw1 hw2 proj1 coll.h
coll.cpp poly.h Oct 17, 2001 CSE 373, Autumn 2001


Download ppt "Stacks A list where insertions and deletions can occur only at the end of the list. linked list or array implementation topOfStack  33 -4 8 10 127 5 operations:"

Similar presentations


Ads by Google