













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














George Mason University, Department of Computer Science
R. Paul Wiegand George Mason University, Department of Computer Science
R. Paul Wiegand George Mason University, Department of Computer Science
Forrest for the trees Making educated & informed decisions Need as designer AND implementor Engineer versus technician
“Don’t know Big-O stuff!” “The JDK comes with a Sort routine...” Etc.
R. Paul Wiegand George Mason University, Department of Computer Science
The statement of a problem specifies in general terms the relationship between input and output Example Sort a set of numbers in non-decreasing order (sorting problem) Input: 〈a 1 , a 2 ,... an〉 Output: 〈a′ 1 , a′ 2 ,... a′ n〉 : a 1 ′ ≤ a′ 2 ≤ · · · ≤ a′ n
A problem instance consists of the input, satisfying whatever constraints are imposed by the problem statement) needed to compute a “solution” to the problem. Example problem instance: Input: 〈 4 , 6 , 7 , 1 , 9 , 3 , 8 , 10 , 5 , 2 〉 Output(solution): 〈 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 〉
R. Paul Wiegand George Mason University, Department of Computer Science
Input: m, n ∈ N, where (m ≥ 0 ∧ n > 0) ∨ (m > 0 ∧ n ≥ 0) Output: Largest integer that divides both m and n evenly
ConsecutiveInteger(m, n): step-1: t ← min{m, n} step-2: if m t ∈ N+, goto step- step-3: if n t ∈ N+, return t step-4: t ← t − 1 , goto step-
R. Paul Wiegand George Mason University, Department of Computer Science
R. Paul Wiegand George Mason University, Department of Computer Science
R. Paul Wiegand George Mason University, Department of Computer Science
Find a given value, called a search key, in a set of values A variety of algorithms exist (sequential search, binary search, etc.) Sometimes data are stored in data structures that make them more conducive for searching (hash maps, red-black trees, etc.) Engineers have to pay attention to applications where the underlying data may change frequently relative to the number of searches.
A string is a sequence of characters from some well-defined alphabet (e.g., binary strings) Large class of problems dealing with the handling of strings An example problem is string matching: Find the positions of a substring in a master string.
R. Paul Wiegand George Mason University, Department of Computer Science
Geometric problems deal with geometric objects (e.g., points, lines, polygons, etc.) For example: Closest-pair problem
Given n points, find the pair of points with the minimum distance between them Convex hull problem (^) Given n points in a set, find the smallest convex poly- gon that contains all these points.
These are different than graph problems!
Problems involving continuous mathematical objects For example: Solving systems of equations Computing derivatives & definite integrals Optimizing numerical functions, etc.
R. Paul Wiegand George Mason University, Department of Computer Science
The following are two elementary data structures useful for produce more ab- stract linear data structures called lists (a finite sequence of data items) array — A sequence of n items of the same data type stored contiguously in memory and accessible using an index Pre-established, fixed size Constant time access, insertion and deletion can be challenging Example: bit string, 1 0 0 1 1 0 1 linked list — A sequence of zero or more nodes, each containing data and pointer(s) to other node(s) Not necessarily fixed in size Linear time access, insertion and deletion are simpler Linked lists can be single-linked or doubly-linked Linked lists can have a header, which stores useful information (e.g., length)
R. Paul Wiegand George Mason University, Department of Computer Science
Graphs are collections of points called vertices and line segments, called edges, connecting (some of the) vertices Formally: G := 〈V , E 〉, where V is a finite set of labels corresponding to vertices (e.g., V := {a, b, c}) and E is a finite set of pairs of these items (e.g., E := {(a, b), (a, c)} Undirected graph: Edges are unordered, i.e., (a, b) = (b, a) Directed graph: Edges are ordered and thus imply a direction
a
b c
a
b c
Complete — every pair of vertices is connected by an edge Dense — most vertices are connected Sparse — few vertices are connected
R. Paul Wiegand George Mason University, Department of Computer Science
adjacency matrix — Enumerate vertices in { 1... n}, create an n × n matrix of boolean values indicating whether an edge exists between the specified vertices Undirected graphs result in symmetric matrices Easily determine if an edge exists, requires space Good for dense graphs
a b c a 0 1 1 b 1 0 0 c 1 0 0
adjacency list — Create a linked list for each vertex containing the vertices to which that vertex is connected Somewhat more difficult to determine edge existence, more compact in space Good for sparse graphs
a → b → c b → a c → a
R. Paul Wiegand George Mason University, Department of Computer Science
A (free) tree is a connected, acyclic graph. A forest is multiple trees, or an unconnected, acyclic graph. |E | = |V | − 1 For every two vertices, there’s always exactly one simple path between them ∴ we can select an arbitrary vertex to be the root For any v ∈ T , all vertices on the path between the root and v are called ancestors The last edge on that path before v is called the parent, v is the child of that node, etc. A vertex with no children is called a leaf A vertex with all its descendants is called a subtree The depth v is the length of the simple path from the root to v The height of a tree is the length of the longest simple path from R. Paul Wiegandthe root to a leaf George Mason University, Department of Computer Science
What is a set? A set is an unordered collection (possibly empty) of distinct items. We can implement a set as a bit vector over the universal set We can implement a set with a list structure (with insertion constraints) A multiset or bag is a set without the uniqueness constraint (an unordered collection of objects) Basic operations of a multiset: Search, Insert, Delete A basic data structure that accomplishes these operations is a dictionary Sometimes we need to dynamically partition some n-element set into a collection of disjoint sets. Sometimes we need to take the union or intersection of sets
R. Paul Wiegand George Mason University, Department of Computer Science