Algorithms Exam 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

directed

Sequence of vertices in which every consecutive pair of the vertices is connected by an edge directed from the vertex listed first to the vertex listed next

Why is a balanced Binary Search Tree search O(log n)

-the choice of the next element on which to perform some action is one of several possibilities -only one will need to be chosen. Similar to looking a person up in a phone book. You don't need to check every person in the phone book to find the right one; instead, you can simply divide-and-conquer by looking based on where their name is alphabetically, and in every section you only need to explore a subset of each section before you eventually find someone's phone number. Of course, a bigger phone book will still take you a longer time, but it won't grow as quickly as the proportional increase in the additional size.

What are essential features of an algorithm

-unambiguous steps -terminates -obtains required outputs from valid inputs in a finite amount of time

What are the fundamental functions used in characterizing an algorithm?

1 (constant), log n, n, n log n, n2, n3, 2n, n!

What data structures can be use to represent graphs?

Adjacency matrix, Adjacency list

Describe the class of graph problems

Algorithms for this include graph traversal (hit all the points in network), shortest-path, and sorting of graphs with directed edges (is a set of courses with their prereqs consistent or contradictory?)

descendants

All the vertices for which a vertex is an ancestor. Proper descendants exclude the vertex itself.

Be able to justify why complexities of n2, 5n2, 12n2 are all considered to be O(n2)

Because those are multiplied by a constant. Therefor, they are all eclipsed by the power of the quadratic

What is an adjacency list?

Collection of linked lists, one for each vertex, that contain all the vertices adjacent to the lists vertex

What is the most challenging class of problems and why?

Combinatorial, because number of combinatorial objects grows very fast with a problem size. Efficient algorithms are hard to find, but shortest path problem (TSP) is considered an exception to this.

What is the approach of bubble sort?

Compare adjacent elements of the list and exchange them if they are out of order.

What is the traveling salesman problem?

Find the shortest tour through n cities that visits every city exactly once

Describe closest pair problem and the algorithm to solve it, and its O

Find two closest point in a set of n points. Compute distance between each pair of points and find the pair with the smallest distance. Make simpler by just finding square, not square root. O(n^2)

ancestors

For any vertex in a tree, all the vertices on the simple path from the root to that vertex are called ancestor of the vertex

Describe convex hull problem and the algorithm to solve it, and its O

Given a set of points in a plane find the smallest convex polygon that would include all the points of a given set. 1) calculate the line between two points 2) Check if any points lie on opposite sides of the line. 3) If so, it is not an edge and try two other points. O(n^3)

What is the approach of brute-force string matching?

Given a string of n characters and a string of m characters, find the substring m in n. Align pattern against first m characters and start matching the corresponding pairs of characters from left to right until either all the m pairs match or mismatching pair is encountered. If mismatched, shift right one and begin again

Describe knapsack problem and the algorithm to solve it

Given n items of known weights and values, and a knapsack of capacity W, find the most valuable subset of the times that fit into the knapsack. Generate all subsets, compute total weight of each, and choose the subset with the largest value among them. Similar to finding the heaviest weight of packages a plane can hold.

What is an adjacency matrix?

Given n vertices, it is an nxn boolean matrix with one row and one column for each of the graphs vertices where each row and column is connected if there is an edge there

siblings

If (u,v) is the last edge of the simple path from the root to the vertex, u is said to be the parent and v is called the child. Vertices that have the same parent are siblings.

What is the worst and best time complexity of selection sort?

Is O(n^2) on all inputs.

How do you find the highest growth order section?

Look for the nesting of loops. Two nested loops would be n^2, three loops would be n^3. Add up the time complexities of individual loops: if one is n^2 and the other is n, then T(n) = n^2+n and O(n) = n^2. Recall that a for loop to a constant number does not increase its time complexity.

best case def

N for which the algorithm runs the fastest among all possible inputs of that size

Describe assignment problem and the algorithm to solve it

N people who need to be assigned to n jobs, on person per job. Cost for I person assigned to j job is C[i,j]. Find the assignments with the lowest cost. Solve by generating all permutation of integers 1...n, compute total cost of each assignment by summing up corresponding elements of cost matrix, and select the one with the smallest sum.

Do different algorithms for the same problem have the same complexity?

No! It depends on how the algorithm is built, not what it solves. One may take more steps, one may have more loops, one may take longer

What does n typically represent?

Size of algorithms input

What are two important properties of sorting problems?

Stability and in place

What are the common strengths/weaknesses of empirical analysis

Strength: easy to implement. Can simply insert a counter to see how many times the base operation of an algorithm is executed. Weakness: A systems time is not very accurate, so you might get different results on repeated runs of the same program on same inputs

What problems are combinatorial problems?

TSP and graph coloring

Examples of exhaustive search

TSP, knapsack problem, and assignment problem.

How can statistical knowledge of the data an algorithm will process affect algorithm selection, with respect to best/worst/average case performance?

The more that is known about the data, the better the algorithm that can be applied/optimized

What factors would go in to deciding whether a breadth-first or depth-first search is more desirable?

The organization of the tree, and what (and therefor where) the answer likely is. If the answer is not far from the root, breadth first is probably better. If tree is very wide, you might want to use depth first.

Why would a sort which built a BST, then traversed it be O(n log2 n)

To create a tree you have to insert n elements in it. To insert the element in a balanced tree you need log(n). Therefore you end up with O(n*log(n)).

cycle

a path of positive length that starts and ends at the same vertex and does not traverse the same edge more than once

parental

a vertex with at least one child

What is the worst and best time complexity of bubble sort?

Worst and average case: O(n^2). Best case: O(n)

What is O

Worst case upper bound

binary search tree

a binary tree where the parent vertex has a number larger than all the numbers in its left subtree and smaller than all the numbers in its right subtree

What is the definition of a graph?

a graph is a collection of points (vertices) and lines (edges)

acyclicity

a graph without cycles

Weighted graph

also known as cost matrix Graph with numbers assigned to edges which represents its weight

What is the approach of sequential search?

compare successive elements of a given list with a search key until either a match is found or the list is exhausted. Improve by appending key to end of list so key is always found and eliminate the end of list check altogether

How to find worst case

analyze the algorithm to see what kind of inputs yield the largest number of basic operations count (C(n))

What is the graph coloring problem?

assign the smallest number of colors to vertices of a graph so that no two adjacent vertices are the same color: present in event scheduling

Give some examples of TSP's

present in circuit board and chip fabrication, x-ray crystallography, and genetic engineering

What is theta

bounded above and below

Describe exhaustive search

brute force approach to combinatorial problems. Generate every element of the problem domain, selecting those that satisfy the constraints, and finding the one that optimizes the objective function

What problems are geometric problems?

closest pair and convex hull

A tree is a ______, _______ _________

connected, acyclic graph

Describe the class of geometric problems

deals with geometric objects such as points, lines, and polygons

depth

depth of a vertex is the length of the simple path from the root to vertex.

how to find best case

determine the kind of inputs for which the count C(n) will be the smallest among all possible inputs of size n. For example: the best case inputs for the sequential search are lists of size n with their first element equal to a search key

average case

efficiency of an algorithm on typical or random input

connectivity

every vertex has some path to every other vertex, possibly by going through other vertices

Describe the class of searching problems

find a given value (search key) in a given set.

How do you analyze a pseudocode algorithm for its time and/or space efficiency?

find the highest growth order section (e.g., n3) as the one determining the upper bound)

Describe Traveling salesman problem and the algorithm to solve it

find the shortest tour through a given set of n cities that visits each city exactly once before returning to the city where it started. Can be modeled with a weighted graph, vertices are cities and edge weights are distances. Then solve using Hamiltonian circuit. Generate all permutations of n-1 intermediate cities, compute the tour lengths, and find the shortest among them.

Describe the convex hull problem

find the smallest convex polygon that would include all the points of a given set

Describe the closest pair problem

given n points in a plane, find the closest pair among them

What are graphs useful for?

in modeling applications (transportation, communication, social/economic networks, scheduling, games)

binary tree

is an ordered tree in which every vertex has no more than two children and each child is designated as either a left or right child. May also be empty

What does in-place mean?

it does not require extra memory

What does stability mean?

it preserves the relative order of any two equal elements

What is Omega

lower bound

What is the objective of algorithm analysis?

machine-independent evaluation of the algorithmic process in order to classify its time and/or space efficiency in terms of order of growth.

height

of a tree is the longest simple path from the root to leaf

Describe the class of string processing problems

particularly string matching - searching for a given word in a text

what is an effective brute-force algorithm to find one word from a list of those present in a word search, and what is its Big-O

probably brute force string matching: O(nm)

Describe the class of combinatorial problems

problems that ask to find a combinatorial object - such as a permutation, combination, or subset - that satisfies certain constraints

Describe the class of numerical problems

problems that involve mathematical objects of a continuous nature: solving equations/systems of equations, computing definite integrals, evaluating functions, etc. Can only solve problems approximately.

Describe the class of sorting problems

rearrange the items of a given list in nondecreasing order, often by a key (such as sorting students by GPA)

By what criteria are different algorithms which perform the same task compared?

required time, space, number of operations

What is the approach of selection sort?

scan entire list to find smallest element and exchange it with the first element, putting the smallest element in the final position in the list. Then scan list starting with second element, find the smallest among those, and exchange with the second element, putting the second smallest element in its final position. Continue.

Definition of doubly-linked list

sequence of 0 or more nodes where every node except the first and last contains pointers to both its successor and its predecessor, as well as data

Definition of linked list

sequence of 0 or more nodes, each containing 2 kinds of information: 1) data 2) pointer to next node

What is the definition of an array?

sequence of n items of the same data type that are stored contiguously in memory and made accessible by specifying an index. Used to implement other data structures like strings

Examples of searching problems

sequential search, binary search (important for storing/retrieving info from databases

Worst case definition

the n that causes the algorithm to run the longest among all possible inputs of that size

Describe brute-force

the straightforward approach to solving a problem, usually directly based on the problems statement and definitions or the concepts involved

What problems are graph problems?

traveling salesman problem and the graph coloring problem

set

unordered (possibly empty) collection of distinct elements of the set

multiset or bag

unordered collection of items that are not necessarily distinct

leaf

vertex with no children

When might empirical analysis be utilized in algorithm analysis?

with algorithms that are very difficult to analyze with mathematical precision and certainty


Kaugnay na mga set ng pag-aaral

12% CHAPTER 5: Real Estate Brokerage Activities: Guides for Sales Associates

View Set

Chapter 3 Study Guide- Personal Finance, Finance Quiz #3, Finance Quiz #4, Finance Quiz #5, Finance Quiz #6, Finance Quiz #7, Finance Quiz #8, Finance Quiz #9, Finance Quiz #10, Finance Quiz #11, Finance Quiz #12, Finance Quiz #13

View Set