data structures & algorithm an alysis in java (cmpe250)
DESCRIPTION
Data Structures & Algorithm An alysis in JAVA (CMPE250). Fatih Alag ö z [email protected] Office: ETA42 Ext.6652 www.cmpe.boun.edu.tr/alagoz. 3, 2, and take off . Data Structures and Algorithm Analysis in JAVA. Data Structure: methods of organizing large amounts of data - PowerPoint PPT PresentationTRANSCRIPT
Dr. Alagoz
Data Structures & Algorithm Analysis in JAVA (CMPE250)
Fatih Alagö[email protected]
Office: ETA42 Ext.6652www.cmpe.boun.edu.tr/alagoz
Dr. Alagoz
Data Structures and Algorithm Analysis in JAVA
Data Structure: methods of organizing large amounts of data
Eg. In the VULCAN Project, Kandilli Obs.&Res.Center will receive about 2GB/day to predict earthquakes in Turkey!!!
Storage, processing, etc.
3, 2, and take off
Dr. AlagozData Structures and Algorithm Analysis in JAVA-2
Algorithm: step-by-step procedure for solving a problem in a finite amount of time.
i.e. Do NOT start coding be4 analyzing the algorithm!!!
Eg. The running time of ARAM algorithm was only 26 hrs, it could have taken approximately 675000
yrs
Could you have done any better? Yes...
Dr. AlagozData Structures and Algorithm Analysis in JAVA-3
JAVA: relatively new language and superior (?) to C++: With being user-friendly, safe, portable, etc At the expense of: Limited I/O support.
JAVA >> convert >> C++ (easy)
C++ >> convert >> JAVA!!! should locate hidden traps with I/O classes first.
Course Content is Language Independent but Use JAVA for implementations
Dr. Alagoz
Course Syllabus (Review)
CATALOG DATA: Data Structures &Algorithms (3+0+2) 4 Complexity, Hashing, Heap Structures, Advanced Sorting,
Search Structures, Graphs, Parallel Algorithms, File organization.
Prerequisite: CmpE 160
Dr. Alagoz
Course Syllabus (Review)
Textbook: M. A. Weiss, Data Structures and algorithm and Algorithm Analysis in Java, Addison Wesley, 2nd edition 2007. (or 99 edition).
References:Drozdek Adam, Data Structures and Algorithms in Java,
Brooks Cole, 2001.
M. T. Goodrich and R. Tamassia, Data Structures and Algorithms in Java(3/e), Wiley and Sons, 2004.
Dr. Alagoz
Course Syllabus (Review)
Teaching Team: Instructor: Fatih Alagoz TAs: Hande Ozgur Alemdar www.cmpe.boun.edu.tr GOAL: To learn the specifications, usage, implementation
& analysis of advanced data structures & algorithms
using JAVA.
Prerequisites by topicProgramming in C, C++Fluency with the implementation of basic data structuresSome background in discrete math
Dr. Alagoz
Course Syllabus (Review)
ABET category content as estimated by faculty member who prepared this course description
Engineering science: 1.5 credits or 37.5 %Engineering design : 2.5 credits or 63.5 %
Grading Policy (Tentative):Midterm exam 1 17.5% Midterm exam 2 17.5% Projects + Pop Quizzes + HWs 25%Final exam 40%
Note: Midterm exam date will be announced a week prior to the exam!
Dr. Alagoz
Math Review
Series Summations:
Logarithms and Exponents
logb(xy) = logbx + logby a(b+c) = aba c
logb (x/y) = logbx – logby abc = (ab)c
logbxa = alogbx ab /ac = a(b-c)
logba = logxa/logxb b = a logab
bc = a c*logab
Proof techniques: induction, counterexample, and contradiction
1ln
11
1
1
1
1
1
1
1
kNi
kk
Ni
a
aa
N
i
k
kN
i
k
NN
i
i
Dr. Alagoz
Programming with Recursion
Dr. Alagoz
11
The Recursion Pattern Recursion: when a method calls itselfClassic example--the factorial function:
n! = 1· 2· 3· ··· · (n-1)· nRecursive definition:
As a Java method:// recursive factorial function public static int recursiveFactorial(int n) { if (n == 0) return 1; // basis case else return n * recursiveFactorial(n- 1); // recursive
case}
elsenfn
nnf
)1(
0 if1)(
Dr. Alagoz
12
Content of a Recursive Method
Base case(s). Values of the input variables for which we
perform no recursive calls are called base cases (there should be at least one base case).
Every possible chain of recursive calls must eventually reach a base case.
Recursive calls. Calls to the current method. Each recursive call should be defined so that
it makes progress towards a base case.
Dr. Alagoz
13
Visualizing Recursion
Recursion traceA box for each recursive callAn arrow from each caller to calleeAn arrow from each callee to caller showing return value
Example recursion trace:
recursiveFactorial(4)
recursiveFactorial(3)
recursiveFactorial(2)
recursiveFactorial(1)
recursiveFactorial(0)
return 1
call
call
call
call
return 1*1 = 1
return 2*1 = 2
return 3*2 = 6
return 4*6 = 24 final answercall
Dr. Alagoz
14
Example – English Rulers(*)
Define a recursive way to print the ticks and numbers like an English ruler:
Dr. Alagoz
15
A Recursive Method for Drawing Ticks on an English Ruler(*)
// draw a tick with no labelpublic static void drawOneTick(int tickLength) { drawOneTick(tickLength, - 1); }
// draw one tickpublic static void drawOneTick(int tickLength, int tickLabel) { for (int i = 0; i tickLength; i++) System.out.print("-"); if (tickLabel = 0) System.out.print(" " + tickLabel); System.out.print("\n");}public static void drawTicks(int tickLength) { // draw ticks of given length if (tickLength 0) { // stop when length drops to 0 drawTicks(tickLength- 1); // recursively draw left ticks drawOneTick(tickLength); // draw center tick drawTicks(tickLength- 1); // recursively draw right ticks }}public static void drawRuler(int nInches, int majorLength) { // draw ruler drawOneTick(majorLength, 0); // draw tick 0 and its label for (int i = 1; i = nInches; i++) { drawTicks(majorLength- 1); // draw ticks for this inch drawOneTick(majorLength, i); // draw tick i and its label }}
Dr. Alagoz
16
Visualizing the DrawTicks Method(*)
An interval with a central tick length L >1 is composed of the following:
an interval with a central tick length L-1,
a single tick of length L,
an interval with a central tick length L-1.
drawTicks(3) Output
drawTicks(0)
( previous pattern repeats)
drawOneTick(1)
drawTicks(1)
drawTicks(2)
drawOneTick(2)
drawTicks(2)
drawTicks(1)
drawTicks(0)
drawTicks(0)
drawTicks(0)
drawOneTick(1)
drawOneTick(3)
Dr. Alagoz
17
HWLA: HomeWorkLikeAssignment
Download the JAVA tutorial from the course website
http://users.cs.fiu.edu/~weiss/dsaajava2/code/
Visit www.cs.fiu.edu/^weiss for Code Availability
Write your first JAVA code that converts Celcius to Fahrenheit for the range [-50 50]. Introduce exception for out of the range inputs.
Solve exercises