Download INTRODUCTION TO COMPUTER SCIENCE FOR REVIEW & STUDY NOTE !! and more Study notes Computer Science in PDF only on Docsity!
Introduction to Computer Science
Algorithms:
- What is an algorithm? An algorithm is a set of instructions for solving a problem.
- Why is it significant that algorithms allow us to capture intelligence and share it with others? Since algorithms are a way of sharing intelligence, many people can use this intelligence without having to know all the background principles involved. No one can become an expert in all fields, so algorithms are an important tool for sharing solutions.
- How does a recipe allow you to reuse "captured intelligence"? A recipe gives you specific instructions for preparing a certain food like a cake. Although you may not be an expert chef, you can still bake the same cake that an expert chef bakes by following his recipe. In this case, the recipe represents the captured intelligence of the chef.
- Why are algorithms important to computers? Computers are general purpose machines that must be given instructions in order to do useful work. We can make computers "intelligent" by programming them with various algorithms. Then the computers can use the algorithms we created to solve problems.
- What limitation do computers have as problem solving machines?
Computers can only solve problems whose solutions can be stated in the form of an algorithm.
Definition of an Algorithm:
- What are the five characteristics of an algorithm? - Algorithms are well-ordered. - Algorithms have unambiguous operations. - Algorithms have effectively computable operations. - Algorithms produce a result. - Algorithms halt in a finite amount of time.
- What does it mean for an algorithm to be well-ordered? In an algorithm that is well-ordered, we always know which instruction should be performed next. There is no uncertainty regarding the execution order of instructions.
- What does it mean for an instruction to be ambiguous? An ambiguous instruction lacks the details necessary for it to be executed. For example, an ambiguous instruction for a person might be "Bake a chocolate cake." More detailed instructions are usually required for a person to solve the problem of making a chocolate cake.
- What are primitives? A primitive is a basic operation used for writing an algorithm. Some primitives that computers understand are "Add these two numbers" or "Compare these two numbers to see which is smaller." By using primitives, we can write unambiguous algorithms for computers.
- Why is it necessary for algorithms to produce a result?
office, turn right onto Jackson road. Then stay on Jackson for about 10 miles. Eventually you will pass the Happy Meadow farm on your right. Just after Happy Meadow, you should turn left onto Brickland drive. My house is the first house on your left.
- Begin at the Quik Mart
- Follow Saddle road for four miles until you reach a stop light
- At the stop light, turn left onto Hollow street
- Follow Hollow street for one mile until you reach the post office
- At the post office, turn right onto Jackson road
- Follow Jackson road for 10 miles until you reach Happy Meadow farm
- At the farm, turn left onto Brickland drive
- Turn left into the first house on Brickland drive
Sorting Algorithms:
- Why are computers good at sorting? Computers are good at sorting because they can compare a large number of items very quickly.
- Is it better to have an algorithm that solves a specific problem or a class of problems? Why? Algorithms which solve a class of problems are better. If we write an algorithm to solve a class of problems, we can use it to solve the specific problem and many others as well.
- EXAMPLE: Determine whether the following statements represent a class of problems or a specific problem. For statements that represent a specific problem, reword the statement to make it represent a class of problems. 1. Finding the name "Barry" on a student role 2. Sorting numbers in ascending order 3. Finding the largest number in the set {2, 3, 6, 9} 4. Ordering a hand of playing cards from highest to lowest
The answer for each statement is listed below
- Specific problem; Finding the name of a student on a student role
- Class of problems
- Specific problem; Finding the largest number in a set of numbers
- Class of problems
Basic Operations:
What two operations do most sorting algorithms have in common? Most sorting algorithms share the comparison and swap operations. What is the purpose of the comparison operation? The comparison operation is the way of determining which item in a list should come first. What is the purpose of the swap operation? The swap operation is the way that items are moved within a list. How many memory cells does a computer need to swap two numbers? A computer needs at least 3 memory cells to swap two numbers. What is the algorithm for swapping two items stored in cells H and Z? The algorithm is listed below. Remember you need an extra memory cell for this operation. This cell is labeled as temp.
- Copy the contents of cell H to temp.
- Copy the contents of cell Z to cell H.
- Copy the contents of temp to cell H.
What operation does the Simple Sort use to move numbers from the unsorted list to the sorted list? The Simple Sort uses the copy operation to move numbers. The swap operation is not needed because the Simple Sort uses two lists rather than one. How many times does the Simple Sort use the copy operation when sorting a list of 7 numbers? of 9 numbers? The Simple Sort uses the copy operation 7 times when sorting a list of 7 numbers and it uses the copy operations 9 times when sorting a list of 9 numbers. How many iterations (loops through steps 3 - 6) does the algorithm make when sorting a list of 7 numbers? of 12 numbers? The algorithm makes 7 iterations when sorting a list of 7 numbers and 12 iterations when sorting a list of 12 numbers. How can we rewrite the Simple Sort algorithm so that it sorts numbers from highest to lowest? First, we need to change our algorithm specification so that we select the largest unsorted number rather than the smallest. Second, we need to change our marker from MAX to MIN (the smallest number a memory cell can hold). These changes are show in italics in the new algorithm below.
Simple Sort Algorithm
(sorting highest to lowest)
- Get a list of unsorted numbers
- Repeat steps 3 through 5 until the unsorted list is empty
- Compare the unsorted numbers
- Select the largest unsorted number
- Move this number to the sorted list
- Store a minimum value in the place of the smallest number
- Stop
Insertion Sort:
- What operation does the Insertion Sort use to move numbers from the unsorted section to the sorted section of the list? The Insertion Sort uses the swap operation since it is ordering numbers within a single list.
- How can we rewrite the Insertion Sort algorithm so that it sorts numbers from highest to lowest? To modify the Insertion Sort Algorithm so that it sorts from highest to lowest, we need to swap the next unsorted card to the left until we reach a smaller card. The modifications to the original algorithm are marked in italics, notice we must simply redefine "correct sorted position".
Insertion Sort Algorithm
(sorting highest to lowest)
- Get a list of unsorted numbers
- Set a marker for the sorted section after the first number in the list
- Repeat steps 4 through 6 until the unsorted section is empty
- Select the first unsorted number
Algorithm Efficiency:
- For a given problem, is there only one algorithm that correctly solves the problem? No; for any given problem we can often find multiple algorithms that correctly solve the problem. The problem of sorting is a good example.
- If our algorithm provides a correct solution to a problem, why would we still want to analyze the algorithm? We would still want to analyze the algorithm to determine whether our particular solution is efficient compared to other algorithms which also solve the problem.
- What two types of efficiency are important for computer algorithms? Space efficiency and time efficiency.
- How do we measure computer algorithms for space efficiency? Space efficiency is measured by determining the amount of computer memory the algorithm requires.
- For sorting algorithms, what three operations make up most of the running time of the algorithm? The comparison operation, the copy operation, and the swap operation.
Space Efficiency :
- What is the minimum number of memory cells required to sort a list of 50 numbers?
The minimum number of memory cells is 50. We need at least this many just to store the numbers we are sorting in the computer's memory.
- Suppose a certain sorting algorithm uses the swap operation to order numbers. Given a list of n numbers, how many memory cells would you expect the algorithm would require? The algorithm would need at least n + 1 memory cells because the swap operation requires a temporary memory cell.
- Suppose a certain sorting algorithm uses only the copy operation to order numbers by moving them to a new list. Given a list of n numbers, how many memory cells would you expect the algorithm would require? Since every item must be copied to some location on the new list, the algorithm will need at least 2* n memory cells.
- If you were given a list of 10 million items to sort, which sorting algorithm do you think would be most appropriate? Either the Selection Sort or the Insertion Sort would be a better choice than the Simple Sort. Since the Simple Sort uses two lists to sort numbers, it would require at least 20 million memory cells to sort the items. This is a very inefficient use of space.
Time Efficiency:
- What is the relationship between swaps and copies? One swap requires three copies.
- Why is it necessary to convert the number of swaps to copies when comparing other sorting algorithms to the Simple Sort? In order to compare other sorts to the Simple Sort, we need to use the same basis of comparison. Since the Simple Sort uses the copy operation rather than the swap operation, this operation is the proper basis for comparison.
- What is the similarity between the millions of switches inside a computer processor and binary numbers? The switches inside a computer processor have only two states: off or on. Similarly, the binary system has only two digits: 0 or 1.
- How do computers use the binary system? The binary system is the language of the computer. All the instructions that the computer processor performs must be coded in this language.
- Can we solve all the arithmetic problems in binary that we solve in decimal? Yes; we can solve all the arithmetic problems in binary that we solve in decimal, but our answers in binary will look much different since we only use 0s and 1s.
Computer Systems Organization :
Introduction to Machine Architecture What are two qualities that computers possess which have contributed to their success as universal machines? Flexibility and efficiency Are computers suitable for any task? No; many problems such as reasoning, decision making, and interpretation are much better performed by humans than computers. For more information on humans and computers, see Humans versus Computers in the Artificial Intelligence module.
Data Storage:
Why is the binary number system important to computers? Bits (binary digits) provide the foundation for all data storage in computers. Since both bits and the binary system work with two digits, they are naturally related. Give three other ways of describing the two states of a binary digit. 0: false, off, low voltage. 1: true, on, high voltage. What is ASCII? ASCII stands for the American Standard Code for Information Interchange. This code assigns particular patterns of bits to represent common symbols such as letters, punctuation marks, and numerals. How is the main memory of a computer organized? The main memory of a computer is composed of millions of storage cells where the size of each cell is the word size of the computer. In some computers, the word size is one byte while in other computers the word size is two, four, or even eight bytes. Each storage cell in main memory has a particular address which the computer can use for storing or retrieving data. Why is a computer's main memory called RAM? RAM stands for Random Access Memory and reflects that fact that any particular memory location is just as accessible as another memory location regardless of the address.
Gates:
to form common programming constructs. This allows programmers to focus more on problem solving and less on the details of constructing a program.
Data Types:
List four common data types that most programming languages include? Integer, real, character, and Boolean. What is an array? An array is a group of adjacent memory cells that have the same type
Input/Output:
What are two types of input and output to computer programs? User I/O and file I/O.
Natural Language Processing:
How are natural languages and computer languages different? Natural languages are ambiguous, that is, a single statement can have more than one meaning. The meaning of the statement depends not only on the combination of words but the tone in which the statement is spoken and the context of the statement. In contrast, computer languages are unambiguous so that each statement has exactly one meaning. What three things must a computer analyze in order to understand the meaning of a statement?
In order for a computer to understand a natural language statement, the computer must understand the syntax, semantics, and context of the statement.
Visual Processing:
Visual processing: optical character recognition (OCR) and handwriting
recognition.
Although current OCR technologies can recognize up to 99% of the characters of a document correctly, this percentage still leaves something to be desired. Why? Because of the large number of characters in a book, a 99% accuracy rate can still leave quite a few words unrecognized. What additional approach do handwriting recognition programs include to improve the accuracy of recognition? Handwriting recognition programs include logic that tries to adapt to a particular writing style over time. Since most writers have unique but consistent patterns for their characters, this approach allows the program to "learn" the handwriting of an individual.
Neural Networks:
- How are artificial neural networks similar to the brain?