Lect 23
Lect 23
1
AP Exam
2
Topics
The AP Multiple Choice end-of-year covers 5 Big Ideas:
1) Creative Development(10%-13%)
2) Data(17%-22%)
3) Algorithms and Programming(30%-35%)
4) Computer Systems and Networks(11%-15%)
5) Impact of Computing(21%-26%)
3
Big Idea 1
4
Big Idea 1
Please read Chapter 2: Big Idea 1: Creative Development. of the AP Barron's
book. The following slides provide a summary of the material covered in this
chapter.
6
Big Idea 1
Collaboration helps people learn from each other. Collaboration that
includes diverse perspectives helps to avoid bias in the development of
computing innovations.
For example, if females play video games at the same percentage as males, a
game company might not avoid bias if it employed males to write the code for
the games. Bringing in female coders could bring additional perspectives that
might not have been achieved otherwise.
Programming companies often hire people who not only are good
programmers but also have interpersonal skills needed to collaborate
effectively. Effective collaboration can help one gain insight and knowledge by
applying multiple perspectives, experiences, and skill sets.
7
Big Idea 1
Collaboration is a learned skill. That skill includes but is not limited to:
■Communication
■Consensus building
■Conflict resolution
■Negotiation
8
Big Idea 1
Online collaboration tools, such as Google Docs, Zoom, Slack, Yammer, and—
by the time you read this—dozens of other tools, allow programmers to
collaborate from home or from anywhere that has internet access.
This triggering is called an event. The event is the action that supplies input
data to a program. Events can be generated when a key is pressed, a mouse is
clicked, a program is started, or by any other defined action that affects the
flow of execution.
10
Big Idea 1
Program outputs are any data sent from a program to a device. Program
output can come in a variety of forms, such as tactile, audio, visual, or text.
Program output is usually based on a program’s input or prior state (e.g.,
internal values). 11
Big Idea 1
A development process can be ordered and intentional, or exploratory in
nature.
12
Big Idea 1
The design of a program incorporates investigations to determine its
requirements. Most programs are designed to be used by people other than
the programmers.
To meet the needs of the users, the investigation must identify the program
constraints as well as the concerns and interests of people who will use the
program.
15
Big Idea 1
Three types of program errors can occur:
Logic Error. The code adds the first number twice in the sum.
17
Big Idea 2: Data
18
Big Idea 2: Data
A bit is shorthand for a single binary digit and is either 0 or 1. A byte is 8 bits. For example, the binary
sequence 0110 1111 contains 8 bits or 1 byte.
Binary sequences can be used to represent all digital data. Binary sequences can represent colors,
Boolean logic, lists, and so on. Anything that can be stored on a computer can be represented by binary
sequences.
Some data take many bits to represent it. For example, a single 10 MP (1 MP is one million pixels)
picture uses 10,000,000 pixels.
Each pixel (16-bit mode RGB) contains 16 * 3 = 48 bits = 6 bytes. That means there are 48 bits *
10,000,000 = 480,000,000 bits in a single 10 MP (16-bit mode) picture.
Logic Error. The code adds the first number twice in the sum. 19
Digital vs. Analog
Many physical phenomena can be modeled by analog signal(sound, colors,
temperature). Analog signals are continuous signals.
Computers can only understand digital signals (discrete or finite signal(0s
and 1s).)
• analog signals are continuous and can take on an infinite possible values(the real
numbers)
• digital signals are finite.
• For example, 8 bit colors can take on one of 256 discrete, finite possibilities. But actual
colors can take on any of an infinite possible values or shades.
Sampling allow computers to
approximate analog signals such
as sound.
The number of samples is the
sampling rate, the higher the rate
the better the quality.
Big Idea 2: Data
In many programming languages, integers are represented by a fixed number of
bits, which limit the range of integer values and mathematical operations on
those values.
Some languages like Python, integers do not have limits on number size but,
instead, expand to the limit of the available memory.
21
Big Idea 2: Data
Example 1:
With 4 bits, the largest integer that can be stored is 2^4-1 = 15.
Example 2:
A 4-bit integer can any value in {0,1,2,..,15}. Thus storing the value of 10 + 6 =
16 would cause an overflow error since the 16 = 10000 requires at least 5 bits.
Example 3:
If x is a 3-bit integer, then x = 111 + 111 will cause an overflow error since the
sum is 1110 which requires at least 4 bits.
22
Big Idea 2: Data
1/3 does not always equal 1/3. A roundoff error occurs when decimals
(real numbers) are rounded.
23
Big Idea 2: Data
Number bases, including binary, decimal, and hexadecimal, are used to
represent and investigate digital data.
24
Big Idea 2: Data
25
14 – 8 = 6
There is one 4 in 6 so:
2 – 2 = 0. Thus
26
Big Idea 2: Data
INFORMATION EXTRACTED FROM DATA
People generate significant amounts of digital data daily. Some always-on
devices are collecting geographic location data constantly, while social media
sites are collecting premium data based on your usage.
27
Big Idea 2: Data
Large data sets may be analyzed computationally to reveal patterns, trends, and
associations.
Cleaning data is a process that makes the data uniform without changing their
meaning.
One example is replacing all equivalent abbreviations with the same word. This
can also be done with various spellings and with different capitalizations.
29
Big Idea 2: Data
Data can get too large for traditional data-processing applications. The ability
to process data depends on the capabilities of the users and their tools. Social
media activity generates an enormous amount of data.
Some data sets are difficult to process using a single computer and may
require parallel systems.
Problems of bias are often created by the types and sources of data being
collected. Bias is not eliminated by simply collecting more data. A large amount
of data is generated by humans. Algorithms that use this data will reflect this
bias.
Despite the advantages of big data, a large sample size can magnify the bias
associated with the data being used. Data can have little value if the sample is
not representative of the population to which the results will be generalized.
30
Big Idea 2: Data
Predicting algorithms use information collected from big data to influence our
daily lives. For example:
■A credit card company can use purchasing patterns to identify when to
extend credit or flag a purchase for possible fraud.
■Social media sites can use patterns to target advertising based on viewing
habits.
■An online store analyzing customers’ past purchases can suggest new
products the customer may be interested in buying.
■An entertainment application may recommend an additional movie to watch
based on the viewer’s interests.
31
Big Idea 2: Data
Using appropriate visualizations when presenting digitally processed data can
help one gain insight and knowledge. Although big data is a powerful tool, the
data will lose their value if they cannot be presented in a way that can be
interpreted.
Python's pandas library can be used to explore, process and visualize data. See
the optional lecture slides "pandas for Tabular data". Python's pandas library is a
powerful alternative to Excel.
32
Big Idea 2: Data
Privacy concerns arise through the mass collection of data. The content of the
data may contain personal information and can affect the choice in storage and
transmitting.
Anything done online is likely to lead to sharing of private data. Using Gmail to
order a pair of shoes from Clarks could result in ads for shoes showing up in
your search engine.
33
Big Idea 2: Data
Metadata are data that describe your data—for example, a picture of you
standing in front of a waterfall is data. The location and time the picture was
taken are metadata.
Metadata are used for finding, organizing, and managing information. Metadata
can increase the effective use of data or data sets by providing additional
information about various aspects of that data.
Changes and deletions made to metadata do not change the primary data.
34
Big Idea 3: Programming and Algorithms
Please see the following reference sheet(also available during the actual exam)
for more details about the syntax.
https://apcentral.collegeboard.org/pdf/ap-computer-science-principles-exam-
reference-sheet.pdf
35
Big Idea 3: Programming and Algorithms
In computer science, an abstraction is a way to represent essential features
without including the background details or explanations. Abstractions reduce
complexity and allow for efficient design and implementation of complex
software systems.
36
Big Idea 3: Programming and Algorithms
Programmers also use abstractions. The purpose of abstraction is to hide
coding details so the programmer can focus on the current problem.
Rarely will programmers deal directly in machine code. Machine code is a base
language where no abstractions are implemented. Programmers have worked
to hide details by using abstractions.
40
Important Procedures(Functions)
41
Assignment uses Arrows not =
Example:
DISPLAY(a = b) false
42
DISPLAY(a <= b) true
43
Big Idea 3: Programming and Algorithms
44
Big Idea 3: Programming and Algorithms
45
Big Idea 3: Programming and Algorithms
46
Big Idea 3: Programming and Algorithms
47
Big Idea 3: Programming and Algorithms
48
49
Lists
50
Lists
51
The INSERT(list, i, item) will insert the item at index i and shift right items
at index i or higher.
52
The APPEND(list, item) will add the item to the end of the list.
53
The REMOVE(list, i) will remove the item at index i and shift left items
at index i or higher.
Line 4: REMOVE(words, 3)
Line 5: DISPLAY(words)
54
Conditionals
55
Loop 1: Repeat n Times
The code in block of statements is executed n times.
56
Loop 2: Repeat Until Condition
The code in block of statements is repeated until the Boolean expression
condition evaluates to true.
57
Loop 3: Looping Through a List
The variable item is assigned the value of each element of aList sequentially,
in order, from the first element to the last element. The code in block of
statements is executed once for each assignment of item.
58
Example: Looping Through a List
59
Example: Looping Through a List
sum 0
n LENGTH(list)
index 1
REPEAT n TIMES
{
sum sum + list[index]
index index + 1
} 61
DISPLAY(sum)
63
What does the code do?
Answer: Add negative numbers from alist to the end of bList.
64
What is the output?
Please know these algorithms and know how to quickly recognize them! If the
code for any of the algorithm above is given with the name "mystery_algorithm",
you should be able to quickly recognize what it does.
68
Find average of a list(implementation #2)
Implementation #2: Use REPEAT n times loop.
PROCEDURE findAverage(list)
{
sum 0
n LENGTH(list)
index 1
REPEAT n TIMES
{
sum sum + list[index]
69
index index + 1
}
RETURN sum / n
}
Find maximum of a list(implementation #1)
Implementation #1: Use for Each Loop.
70
Find maximum of a list(implementation #2)
Implementation #2: Use REPEAT n times loop.
count 1
count count + 1
Common Error Example 1
The AP exam will try to give you code that is the wrong implementation of an
algorithm. Can you find the error?
72
Common Error Example 2
The AP exam will try to give you code that is the wrong implementation of an
algorithm. Can you find the error?
PROCEDURE findMinimum(list)
{
min list[1]
FOR EACH item IN list
{
IF(item < min)
min item
ELSE
min 0
}
RETURN min
}
73
Correct findMinimum
Here's the correct implementation of findMinimum.
PROCEDURE findMinimum(list)
{
min list[1]
FOR EACH item IN list
{
IF(item < min)
min item
}
RETURN min
}
Find word from list of words
PROCEDURE findWord(list, word)
{
index 1
FOR EACH item IN list This code also works if we remove
{ the Else block:
IF(item = word)
{ IF(item = word)
RETURN index
{
}
ELSE RETURN index
{ }
index index + 1 index ß index + 1
}
}
78
Big Idea 3: Programming and Algorithms
79
80
81
What is the result of executing the above code?
82
Does the code work as intended?
Yes, as an exercise, trace the code to convince yourself that the robot will
reach destination. 83
Does the code work as intended?
No! Robot get stuck in an infinite loop at the top right corner.
84
85
86
87
88
89
90
91
92
93
Program Design
94
95
Trace the code and determine the output of the following program.
Answer:
96
Trace the code and determine the output of the following program.
Answer: Display 3.
97
Algorithmic Efficiency
Some problems cannot be solved in a reasonable amount of time because
there is no efficient algorithm for solving them. In these cases, approximate
solutions are sought.
However, there exists important and practical problems for which there exists
no known polynomial time algorithm. Algorithms with exponential or factorial
efficiencies are examples of algorithms that run in an unreasonable amount
of time.
98
Algorithmic Efficiency
99
Programmers break down problems into smaller and more manageable pieces. By
creating procedures and leveraging parameters, programmers generalize
processes that can be reused.
Procedures allow programmers to draw upon existing code that has already been
tested, allowing them to write programs more quickly and with more confidence.
100
Application program interfaces (APIs) are specifications for how the procedures
in a library behave and can be used.
For example, Twitter's API allow programmers to access and analyze tweets.
A computing device is a physical artifact that can run a program. Some examples
include computers, tablets, servers, routers, and smart sensors. The device must be able
to take inputs, process the inputs, and then calculate results based on those inputs.
102
Big Idea 4: Computer Systems and Networks
A computing device is a physical artifact that can run a program. Some
examples include computers, tablets, servers, routers, and smart sensors. The
device must be able to take inputs, process the inputs, and then calculate results
based on those inputs.
103
Big Idea 4: Computer Systems and Networks
A path between two computing devices on a computer network (a sender and
receiver) is a sequence of directly connected computing devices that begins at
the sender and ends at the receiver. Routing is the process of finding a path
from sender to receiver.
If the path from sender to receiver is broken, the path will be rerouted. This
fault-tolerant nature of the internet makes connections between computing
devices more reliable.
The internet connects devices and networks from all over the world. The
internet is a physical network of fiber optics, radio transmitters, and cabling.
Devices and networks that make up the internet are connected and
communicate using standardized, open communication protocols.
104
Big Idea 4: Computer Systems and Networks
A protocol is an agreed-upon set of rules that specify the behavior of a
system.
These internet protocols, including those for addresses and names, have
evolved to allow for the internet to be scalable.
The scalability of a system is the capacity for the system to change in size and
scale to meet new demands.
Internet protocol (IP) is responsible for addressing and routing your online
requests. For a device to connect to the internet, it is first assigned an internet
protocol address.
105
Big Idea 4: Computer Systems and Networks
Currently, we are switching between the fourth and sixth versions of the
internet protocol.
The fourth version (IPv4) uses 32 bits to store IP addresses. These 32 bits can
hold 2^32 IP addresses. When multiplied out, 2^32 is actually 4,294,967,296
unique addresses.
The newer version, IPv6, uses 128 bits, which can hold 2^128 IP addresses.
Redundancy is the inclusion of extra paths that can mitigate the failure of a
system if other components fail. This is important because elements can fail at
any time, and fault tolerance allows users to continue to use the network.
107
Big Idea 4: Computer Systems and Networks
The internet refers to the hardware. It is made up of the computers, cables,
routers, and many more components that make up the entire network. It is a
global decentralized network connecting millions of computers.
The World Wide Web, in contrast, refers to the software used on the
internet. HTTP is a protocol used by the World Wide Web to transmit data.
The internet allows access to the World Wide Web, which is a system of linked
pages, programs, and files.
108
Big Idea 4: Computer Systems and Networks
Sequential computing is a computational model in which operations are
performed in order one at a time. A sequential solution takes as long as the
sum of all of the steps.
A sequential computing solution takes as long as the sum of all its steps. In the
above example, the total processing time is 4 + 1 + 6 + 2 + 3 + 1 + 5 + 1 = 23
seconds.
109
Big Idea 4: Computer Systems and Networks
In contrast, parallel computing involves breaking up a task into smaller,
sequential pieces. Then those sequential pieces are all executed at the same
time, each on its own processor or on a set of computers that have been
networked together.
112
Big Idea 4: Computer Systems and Networks
Many problems are so large and complex that it is impractical to solve them on
a single computer, especially given limited computer memory. Distributed
computing is a computational model in which multiple devices are used to
run a program.
Much larger problems can be solved more quickly using distributed computing
than using a single computer.
114
Big Idea 5: Impact of Computing
The digital divide is the difference in access to technology including access to
computers and the internet.
115
Big Idea 5: Impact of Computing
A computing innovation includes a program as an integral part of its
function. Some examples of modern computing innovations include the
following:
116
Big Idea 5: Impact of Computing
A computing innovation can have both a beneficial and a harmful effect on
societies, cultures, or economies. An effect may be an impact, a result, or an
outcome. Beneficial and/or harmful effects are contextual and interpretive.
A single effect can be viewed as both beneficial and harmful by different people
or even by the same person.
For example, GPS in a car can predict the time of arrival during a long car trip
by tracking the speed of a car and the distance needed to travel. This can be
beneficial to the driver to know his or her time of arrival. However, this same
innovation can be harmful to the user if the police gain access to this data and
give the driver a speeding ticket.
117
Big Idea 5: Impact of Computing
Computing innovations can reflect existing human bias.Since computing
innovations are created by people, the innovations created can reflect bias that
the programmers bring with them. Programmers should take action to reduce
biases at all levels of software development. Machine learning algorithms that
are trained on biased datasets will give biased results.
Creative Commons—a public copyright license that enables the free distribution
of an otherwise copyrighted work. This is used when the content creator wants to give
others the right to share, use, and build upon the work they have created.
open source—programs that are made freely available and may be redistributed and
modified(examples: Firefox browser, OpenOffice(in competition with Microsoft Office).
open access—online research output free of any and all restrictions on access and free
of many restrictions on use, such as copyright or license restrictions
Open Access
Big Idea 5: Impact of Computing
Security is needed to protect the confidentiality, integrity, and availability of
information. Security protects that data from cyber attacks and hacking.
120
Big Idea 5: Impact of Computing
PII can be analyzed and processed by businesses and shared with other
companies. PII has monetary value. The entire business model for some
computing innovations is to sell user information to targeted advertisers.
As a result, concerns have been raised over how companies handle the
sensitive information of their consumers.
121
Big Idea 5: Impact of Computing
Authentication measures protect devices and information from unauthorized
access. Examples of authentication measures include passwords and multifactor
authentication. A strong password should be easy to remember but difficult for
someone else to guess.
122
Big Idea 5: Impact of Computing
Digital certificate authorities issue digital certificates that validate the
ownership of encryption keys used in secure communications and are based on a
trust model.
Symmetric key encryption uses the same key for both encryption and
decryption. The one key is a shared secret and relies on both sides keeping their
key secret.
Computer viruses are malicious programs that can copy themselves and gain
access to a computer in an unauthorized way. Viruses often perform some type
of harmful activity on infected host computers.
124
Big Idea 5: Impact of Computing
Unauthorized access can be gained to computers in several ways. One method
is phishing. Phishing is a technique that directs users to unrelated sites that
trick the user into giving personal data. Phishing is a technique used by cyber
criminals posing as a legitimate institution to lure individuals into providing
sensitive data, such as PII, banking and credit card details, and passwords.
Data sent over public networks can be intercepted, analyzed, and modified. One
way that this can happen is through a rogue access point. A rogue access
point is a wireless access point that gives unauthorized access to secure
networks.
125
References
126