1 / 19

ITEC 2620M Introduction to Data Structures

ITEC 2620M Introduction to Data Structures. Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: DB 3049. Course Objective. Course is about concepts what you can program, not how Traditionally, second course in computer science

chilton
Download Presentation

ITEC 2620M Introduction to Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 2620MIntroduction to Data Structures Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm 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 • “Data Structures and Algorithm Analysis in Java” third edition by Clifford A. Shaffer. • Lecture notes and announcements will be made available at: http://people.math.yorku.ca/~zyang/itec2620m.htm

  4. Marking Scheme • Assignment 1: 10% • Midterm:30% • about 1/3 code, 2/3 concepts • Final:60% • about 1/3 code, 2/3 concepts • 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 • 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: • 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!

More Related