Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

Data Structures Static and Dynamic.
Programming and Data Structure
CPSC 335 Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Lecture # 02 07/02/2013Dr. Muhammad Umair 1. 07/02/2013Dr. Muhammad Umair 2  Numeric  Integer Numbers  0,10,15,4563 etc.  Fractional Number  10.5,
Lecture - 1 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Data Type and Data Structure Data type Set of possible values for variables.
Advance Database System
Hash Table indexing and Secondary Storage Hashing.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Disk Storage, Basic File Structures, and Hashing by Pinar Senkul resources: mostly froom.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
The Design and Analysis of Algorithms
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Slides modified by Erin Chambers Problem Solving and Algorithm Design, part 2.
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 Disk Storage, Basic File Structures, and Hashing.
Lecture No.01 Data Structures Dr. Sohail Aslam
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
CSC 211 Data Structures Lecture 7
Introduction. 2COMPSCI Computer Science Fundamentals.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Computer Science Department Data Structures and Algorithms Lecture 1.
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Data Structure: Introduction.
Instructor Information: Dr. Radwa El Shawi Room: Week # 1: Overview & Review.
Chapter 11 Arrays Continued
DATA STRUCTURES (CS212D) Week # 1: Overview & Review.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Lists. Container Classes Many applications in Computer Science require the storage of information for collections of entities e.g. a student registration.
1 CS 350 Data Structures Chaminade University of Honolulu.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
Chapter 1 Data Structures and Algorithms. Primary Goals Present commonly used data structures Present commonly used data structures Introduce the idea.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
1 String Processing CHP # 3. 2 Introduction Computer are frequently used for data processing, here we discuss primary application of computer today is.
1 Data Organization Example 1: Heap storage management –Keep track of free chunks of memory Example 2: A simple text editor –Maintain a sequence of lines.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
2 Obaid Ullah HOD Computer Science Dept. Superior University Sialkot Campus.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
REEM ALMOTIRI Information Technology Department Majmaah University.
Data Structure and Algorithms
Data Structure & Algorithms
Chapter 5 Record Storage and Primary File Organizations
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
UNIT-II Topics to be covered Singly linked list Circular linked list
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Introduction toData structures and Algorithms
Course Developer/Writer: A. J. Ikuomola
Data Structure Interview Question and Answers
Data Structures Interview / VIVA Questions and Answers
Introduction to Data Structure
Further Data Structures
Introduction to Data Structures
Introduction to Data Structures
Introduction to Data Structure
Data Structures & Algorithms
Indexing, Access and Database System Architecture
Presentation transcript:

Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009

Introduction to Data Structures In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. For Example ◦ Imagine that you are hired by company XYZ to organize all of their records into a computer database. ◦ The first thing you are asked to do is create a database of names with all the company's management and employees. CSE 246 Data Structures and Algorithms Fall 2009 Lecture #1 2

Introduction You also want your database to represent the relationships between management and employees at XYZ These two diagrams are examples of different data structures This is very useful for keeping the names of the employees in alphabetical order so that we can locate the employee's record very quickly. However, this structure is not very useful for showing the relationships between employees. A tree structure is much better suited for this purpose. CSE 246 Data Structures and Algorithms Fall 2009 Lecture #13

Introduction During this course, you will learn how data structures are created inside a computer. You will find there is quite a difference between your mental picture of a data structure and the actual way a computer stores a data structure in memory. You will also discover that there are many different ways of creating the same data structure in a computer. These various approaches are tradeoffs that programmers must consider when writing software. CSE 246 Data Structures and Algorithms Fall 2009 Lecture #14

Computer Memory Every piece of data that is stored in a computer is kept in a memory cell with a specific address. We can think of these memory cells as being a long row of boxes where each box is labeled with an address. Computer memory is linear. The computer can store many different types of data in its memory. These include basic data types integers, float and characters etc. Once the computer stores data in the memory cells, it can access the data by using the address of the data cells. CSE 246 Data Structures and Algorithms Fall 2009 Lecture #15

Computer Memory For example, consider the following instructions for adding two integers together. For example, suppose we want a data structure that can store a group of characters as a word. In many computer languages, this data structure is called a string. If we store the characters for the string 'apple' in the computer's memory CSE 246 Data Structures and Algorithms Fall 2009 Lecture #16

Computer Memory But what happens when we try to represent our tree diagram of company XYZ? It doesn't make sense to store the names one after the other because the tree is not linear. Now we have a problem. We want to represent a nonlinear data structure using computer memory that is linear CSE 246 Data Structures and Algorithms Fall 2009 Lecture #17

Elementary Data structures Elementary Data Structure are fundamental approaches to organizing data. These are the building blocks that will be used to implement more complex Abstract Data Types. 1. Scalar (built-in) data types 2. Arrays 3. Linked Lists 4. Strings CSE 246 Data Structures and Algorithms Fall2009 Lecture #18

Arrays Data structures that store a large collection of data and allow direct access to the elements by using an index. ◦ Have a fixed length. A programmer must specify the size of an array at the point of its declaration. ◦ Applications often need storage structures, which grow and contract as data is added and removed. CSE 246 Data Structures and Algorithms Fall2009 Lecture #19

Array List Indexing features of an array Created with initial capacity that designates the available space to hold elements. Ability to grow dynamically to meet the runtime needs of a program CSE 246 Data Structures and Algorithms Fall2009 Lecture #110

Array List Not an efficient storage structure for general insertion and deletion of items at an arbitrary position in a list. ◦ Insert requires shifting a block of elements to the right to make room for a new item. ◦ Deletion requires shifting a block of elements to the left to fill in the gap created by the missing item. CSE 246 Data Structures and Algorithms Fall2009 Lecture #111

Data Structures and Algorithms Data structures have operations that manipulate the data. The design and implementation of these operations involve algorithms that consist of a finite sequence of instructions to perform a task. CSE 246 Data Structures and Algorithms Fall2009 Lecture #112

Data structures and Algorithms There is a famous saying by the renowned teacher and scholar, Nicolas Wirth that “Algorithms + Data Structures = Programs” (Wirth) “For many applications, the choice of the proper data structure is the only major decision involving the implementation: once the choice is made, the necessary algorithms are simple.” (Sedgewick) CSE 246 Data Structures and Algorithms Fall 2009 Lecture #113

Data Structure Suppose we have a list of sorted data on which we have to perform the following operations: ◦ Search for an item ◦ delete a specified item ◦ insert (add) a specified item Example: suppose we begin with the following list: data: location: What is a list? ◦ A list is a data structure where data is represented linearly. ◦ Finite sequence of items from the same data type ◦ If arrays are used, items are stored contiguously in the memory CSE 246 Data Structures and Algorithms Fall 2009 Lecture #114

List implementation using an Array Example: suppose we begin with the following list: data: location: Now, delete item 358 from the above list Q:What is the algorithm to delete an item? Q: What is the cost of deleting an item? data: location: Q: When we delete 358, what happens to that location? Now, add item 498 onto the above list Q:Where would that item go? data: location: Q: What is the cost of inserting an item? Conclusion: Using a list representation of data, what is the overall efficiency of searching, adding, and deleting items? CSE 246 Data Structures and Algorithms Fall 2009 Lecture #1 15

Deletion of an Element from a List Algorithm: 1.locate the element in the list (this involves searching) 2.delete the element 3.reorganize the list and index Example: data: location: Delete 358 from the above list: 1.Locate 358:if we use ‘linear search’, we’ll compare 358 with each element of the list starting from the location 0. 2.Delete 358: remove it from the list (space=10) data: location: Reorganize the list: move the remaining elements. (space=9) data: ?(797) location: CSE 246 Data Structures and Algorithms Fall 2009 Lecture #116

Insertion of an Element in List Algorithm: 1.locate the position where the element in to be inserted (position may be user-specified in case of an unsorted list or may be decided by search for a sorted list) 2.reorganize the list and create an ‘empty’ slot 3.insert the element Example: (sorted list) data: location: Insert 505 onto the above list: 1.Locate the appropriate position by performing a binary search. 505 should be stored in location 4. 2.Create an ‘empty’ slot data: location: Insert 505 data: location: CSE 246 Data Structures and Algorithms Fall 2009 Lecture #117

Methods for defining a collection of objects Array ◦ successive items locate a fixed distance disadvantage ◦ data movements during insertion and deletion ◦ waste space in storing n ordered lists of varying size possible solution ◦ linked list ◦ linked lists are dynamically allocated and make extensive use of pointers CSE 246 Data Structures and Algorithms Fall 2009 Lecture #118

Lab # 01 Task 1: Find max number from array list of 10 item. Find total number of comparisons need to perform this task. CSE 246 Data Structures and Algorithms Fall 2009 Lecture #119

Lab # 01 Design a program that records and reports the weekly sales amounts for the salespeople of a company. Each of the n salespeople is assigned a unique identification number in the range of 1 to n. The program prompts the user to enter the number of salespeople, and it uses that value to create an array of sales amount. CSE 246 Data Structures and Algorithms Fall2009 Lecture #120

Sample code import java.util.Scanner; public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter TWO dates: "); String myStr = ""; String myStr2 = ""; while (input.hasNext()) { myStr = input.next(); myStr2 = myStr2 + myStr; } input.close(); System.out.print("You entered:" + myStr2); } } CSE 246 Data Structures and Algorithms Fall2009 Lecture #121