Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 2620M Introduction to Data Structures

Similar presentations


Presentation on theme: "ITEC 2620M Introduction to Data Structures"— Presentation transcript:

1 ITEC 2620M Introduction to Data Structures
Instructor: Prof. Z. Yang Course Website: Office: DB 3049

2 Course Objective Course is about concepts
what you can program, not how Traditionally, second course in computer science still separates top third of programmers not taught in any known college diploma program Learn and use efficient programming patterns “an efficient programmer can often produce programs that run five times faster than an inefficient programmer”

3 Textbooks http://people.math.yorku.ca/~zyang/itec2620m.htm
“Data Structures and Algorithm Analysis in Java” third edition by Clifford A. Shaffer. Lecture notes and announcements will be made available at:

4 Marking Scheme Assignment 1: 10% Midterm: 30% Final: 60% Late Policy
about 1/3 code, 2/3 concepts Final: 60% Late Policy Late assignments will NOT be accepted. If you miss it for an approved excuse, the weight will be added to the midterm. NO makeup assignment will be provided. If you miss the midterm for an approved excuse, the weight will be added to the weight of the final exam. A medical note is required. NO makeup midterm will be provided.

5 Course Organization Key concepts first Concrete to concept
searching, sorting, complexity analysis, linked structures Concrete to concept searching  sorting  complexity analysis binary tree  recursion

6 Introduction

7 Need for Data Structure
Computer Store and retrieve information Perform calculation Costs and benefits A data structure requires a certain amount of space for each data item it stores, a certain amount of time to perform a single basic operation, and a certain amount of programming effort.

8 Problem, Algorithms and Programs
Problem: a task to be performed Algorithm: a method or a process followed to solve a problem Program: an instance, or concrete representation, of an algorithm in some programming language.

9 Algorithm Efficiency Design goals: Algorithm analysis
Design an algorithm that is easy to understand, code, and debug. Design an algorithm that makes efficient use of the computer’s resources. Algorithm analysis

10 Three keys to programming
Algorithm Design Sequence, branching, looping – flowcharts and pseudocode Efficiency and time-space tradeoffs (linkages between algorithms and data structures) Data Organization objects and classes data structures Modularization methods (modularization of algorithms) classes and inheritance (modularization of data/objects)

11 Searching

12 Key Points Searching arrays Linear search Binary search
Best, average, and worst cases

13 Searching in General “A query for the existence and location of an element in a set of distinct elements” Elements have searchable keys associated with a stored record. search on keys – e.g. name to find an element – e.g. phone number Two goals of searching existence  does the person exist? location  where are they in the phone book? Isolate searching for “keys” – all keys have the same data type

14 Definition Suppose k1, k2, …, kn are distinct keys, and that we have a collection T of n records of the form (k1, I1), (k2, I2), …, (kn, In), where Ij is information associated with key kj. Given a particular key value K, the search problem is to locate the record (kj, Ij) in T such that kj = K. Exact-match query Range query

15 Review of Array Algorithms
Write a static method that determines the range (the difference between the largest and smallest element) for a fully populated array of ints. How is the above example similar to searching? find the largest/smallest value in a set of elements Searching  find a given value in a set of elements

16 Searching Arrays Write a static method that determines the location (the array index) for a given value in a fully populated array of ints, return “–1” if the value is not in the array. Example

17 Binary Search Make your first guess in the middle of the range.
If not the target element, determine which sub-range you have to search. Make your next guess in the middle of this sub-range. Repeat Example

18 Best, Worst and Average What’s the best case for search?
Linear  first element  1 compare Binary  middle element  1 compare What’s the worst case for search? Linear  not there  n compares Binary  not there  logn compares What’s the average case for search? Linear  middle element  n/2 compares Binary  50/50…  logn - 1 compares

19 What’s the difference? Toronto phone book  2 million names
Avg. Linear  1 million compares Avg. Binary  20 compares For 2 million records, binary search is 50,000 times faster on average. What’s the cost To do binary search, we need a sorted array Sorting…next lecture!


Download ppt "ITEC 2620M Introduction to Data Structures"

Similar presentations


Ads by Google