### What is CS171 about ?

• Introduction

• Instructor's name: (variable)

• CS 171: a continuation of CS 170

• Programming and problem solving (with computer), with applications

• What is a (computer) program:

• Algorithms --- methods to solve problems

 We will also study the performance of algorithms (how efficient is the algorithm) ---- algorithm analysis

• Data structures --- methods to store and manage (retrieve) information (an algorithm cannot operate without information !)

• What is an algorithm ?

• Algorithm:

 Algorithm = a method for solving a problem expressed as a sequence of steps that is suitable for execution by a computer (machine)

• The are many different ways to represent (describe) algorithms:

• natural languages

 Not preferred due to ambiguity

• Flow charts

 Good for conceptualization of the algorithm

• Pseudo code

 Good for algorithm development

• programming languages

 Good for communicating the algorithm to a machine (computer)

• Algorithm in natural language

• Determine if a number n is a prime number:

 Divide n by the numbers 2 upto and including n − 1 If there is a number that divides n, then n is not prime Otherwise, n is prime

• Algorithm in flow chart form

• Determine if a number n is a prime number:

Explanation:

• Flow chart has:

 One begin point and One end point (some flow charts have multiple end points, you can easily unite them into one end point)

• Square-shaped boxes are actions

• Diamond-shaped boxes are 2-way decisions

• A guide to understand flow chart in flow chart form (from XKCD click here )

• Algorithm in pseudo code

• Determine if a number n is a prime number:

 ``` k = 2; As long as (k < n) do { 1. Divide n by k 2. If n is divisible by k, then return NO 3. Otherwise, increase k by 1 } return YES ```

• Algorithm in programming language (Java)

• Determine if a number n is a prime number:

 ``` public static boolean isPrime( int n ) { int k = 2; while ( k++ < n ) { if ( n%k == 0) return false; } return true; } ```

• What is a data structure ???

• Data structure:

 Data structure = a way to organize (= insert and delete) and access (= retrieve) data

• There are many way to organize data

 If you have a lot of Compact Disks (music lover), you can compare "organizing data" to organizing your CD collection You want to find a way to find the CD as fast as possible when you need it (within some acceptable cost limit)....

• Examples of data structures:

• Array: (this is CS170 material)

Notable facts:

 The data is stored in consecutive memory cells (= array elements) The array elements are accessed through a index

• Lists, Trees and Graphs (we will study these in CS171)

Example: tree

• What you will learn in CS170:

 Fundamental data structures and their operations How to use Java's provided data structures (in Java's util package) How to implement some of them How to evaluate them and decide when to use which data structure

• What is a program ???

• Program:

 Program = Algorithm + Data Structure(s)

Explanation:

• A program solves a program or accomplishes a certain task

• In order to achieve this, a program will:

• execute an algorithm....

• The algorithm will need information to figure out what to do:

 The program must use some data structure to store its information (data)

• Program:

 Program = algorithm that manipulates some data stored in the data structures to accomplish a desired task (or solve a specified problem)

• Writing (computer) programs

• What a programmer must do to write a (computer) program:

 Design the (appropriate) data structures to store the information (used by the algorithm) Design the algorithm to accomplish the task (the algorithm will make use of the information stored in data structures to solve the problem) Implement the algorithm (and the data structures)

• What's more important: algorithm or data structure ?

• Quote from a well-known system programmer Linus Torvalds (creator of Linux):

 "I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships."

• Good computer programs....

• Keys to write good programs:

 Good algorithms     and Good data structures

• Example scenario: maintaining a phone directory or social network

 We have a large number of records We will need to design a data structure that enable use to perform addition, deletion and searching efficiently Can the data structure handle missing fields ??? We may need to develop specialized search algorithms (e.g., partial name lookup)

• How to measure the "goodness" of algorithms/data structures

• Metrics used to measure the goodness of algorithms:

• Running time (i.e., how long does it take for the program to finish)

 In CS171, we will learn running time analysis of algorithm (The running time will be expressed in order of magnitude using the Big-O notation)

• Storage requirment (i.e., how much memory does the program need to use to store the necessary information)