I learn a lot about array in this weeks. I used to be a Java beginner who have no idea about how to manipulate array in OOP. In this week, I learn how to use array in class, how to use array as instance variables, how to copy array, and how to change the array’s size.
The code that I list here is the methods to convert string into char, compare two array, and copy an array.
public class ArrayPart2
{
public static char[] stgToCharArry(String something){
char [] temp = new char[something.length()];
for(int i=0;i<something.length();i++){
temp[i]= something.charAt(i);
}
return temp;
}
public static String cpString(double [] a, double [] b){
boolean isEqual = true;
String result;
if(a.length!=b.length){
isEqual=false;
}else{
for(int i=0;i<a.length&&isEqual;i++){
if(Math.abs(a[i]-b[i])>0.0001){
isEqual = false;
}
}
}
if(isEqual){
result=”a and b are equal”;
}else{
result=”a and b are not equal”;
}
return result;
}
public static double [] CopyingArray(double [] c){
double billBackup [] = new double [c.length];
for(int i=0;i<c.length;i++){
billBackup[i]=c[i];
}
return billBackup;
}
}
Actually, before this lesson, I personally tried to compare two array without receiving parameters, here is what I got:
public class Convet
{
public static void main(String args[]){
String a = “sgsrg”;
}
public void convertString(String a){
char [] array = new char [a.length()];
for(int i=0;i<a.length();i++){
array[i]=a.charAt(i);
System.out.print(array[i]);
}
}
}
In the next step, I was asked to finish a project. Here is the code for CS_Gradebook
import java.util.Scanner; /**
Write a description of class CS_Gradebook here. *
@author (your name)
@version (a version number or a date) */ public class CS_Gradebook { public static void changeGN(int [] grade,String [] name){ Scanner input = new Scanner(System.in); for(int i=0;iname.length){ for(int i=0;i<size;i++){ newarray[i]=name[i]; } } name=newarray; newarray=null; } public static void print(String [] name, int [] grade,int size){ for(int i=0;i<size;i++){ System.out.println(name[i]+”:”+grade[i]); } } }
Here is the code for GradeBook client:
public class Gradebook_Client { public static void main(String args[]){ String [] name=new String[10]; int [] grade=new int[10]; int size=5; CS_Gradebook book1 = new CS_Gradebook(); book1.changeGN(grade,name);
This week, I keep gaining experience of Java. I get more idea about Java because I learn Objective, Oriented programming. I am going to mention following things in my blog post.
Sequential search
Binary search
Bubble sort
Selection sort
One/two-dimensional array
Methods
Homework and activities
Summary
Sequence search
Sequence search is used when we try to find the index of a value in an array. The computer would compare the target to all the numbers in that array one by one until the target is found. For example, 4,5,3,6,2 is an array. We hope to find 3 in this array. The computer would compare 3 with 4 then compare 3 with 5 then compare 3 with 3. Then 3 equals 3, the program would output the index of three in the array, which is 3.
Pseudocode of sequence search
Java code for sequence search
Result
value:8
output:2
Binary search
Binary search is a searching algorithm. It works more efficient than sequence search. It begins at the middle of an array. It would compare the number that is in the middle of unexamined array until the target is found. However, binary search require the array to be aligned from small to large.
Pseudocode of binary search
Java code for binary search
Result
Please input the value of the number: 9
output:3
Bubble sort
Bubble sort is a sorting algorithm. Bubble sort compare a group of numbers that are next to each other. Computer would swap them if they are in the wrong order. After grouping all the numbers, computer would loop these process over and over again until the array is ascending or descending.
Pseudocode of bubble sort
Java code for bubble sort
Result
output:4,5,6,7,8115,927,999
Selection sort
Selection sort is also a sorting algorithm. Selection sort find the smallest number in an array. Them the computer would swap it with the leftmost number. For each times of the sorting, the boundary would move one element to the right.
Result
output:
Pseudocode of selection sort
Java code for selection sort
Result
output:1,6,7,811,15,31,49
Arrays
One-dimensional arrays
One dimensional array are a group of number that have special orders. It can be declared as datatype[] array name= new int [length], or datatype[] array name={numbers in order}.
Two dimensional arrays
Two dimensional arrays are arrays that have two dimension. In other word, it is matrix. It can be declared as datatype[] []array name= new int [length] [length], or datatype[] array name={numbers in order},{numbers in order}………{numbers in order}.
It can be visualized as a two-dimensional display with the first index giving the row, and the second index giving the column.
Methods
The methods implement the behavior of an object. They provides its functionality. They have header and body parts. They always include a pair of parentheses. The body is always enclosed by a matching pair of curly bracket. Methods body contains the declaration and statement.
Method structure
The header tells the visibility of objects of other classes and whether the methods would return a value and the name of the method and whether the method would takes parameters. The body encloses the methods’ statement. Method signature does not include the return type.
Method classification
Methods are classified as Constructor, Accessor, Mutator, and utility.
Constructor is to set up an object.
Accessor includes get method. It return the current values of object data. The return type is written just before the method name.
Mutator would set the methods. It would change the value of the object data.
Benefit
I think the benefit of the methods is that it make the code to be more readable and changeable. Normally, or month ago, when we have no idea about the methods, probably I would write a long code. There would be too many parameters that alphabet is not enough. Situation is relived since I know to use method. I can just abstract my program and write the code for each abstract step. Then gathering them up using method structure. Things are getting much easier because if something wrong with the parts of the code I would easily know it and change it. Plus, the method could be used for more than one times, which increase the efficiency of coding.
Homework
This is the my homework. It is a program of intelligence detector. By recording each person’s height, weight, and whether they are in relationship into a two dimensional array, the computer would do simple math to calculate individuals intelligence. And individuals’ intelligence are stored in an array. Then, I would use bubble sort to sort all those numbers of intelligence, and output the person who get the highest intelligence and the lowest intelligence. My coding ability is improved during this task which bring me joy.
Summary
This week, i learn many searching algorithm and sorting algorithm like sequence search, binary search, bubble sort and sequence sort. I also gain more depth inside java by learning method, which makes the code to be more readable, and modifiable. By accomplishing the mini project, not only my coding ability is improved, but also I get the idea that how coding or computational thinking works in real-life situation.
This week is so interesting for me because I learn programming! I am going to mention following things in the blog:
Algorithm
Trace table
Pseudocode
Programming
Activity and homework
Summary
Algorithm
Algorithm is the core of a program. Its definition is that A set of step-by-step clear instructions to solve a problem, as what I have mentioned for many times in other blogs. It decides the syntax structure of the program, and the methods and key words that programmer used in the program.
Property of algorithm
1.Finiteness
2.definiteness
3.Input
4.Output
5.effectiveness
Expression of algorithm
Natural language: simple english
Flow chart: formalized graphic representation
Pseudocode: generic artificial language.
Programming language: artificial language that can communicate with the computer
How to make algorithm?
While, the use of algorithm is to solve the daily problems. Before that, a decision making process is necessary. Decision making is the process of making choices by identifying a decision, gathering information, and assessing alternative resolutions. Using a step-by-step decision-making process can help you make more deliberate, thoughtful decisions by organizing relevant information and defining alternatives.
Pseudocode
Pseudocode is a transition between natural language and programming language, so it’s necessary for me to learn before learning programming. I can say that it’s easy to create, because it hasn’t any grammar like programming language, but just adds logic and clean structure from the base of natural language.
Pseudocode notation
Pseudocode notations contains input, output, while, for, repeat-until, if-then-else, etc. Input indicates that a user will input something through typing or other ways. Output indicates that something as output will appear on the screen. While is the notation of loop (iteration that has a condition at the beginning), and for is notation of another kind of loop which is similar to while loop. Repeat-until is the notation of loop as well (iteration that has a condition in the end). Finally, if-then-else is the structure of selecting decision in which a choice is made.
Trace table
Trace table is a techniques used to test the algorithm. It can be used to record the result of the test. To make sure that no logical errors occur whilst, the algorithm is being processed. Here are steps of making trace table.
1. Write down all the variables as well as conditions, and output in the first row (I, X, NUM, X < 5, output, etc.)
2. Start filling in initial values in the second row
3. Input all loop values (i) vertically in rows after that
4. Follow each statement in the code and fill the respective values of the variables for each value change
5. Write down the final result
Programming
After gaining understanding of computational thinking, I can finally do the programming. We use BlueJ as our IDE. Because I was in USA attending IGEM competition, so I generally learnt it by myself, although my teacher gave me a lot of instructions and guidance. I found that programming is generally similar to the Pseudocode though we need to remember special language for programming.
Programming structure
Input some data (from keyboard, file, another process or program)
Perform some processing on the data
Output the result to the computer
Here are the general step for the programming:
1. Identify the data we know
2. Identify other data we will need
3. Declare variable names
4. Initialize the value of any possible identifiers
5. Perform the calculation (processing)
6. Output or return the result
Good programming conventions
Good programming conventions identify the rule that every program and programmer should follow. Firstly, every program should begin with: a comment that explains the purpose of the program, the author, the date and time the program was last modified. Secondly, each comment has specific notation to represent, two normal notation is // for single-line comment, and /* COMMENT */ format for multiple-line comment. Thirdly, using blank lines and space characters to make programs easy to read for other programmers. Finally, all class names in Java should start with a capital letter and capitalize the first letter of each word they contain. For example, “MakeFun” is a good class name, but “makefun” is not a good name.
Important terms
Identifiers
1. Identifiers are used to name classes, variables, and methods (as a place holder or container)
2. To declare a variable you will need:
Name (should be meaningful and reflect the data they will store)
Type (int, double, boolean, char, string)
Value (optional during declaration)
3. Variable names must begin with either a lowercase letter, an underscore ( _ ), or a dollar sign ($)
4. Every word in the name after the first word should begin with a capital letter (e.g., firstNumber)
5. After the first initial letter, variable names may also contain letters and the digits 0 to 9.
6. You cannot use a reserved word for a variable name
7. No spaces or special characters are allowed
Java keywords
1. Each high level linage has a unique syntax and a specific limited vocabulary
2. 50 keywords are currently defined in the Java language
3. These keywords cannot be used as names for a variable, class or method
Primitive data type
include byte, short, int, long, float, double, boolean and char.
Activities
battleship game
In order to understand the searching algorithm, our teacher gave us an interesting task, called battle ship. On the paper, many hulls were printed with numbers on them. First, two people form a group and they fight. Then everyone chooses a ship and tells his opponent the ship number. Next, they can guess the position of the ship in letters. Finally, the first person who guessed the right one can win the game.
There are three papers, and each paper represent a searching algorithm. Without boasting, I am the one true king in this game—I never lose the game!
In this paper, the boats that represent files are randomly arranged, it is very hard to find out with one is the target, so searching it would waste a lot of time.
In this paper, the boats are arranged in some order least, the value of the boats are from the smallest to the largest. It took less time for me to search the target boat.
The boats in this paper are arranged into different categories, knowing the right categories of target, I spend less time finding the right number of the target boat.
We can see three algorithm from these three paper. The algorithm in the first paper aim at looking for all the files to the target one. The algorithm in the second paper aim at searching there files in a range that decrease the work of searching and saving the time. The Last paper is the best algorithm that could find the target file in the smallest time. The algorithm firstly categorizes the files, then finds the files in given category. Because files inside a category are much less than the overall files, time for searching is greatly reduced.
Basic programming exercise
HelloWorld programmeProgram of calculating the area of circle
Summary
In this week, I finally step into the world of Java. From I young rookies who just know Pseudocode, flowchart, and trace table, to an old rookies who know how to print Hello World in Java language, I got a lot of progress. To reflect myself, I have to say that Java programming is very different from what I thought. Because I used to be a Python programmer and Wolfram Mathematica user, too abstract language discount the effect of computational thinking. Consequently, my algorithms always have bug. On the contrary, computational thinking is highly involved in Java programming, which would benefit me a lot although I have to remember a lot of terms.
This week, we learn java looping, in which I am able to say that I am a Java learner. Sadly, I was still in America when Java looping was taught by my teacher. However, I caught up soon when I got back, thanks to my CS teacher. I am going to mention following things in my blog:
Scanner class
While, Do-while, and For loops
Use of Scanner class and While loop for Type-Safe input
Guessing game
Logical operations
Arithmetic operations
Typing casting
Exercise
Summary
Scanner
Scanner provides method for reading bytes, short, int, long, float, double, and String data types from Java console and other sources. Scanner is in the java.util package. Scanner spares input into sequence of characters called tokens. By defaults, tokens are separated by standard white space characters. In order to read this datatype, methods are needed. For example, nextDataType( ) can make the computer to return the next token and the datatype of it can be bytes, short, int, long, float, double. There are also next(), nextLine() that can make the computer to return the token in the input stream as a string.
While, Do-while, and For loops
While loop is best used when the loop would repeat an unknown number of times. The condition of while loop is in the first bracket. The loop would go on as long as the condition is true.(the condition would be checked at first)
Do-while loop is different form while loop because the condition of the loop is at the end of the loop. Therefore, no matter what the condition is, the loop would be executed for at least one time.
For loop is the third kind of loop. The condition of the loop is in the beginning of the loop. Therefore, only condition is true, the execution would go on. It is different form the While loop because the number of the loop repeated should be clear in the condition.
Type-Safe Input
Type safe input is very special because it can check whether the datatype the user input is the correct one accords with the right one. If not, the error would not happen, instead of that, it would ask for another input.
Logical operation
In the unit of logic gate, we have some idea about the logical operation, such as and, or, xor. However, there are logical operation in Java. “==” in Java means equal. “!=“means not equal. ‘!’means not obviously. And && means “and”. || means or. If && appear together with||, then && comes first, and || goes next, which is like the logic gate.
Arithmetic operations
The basic arithmetic operations contain add(+), subtract(-), multiplication(*),division(/),modulus(%),++,- -.
++, – – are short cut operators. ++ means plus one. – – means minus one.
There are also escape sequence. \t means inserting a tab in the text at this point. \b means inserting a backspace in the text at this point. \n means inserting a new line at this point. \r means inserting a carriage return in the text at this point. \f would insert a formatted in the text at this point. \’ would insert a single quote character in the text at this point. \” would insert a double quote characters in the text at this point. \\ would insert a backlash character in the text at this point.
Type casting
Implicit type casting
When performing calculations with operands of different data types, lower precision operands are promoted to higher-precision data types and then operands is performed. The Promotion is effective only for expression evaluation, not a permanent change.
Explicit casting
The intentional modulation is needed. The programmer should add data type in front of the a variable, therefore the result would be converted to such data type. For example, (double)1/2 = 0.5 the result won’t be 0 again.
Rules of promotion
If either operand is a double, the other operand is converted to a double.
If either operand is a float, the other operand is converted to a float.
If either operand is a long, the other operand is converted to a long.
If either operand is an int, the other operand is promoted to an int
If neither operand is a double, float, long, or an int, both operands are promoted to int.
Exercise
This picture shows the program for the bubble sort. As for the name, it is about sorting due to the value of the numbers. The program is very simple, so so it saves a lot of time while sorting.
This picture shows the program for addition. The user could input two numbers, and computer would add them up and output the result. The thing is, if the use input other datatype instead of integers, the program would ask thee user to input again until user input integers.
This program shows the procedure calculating the area of the circle. It is very simple, but I learn that things like Pi need to add”final”and capitalize “pi”.
This picture shows the program for array. We learn how to create an array and add value into it.
This picture shows the introduction to Java looping. We learn how to use looping to output the value we want.
This picture shows one of the practice we did in the class. It is about finding the prime numbers within a boundary. I develop java programming skills.
Summary
In this week, I learn java looping. I feel like I can solve some problem in my real-life. For example, during the math modeling competition, I use java looping to find the abnormal value of the data set. Honestly, java is not very kind with importing the data comparing to Matlab, Mathematica, or Python. But java did run very fast, which help me a lot.
This week, we learnt about computing component and the way they execute instructions. I used to have no idea about how computer works, so I think computer is something magic. But having been taught, I think computer is logic that it follows some of procedures when it is processing.
I am going to mention following things in the blog post:
IPO model
Main component of CPU
Memory
Instruction Cycle
Activities
Homework
Summary
IPO model
IPO is the fundamental model which describes the structure of an information processing program. The further instruction executing process inside CPU also bases on this basic model. Next, I will introduce input, process, output and storage separately. Input means that an input device offers available data to the process component. Process basically means manipulating data, which contains decoding the data into machine language and doing arithmetic or logical calculation in detail. Output means that processing unit sends the result of process, which contains number, graph, and words usually, to the output device. After that, output device demonstrates human then result. Storage can be considered as an extra part of IPO model, it usually means secondary memory (I will introduce it later), that can store data for long time.
Input: keyboard, mouse, scanner, punch cards. Processing: CPU executes the computer program. Output: monitor, printer, fax machine. Storage: hard drive, optical media, diskettes, magnetic tape. Chapter 1 Computer Systems.
Main component of CPU
The main components of CPU actually include ALU, CU, RAM, Cache, and Registers MAR, MDR and so on, which is very complicated.
CPU
CPU is the key component of computing system. It contains the circuitry which can interpret and execute the instructions.
CU, ALU, Register
CU is the acronym of of Control Unit. It decodes the instructions and controls other components of CPU. It can direct the data flow and operate the execution of the ALU.
ALU is the acronym of Arithmetic Logic Unit. It does all the arithmetic (+/-) and logical (AND/OR) calculations. It also referred to as ‘core’ of the CPU.
Registers are small and very fast temporary storage units inside the CPU. MAR and MDR are two kinds of registers, and they are very important in the instruction cycle.
Memory
All kinds of computers have memories to store a huge quantity of data. The memory of computer can be mainly divided into two large types —— primary and secondary memory. They have different properties separately. Primary memory is the only storage that is directly accessible by the CPU, and it always interacts with CPU when computer is executing instructions. Secondary or auxiliary storage is slow but has higher capacity compare with primary memory. People usually intentionally use it to store information for a long time.
Primary memory
According to detailed functions, primary memory contains three main types —— RAM, ROM and cache memory.
RAM is random access memory, it is widely used to contain the data (includes number, instruction, address, and letter), the computer has loaded since starting up and everything the user has opened/loaded. It’s volatile, in other words, its data will lose after people turning off the computer power.
ROM, read only memory, can’t be modified or rewritten by user originally, but currently, some specific ROM like EPROM (Erasable Programmable Read-Only Memory) and EEPROM (Electrically Erasable Programmable Read-Only Memory) can be rewritten. ROM is nonvolatile, that means data won’t be eliminated even if computer is turned off. Because of this property, people store BIOS (Basic Input Output System), the program which allows computer finding the operating system to “boost” computer after the power is restored, in ROM.
Cache memory has a definition: A type of smallhigh-speed memory inside the CPU used to hold frequently used data. Computer can find the data which is frequently used, and store it in cache. When computer is executing instructions, it always finds data which is needed in the process in cache firstly. Only if it doesn’t find the data in cache, it will find data in RAM. Therefore, cache can rise up the working efficiency of computers a lot. People divide cache into different levels according to the using frequency of data. The first level stores the data which is used the most frequently. Chip of level 1 is the fastest, smallest, and is usually set in CPU. The caches of second and third level are usually out of CPU, and they are bigger and slower than that of level 1.
Secondary memory
The ability of primary memory is limited. Users need space to persistently store information like images, audios, videos, and texts in computer. So secondary memory which satisfied this demand is invented. Secondary memory contains HDD, SSD, Flash, CD, and DVD, and they have different properties and ways of storing and reading.
Instruction Cycle
Before learning the instruction cycle of computer, I predicted it should be difficult and complex. But I found that the general structure of instruction cycle is easy to understand after learning. The only difficulty is that some detailed points of executing are complicated and professional. I was confused because I haven’t seen the infrastructure of CPU before, so the knowledge is totally new and abstracted for me.
In order to form the machine instruction cycle, all the components of CPU need to work together, because all of them have different roles and functions in the cycle.
The image above shows the general steps of instruction cycle. People divide the instruction cycle into four parts, according to the purpose. The first part is fetch, it describes the process that CU fetches data from memory. In the process of fetching, data shifts from a component to another for many times, and finally arrives the Control Unit. The second part is decode. Control Unit decodes the data that is just fetched from memory, so the data can be understood by ALU after decoding. The third part is execute. ALU calculates decoded data according to the instruction, and gets and shows the result or output. The four part is store. ALU sends arithmetical results to memory, so the data can be stored. However, sometimes memory needn’t to store data, because if ALU gets a logical result, it will sends the result to CU directly.
Next, I will talk about the components which involve in the instruction cycle and their functions.
PC contains the address of the next instruction to be executed.
MAR(memory address register) contains an address in the main memory that is currently being read or written.
MDR(memory data register) is a two-way register that holds the data fetched from memory (RAM) or data waiting to be stored in memory (RAM).
IR(instruction register) holds the instruction currently being executed or decoded.
Accumulator register stores immediate result from ALU.
Activities
This week, we mainly did two activities. The first is little man computer. The second is Designing my own PC.
Little man computer programming.
We develop understanding of assembly language and appreciate the simplicity of assembly language by little man computer.
This is the picture that shows the program for four numbers’ sum. The program could be illustrated by formula sum=(a+b)+(c+d). I did not do well because the length of the code is huge. Actually storage step could be deleted but it would increase the change of making mistakes.
This is the picture that shows three number’s sum. The program could be illustrated by formula sum=a+b+c.
The two picture above are multiplication and division. They are more complicated than adding task since I could not input two number and multiply them. I have to use loop. A times B equal to the sum of A numbers of B. After each step of adding, the remaining times would minus one. Similar things happen to division, where we could use subtract.
Design your own computer
This project was held for gaining more understanding about computers because . It did work actually. Our computer is designed for gaming and 3D structuring.
davdav
Reflection
I gain understanding of computer by knowing the component and constructing the computer. Because when I was finding the right choice for the CPU, GPU, I have to equalize the performance of them to the aim we set. It turned out that 3D structuring do need strong performance and many thread but intel E7 CPU is too much. Besides, the computer also need to be good at playing games, so it need a graphic card. With thoughtful consideration and a mass of investigation, we did construct good computer.
However, I can do better because I randomly choose a screen for the computer, which seems not to be the best options. If I have another change, I would bet willing to spend more time on choosing a better screen.
Summary
This week was very interesting for me because I learnt a lot about the computer. Computer used to be something magic to me as I did not know how it works. But now, I know exactly how computers functions. Besides, I gain better understanding about the component of the computer, which is very beneficial.
This is a tough week, since we need to stay in school on Saturday. Not to mention, I could not stop writing blog. I am going to mention following things in the main paragraph.
Data presentation poster
Thinking of computers
Boolean expressions
How transistors and combined gates work
Boolean algebra
How computers add numbers
We made a poster 2 weeks ago. The topic is data representation, which links to previous blog. There are five parts in the poster, which are Number, Character, Image, Audio, Video. My idea here is that character, image, audio and video could be digitized into numbers using compression method. And numbers that are expressed into different base could be translated to each other. To reflection, I should say that I did not pay much attention on the terminologies and their definition because I spend too much time on the designing of the poster.
2. Actually computers do not have their own thoughts. They just follow the instructions written by human. Those instructions are stored in the memories, and the core of computers—CPU— follow those instructions to “think”.
3. Computers are binary system, so human need to design a special computing system for them. George Boole, an English mathematician, introduced Boolean algebra, which is ideal for binary number system. Basically, the algebra are about answering questions “yes” or “no”. Logic gates are digital application of Boolean algebra, which is A device that performs a basic operation on electrical signals, accepting one or more input signals and producing a single output signal. I was taught with 6 gates, which are NOT gate, OR gate, AND gate, NAND gate, NOR gate, XOR gate.
Not gates return opposite signals of input as output. An OR gate accepts two input signals
If both are 0, the output is 0; otherwise, the output is 1 At least one of the inputs needs to be 1. An AND gate accepts two input signals. If both are 1, the output is 1; otherwise, the output is 0.
The NAND gate accepts two input signals. If both are 1, the output is 0; otherwise, the output is 1. The NOR gate accepts two input signals. If both are 0, the output is 1; otherwise, the output is 0. Note the difference between the XOR gate and the OR gate; they differ only in one input situation When both input signals are 1, the OR gate produces a 1 and the XOR produces a 0. XOR is called the exclusive OR because its output is 1 if either one input or the other is 1, excluding the case that they both are.
4. A transistor acts like a switch. It has no moving parts and it’s made of a semiconductor material. A transistor has three terminals (source, base, and emitter) If the electrical signal is grounded, it is allowed to flow through an alternative route to the ground (literally) where it can do no harm.
Gates are combined into circuits by using the output of one gate as the input for another. Three inputs require eight rows to describe all possible input combinations. This same circuit using a Boolean expression is (AB + AC). However, there are many ways of combination of the gates. For example, we did an activity that need us to create a truth table to justify the effect of the circuits.
Pictures above are the activities we did in the class. I gain understanding of how logic gates work and how logic gates are combined into circuits because of the activities.
5. Commutative: The commutative property says that binary operations
AND and OR may be applied left to right or right to left. (A AND B is
the same as B AND A; A OR B is the same as B OR A.)
Associative: The associative property says that given three Boolean
variables, they may be ANDed or ORed right to left or left to right.
((A AND B) AND C is the same as A AND (B AND C); (A OR B) OR
C is the same as A OR (B OR C).)
Distributive: The distributive property says that given three Boolean
variables, the first AND the result of the second OR the third is the
same as the first AND the second OR the first AND the third. (A
AND (B OR C) = (A AND B) OR (A AND C). Also, the first OR the
result of second AND the third is the same as the first OR the second
AND the result of the first OR the third. (A OR (B AND C) = (A OR
B) AND (A OR C).)
Identity: The identity property says that any value A AND the OR
identity always returns A and that any value A OR the AND identity
always returns A. (A AND 1 = A; A OR 0 = A.)
Complement: The complement property says that any value AND the
compliment of that value equals the OR identity and that any value
OR the compliment of that value equals the OR identity. (A AND (A’)
= 0; A OR (A’) = 1.)
DeMorgan’s Law: DeMorgan’s Law says that the complement of A
AND B is the same as the complement of A OR the complement of B,
and the complement of A OR B is the same as the complement of B
AND the complement of A. ((A AND B)’ = A’ OR B’; (A OR B)’ = A’
AND B’).)
6. Computers use adder to add numbers. Adder are a kind of circuit that takes the carry-in value into account. For example,
This is full adders, which is a combined circuit that uses a gate circuit to add two binary numbers and find the sum, called a full adder. A full adder can handle the low carry and output the local add carry. Multi-bit full adder can be obtained by cascading multiple one-bit adders.
This is the example of full adder. In the class, we did an activity about the picture above. It is cut into many pieces and our job into put them back. During the activities, we gain knowledge and understanding of the function of adders because when we are put things back, we need to use the logic of adders to help us figure out in which order the pieces of the pictures should be put together.
The half adder does not receive the carry input, and the full adder has a carry input. When adding two multi-bit binary numbers, except for the lowest bit, each bit must consider the carry from the lower bit.
The characteristic of XOR is the same as adding, but do not have carry-in function.
These are the full adder that I created in the website. The upper output are the result of the computing and the other one is carry-in.
Conclusion, I learn lot about computers this week. Based on what I learned, I feel like computer is not magic to me any more, and it is just a machine that do what we order. Besides, I was shocked by how computer works. Logic as simple as Boolean algebra could create such machine that make human’s life a big difference!
I am going to mention following things in my blog.
Bit, Byte, Binary and Hexadecimal
Image and Sounds Representation
Data Compression and Encoding
4. Huffman Encoding
First, Bit, Byte, Binary and Hexadecimal
The positional notation. The base of a number determines the number of different digit symbols(numerals) and the values of digit positions.
This formula shows the value of numbers in decimals
Binary numbers and Computers. Computers have storage units called binary digits or bits
It is the smallest unit of data in computing. Bits can be grouped together to make them easier to work with. And one byte equals to eight bits.
This picture shows the different unit of data
This picture shows the different unit of data
Hexadecimal. Hexadecimal is base 16 and has 16 digits: used to represent very large numbers quickly, such as those used in color representation. The digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E.
The picture shows how to convert binary into hexadecimals. The picture simplifies the converting between binary and hexadecimal
Class activities.
This activity trains my skill of converting hexadecimal into binary.
Human use two’s complement to represent negative values in computers.
Second, Date representation
Analog and digital information. Information can be divided into two ways, Analog data,A continuous representation, analogous to the actual information it represents, and digital data, A discrete representation, breaking the information up into separate elements. Because computer cannot work well with analog data, so we digitize the data, which breaking the data into pieces, and representing those pieces separately.
Electronic signals. An analog signal continually fluctuates in voltage up and down.A digital signal has only a high or low state, corresponding to the two binary digits. All electronic signals (both analog and digital) degrade as they move down a line. The voltage of the signal fluctuates due to environmental effects Periodically, a digital signal is reclockedto regain its original shape.
Representing text. There are a finite number of characters to represent, so list them all and assign each a binary string. Character set is a list of characters and the codes used to represent each one at which computer manufacturers agreed to standardize.
Example of standard code
Representing of image. There are two kinds of image, bitmap and vector. Bitmap has resolution to measure if the picture is clear. Vector does not because vector is generated according to math equation by the computer. Usually human use RGB to represent pictures, because the combination of RGB could represent many colors. The color depth means how much red or green or blue does a dot of the picture contain.
Representing audio. Pulse Code Modulation (PCM) is a method used to digitally represent sampled analog signals. It has three steps, sampling, quantizing and encoding. Sampling is a process of acquiring audio sampling rate, which is number of samples per second that are used to digitize a particular sound.Quantization is the process of converting a continuous range of values into a finite range of values. Encoding is a process of converting (information or an instruction) into a particular form.
The picture shows how PCM goes
Third, Compression and encoding.
Activities: in the class we did a interesting activity that we compress a files according to the knowledge we just learn.
There are some characters that are repeated in the files. To minimize the space of the files, we could delete the repeated characters, only record how and what they are repeated. I have similar homework that need me to compress an article. I compressed an article from TOEFL reading. It turned out that I mastered compression skills, the compression rate of the article is surprisingly 10 percent.
Last, Huffman coding. Given a weight of N as a leaf node, construct a binary tree. If the length of the weighted path of the tree is the smallest, the binary tree is called the optimal binary tree, also known as the Huffman Tree. The Huffman tree is the tree with the shortest weight path, and the node with larger weight is closer to the root.
Conclusion, this week, I learn Bit, Byte, Binary and Hexadecimal, Image and Sounds Representation, and Data Compression and Encoding. Those knowledge are very important because the idea behind encoding and compression are very profound.
This is the fift reflection. The term is about to finished. In this reflection, I am going to mention following things.
Hierarchy of Software
System Software
Application Software
Flowchart poster picture and my experience from the project
The hierarchy of software
Software are generally classified as system software and application software.
the hierarchy of the software
The system software
It is a software designed to operate the computer hardware and to provide a platform for running application software. Programming language translators, utility programs, library programs, and operating systems are four category under system software.
Operating Systems are a collection of programs that make the computer hardware conveniently available to the user. It hides the complexities of the computer’s operation. It is an interface between the application software and computer. OS interprets commands issued by application. software. Without the operating system, the application programs would be unable to communicate with the computer.
macOS is a series of graphical operating systems developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple’s Mac family of computers. Within the market of desktop, laptop and home computers, and by web usage, it is the second most widely used desktop OS, after Microsoft Windows
Library program is a collection of compiled routines/functions that other programs can use.
It contains code and data that provide services to other programs such as interface, printing, network code, the graphic engines of computer games. All Microsoft Office programs have the same look and feel because they are using the same graphical user interface libraries. Computer game developers often buy graphical libraries to speed up development. This will allow them to quickly develop a good looking game that runs on the desired hardware. For example Battlefield 3 and Need for Speed both use the same Frostbite engine. For example: game engine and code.
the game engine of Battle field 4
Utilities are programs that perform a very specific task related to working with computers. They are small, powerful programs with a limited capability. They are usually operated by the user to maintain a smooth running of the computer system
Finder in Mac OS is an example of utility program, which is a kind of disk manager
Translator software is a software that allows new programs to be written and run on computers, by converting source code into machine code. In the class, Mr. Pete showed a video to us, which explained how translator works. There are three main kinds of translator assemblers, compiler, and interpreter. Assembler is a program that translates an assembly language program into machine code. Compiler is a program that takes a program in a high-level language, the source code, and translates it into object code all at once. Interpreter analyses and executes each line of a high-level language program one line at a time. Generally, complier works more efficiently, but all the works done by compiler would be ruined, if it makes even a small mistake. Although interpreter works every slow, but people would soon find out the mistake and correct it when mistake is made, which would not ruined every work we did. However, this video teach me more than just computer knowledge about translator, but also life experience: Shadow always exist with sunshine. Good sides and bad sides of one thing would always exist——good or bad sides could not exist lonely.
Application software
It allows users to perform non-computer tasks. It is a software designed to help the user to perform specific tasks, such as writing a letter or processing orders. It is designed for end users to perform tasks that they consider useful. Three categories of application software are presented: General purpose application software, special purpose application software, and Bespoken application software.
General-purpose software is a type of software that can be used for many different tasks.It is not limited to one particular function.
Wolfram Mathematica (usually termed Mathematica) is a modern technical computing system spanning most areas of technical computing – including neural networks, machine learning, image processing, geometry, data science, visualizations, and others. The system is used in many technical, scientific, engineering, mathematical, and computing fields. It was conceived by Stephen Wolfram and is developed by Wolfram Research of Champaign, Illinois. The Wolfram Language is the programming language used in Mathematica.
Special purpose application software is a type of software that created to execute one specific task.
calculator is designed only for calculating
Bespoke software is tailor made for a specific user and purpose.
this is a bespoken application designed for Electrical equipment automation company to control the equipment
Flow chart
This week, we had a group activity called flow chart which is the general structure of how the computer works. I and Hania were in a group. Our topic is to classifying 16 personalities. MBTI theory believes that a person’s personality can be analyzed from four angles, with the letters representing the following:
1. Source of driving force: outgoing E—inward I
2. Ways of accepting information: feeling S—intuition N
3. The way of decision making: thinking T—emotion F
4. Attitude towards uncertainty: judging J—perception P
Two or two combinations can be combined into 16 personality types. So our flow chart is about classifying each of the four dimension and combine those result. To form 16 kinds of basic personalities. In the very beginning of the flow chart, we design a loop: if you are going to do the test? If no, then try again, if yes, then welcome to the test. After that loop , the main part of the flow chart is. consisted of four parallel group of questions. The “yes’ or “ No” would lead the user to different next step. I learn a lot from the activity. First, teamwork is really important, because I made good teamwork with Hania. The devision of work is clear so we did not waste any time. Second, I should try my best to increase the efficiency of the work. In the activities, I spent about 6 hour writing the Pseudocode, but most of the work is repetitional. If I use abstraction, I would finish the work in 1 hour.
This is the fifth reflection I wrote. I learned the definition and properties of algorithm. And there were algorithm magic shows and role playing activities during the class. I am going to talk about following things in my reflection.
the definition and properties of algorithm.
Expressions for an algorithm
Designing an Algorithm and understanding the Problem
Explain 3 algorithms that I learned from the video “The Secret Rules of Modern Living: Algorithms”
How I would improve and apply the knowledge with computation thinking
Firstly, algorithm is a step by step clear instructions to solve a problem. The algorithms detail the specific instructions a computer should perform to carry out a specific work.Because the algorithm is precise, the order of computation is always critical to the functioning of algorithm. The algorithm has several properties, which are finiteness, definiteness, input, output, effectiveness.
This picture shows the explanation of individual properties of algorithm.
Secondly, the expression of algorithm are consisted of Natural language, flow chart, pseudocode, and programming Language. Natural language is simple English. Flow chart is formalized graphic representation. Pseudocode is generic artificial language. Programming language is artificial language to communicate with computer system.
Designing an algorithm has two main things to look at. One is the big picture, what is the final goal. The other is the individual stages, what barriers need to be overcome on the way. Before an algorithm can be designed, it is important to check if the problem is well understood. We need to ask ourself some questions checking if we understand the problem. Those questions include:
What are the inputs into the problem?
What will be the outputs of the problem?
In what order do instructions need to be carry out?
What decisions need to be made in the problem?
Are any area of problem repeated?
“The Secret Rules of Modern Living: Algorithms” introduces us several amazing algorithms that benefits us in our daily life. I would explain three of those amazing algorithms.
Face detection
a mathematical game with a jar full of chocolates and one red hot chilli
Euclidean greatest common divisor
Face detection belongs to the category of computer vision. In the early days, people’s main research direction was face recognition, which means that the identity of a person is recognized according to the face. Later, the face detection needs in complex backgrounds are getting bigger and bigger, and face detection is gradually increasing. Developed as a separate research direction.
“The knowledge-based approach mainly uses prior knowledge to treat faces as a combination of organ features, detecting faces based on the characteristics of organs such as eyes, eyebrows, mouth, nose, and geometric positions. The statistical method is based on Think of the face as a holistic model—a two-dimensional pixel matrix. From a statistical point of view, the face pattern space is constructed by a large number of face image samples, and the presence of the face is judged according to the similarity measure. Under these two frameworks, A number of methods have been developed. At present, with the continuous introduction of various methods and changes in application conditions, a comprehensive system combining knowledge models with statistical models will become a future research trend.” (From the paper “Adaboost-based face detection method” And eye localization algorithm research)
How face detection is achieved
There is a math game with a jar full of chocolates and one red hot chilli. Two people play the game, each person can take out 1 or 2 or 3 chocolates from each time, the pepper can only be taken at the end, whoever has to take the pepper will have to eat her, and lose.
The strategy is, if the number of the chocolate could be divisible by 4, the other people take the chocolate first and he can take 1 or 2 or 3 chocolate. Then you take the chocolate in the next, you take the number of chocolate that equals 4 minus the number that the other people just take. If the number of the chocolate could not be divisible by 4, you take the chocolate first. After you take the chocolate, the number of the chocolate is always divisible to 4.
In short,
The algorithm is to find a balance point.If the initial state is balanced, then the other party will come first, let him break the balance, and then he will maintain balance again.If the initial state is not balanced, then you should come first, maintain balance, then let the other party break, and then maintain balance yourself.
The Euclidean algorithm is the greatest common divisor used to calculate two positive integers a, b.
This is because The greatest common divisor of two integers is equal to the greatest common divisor of the smaller integer and the division remainder of the two integer.
when the added number is 0, the greatest common divisor of two integers is 1
This week, we had several activities in the class. The first one is role play. Lucybillact as a blind robot that need to catch a bottle in the desk. Kingsly was the person who gave order to Lucybilly teaching telling her how to get the bottle. They did catch the bottle. I learn from this activity that order need to be specific, or the order would fail the whole process.
The second activity is guided tour city tube map. We need to find a route that goes through all the tourist attraction without repeating journey. Such activity benefits me in the real life. Because when I visit a city, I can plan a route pass through every site that I hope to visit without repeating journey. I would save the time and cost of the transportation as the high efficiency of the route.
We designed several algorithm this week. The most impressive one is about recognizing parity. It can determine the parity of the numbers that if the numbers are divisible to 2. It can determine the parity of the numbers that if the last digit of the numbers is”1″in binary system. The reasons why this algorithm impressed me is the involvement of two solutions other than one solution. I learned that everything could be. solved in more than one ways.
Magic show this week took a lot of time of us. We prepared it until the dawn is coming. The magic has four step:
rank the card from 1 to 54. The card has individual serial number
remember the content of the card 16. The card is in 16th of those 54 cards
dividing those 54 card into two group. Each group should have number between 16 to 32 due to the position of card we just remember.(all card are facing up)
we pick the group of card that contain the 16th card.
we process those card. one card face down, next one face up in another group. ( process 1)Repeating step 4 and 5 until there is only one card. ( so we might have process it for 4 to 5And that card is the card we pick in step2
The magic card
We might wonder, why 16. 2 to the power of 4. Step 4: one card face down, next one face up in another group. we process those card. one card face down, next one face up in another group. ( process 1) if we do it again, we call it process2 or 3 or 4 or5 and so onThis magic is a classification system. The number are classified by their divisor of 2. We say 1 to 54. Those are the serial number of the card.1 equals 2 to the power of 0, so it is classified as those humber that have no divisor to 2. Which this process are done in the process 1 in which you just manipulated the card for once. 16 is classified as those number whose divisor of 2 have the power of 4. So the system works as classification system.
We could say the magic classify the card due to order of the card in binary system as well. I mean the classification system has nothing to do with the content of the card, just relate to its serial number. So we translate the serial number of the card from 1 to 54, in binary system. During the process 1, if the binary number has 1 in this line, it is classified Into one category, as we make it facing down and discard it later. And in second process, we do this again, card that are not discarded in the process one, whose serial number could be exact divided by two, are manipulate similarly. Serial number that has 1 in this line, are classified as another category, which is discarded. So 16 would not be discarded for a long time. After process 4, all the card that can not be exact divided by 16 is discarded or we could say have already classified into other category. So only serial number 16 is left.
I was in charge of explaining the logic of this magic show. So I have a deep understanding of this magic show. Therefore my skills of computational thinking is developed. I used decomposition to give each card a serial number. I used abstraction to group those card by their serial number. I used pattern recognition to estimate the attribution of the card. I used algorithm to figure out which card is survived. Using computational thinking to solve and study real life problem makes my computational thinking skills to be more proficient, and I benefit from that.
In conclusion, this week, CS class pushes the gate of algorithm for me. Therefore, my skills of computational thinking improved that I could tackle with real life problem by using computational thinking skills, which benefits me a lot.
Hello, guys. This is the third blogs I ever write. This blog is different from any other blogs because I have gone through so much. I would explain that later.
My personal experience and thought.
The knowledge I learn about computer out of the class.
The knowledge I learn from the class and group activity.
Mypersonal experience this week is full of pain, but joviality is accompanied, which is like the Oreo in the milkshakes. On April 2, I should be playing basketball happily in the basketball court, but I fell down when I was trying to catch the ball. I accidentally use my hand to push the ground when I just “touch” it. Pain engulfed my mind before I realized what is happening. The consequence is obvious that my hand fractures, right hand, the hand I used to write, to grab the chopsticks, to brush my teeth, to play basketball. I can no longer do that in the next 3 to 4 month due to the slow recovering rate of the type of bones that fractured. I started to wonder what to do in the next 3 to 4 month because I am an IB student, I have to study and I have a bunch of homework waiting for me as well as test and quiz. Pain came from my mind even exceeds the the physical pain as I did not see the bright side of the future.
However, my dad said, life is life, broken hand is broken hand, you can do nothing about it. So you just follow it, just like function change direction would follow the gradient direction if the function wanna increase in maximum rate. Therefore, I accepted the fact that I would minimally use my right hand, try to do everything in my left hand. It is such a transformation that I took a few days to adapt to it. However I appreciate the what have been gone through on me. I gain skills that I could write by my left hand. I gain friendship when people help me and I say thanks. I gain faith that I would not give up but fighting against the plight. I gain confidence that whatever problems I meet, I would solve it. Those are the joviality I gained.
During this week, I learned what is float operation. it is addition, subtraction, multiplication and division of decimals. There is no decimal point in the hardware of the computer. The things that cpu can handle are all. Therefore, decimals are expressed in a way similar to scientific notation. Such as 1.234 in the computer, can be understood as using 1234 and -3 two integers to represent 1234 * 10 -3 power, such numbers are called floating point numbers. Due to the limitations and complexity of this representation. Real numbers in computers are limited by precision. For example, it can only be accurate to 20 decimal places. Moreover, cpu requires a much more complicated circuit design than integer arithmetic when dealing with such numbers, and the speed is much slower than integer arithmetic.
I have a deeper understanding about computer during the class.
Binary system is the basis of computer. Data and information are based on it. So it can represent everything. it has multiple patterns of representing the information or data. In the class time, we had a group activity that we would translate number from 0 to 63 into the language of computer, BINARY.
EG: There are two levels of high level and low level in the computer. For example, the high level is 3.3v and the low level is 0v.The high level represents 1 and the low level represents 0. Such a combination of high level and low level is a binary number such as 10101101.So the computer stores information in binary. Other hexadecimal numbers are also converted from binary.In addition, the picture you are talking about uses the principle of binary. First, the picture is composed of many pixels. Each pixel is described by three numbers. For example, a pixel value (255, 111, 222) represents the three primary color values of the pixel. Values are converted to binary storage.
Transformation: binary to decimal and decimal to binary
m×10^n : m indicates the value of the current bit, and n indicates that there are n numbers to the right of the current bit. For example, the understanding of the hundred digits 6×10^2 means that the current digit value m is 6, and the index 2 indicates that there are still two numbers on the right side of the current hundred digits. Decimal is the base 10 index. Similarly, the binary difference is the base 2 index. The binary representation is as follows:
m×2^n : m indicates the value of the current bit, and n indicates that there are n numbers to the right of the current bit. According to the above formula, we can try to convert a binary value: 11011 =1×2^4 1×2^3 0×2^2 1×2^1 1×2^0 =2^4 2^3 2^1 2^0 =16 8 2 1 =27 From the above calculation we can see that the binary only has 0 and 1, so we generally consider that there are 1 bits in the calculation, and then we can sum them.
After that, we were provided with another example. The example that tells us real life application of binary. The light up or not is a representation of ”1″ and”0″ in binary system. In this example, light up or not are reflected to binary'”1″ or “0”. “1” or “0” are reflected to numbers. Number are reflected to letters. Letters make the sentence.
The function of CPU
processing the instruction
perform an action
Control time
process data
The function of CU
Direct computer components to work automatically and consistently
Buffering of data
Error control
Data exchange
Stating thee statues
receive and recognize the order
The function of ALU
The ALU arithmetic logic unit is the execution unit of the central processing unit (CPU). It is the core component of all central processing units. The arithmetic logic unit consists of “And Gate” and “Or Gate”. The main function is to perform two-bit arithmetic operations, such as addition, subtraction, and multiplication (excluding integer division).
The function of Register
Cache is to solve the speed difference between CPU speed and memory speed
The most frequently accessed data and instructions in the memory are copied into the cache in the CPU, so that the CPU can not fetch data into the slow memory like “snail”. The CPU only needs to go to the cache to fetch it. And the cache is much faster than the memory.
Cache is to solve the speed difference between CPU speed and memory speed The most frequently accessed data and instructions in the memory are copied into the cache in the CPU, so that the CPU can not fetch data into the slow memory like “snail”. The CPU only needs to go to the cache to fetch it. And the cache is much faster than the memory.
The function of Bus
It is to perform hardware communication and data transmission between hardware\
How does CPU work?
The first step: fetch instructions, cpu controller reads an instruction into the instruction register.
The second step: instruction decoding, decoding the instruction in the instruction register, determining the operation of the instruction, and the operand address.
The third step: execute the instruction, use the operand address to find the operand, and perform the operation.
ASCII and UNICODE
ASCII:It is a computerized coding system based on the Latin alphabet, mainly used to display modern English and other Western European languages. It is the most versatile single-byte encoding system available today and is equivalent to the international standard ISO/IEC 646.
UNICODE:It is an industry standard in the field of computer science, including character sets and coding schemes. Unicode is created to address the limitations of traditional character encoding schemes. It sets a uniform and unique binary encoding for each character in each language to meet cross-language, cross-platform text conversion and processing requirements.
Role play activity
In order to better understand the patterns that the computer works, 6 people in a group would act all 5 component of the computer, which are CPU, ALU, Bus, Register, Display, CPU clock. I act as a CPU clock. My job is to record the times that CPU works. My job is repeating and boring. I learn that If the CPU is multi-threaded, my workload will increase a lot. However, in role play, CPU is not multi-threaded.