











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












George N. Rouskas Department of Computer Science North Carolina State University CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Problems and Problem Instances
Algorithms and Their Properties
Abstract Data Types
Pseudo-Code CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Parameters: a finite set
c 1 , c 2
, c n
of n “cities” for each pair
c i , c j
of cities, the distance d
c i , c j
between them Solution: an ordering < c π (1) , c π (2)
, c π ( n )
of the n cities that minimizes the tour length : { n − 1 ∑^ i = d
c π ( i ) , c π ( i +1)
d
c π ( n ) , c π (1)
CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
n
cities,
c 1 , c 2 , c 3 , c 4
d
c 1 , c 2
,^ d
c 1 , c 3
,^ d
c 1 , c 4
,^ d
c 2 , c 3
, d
c 2 , c 4
,^ d
c 3 , c 4
CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
n
cities,
c 1 , c 2 , c 3 , c 4
d
c 1 , c 2
,^ d
c 1 , c 3
,^ d
c 1 , c 4
,^ d
c 2 , c 3
, d
c 2 , c 4
,^ d
c 3 , c 4
5 C C C C 1 2 3 4 10 6 9 9 3 Solution:
c 2 , c 4 , c 3 , c 1
, length= CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Algorithm: description of a finite number of steps to solve a problem Algorithm
is said to “ solve ” problem
if: A can be applied to any instance
of
always produces a solution for any instance
Note: solution must satisfy all properties set forth in
’s specification → an algorithm does not solve TSP unless it always constructs a tour of minimum length CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Our primary interest is in algorithms per se and their properties Expressing algorithms in syntax of Java is of secondary interest → you must already be fluent in Java Objectives:^ 1. study most important algorithms for frequently arising problems
selecting the “best” algorithm whenever we have a choice CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Pseudo-Code: high-level descriptions of algorithms combine natural language and structures from programminglanguage clear and informative not computer programs
for human eyes only more compact than Java code
easier to read/understand facilitate analysis of correctness and running time of algorithms CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
procedure MergeSort (Array
, n
, int f irst , int last )
int middle
if ( f irst < last
) then
middle
f irst
last
MergeSort ( T, f irst, middle )
MergeSort ( T, middle
, last )
Merge ( T, f irst, middle, middle
, last ) CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Correctness
always gives the right answer Termination:
no infinite loops Robustness:
able to handle unexpected inputs Complexity of resulting program:
easily translates into code Adaptability:
easy to adapt to small changes in problem specs Efficiency:
low utilization of computational resources
CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Data structure: a systematic way of organizing and accessing data logical organization of computer memory Classification: amount of data contained in the structure can’t change w/o recreating it from scratch
static DS
array may increase/decrease at will
dynamic DS
linked list CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Abstraction: decomposes complex system into fundamental parts describes functionality of each part in simple, precise terms Information hiding: conceals internal details of implementation allows freedom in implementing the desired functionality CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas
Stack: container of objects operating under the LIFO principle objects may be inserted into a stack at any time only most-recently inserted object can be removed at any time Stack is an ADT supporting two operations (methods):^ 1. push( o ): insert object o at top of stack
pop(): remove and return top object of stack; error if stack empty CSC 316 – Fall 2011: Introduction Copyright c© 2011by George N. Rouskas