Concepts in Computer Science - PowerPoint PPT Presentation

About This Presentation
Title:

Concepts in Computer Science

Description:

... for permanent storage ... of a single row of storage locations, each referenced by a numerical ... click on Start, then Programs, then Accessories then Notepad) ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 52
Provided by: lindaga
Learn more at: http://www.cs.ucf.edu
Category:

less

Transcript and Presenter's Notes

Title: Concepts in Computer Science


1
Concepts in Computer Science
  • COP 2500
  • http//www.cs.ucf.edu/courses/cop2500
  • Keith Garfield
  • garfield_at_cs.ucf.edu

2
The World of Computer Science
Theory of Algorithms
Algorithms
Theoretical Model of Computers
Theory of Languages
Languages
Architecture
Real World
World of Theory
3
What is Computer Science all About?
What problems can a computer solve?
What is the computational cost of the
solution?
  • The answer to the first question tells us
    whether a problem should even be attempted using
    a computer.
  • Some problems are perfectly suited for computers,
    others are not.
  • The answer to the second question tells us if it
    is worth doing.
  • The cost is in terms of some resource like time
    or memory usage.
  • We attempt to relate cost to problem size.
  • Problems are grouped into classes depending on
    their cost (Chptr 11)

4
Purpose of the Course
  • Computer Capabilities Inherent capabilities of
    any autonomous computing machine.
  • Basic CS concepts Allows you to communicate with
    and work with CS people, and validate (or
    disprove), their ideas.
  • Programming? Not trying to teach you to be
    programmers, but will require some programming to
    develop topics.
  • Program design How does one go about planning a
    computer program?
  • Program implementation How does my design get
    turned into working code?

5
Course Outline
  • Throughout the course we will use searching and
    sorting problems to illustrate points.
  • Topics (roughly in the same order as they are
    introduced)
  • Binary math
  • Basic computer architecture
  • Our model of a computer
  • Introduction to Algorithms and Functions (Chapter
    2)
  • The cost of computation (Chapter 9)
  • Transforming algorithms into code (Chapter 3,
    supplemental text)
  • Computer languages data types and data
    structures. (Chapter 3)
  • Computer languages program control mechanisms
    (Chapter 4)
  • Computer Languages Types of languages (Chapter
    7)
  • More about functions recursion, iteration,
    modularity. (Chapter 4)
  • Complex Data Structures. (Chapter 3, 5)
  • The hierarchy of problems (Chapter 11)

6
Some First Thoughts
  • Computers are amazingly stupid. They have no
    sense of self, situation, or history.
  • Computers will only do what you tell them, and
    you must give them their directions in minute
    detail.
  • Computers store information in very limited ways.
  • Because of the above, computers are very good at
    some types of tasks and very bad at others.
  • Good Mindless repetition with accuracy.
  • Bad Creativity, intuition, common sense, and
    sensing.
  • We will use the above to discuss what computers
    can and cannot do Can it be computed?

7
CS Concepts Computational Power
  • Computational power refers to the types of
    problems a computer can solve.
  • It has nothing to do with how fast a computer is
    nor how nice the graphics are.
  • It turns out very simple computers are just as
    powerful than very expensive ones (although
    slower).
  • So in terms of computational power, all computers
    are equal.
  • This allows generalized solutions - solve a
    problem for one and we solve it for all.
  • Since all computers are equal, we tend to focus
    on types of problems rather than types of
    computers.
  • Is the problem computable?

8
CS Concepts Computable Problems
  • Since all computers are equal, we tend to focus
    on types of problems rather than types of
    computers,
  • Is the problem computable? If yes, well find a
    fast computer.
  • We are implying some problems are not (currently)
    computable.
  • Weather prediction is the most well known
    example.
  • Route planning is another.
  • Natural Language Processing is another.
  • This class focuses on computable problems
  • Sorting and searching.
  • We will look at sorting and searching methods in
    order to discuss basic CS ideas, terminology, and
    good practices.
  • This corresponds to chapters 2, 3, 4, 5, and 6 of
    text.

9
CS Concepts What is computable?
We will identify a small set of problems that
Are computable, and a small set that are not
Computable during this class. New problems
can be mapped (correlated, Compared, translated)
to the known problems And then deemed computable
or not.
10
Patterns of 2s in Computing
  • Computers operate on a binary system
  • Binary systems allow only two values
  • Zero or One
  • On or Off
  • True or False
  • Early computers were composed of groups of
    mechanical switches, each of which was On or
    Off at any time.
  • Modern computers store bits of data. Each bit
    can have the value of Zero or One.
  • The word BIT is a shortening of BINARY DIGIT

11
Computers Store Everything in Binary Form
  • So computer memory is nothing more than long
    sequences of bits (0s and 1s).
  • The most common unit of computer memory you see
    is the BYTE, which is simply a group of 8 bits.
  • How much memory does your PC at home have? It is
    always given in bytes, not bits. The same is
    true of file sizes.
  • These bits must be interpreted in special ways to
    be meaningful to humans
  • All data is represented as lists of 0s and 1s
  • Different types of data require different methods
    of interpretation to be meaningful. Numbers are
    different than letters, for example.
  • We will talk much more about data types
    throughout the semester.

12
Comparing Human and Computer Formats
  • The human digits 0,1,2,3,4,5,6,7,8,9
  • Computer digits 0,1
  • Some human numbers 17 42 31
  • Computer numbers 10001 101010 11111
  • The human alphabet Aa, Bb, Cc, Dd, Ee, .. Xx,
    Yy, Zz
  • Computer alphabet 0, 1
  • Some human words dog cat
  • Computer words 0110010001101111101100111
  • 0110001101100010001110100

13
Lets Look at Regular Math Again
  • Consider two math operations taking a number to
    a power, and taking the log of a number.
  • We will focus on the number 2 (binary no
    surprise)

14
How Much Information can we Store?
  • The number of bits assigned to a piece of
    information tells us how well we can describe the
    information.
  • The most abstract case n bits allows 2n
    distinct values.

15
Example 1 Color Depth
  • How many colors are available if each pixel uses
    n bits?
  • How many bits are required for 256 colors?
  • 8 bits, because log2 256 8
  • Thats one byte coincidence???

16
Example 2 Red-Green-Blue Format
  • One way to designate colors is setting values for
    the amount of red, green, and blue present in the
    mix.
  • The digits allowed in this system are 0, 1, 2,
    3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
  • Each color component can have a value from 00 to
    FF
  • Examples of RGB colors might be FF 00 FF
    (fuschia), C0 C0 C0 (silver)
  • How many bits are need to store the value of the
    color?

17
Example 2 Red-Green-Blue Format (cont)
  • How many bits are need to store the value of the
    color?
  • How many distinct colors can be specified?

How many bits are required for each
digit? There are 16 distinct digits, and log 16
4 Each color component has two digits,
so Each color component requires 8 bits (or one
byte coincidence? A color is made up of three
color components, so 8 x 3 24 bits to specify
a color.
24 bits are used to specify the color, so 224
16,777,216 (but in practice this is not done)
18
Example 3 Computer Memory
  • How much memory is on your computer? Is it a
    power of 2?
  • Lets assume a machine having 64 MB of RAM
  • How about 128 MB of RAM?

How many bits are required to specify a distinct
memory location? Lets try 25 bits ? 225
33,554,432 (not enough) Lets try 26 bits ? 226
67,108,864 distinct values. 26 bits are required
to specify a memory location.
27 bits ? 227 134, 217, 728 27 bits are now
required to specify a memory location. (twice the
memory for one more bit coincidence?)
19
Example 4 Computer Memory
  • What if we needed to assign a unique binary
    number to each of you in this class? How many
    bits would we need for each number?
  • How many bits do we need to add if we double the
    class size?

There are about 90 of you. 1 bit ? 21 2
numbers. 2 bits ? 22 4 numbers. 3 bits ? 23
8 numbers. 4 bits ? 24 16 numbers. 5 bits ? 25
32 numbers. 6 bits? 26 64 numbers. 7 bits? 27
128 numbers. (This is more than the 90
required). Answer 7 bits. This allows 90
unique values.
20
Example 5 The Hi-Lo Game
  • I will give you five chances to guess an integer.
    Whenever you guess wrongly I will tell you
    whether the answer is higher or lower than your
    guess.
  • Under what circumstances are you guaranteed
    success (the range of numbers can be considered
    the size of the problem)?
  • The numbers range from 0 3
  • The numbers range from 0 7
  • The numbers range from 0 15
  • The numbers range from 0 31
  • The numbers range from 0 63

We want the fifth guess to be perfect, so we only
have fours guesses to play with. Each guess can
correspond to a bit of information. 24 16 so I
can discern 16 distinct values with my guesses.
Answer 0 15.
21
Example 5 The Hi-Lo Game (cont)
  • Here is how to guess to guarantee success (note
    the dirty trick -- even though the numbers we are
    guessing are integers, we can guess non-integers)

22
By the way Memorize this!
Depth Dots 0 1 20 1
2 21 2 4 22 3 8
23 4 16 24
In general, a structure like this having depth d,
has N 2d objects at the bottom row.
23
Why do we Care?
  • We are trying to determine what kinds of problems
    are computable (ie capable of being solved by a
    computer).
  • These patterns weve seen will show up again and
    again
  • Developing methods to solve problems and to
    determine the computational cost of the
    solution.
  • Determining what problem sizes are computable
    (example hi-lo with 5 guesses and a range of 0
    1000 is not computable.)
  • Divide and Conquer (section 6.4)
  • A basic and powerful method of solving problems.
  • We attempt to cut the size of the problem in half
    at each step.
  • This leads to a log n number of steps for
    problems of size n (and thats good)

24
A Computer Model
  • Computer science is concerned with computation
  • What is computable?
  • How much effort is it to compute something?
  • We want the results to apply to all computers,
    not specific types or brands.
  • We need to develop an abstract model of a
    computer
  • Develop properties for the theoretical computer.
  • Apply the properties to all real world computers.

25
A Computer Model
  • Computer science is concerned with computation
  • What is computable?
  • How much effort is it to compute something?
  • We want the results to apply to all computers,
    not specific types or brands.
  • We need to develop an abstract model of a
    computer
  • Develop properties for the theoretical computer.
  • Apply the properties to all real world computers.

26
Computer Architecture (the Basics)
  • The following are components of a computer system
    from a commercial standpoint
  • The Central Processing Unit (CPU)
  • Memory (Temporary data storage)
  • Disk Space (permanent data storage)
  • Monitor
  • Keyboard
  • Other input/output devices
  • Do we need all of this for our abstract model?

27
Computer Architecture (the Basics)
  • Computer science is concerned with computation
  • What is computable?
  • How much effort is it to compute something?
  • Computer science focuses on the parts of the
    computer that deal with computation
  • Memory stores data and instructions
  • The CPU operates on the data per the instructions
  • Not input/output devices (monitors, keyboards,
    mice, etc)
  • We need a model for the CPU.
  • We need a model for memory

28
The CPU (Processor) Model
  • A real CPU has many elements, each devoted to
    specific types of operations (addition,
    multiplication, working with real numbers etc)
  • Our model of a Processor is much simpler
  • A processor is a black box that can perform
    arithmetic and logical operations.
  • A processor performs one discrete operation at a
    time
  • Discrete Add two numbers
  • Discrete Compare two numbers to see which is
    larger
  • Discrete Fetch a value from memory
  • Not Discrete Find the average of 20 numbers
    (too many operations)

Processor Model A black box that performs
specific instructions representing discrete
arithmetic and logical operations.
29
The Memory Model
  • Real Computers have a hierarchy of memory
  • Registers hold individual pieces of data inside
    the PCU itself
  • Cache holds a limited amount of data readily
    available for the PCU
  • RAM (Random Access Memory) contains programs and
    data currently in use (temporary)
  • Disks contain data for permanent storage
  • In the real world this has implications in terms
    of speed of accessing data. We are not concerned
    with this in computer science.

30
The Memory Model
  • Our model of a computer only has one level of
    memory
  • Any memory location can be accessed just as
    easily as any other using its numerical address
  • That is, you can pick any location at random and
    access it (Random Access Memory RAM)
  • How much memory? Infinite.

Memory Model Memory is composed of a single row
of storage locations, each referenced by a
numerical address.
0 1 2 3 4 5 6 7 8 9
10 11 12
31
A Computer Model
Processor Model A black box that performs
specific instructions representing discrete
arithmetic and logical operations.
Memory Model Memory is composed of a single row
of storage locations, each referenced by a
numerical address.
32
Summary of Theoretical Computer Model
  • This course is investigating what computers can
    and cannot do.
  • We want the results of this course to apply to
    all computers, not specific types or brands.
  • Therefore we use an abstract computer model that
    has the following characteristics
  • Processor A black box that performs specific
    instructions representing discrete arithmetic and
    logical operations.
  • Memory An infinite number of boxes or
    pigeonholes, each referred to by a numeric
    address.
  • Now we can talk about what this thing can do.

33
Introduction to Variables
  • Remember that memory is a long series of boxes
    referred to by numerical addresses.
  • We could allow any numeric memory location to be
    used in our algorithms to store data in memory
    and then retrieving the data when we needed it.
  • The problem with using numeric memory addresses
    directly is twofold.
  • Programs with more than a few pieces of data
    would drive you crazy trying to keep track of
    where you put it.
  • Different real world machines have different
    memeory structures.

1
8
x
y
34
Introduction to Variables
  • We use the concept of a variable to assign a name
    to the memory location.
  • Lets call our data "x" and "y".
  • We use a data declaration to tell the computer
    that we are using variable names to help us store
    data.
  • Declarations need to specify the variable NAME,
    TYPE, and STRUCTURE.
  • The computer will assign memory locations to each
    variable
  • Here, x is associated with memory location 1.
  • Here, y is associated with memory location 8.

1
8
x
y
35
Data Types and Data Structures
  • When specifying data in a program we need to
    describe its name, type and its structure.
  • Data's type impose meaning onto data (semantics)
    and data's structure impose organization (syntax)
    onto data.
  • Data Type (definition) A label applied to data
    that tells the computer how to interpret and
    manipulate data.
  • Type tells the computer how much space to reserve
    for variables and how to interpret operations on
    them.
  • Data Structure (definition) The way data is
    organized logically.
  • Describes how different pieces of data are
    organized.

36
Using the Computer
  • Turning it on Your computers in the lab should
    be turned on, but if you arrive and the screen is
    blank, do the following
  • Hit the return key to make sure the machine is
    not in power-saving mode
  • Ask the lab instructor if the machine is turned
    off for a reason, like repairs
  • Make sure it is plugged in.
  • Press power button for the computer probably in
    the middle front of the tower.
  • Press power button for the monitor probably
    below the screen.
  • Turning it off (do one of the following and
    follow the instructions)
  • Use the START button and select SHUT DOWN.
  • Use ALT-CTRL-DELETE
  • Unplug it
  • Breaking it
  • You cant break the machine by typing anything
    wrong or turning it off or on.
  • You can break it by forcing floppy discs into the
    wrong places.

37
Using the Computer
  • Turning it off you shouldnt have to do turn
    the machine off during lab unless it stops
    responding completely. You will want to log off
    at the end of lab, though. Do one of the
    following and follow the instructions the machine
    provides.
  • Click the START button (lower left corner of
    screen) and select SHUT DOWN. Then select shut
    down, restart, or log off from the menu.
  • Use ALT-CTRL-DELETE then follow directions
    (particularly if the machine has stopped
    responding)
  • Unplug it last resort, ask lab instructor
    first.
  • Breaking it
  • You cant break the machine by typing anything
    wrong or turning it off or on.
  • You can break it by forcing floppy discs into the
    wrong places.

38
Using the Computer
  • Breaking it its pretty hard to break it.
  • You cant break the machine by typing anything
    wrong or turning it off or on. So dont worry
    about experiementing with your programs. A good
    way to learn things like JavaScript is to say I
    wonder what happens when I do THIS. and then go
    do it. The worst that can happen is that you
    have to restart the machine.
  • Deleting important files. This is possible, but
    hard to do by accident. You should always keep
    the lab machines free of your assignments. Bring
    floppy disks to lab to store your files on, or
    transfer them to Pegasus and then delete them
    from the lab machine. When you delete files, the
    machine will ask you if you are sure you want to
    do it. Be careful at this point just verify
    that only the files you want deleted are selected
    before you hit the ok button.
  • You can break it by forcing floppy discs into the
    wrong places.

39
Using the Computer
  • Finding Files
  • Use the Find files feature if you know the file
    name. Click Start and then Find.
  • A quicker way (usually) is to traverse the
    directory structure using My Computer icon.
    Double click on the icon and then maneuver your
    way around the directory structure with more
    clicking. For the most part, you will only need
    to go to the A directory (the floppy disk) and
    the Desktop.
  • Editing files
  • The main thing is to remember that your files
    must be text only. In other words, using MS Word
    with the default save settings will not work. My
    favorite program for editing in a text-only mode
    is Notepad. It comes standard on MS machines
    (usually click on Start, then Programs, then
    Accessories then Notepad).
  • You may use any other editor you like, but make
    certain it saves in plain text format.

40
Some Notes on Programming Languages
  • Syntax the mechanical way that programs can be
    assembled
  • Programming languages are very specific about
    syntax
  • This means that putting in a single quote where
    a double quote should be can ruin your entire
    program.
  • Putting a square bracket where a parenthesis (
    should be can ruin your entire program.
  • This can be frustrating.
  • Capitalization almost always counts. Be
    conscious of things like that.
  • Many things come in pairs (quotation marks,
    parenthesis for example). Make sure that things
    that should be in pairs are.
  • If your program does absolutely nothing, you
    probably have a small syntax error.
  • If your program does something, but its wrong,
    then you probably have an error in your logic
    when you designed the program.

41
Introduction to HTML
  • HTML Hypertext Markup Language Language
  • HTML is
  • A very weak computational language (basically
    nil).
  • An interpreted language (interpreted by the
    browser).
  • Designed specifically to tell browsers how to
    display web pages.
  • Requires a browser for the page to be displayed.
  • Can only suggest display preferences to the
    browser (this surprises a lot of people).

42
Structure of HTML
  • HTML uses tags to suggest how to display items on
    a page
  • Learning HTML is really about learning how to use
    the tags.
  • Makes it easy to do useful pages quickly.
  • Most tags come in pairs
  • lttaggt starts the action
  • lt/taggt stops the action
  • Example ltHTMLgt begins all html documents and
    lt/HTMLgt ends them
  • Example ltcentergtTitlelt/centergt will center the
    word Title on the page.
  • Some tags do not come in pairs
  • ltbrgt is a line break, causing the display to
    continue on a new line
  • lthrgt inserts a horizontal rule (line) across the
    page.

43
Structure of HTML
  • Anything that is not specified by tags is
    displayed per the browsers preference
  • Adding extra spaces in between words wont have
    any effect on the page.
  • Putting things on a new line wont have any
    effect on the displayed web page (the ltBRgt tag
    does that).
  • Example
  • Hello, World. and Hello, World.
    will look the same.
  • Hello, World. and Hello,
  • World.
    will both be shown on the same line.

44
Structure of HTML
  • There are 4 tags required in any HTML document.
  • ltHTMLgtlt/HTMLgt Tells the browser where the web
    page starts and stops
  • ltHEADgtlt/HEADgt Tells the browser where the
    informational portion of the web page starts and
    stops
  • ltBODYgtlt/BODYgt Tells the browser where the
    displayed portion of the web page starts and
    stops
  • ltTITLEgtlt/TITLEgt Tells the browser what title to
    display for this page.

45
Structure of HTML
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtExample of HTML structurelt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • lt/BODYgt
  • lt/HTMLgt

Information hidden from the viewer.
Visible web page.
46
Hello, World!
  • There is a particular, simple program called
    Hello, World! that many CS people use when
    first encountering a new language.
  • Hello, World! prints the words Hello, World!
    on the screen.
  • The idea is that if you can get this simple thing
    to work, then-
  • Youve learned how to write, save, and run the
    program.
  • The language is working on your computer.
  • Your computer is working as expected.
  • So Hello, World! acts as a simple check that
    things are working ok before you get involved in
    a complicated programming effort.

47
An HTML Example
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtHello, World!lt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • Hello, World!
  • lt/BODYgt
  • lt/HEADgt
  • lt- Begins HTML -gt
  • lt- Begins Header portion -gt
  • lt- Title -gt
  • lt- Ends Header portion -gt
  • lt- begin body -gt
  • lt-Displayed on web page -gt
  • lt- End body -gt
  • lt- End HTML -gt

48
Introduction to JavaScript
  • JavaScript
  • Was developed to be compatible with web page
    design, so it runs inside of web page documents.
  • That means that JavaScript programs sit inside of
    HTML documents. It allows computation to be
    performed within web pages, and uses the web page
    for input and output.
  • The ltscript languageJavaScriptgt and lt/scriptgt
    tags define the limits of the JavaScript program
    inside of the HTML document.
  • JavaScript is general purpose (fully
    computational language), but it is limited as to
    file access for security reasons.
  • An interpreted language (interpreted by the
    browser). This makes it a little slow when
    running, but makes it easy to quickly change your
    program and see the result.

49
A JavaScript Example
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtJavaScript Hello, World!lt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • ltSCRIPT LANGUAGEJavaScriptgt
  • document.write(Hello, World!)
  • lt/SCRIPTgt
  • lt/BODYgt
  • lt/HEADgt
  • lt- Begins HTML -gt
  • lt- Begins Header portion -gt
  • lt- Title -gt
  • lt- Ends GHeader portion -gt
  • lt- Begin Body -gt
  • lt- Begin Script -gt
  • lt-Displayed on web page -gt
  • lt- End Script -gt
  • lt- End body -gt
  • lt- End HTML -gt

50
Getting Started with JavaScript
  • JavaScript requires that you declare every
    variable you intend to use. Declarations look
    like this for simple variables
  • var x
  • Var myvariable
  • JavaScript uses the following arithmetic
    operators on integers and numbers
  • is addition
  • - is subtraction
  • is multiplication
  • / is division
  • JavaScript has many special purpose functions
    built in for your convenience

51
Output of Results with JavaScript
  • JavaScript is an Object-Oriented language, which
    means it treats everything as if it were a
    physical object.
  • There are specific built-in objects with specific
    built-in functions.
  • The object that deals with input and output is
    the document object. Outputting results with
    the document object looks like this
  • document.write(Hi.) -gt Displays the word
    Hi.
  • document.write(17) -gt Displays the number 17
  • document.write(x) -gt Displays the value of x.
  • document.write(x) -gt displays the letter x.
Write a Comment
User Comments (0)
About PowerShow.com