Docsity

Slides on the Need for Data Structure - Data Structures and Algorithms | CS 3114, Study notes of Computer Science

Partial preview of the text

Download Slides on the Need for Data Structure - Data Structures and Algorithms | CS 3114 and more Study notes Computer Science in PDF only on Docsity!

Coursenotes

CS3114: Data Structures and

Algorithms

Clifford A. Shaffer Yang Cao Department of Computer Science Virginia Tech Copyright © 2008-

Goals of this Course

  1. Reinforce the concept that costs and benefits exist for every data structure.
  2. Learn the commonly used data structures.
    • (^) These form a programmer's basic data structure ``toolkit.'‘
  3. Understand how to measure the cost of a data structure or program.
    • (^) These techniques also allow you to judge the merits of new data structures that you or others might invent.

Organizing Data

Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.

Efficiency

A solution is said to be efficient if it solves the problem within its resource constraints.

  • (^) Space
  • (^) Time
  • (^) The cost of a solution is the amount of resources that the solution consumes.

Some Questions to Ask

  • (^) Are all data inserted into the data structure at the beginning, or are insertions interspersed with other operations?
  • (^) Can data be deleted?
  • (^) Are all data processed in some well- defined order, or is random access allowed?

Costs and Benefits

Each data structure has costs and benefits. Rarely is one data structure better than another in all situations. Any data structure requires:

  • (^) space for each data item it stores,
  • (^) time to perform each basic operation,
  • (^) programming effort.

Example 1.

Problem: Create a database containing information about cities and towns. Tasks: Find by name or attribute or location

  • (^) Exact match, range query, spatial query Resource requirements: Times can be from a few seconds for simple queries to a minute or two for complex queries

Abstract Data Types

Abstract Data Type (ADT): a definition for a data type solely in terms of a set of values and a set of operations on that data type. Each ADT operation is defined by its inputs and outputs. Encapsulation: Hide implementation details.

Metaphors

An ADT manages complexity through abstraction: metaphor.

  • (^) Hierarchies of labels Ex: transistors  gates  CPU. In a program, implement an ADT, then think only about the ADT, not its implementation.

Logical vs. Physical Form

Data items have both a logical and a physical form. Logical form: definition of the data item within an ADT.

  • (^) Ex: Integers in mathematical sense: +, - Physical form: implementation of the data item within a data structure.
  • (^) Ex: 16/32 bit integers, overflow.

Example 1.

A typical database-style project will have many interacting parts.

Scheduling

  • (^) Managing large-scale projects involves scheduling activities - (^) It is human nature to work better toward intermediate milestones.
  • (^) The same concepts can/should be applied to mid-sized projects encountered in class. - (^) For any project that needs more than a week of active work to complete, break into parts and design a schedule with milestones and deliverables.

Real Results

Amount Done 1 Week Prior to Due Date

Real Results

  • (^) Results were significant:
    • (^) 90% of scores below median were students who did less than 50% of the project prior to the last week.
    • (^) Few did poorly who put in > 50% time early
    • (^) Some did well who didn’t put in >50% time early, but most who did well put in the early time