Analysis Of Algorithms
Montgomery Blair High SchoolClass Period 2
Name Lucia Wang
1st MP Test Review Answers
Some of the terms are used more than once, some are not used.
Growth Rates
O(1)
O(n)
Best Case
linear
O(nlogn)
Worse Case
logarithmic
O(n^2)
O(2^n)
dynamic approach
Average Case
Big O Notation
Constant
𝑛 𝑛
𝑂( 𝑙𝑜𝑔𝑛 )
Fast
exponential
convex hull
Gift Wrapping
O(logn)
quadratic
recursion
back tracking approach
Graham’s
Divide And Conquer Approach
1. If the time is not related to input size, the algorithms is said to be in constant time with the
notation of o(1).
2. Euclid’s GCD algorithm takes o(n) time.
3. The Eight Queens Problem can be solved using a recursive backtracking approach
4. Binary Search takes o(logn) time. An algorithm with this time complexity is called a
logarithmic algorithm and it exhibits a logarithmic growth rate.
5. The closest pair can be found in O(n^2) time using the divide and conquer approach.
6. An Average case analysis attempts to determine the average amount of time among all
possible input of the same size. Average case analysis is ideal, but difficult to perform because
for many problems, it is hard to determine the relative probabilities and distributions of various
input instances.
Analysis Of Algorithms
Montgomery Blair High SchoolClass Period 2
Name Lucia Wang
7. The worst time complexity for selection sort is o(n^2). An algorithm with this complexity is
called a quadratic algorithm and exhibits a/an quadratic growth rate.
8. The Big O notation is a theoretical approach for analyzing the performance of an algorithm.
It estimates how fast an algorithm’s execution time increases as the input size increases, which
enables you to compare two algorithms by examining their big o notation.
9. An input that results in the shortest execution time is called the best case input, and one that
results in the longest execution time is called the worst case input. Best-and-worst case
analyses are not representative, but Big O Notation analysis is very useful. You can be assured
the algorithm will be never slower than the worst case.
10. Linear Search takes O(n) time. An algorithm with this time complexity is called a linear
algorithm and it exhibits a constant growth rate.
11. The time complexity for the Tower of Hanoi problem is O(2^n). An algorithm with this time
complexity is called an exponential algorithm because it exhibits an exponential growth rate.
12. Convex hull is the process of solving sub problems, the combining the solutions of sub
problems to obtain an overall solution. The key idea behind it is to solve each sub problem only
once and store the results for sub problems for later use to avoid redundant computing of the
sub problems.
13. The back tracking approach searches for a candidate solution incrementally, abandoning
the option as soon as it determine the candidate cannot possibly be a valid solution, then looks
for a new candidate.
14. The dynamic approach divides the problem into sub problems, solves the sub problems,
and then combines the solutions of the sub problems to obtain the solution for the entire
problem. The sub problems don’t overlap, and you can apply _recursion_ to solve the problem
Terms may be used more then once. Some are not used
Analysis Of Algorithms
Montgomery Blair High SchoolClass Period 2
LinkedHashMap
Hash Function
Name Lucia Wang
HashMap Set
Hash Code
Indexes
Hash Table
Map
Collision
Quadratic Probing
Linear Probing Double Hashing
One
Two
Duplicate
List
Hashing
Value
O(1)
key
Open addressing
Separate Chaining
Bucket
15. A Map stores key/value pairs. It provides a quick lookup for a value using a key.
16. A HashMap stores non-duplicate elements to allow duplicate elements to be stored in a
collection, you need to use a list.
17. The Hash Function Interface maps keys to the elements. The keys are like Indexes.
18. In a LinkedHashMap the indexes are integers.
19. A map cannot contain Duplicate keys. Each key can map to at most one value(s).
20. TreeMap is efficient for traversing the keys in sorted orders. The keys can be stored using
the Comparable Interface or the Comparator Interface.
21. A Treemap supports ordering of entries in a map. They may be retried either in the order in
which they were inserted into the map (known as insertion order) or in the order in which they
were last accessed, known as access order.
22. The entries in a Hashmap are not ordered.
23. A Map is a data structure that stores entries. Each entry contains two parts: A key and a
value.
24. A collission occurs when two keys are mapped to the same index in a hash table. Generally,
there are two ways for handling collisions: linear probing and quadratic probing.
25. You can implement a map to obtain O(1) time complexity on searching, retrieval, insertion,
and deletion using the hashing technique.
Analysis Of Algorithms
Montgomery Blair High SchoolClass Period 2
Name Lucia Wang
26. A Typical hash function first converts a search key to an integer value called a value, then
compresses the hash code into an index to the value.
27. Hashing is a technique that retries the value using the index obtained from the key without
performing a search.
28. Open addressing is the process of finding an open location in the hash table in the event of
collision. It has several variations: linear probing, and quadratic probing.
29. The separate chaining scheme places all entries with the same hash index into the same
location, rather than finding a new location. Each location in the this scheme is called an index.
30. Insert These Keys 701, 145, 217, 19, 13, 749 into this table using linear probing. Assume no
load factor
0
1
2
3
4
5
6
217, 749
701
147, 19
31. Insert these numbers into the table using quadratic probing: 0, 16, 32, 15, 31
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
16
32
31
15
Analysis Of Algorithms
Montgomery Blair High SchoolClass Period 2
32. Use double hashing to insert the following into the table
h(key) = key % m
h’(key) = 7-(key % 7)
19, 27, 36, 10,
0
1
2
3
4
5
6
7
8
9
10
11
12
7
19
27
36
33. Use the table below to insert the following values using separate chaining
55, 24, 19, 41, 10
0
1
55, 10
41
2
3
4
24, 19
Name Lucia Wang