introduction to computing -...

15
6 CHAPTER 1 Introduction to Computing Chapter One Introduction Computer Science is one of the most influential sciences in the modern world, enabling technologies and innovations that directly affect the lives of individuals and communities. Computer applications have a tangible and distinctive presence in all aspects of life, such as health, education, economics, social issues and agriculture. For instance, Computer Molding demonstrates the importance of computer applications in health, enabling doctors and scientists to make new drugs to combat deadly diseases like AIDS. In fact, computer programmers have a leading role in the development of many new innovative technologies.

Upload: others

Post on 05-Jun-2020

27 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

6

C H A P T E R 1

Introduction to Computing

Chapter One

IntroductionComputer Science is one of the most influential sciences in the modern world, enabling technologies and innovations that directly affect the lives of individuals and communities.

Computer applications have a tangible and distinctive presence in all aspects of life, such as health, education, economics, social issues and agriculture. For instance, Computer Molding demonstrates the importance of computer applications in health, enabling doctors and scientists to make new drugs to combat deadly diseases like AIDS. In fact, computer programmers have a leading role in the development of many new innovative technologies.

Page 2: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

7

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

Learning Objectives

• To recognize the importance of technology in our lives and the importance of developing new technologies

• To define a computer program

• To understand the role of computer programmers

• To learn about programming languages and their uses

• To identify the skills required to create computer applications

• To define an algorithm and give examples

• To understand the factors when determining an algorithm

• To define computer science

• To list the sub-fields of computer science and their applications

• To understand the purpose of Alice

Alice will get you started with the requisite skills and knowledge so you can develop new and innovative applications and become a creative programmer and technology maker.

Page 3: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

8

C H A P T E R 1

1-1 Technology in Our Lives We live in a world where technology is all around us, and nearly all of us are experts in using it. We see applications like PhotoShop and Power Point that help us become more productive. We use Google to search the internet to do research for homework and when we get bored we play fun games like Flappy Birds and Candy Crush. Even little children use smartphones, playing all kinds of educational and entertaining games.

1-2 Computer Programming

What is even more fascinating is how these programs are created. All applications are a set of instructions written in a language that the com-puters can understand. They are computer programs and the process of writing these programs is called computer programming.

Computer programming is an essential science, helping us write instruc-tions to solve specific problems using a computer.

These instructions are written in a programming language. People who make applications are called computer programmers.

Computer Program

A set of instructions that tells the computer what to do.

What does it take to create cool applications?

It is not extremely hard to write computer programs. It does take a little bit of creativity, logical reasoning, problem solving skills and knowledge of a programming language.

Computer programs are made up of very simple ideas; it is up to you to put together these simple ideas into fascinating applications.

Think

Page 4: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

9

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

Programming Languages There are many programming languages, such as Python, C, Java, C++, C Sharp, ML, PHP, Java Script, Haskell and Scheme. Each programming language has its own purposes, benefits and drawbacks and the choice of each depends on your expertise, your field of work or study and your requirements. Programming languages are tools to solve problems, but they don’t solve problem themselves. They are designed in a way that helps you solve or think about different kinds of problems, although most problems can be solved with any language.

Think of world languages like Arabic, English and French. You can convey most ideas in any language, but because of different vocabulary and grammar, some ideas are more easily described in certain languages. For example, scientific concepts are more straightforward in English, however a language like Arabic is more complex and multidimensional. The same concept applies to programming languages.

1-3 AlgorithmsAlgorithms are one of the fundamentals of programming. To create computer programs, you must first learn how to develop algorithms which can be transferred to computer instructions that are written in any programming language.

Developing algorithms requires more effort and logical thinking than writing programs because the hardest part of solving a problem is to find an appropriate solution, and then check if it works.

To solve a problem: . 1 Identify the problem. . 2 Analyze the problem by specifying:

a. Input b. Output c. Processing (arithmetic and logical operations needed) . 3 Write the algorithm.. 4 Test the solution.

Algorithm

A set of instructions that solves a problem.

Page 5: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

10

C H A P T E R 1

To specify an algorithm, make sure you:. 1 Give all the instructions and take into account all possibilities.. 2 Give correct instructions.. 3 Give the right sequence of instructions.. 4 Give only those instructions that are needed.

Example 1Tell someone how to bake a cake.

The problem: bake a cakeInput: ingredients (flour, sugar, eggs and oil), pan and ovenOutput: a cake

Algorithm:1. Beat the eggs. 2. Mix flour, sugar and oil in a baking pan.3. Add eggs to the pan.4. Heat the oven to 375 degrees.5. Put the pan in the oven and bake for 45 minutes.

A recipe is a step by step instruction on how to solve a problem (bake a cake). This is an algorithm.

Example 2Calculate the average of three numbers, 50, 20 and 70.

The problem: find the average of numbersInput: integers (50, 20 and 70) Output: the average of the input numbers

Algorithm: 1. Add all the integers. (50+ 20+70 = 140) 2. Divide the result by the number of integers in the set.

(140/3 = 46.6)

Examples

Page 6: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

11

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

Example 3Put the following list of numbers into increasing order:8, 31, 45, 12, 23, 89, 70, 105, 19, and 67

The problem: sort a list of numbers into increasing orderInput: an unsorted number listOutput: a sorted number list

Algorithm: 1. Find the smallest number and swap it with the first in the list. 2. Find the second smallest number and swap it with the second

number in the list. 3. Continue until the list is sorted.

Let’s try it out

The smallest number 8 is in the sorted position. 8, 31, 45, 12, 23, 89, 70, 105, 19, and 67

The second smallest is 12: swap it with 31.8, 12, 45, 31, 23, 89, 70, 105, 19, and 67

The third smallest is 19, swap it with 45.8, 12, 19, 31, 23, 89, 70, 105, 45, and 67

The fourth smallest is 23, swap it with 31.8, 12, 19, 23, 31, 89, 70, 105, 45, and 67

The fifth smallest “31” is in the correct position.

The sixth smallest is 45, swap it with 89.8, 12, 19, 23, 31, 45, 70, 105, 89, and 67

The seventh smallest is 67, swap it with 70.8, 12, 19, 23, 31, 45, 67, 105, 89, and 70

The eighth smallest is 70, swap it with 105. 8, 12, 19, 23, 31, 45, 67, 70, 89, and 105

The last two numbers, 89 and 105, are correct, so the list is now sorted.

The preceding algorithm is called a “selection sort algorithm.”

Examples

Page 7: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

12

C H A P T E R 1

Example 4

Abdullah wants to send Ahmed sensitive data, and wants to be sure that only Ahmed can read it. How can Abdullah protect this data and ensure that only Ahmed can access it?

The problem: send sensitive data from one person to another without having anyone else access it.Input: Ahmed, Abdullah, sensitive data (currently with Abdullah)Output: the data are with Ahmed, and no one else could have viewed it

You may think that Abdullah can simply put a lock on it, but then how he can send the key to Ahmed? If Abdullah sends the key, how can he be sure that no one else can open it in the middle and close it again?

Algorithm:Here is one way of solving the problem. Abdullah locks the box and sends it to Ahmed without the key. Ahmed puts his own lock on the box and sends the box back to Abdullah. Now the box has two locks. Abdullah unlocks his own lock, removing it from the box. Now the box has only Ahmed’s lock. Abdullah sends the box back to Ahmed, who can then unlock it with his own key.

So you can see, sometimes you have to think hard to solve simple problems.

Examples

Page 8: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

13

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

1-4 What is Computer Science?

Computer scientists deal primarily with software and software systems; this includes theory, design, development and application.

Discuss with your fellow students

Shortest Path

Suppose you want to go from your home to Landmark Mall and you have 5 roads available that have different travel times. What is the fastest way of going from your home to Landmark?

Think deeply about how you to solve this problem. You know which roads are available and what is doable, so you need to figure out the shortest, best path. How will you check that this is the best way to go?------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

“Shortest path” is a very intuitive problem that we use all the time.

Computer Science

The study of principles, applications and technologies of computing and computers.

Page 9: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

14

C H A P T E R 1

Major Fields of Computer Science1. Mobile Computing and ApplicationsThis field is comprised of designing and building new amazing mobile applications like Flappy Birds and WhatsApp. Mobile applications run on devices people carry with them as they move, like smartphones and tablets. Mobile applications can be created in programming languages like C#, objective c and Java.

2. Web DevelopmentThis area involves developing websites for the Internet using platforms and languages like HTML, MySQL, PHP and Ajax.

3. Graphics and Computer VisionThis field involves acquiring, processing, analyzing and understanding images to extract information. Algorithms in this field can, for example, allow Facebook to recognize faces in a picture.

4. Robotics and Artificial IntelligenceThose who work in this field study and design intelligent machines and robots. For example, Google is developing a car that drives by itself.

5. DatabasesThis field involves operating large quantities of information through inputting, storing, retrieving and managing it using software applications like MySQL and PostgreSQL.

6. Communications and NetworksInternet is one of the oldest and greatest applications in this area. In the current era, specialists in the field of engineering networks create and develop data-communication techniques such as Bluetooth, Ethernet and Wi-Fi.

7. Architecture and HardwareComputer architects design computers, organize processors and improve storage technologies. Scientists in this field develop faster computers.

Page 10: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

15

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

1-5 AliceThis year we will be learning skills that will help us understand how computers can be programmed. We will learn this through Alice.

Why Alice?Alice is a simple programming tool that helps you create 3D animations to visualize stories that you create. Alice enables its users to design and choose objects to represent a story’s main characters and then animate the events of the story through instructions.

Alice is a good start to learn: 1. How to write programs2. How to think like a computer scientists3. How to communicate your ideas to computers by translating your human

language and thinking to a computer language.4. Understand the basic constructs behind any programming language.

Alice

A software program that allows you to be the director of a movie or the creator of a video game, and 3D objects move according to the instructions that you give.

Page 11: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

16

C H A P T E R 1

Summary of Terms

Computer Program

A set of instructions that tells the computer what to do.

Instruction

An action to be performed.

Algorithm

A set of instructions that solves a specific problem.

Computer Science

The study of principles, applications and technologies of computing and computers.

Page 12: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

17

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

1- Choose the correct answer: i. A computer program is----------- a. Actions occur at a specific time. b. A set of instructions that tells the computer what to do. c. A list of actions to perform a task or solve a problem.

ii. All of the following skills are required to create computer applica- tions except:

a. Creativity and logical thinking b. Problem-solving c. Engineering circuitry in a computer

iii. A list of detailed and chained procedures to perform a task or solve a problem is called------------- a. a computer program b. an algorithm c. a computer application

iv. Ali writes a program to calculate the area of a square building. This makes Ali: a. a computer programmer. b. an architect. c. a hacker.

2- Fill-in the correct answer: ii. Google Maps uses a step by step set of instructions to find the directions between your house and the nearest amusement park with the shortest distance. This is an example of an ____________.

iii. Mohammed Hossain is a computer scientist working in Microsoft, designing MS office and windows applications. Computer scientists like Mohammed Hossain are involved in the _________ and ___________ of applications.

3- List all the technological devices that you use everyday. For each one, write why you use it or how it is useful. ---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

Questions

Page 13: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

18

C H A P T E R 1

4- List four sub-fields of Computer Science.

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

5- List what to consider when determining an algorithm.

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

6- Algorithms are a set of instructions. Give instructions to your best friend about how to:

Get ready for school---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

Draw a picture of the sun in Microsoft Paint---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- Find the tallest person in your class---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- Drive a car. ---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

Questions

Page 14: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

19

C H A P T E R 1 : I n t r o d u c t i o n t o C o m p u t i n g

7- Omar wrote the following descriptions of an algorithm to find the cost of going from point A to point B on a map by Karwa taxi and splitting the cost with his friends. Which of the following versions of the algorithms are correctly described?

For all algorithms, write “Valid” if it is a correct description. If not, specify why (e.g. not right sequence or not correct instructions).

a. 1- Calculate the distance between Point A and B. 2- Calculate the distance between Point B and A. 3- Add both the distances and divide by 2. 4- Multiply the result by the rate per kilometer of the taxi. 5- Add the minimum fare for the taxi to the result. 6- Divide the result by the number of people.

------------------------------------------------------------------------------- b. 1- Multiply the result by the rate per kilometer of the taxi. 2- Calculate the distance between Point A and B. 3- Divide the result by the number of people. 4- Add the minimum fare for the taxi to the result.

-------------------------------------------------------------------------------c. 1- Calculate the distance between Point A and B. 2- Convert the distance to miles. 3- Multiply the result by the rate of charge per kilometer of the taxi. 4- Add the minimum fare for the taxi to the result. 5- Divide the result by the number of people.

-------------------------------------------------------------------------------

d. 1- Calculate the distance between Point A and B. 2- Multiply the result by the rate per kilometer of the taxi. 3- Add the minimum fare for the taxi to the result. 4- Divide the result by the number of people.

-------------------------------------------------------------------------------

e. 1- Calculate the distance between Point A and B. 2- Multiply the result by the rate of charge per kilometer of the taxi. 3- Add the minimum fare for the taxi to the result. -------------------------------------------------------------------------------

Questions

Page 15: Introduction to Computing - alice.qatar.cmu.edualice.qatar.cmu.edu/alice2/wp-content/uploads/2016/... · Introduction to Computing Chapter One Introduction Computer Science is one

20

C H A P T E R 1

8- Suppose we need to create an exam schedule with different subjects, but many subjects have common students (a minimum of two). How do we schedule the exam so that no two exams with a common student are scheduled at same time? What is the minimum number of time slots needed to schedule all exams?

Subjects: Math, English, Chemistry, Programming, History

Enrolled students: Student 1: Math, English, ChemistryStudent 2: Math, English, Chemistry, ProgrammingStudent 3: Math, History Student 4: English, Programming, History

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

-----------------------------------------------------------------------------

Questions