1 / 15

CSE 246 Data Structures and Algorithms

CSE 246 Data Structures and Algorithms. Spring2012 Lecture#2. Introduction. 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

iona
Download Presentation

CSE 246 Data Structures and Algorithms

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. CSE 246Data Structures and Algorithms Spring2012 Lecture#2

  2. Introduction • 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. Quratulain Rajput

  3. 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 a software. Quratulain Rajput

  4. Why need Data structures • In computer systems we do not have the option of using or not using data structure. Computers has to store and use data. Computers cannot do without data, and wherever data exists it must have some kind of data structure. • Data structures helps to organized dataefficiently. • Data structures can support to increase efficiency of a program without hardware change. Quratulain Rajput

  5. Organized data • The mechanism to store collection of record that can be search, process and modified. • The selection of data structures and algorithms makes the difference in making a program efficient. Quratulain Rajput

  6. What is efficiency? • A solution of a problem is called efficient if its solve the problem within its resource constraints. • Time • Space • The cost of the solution is the amount of resources that the solution consumes. Quratulain Rajput

  7. How to select data structure? • Analyze a problem to identify resource constraints need for solution. • Analyze basic operation requires in a solution. • Then select a data structures to meet the above requirements Quratulain Rajput

  8. Basic operations • Insertion: where have to insert or only insert all at once. • Deletion: • Search Quratulain Rajput

  9. Data structures • Each data structure has cost and benefits. • No data structure is ideal for all problem. • The use of data structures requires: • Memory to store data • Time to perform operation • Programming effort Quratulain Rajput

  10. Arrays • Array is a built-in data structure in programming languages. intarr={10, 29,44,34,2,1}; • Each cell contains same type of data. • Array is linear list of consecutive memory locations. • To access we used arr[3]; • Array arr is a reference to the beginning of an array list. Quratulain Rajput

  11. Dynamic Array • When size of data is not fixed then we can use dynamic array. Int[] arr=new int[n]; Quratulain Rajput

  12. List data structures • List is a most generic data structure. Examples are grocery list, shopping list, list of people, list of students. • Items in a list is in linear order. • Insertion, deletion can be done in any order. Quratulain Rajput

  13. List Operations Useful operations • createList(): create a new list (presumably empty) • copy(): set one list to be a copy of another • clear(); clear a list (remove all elments) • insert(X, ?): Insert element X at a particular position in the list • remove(?): Remove element at some position in the list • get(?): Get element at a given position • update(X, ?): replace the element at a given position with X • find(X): determine if the element X is in the list • length(): return the length of the list.

  14. How to implement a List using Array • First define interface of the List then implement operation of the List defined in interface. Quratulain Rajput

  15. Analysis of Array List • Insertion or deletion from particular location of List requires shift operation. • Worst case, when need to insert/delete at the beginning of a List. • Find operation search item in a list. In worst case, item is not present in a list or at end that requires to search the entire array. Quratulain Rajput

More Related