SlideShare a Scribd company logo
Introduction to Programming
Visual Basic .NET
CS A109
Introduction and Brief History of
Programming
• Hardware
– Physical components that make up a computer
• Computer program or software
– A self-contained set of instructions used to operate a
computer to produce a specific result
Knowing About: Computer
Hardware
• Computer hardware components
– Memory unit
• Stores information in a logically consistent format
– Each memory location has an address and data that can be
stored there, imagine a long line of mailboxes starting at
address 0 and going up to addresses in the billions
• Two types of memory: RAM and ROM
– Random Access Memory, Read Only Memory (misnamed)
– Control unit
• Directs and monitors the overall operation of the
computer
Knowing About: Computer
Hardware (Continued)
– Arithmetic and logic unit (ALU)
• Performs all the arithmetic and logic functions
– E.g. knows how to add, subtract, manipulate data
– Input/output (I/O) unit
• Provides access to and from the computer
• E.g. network, keyboard, video
– Secondary storage
• Provides a permanent storage area for programs and
data
Knowing About: Computer
Hardware (Continued)
Figure 1-32: Basic Hardware Units of a Computer
• Evolution of hardware
– 1950s: all hardware units were built using relays and vacuum tubes
– 1960s: introduction of transistors
– mid-1960s: introduction of integrated circuits (ICs)
– Present computers: use of microprocessors
• Bit: smallest and most basic data item in a computer;
represents a 0 or a 1
• Byte: a grouping of eight bits
– E.g., 00010001
– What does this represent?
• Word: a grouping of one or more bytes
Knowing About: Computer
Hardware (Continued)
First-Generation and Second-
Generation (Low-Level)
Languages
• Low-level languages
– First-generation and second-generation languages
– Machine-dependent languages
– The underlying representation the machine actually understands
• First-generation languages
– Also referred to as machine languages
– Consist of a sequence of instructions represented as binary numbers
– E.g.: Code to ADD might be 1001 . To add 1+0 and then 1+1 our
program might look like this:
• 1001 0001 0000
• 1001 0001 0001
• Second-generation languages
– Also referred to as assembly languages
– Abbreviated words are used to indicate operations
– Allow the use of decimal numbers and labels to indicate the location of
the data
• Assemblers
– Programs that translate assembly language programs into machine
language programs
– Our add program now looks like:
• ADD 1,0
• ADD 1,1
First-Generation and Second-
Generation (Low-Level)
Languages (Continued)
1001
0001
0000
1001
0001
Assembler
• High-level languages
– Third-generation and fourth-generation languages
– Programs can be translated to run on a variety of computer types
• Third-generation languages
– Procedure-oriented languages
– Object-oriented languages
• Our Add program might now look like:
sum = value1 + value2
Third-Generation and Fourth-
Generation (High-Level)
Languages
1001
0001
0000
1001
0001
0001
Compiler
Figure 1-4: The
Evolution
of Programming
Languages
Third-Generation and Fourth-
Generation (High-Level)
Languages (Continued)
• Procedure-oriented languages
– Programmers concentrate on the procedures used in the
program
– Procedure: a logically consistent set of instructions which
is used to produce one specific result
• Object-oriented languages
– Items are represented using self-contained objects
– Often used for graphical windows environments, ability to
re-use code efficiently
Third-Generation and Fourth-
Generation (High-Level)
Languages (Continued)
• Graphical user interface (GUI)
– Provides a graphical way for the user to interact with the program
– Uses events
• Event
– A specific procedure that is connected to an object
• Visual languages
– Permit the programmer to manipulate graphical objects directly, with
the language providing the necessary code
– Permit users to access and format information without the need for
writing any procedural code
Third-Generation and Fourth-
Generation (High-Level)
Languages (Continued)
The Visual Basic .NET Platform
• Visual Basic .NET is in a sense one step removed from a
typical high-level language
• VB.NET runs using a “Virtual Machine” or “Common
Language Runtime”
– The physical computer simulates a virtual computer that runs your
program
• What is .NET?
– Microsoft’s vision of the future of applications in the Internet age
• Increased robustness over classic Windows apps
• New programming platform
• Built for the web
– .NET is a platform that runs on the operating system
.NET
• .NET is actually a program that sits on top on the
Operating System (currently all the Windows 9x, NT,
ME & XP; subset exists for FreeBSD, Linux,
MacOS)
• Provides language interoperability across platforms
• Strong emphasis on Web connectivity, using XML
web services to connect and share data between smart
client devices, servers, and developers/users
• Platform/language independent
.NET Framework
Framework Class Library
ADO.NET
Network
XML
Security
Threading
Diagnostics
IO
Etc.
Common Language Runtime
Memory Management Common Type System Lifecycle Monitoring
C# VB.NET C++.NET Other
Operating System
Visual
Studio
.NET
Common Language Specification
Windows Forms
ASP.NET
Web Services
ASP.NET Application Services
Web Forms Controls Drawing
Windows Application Services
.NET: Language-Independent,
Mostly Platform Specific
Person.vb
Address.cs
Company.cbl
CLR
Person
MSIL
Company
MSIL
Address
MSIL
Windows
Windows
Others?
CLR
CLR
CLR
Deploy
(Visual Basic)
(C#)
(Cobol)
Problem Solution and Software
Development
• Three overlapping phases of software development
– Design and development
– Documentation
– Maintenance
Figure 1-9: The Three Phases of Program Development
Phase I. Design and Development
• Steps of the design and development phase
– Analyze the problem
• Ensure that the problem is clearly defined and
understood
– Develop a solution
• Identify and select a solution for solving the problem
Phase I. Design and Development
(Continued)
– Program the solution
• Also referred to as implementing the solution
• Translate the solution into a usable application
– Test and correct the application
• Test the completed application to ensure that it provides
a solution to the problem, and correct any errors that are
found
Phase II. Documentation
• For every problem solution, five document types
should be provided for complete documentation:
– Initial application description
– Description of modification and changes
– Well-commented code listing
– Sample test runs
– User’s manual
Phase III. Maintenance
• Maintenance includes:
– Correction of newly found errors
– Addition of new features and modifications to existing
applications
• Maintenance of existing programs currently accounts
for approximately 75% of all programming costs
Introduction to Modularity
• Modular application
– Each part of the application is designed and developed to
perform a clearly defined and specific function
• Modules
– Segments used to construct a modular application
• Form modules
– Modules that contain both the visual parts of a program and
the code associated with objects on the screen
Procedural Code
• A procedural unit receives data, operates on the data,
and produces a result
• Types of procedural units
– Sub-procedures
• E.g., Code that handles reading data from a file
– Function procedures
• E.g., calculate some mathematical formula, f(x,y)
– Event procedures
• E.g., what to do when a button is clicked
Algorithms
• Algorithm
– A step-by-step sequence of instructions that must terminate
– Example: Steps in a recipe to make a cheesecake.
– Pseudocode
• Use of English-like phrases to describe an algorithm
– Formula
• Use of mathematical equations to describe an algorithm
– Flowchart
• Use of diagrams that employ symbols to describe an algorithm
Algorithms (Continued)
Figure 1-25: Flowchart Symbols
Class Average Algorithm
• Problem: Calculate and report the grade-point average for a
class
• Discussion: The average grade equals the sum of all grades
divided by the number of students
Output: Average grade
Input: Student grades
Processing: Find the sum of the grades; count the number of
students; calculate average
Flowchart
Pseudocode
Program:
Determine the average grade of a class
Initialize Counter and Sum to 0
While there is more data
Get the next Grade
Add the Grade to the Sum
Increment the Counter
Loop
Computer Average = Sum/Counter
Display Average
Hierarchy Chart
Algorithm Selection
• Our choice of algorithm can have a large impact on
the performance of the program
• Consider the problem of searching for a name in a
phone book
• The phone book is sorted by name
Algorithm 1 – Linear Search
• Search through the list of names for our target starting at the
beginning and go through them one at a time until we reach
the end
Apple, Bob
Atto, Tom
Attrick, Jerry
DeBanque, Robin
Fresco, Al
Guini, Lynn
Oki, Kerry
Wright, Eaton
Must check up to 8 names
What if millions of names?
Algorithm 2 – Binary Search
• Takes advantage of the fact that the list of names is sorted
• Start at the name in the middle of the list and compare to the
target
– If equal, there is a match!
– If the target is alphabetically less, repeat the process on the first half of
the list
– If the target is alphabetically greater, repeat the process on the second
half of the list
– Stop and no match if the list is ever empty
Algorithm 2 – Binary Search
• Searching for Guini, Lynn
Apple, Bob
Atto, Tom
Attrick, Jerry
DeBanque, Robin
Fresco, Al
Guini, Lynn
Oki, Kerry
Wright, Eaton
Guini, Lynn
Oki, Kerry
Wright, Eaton
Guini, Lynn
Only checked 3 names!
What if millions of names?
Algorithm Analysis
• Algorithm 1 runs in time linear to the number of names;
– 1 million names requires searching on average 500,000 names, all 1
million in the worst case
• Algorithm 2 runs in time log2 to the number of names
– This is because we cut the size in half each time
– For 1 million names, log2 1000000 is about 20.
– Much better performance than algorithm 1!

More Related Content

Similar to Chapter1.ppt

Software and Hardwew
Software and HardwewSoftware and Hardwew
Software and Hardwew
sbpatel199688
 

Similar to Chapter1.ppt (20)

C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
 
Ch0 computer systems overview
Ch0 computer systems overviewCh0 computer systems overview
Ch0 computer systems overview
 
Management information system software
Management information system softwareManagement information system software
Management information system software
 
Organization of modern digital computers
Organization of modern digital computersOrganization of modern digital computers
Organization of modern digital computers
 
cpphtp4_PPT_01.ppt
cpphtp4_PPT_01.pptcpphtp4_PPT_01.ppt
cpphtp4_PPT_01.ppt
 
Chapter 04 C++ Programmings Fundamental.
Chapter 04 C++ Programmings Fundamental.Chapter 04 C++ Programmings Fundamental.
Chapter 04 C++ Programmings Fundamental.
 
Topic -Anatomy of Computer.pptx
Topic -Anatomy  of Computer.pptxTopic -Anatomy  of Computer.pptx
Topic -Anatomy of Computer.pptx
 
PPS Unit-1.pdf
PPS Unit-1.pdfPPS Unit-1.pdf
PPS Unit-1.pdf
 
Savitch Ch 01
Savitch Ch 01Savitch Ch 01
Savitch Ch 01
 
Software and Hardwew
Software and HardwewSoftware and Hardwew
Software and Hardwew
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
Plc part 1
Plc part 1Plc part 1
Plc part 1
 
Computer and programing basics.pptx
Computer and programing basics.pptxComputer and programing basics.pptx
Computer and programing basics.pptx
 
CHAPTER-1.ppt
CHAPTER-1.pptCHAPTER-1.ppt
CHAPTER-1.ppt
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
CSC204PPTNOTES
CSC204PPTNOTESCSC204PPTNOTES
CSC204PPTNOTES
 
Program Logic and Design
Program Logic and DesignProgram Logic and Design
Program Logic and Design
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Concepts
 
c programming 1-1.pptx
c programming 1-1.pptxc programming 1-1.pptx
c programming 1-1.pptx
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 

Recently uploaded

Recently uploaded (20)

Ransomware Mallox [EN].pdf
Ransomware         Mallox       [EN].pdfRansomware         Mallox       [EN].pdf
Ransomware Mallox [EN].pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

Chapter1.ppt

  • 2. Introduction and Brief History of Programming • Hardware – Physical components that make up a computer • Computer program or software – A self-contained set of instructions used to operate a computer to produce a specific result
  • 3. Knowing About: Computer Hardware • Computer hardware components – Memory unit • Stores information in a logically consistent format – Each memory location has an address and data that can be stored there, imagine a long line of mailboxes starting at address 0 and going up to addresses in the billions • Two types of memory: RAM and ROM – Random Access Memory, Read Only Memory (misnamed) – Control unit • Directs and monitors the overall operation of the computer
  • 4. Knowing About: Computer Hardware (Continued) – Arithmetic and logic unit (ALU) • Performs all the arithmetic and logic functions – E.g. knows how to add, subtract, manipulate data – Input/output (I/O) unit • Provides access to and from the computer • E.g. network, keyboard, video – Secondary storage • Provides a permanent storage area for programs and data
  • 5. Knowing About: Computer Hardware (Continued) Figure 1-32: Basic Hardware Units of a Computer
  • 6. • Evolution of hardware – 1950s: all hardware units were built using relays and vacuum tubes – 1960s: introduction of transistors – mid-1960s: introduction of integrated circuits (ICs) – Present computers: use of microprocessors • Bit: smallest and most basic data item in a computer; represents a 0 or a 1 • Byte: a grouping of eight bits – E.g., 00010001 – What does this represent? • Word: a grouping of one or more bytes Knowing About: Computer Hardware (Continued)
  • 7. First-Generation and Second- Generation (Low-Level) Languages • Low-level languages – First-generation and second-generation languages – Machine-dependent languages – The underlying representation the machine actually understands • First-generation languages – Also referred to as machine languages – Consist of a sequence of instructions represented as binary numbers – E.g.: Code to ADD might be 1001 . To add 1+0 and then 1+1 our program might look like this: • 1001 0001 0000 • 1001 0001 0001
  • 8. • Second-generation languages – Also referred to as assembly languages – Abbreviated words are used to indicate operations – Allow the use of decimal numbers and labels to indicate the location of the data • Assemblers – Programs that translate assembly language programs into machine language programs – Our add program now looks like: • ADD 1,0 • ADD 1,1 First-Generation and Second- Generation (Low-Level) Languages (Continued) 1001 0001 0000 1001 0001 Assembler
  • 9. • High-level languages – Third-generation and fourth-generation languages – Programs can be translated to run on a variety of computer types • Third-generation languages – Procedure-oriented languages – Object-oriented languages • Our Add program might now look like: sum = value1 + value2 Third-Generation and Fourth- Generation (High-Level) Languages 1001 0001 0000 1001 0001 0001 Compiler
  • 10. Figure 1-4: The Evolution of Programming Languages Third-Generation and Fourth- Generation (High-Level) Languages (Continued)
  • 11. • Procedure-oriented languages – Programmers concentrate on the procedures used in the program – Procedure: a logically consistent set of instructions which is used to produce one specific result • Object-oriented languages – Items are represented using self-contained objects – Often used for graphical windows environments, ability to re-use code efficiently Third-Generation and Fourth- Generation (High-Level) Languages (Continued)
  • 12. • Graphical user interface (GUI) – Provides a graphical way for the user to interact with the program – Uses events • Event – A specific procedure that is connected to an object • Visual languages – Permit the programmer to manipulate graphical objects directly, with the language providing the necessary code – Permit users to access and format information without the need for writing any procedural code Third-Generation and Fourth- Generation (High-Level) Languages (Continued)
  • 13. The Visual Basic .NET Platform • Visual Basic .NET is in a sense one step removed from a typical high-level language • VB.NET runs using a “Virtual Machine” or “Common Language Runtime” – The physical computer simulates a virtual computer that runs your program • What is .NET? – Microsoft’s vision of the future of applications in the Internet age • Increased robustness over classic Windows apps • New programming platform • Built for the web – .NET is a platform that runs on the operating system
  • 14. .NET • .NET is actually a program that sits on top on the Operating System (currently all the Windows 9x, NT, ME & XP; subset exists for FreeBSD, Linux, MacOS) • Provides language interoperability across platforms • Strong emphasis on Web connectivity, using XML web services to connect and share data between smart client devices, servers, and developers/users • Platform/language independent
  • 15. .NET Framework Framework Class Library ADO.NET Network XML Security Threading Diagnostics IO Etc. Common Language Runtime Memory Management Common Type System Lifecycle Monitoring C# VB.NET C++.NET Other Operating System Visual Studio .NET Common Language Specification Windows Forms ASP.NET Web Services ASP.NET Application Services Web Forms Controls Drawing Windows Application Services
  • 16. .NET: Language-Independent, Mostly Platform Specific Person.vb Address.cs Company.cbl CLR Person MSIL Company MSIL Address MSIL Windows Windows Others? CLR CLR CLR Deploy (Visual Basic) (C#) (Cobol)
  • 17. Problem Solution and Software Development • Three overlapping phases of software development – Design and development – Documentation – Maintenance Figure 1-9: The Three Phases of Program Development
  • 18. Phase I. Design and Development • Steps of the design and development phase – Analyze the problem • Ensure that the problem is clearly defined and understood – Develop a solution • Identify and select a solution for solving the problem
  • 19. Phase I. Design and Development (Continued) – Program the solution • Also referred to as implementing the solution • Translate the solution into a usable application – Test and correct the application • Test the completed application to ensure that it provides a solution to the problem, and correct any errors that are found
  • 20. Phase II. Documentation • For every problem solution, five document types should be provided for complete documentation: – Initial application description – Description of modification and changes – Well-commented code listing – Sample test runs – User’s manual
  • 21. Phase III. Maintenance • Maintenance includes: – Correction of newly found errors – Addition of new features and modifications to existing applications • Maintenance of existing programs currently accounts for approximately 75% of all programming costs
  • 22. Introduction to Modularity • Modular application – Each part of the application is designed and developed to perform a clearly defined and specific function • Modules – Segments used to construct a modular application • Form modules – Modules that contain both the visual parts of a program and the code associated with objects on the screen
  • 23. Procedural Code • A procedural unit receives data, operates on the data, and produces a result • Types of procedural units – Sub-procedures • E.g., Code that handles reading data from a file – Function procedures • E.g., calculate some mathematical formula, f(x,y) – Event procedures • E.g., what to do when a button is clicked
  • 24. Algorithms • Algorithm – A step-by-step sequence of instructions that must terminate – Example: Steps in a recipe to make a cheesecake. – Pseudocode • Use of English-like phrases to describe an algorithm – Formula • Use of mathematical equations to describe an algorithm – Flowchart • Use of diagrams that employ symbols to describe an algorithm
  • 26. Class Average Algorithm • Problem: Calculate and report the grade-point average for a class • Discussion: The average grade equals the sum of all grades divided by the number of students Output: Average grade Input: Student grades Processing: Find the sum of the grades; count the number of students; calculate average
  • 28. Pseudocode Program: Determine the average grade of a class Initialize Counter and Sum to 0 While there is more data Get the next Grade Add the Grade to the Sum Increment the Counter Loop Computer Average = Sum/Counter Display Average
  • 30. Algorithm Selection • Our choice of algorithm can have a large impact on the performance of the program • Consider the problem of searching for a name in a phone book • The phone book is sorted by name
  • 31. Algorithm 1 – Linear Search • Search through the list of names for our target starting at the beginning and go through them one at a time until we reach the end Apple, Bob Atto, Tom Attrick, Jerry DeBanque, Robin Fresco, Al Guini, Lynn Oki, Kerry Wright, Eaton Must check up to 8 names What if millions of names?
  • 32. Algorithm 2 – Binary Search • Takes advantage of the fact that the list of names is sorted • Start at the name in the middle of the list and compare to the target – If equal, there is a match! – If the target is alphabetically less, repeat the process on the first half of the list – If the target is alphabetically greater, repeat the process on the second half of the list – Stop and no match if the list is ever empty
  • 33. Algorithm 2 – Binary Search • Searching for Guini, Lynn Apple, Bob Atto, Tom Attrick, Jerry DeBanque, Robin Fresco, Al Guini, Lynn Oki, Kerry Wright, Eaton Guini, Lynn Oki, Kerry Wright, Eaton Guini, Lynn Only checked 3 names! What if millions of names?
  • 34. Algorithm Analysis • Algorithm 1 runs in time linear to the number of names; – 1 million names requires searching on average 500,000 names, all 1 million in the worst case • Algorithm 2 runs in time log2 to the number of names – This is because we cut the size in half each time – For 1 million names, log2 1000000 is about 20. – Much better performance than algorithm 1!