csc chapter 5
abstraction in computing
High-level programming languages provide abstractions of procedures that can be reused frequently without understanding of the underlying binary code.
how does comp understand programming languages
Computers use a compiler to convert code written in a high-level programming language into assembly language code, which is a lower level of abstraction Finally, computers use an assembler to convert assembly language code into binary sequences
For binary search, about how many comparisons are needed to determine if 5 exists? 2 10 250
10 First, binary search checks the value in the middle of the range of 500. Next, a range of 250 is checked. Then 125, 63, 32, 16, 8, 4, 2, and 1. So about 10 checks are needed, until search realizes the 5 doesn't exist. Sometimes binary search is slower than linear search.
Over large numbers of varied searches of values, linear search might average _____ comparisons, while binary search might average _____. 2, 10 500, 10 250, 10
250, 10 On average, linear search might have to search halfway through the list (sometimes stopping sooner, sometimes later). On average, binary search will shrink the search range in 10 steps (or fewer). Using efficient algorithms is one way that software, like web searching, can perform so fast.
For linear search, about how many comparisons are needed to determine if 5 exists? 2 250 500
500 Since linear search does not know if a list is sorted or not, if a number does not exist in the list, the worst case occurs; every number is compared. 500 is the worst case.
A similar algorithm can be used to add any number of consecutive integers starting and ending with any integer.
Abstraction Abstraction is used to generalize the process so that any similar problem can be solved through a similar process.
Count the number of sums from the previous question. Multiply this number by 101. This number is the sum of the integers between 1 and 100.
Algorithms
An algorithm's best and worst case scenarios are always different. True False
An algorithm can have the same best and worst case, in which case the algorithm always does the same number of operations regardless of input data.
Computational Thinking concepts
Decomposition pattern recognition Algorithms abstraction
When the outermost numbers (1 and 100), then the next-outermost numbers (2 and 99), and so on are added, all such sums (1 + 100, 2 + 99, 3 + 98,...) have a sum of 101.
Pattern recognition Solving these smaller problems a few times reveals a pattern.
Algorithm time efficiency
The number of calculations required to solve a problem. Efficient algorithms tend to be less simple, so programmers should consider efficiency only when needed, like when dealing with very large data sets that result in slow program execution.
hypothesis of a cause.
The statement is a solution, not a cause. A hypothesis of a cause might be: The software has a bug that is preventing the phone from getting a signal.
Nearly every algorithm has a best case time complexity when N = 0. True False
The variable value N cannot be replaced with a constant of 0 to describe a best case scenario. A best case scenario must describe the contents of the data being processed.
worst case
The worst case is when no items in the list are less than value. All array elements are compared against value, then value is returned. Correct
low-level abstractions
a 0 bit represents switches that are off and a 1 bit represents switches that are on
high level abstraction
a computer uses binary data to represent decimal numbers, hexadecimal numbers, characters, colors, and programming languages
S(N) = N + k
algorithm to find the maximum number
Algorithm
are sequences of instructions used to solve problems or perform tasks in a structured manner.
S(N) = k
auxiliary space complexity
Algorithm efficiency is most commonly measured by what
by the algorithm runtime, and an efficient algorithm is one whose runtime increases no more than polynomially with respect to the input size
Instead of adding all 100 numbers at once, the final sum can be found by adding together 50 sums of two numbers each. what is this concept
decomposition
Runtime and memory usage are the only two resources making up computational complexity. True False
false Although runtime and memory usage are the most common, computational complexity can include other factors, such as network communication.
Two different algorithms that produce the same result have the same computational complexity. True False
false Two different algorithms can produce the same result in various ways and may have different computational complexities.
what is the challenge of sorting
hat a program can't "see" the entire list to know where to move an element. Instead, a program is limited to simpler steps, typically observing or swapping just two elements at a time. So sorting just by swapping values is an important part of sorting algorithms.
Space Complexity
is a function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N
Troubleshooting
is a systematic process for finding and fixing a problem's cause in a (typically mechanical or electronic) system
Computational complexity
is the amount of resources used by the algorithm. The most common resources considered are the runtime and memory usage.
decomposition
is the breaking down of a complex problem into a series of smaller or simpler problems.
abstraction
is the generalization of a problem so that a solution can be applied to different specific problems.
Sorting
is the process of converting a list of elements into ascending (or descending) order. For example, given a list of numbers [17, 3, 44, 6, 9], the list after sorting is [3, 6, 9, 17, 44].
best case
is the scenario where the algorithm does the minimum possible number of operations.
auxiliary space complexity
is the space complexity not including the input data
S(N) = 2N + k
memory used for things like the loop counter and list pointers.
pattern recognition
s the identification of common characteristics among different problems and within the same problem. Recognizing these patterns can further simplify the problem.
Computational complexity analysis allows the efficiency of algorithms to be compared. True False
true Runtime and space complexity analysis, discussed below, provide a mathematical way to compare algorithm efficiency.
The list is sorted into descending order: ['F', 'D', 'C', 'B', 'A'] t or f
true The list of characters are in reverse alphabetical order.
The list is sorted into ascending order: ['chopsticks', 'forks', 'knives', 'spork'] t or f
true The list of strings are in alphabetical order.