Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known.

Similar presentations


Presentation on theme: "Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known."— Presentation transcript:

1 Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known as a data structure. ● Data Structures are used to store and make use of data in a computer efficiently.

2 Efficient Computer Use ● So, what does it mean to use a computer efficiently? – Think back to the Fibonacci Sequence recursive/iterative demonstration. – Which version was faster? Which version required less memory? – How can we describe this mathematically?

3 Big O notation ● There is a mathematical notation which lets you analyze what the worst case scenario for a function is. ● We will not go into this in detail; however, the basic notion is that something that runs in O(n) time is much faster than O(n^2) which is much faster than O(2^n). ● What this says is that given an input of size n, O(_) describes how long it would take relative to that input's size.

4 Thinking about efficiency on an easier level ● Consider this scenario: – I'm thinking of a number from 1 to 1000 – I'm willing to give you a prize if you can guess it. – I'll give you multiple chances to guess, but the more you guess, the smaller your prize will be. – Each time you guess, I'll tell you if you are correct, too high, or too low. ● How might you develop a technique to guess? ● What would your algorithm look like?

5 Thinking about efficiency on an easier level ● Other similar scenarios: – Finding a word in the dictionary. – Getting an entry from your address book. ● Other things to think about: – Sorting: how can you quickly sort a list of number you have never seen before?

6 Motivating Data Structures ● The develop of data structures is typically driven by a desire to make actions regarding a set of data more efficient, and to make the storage of the data easier to use. ● For example, what kind of actions might you do with a list? – Add items – Delete items – Search for an item – Update an item ● How might you store items in order to facilitate these actions?

7 Designing a Data Structure Class ● You should begin by considering what you want your class to do. – What data should it hold? – What operations should it use? ● Once you determine what data it should hold, you should figure out how you will store it. ● For our purposes, a linked list type will almost always be OK. As you get further into programming, this will stop being the case.

8 Designing a Data Structure Class ● The first step, then, is to determine how exactly to store your data. For linked lists, it is usually sufficient to create a struct with (at least) a next pointer, and to dynamically allocate those structs to build your list. ● This class will require dynamic memory, so what does this class need to have?

9 Designing a Data Structure Class ● Once you have decided how to store data, you should think about how you will access it. ● Your class will have member functions that allow you to perform the tasks you need. ● For a set of data, you typically need – Add item – Delete item – Find item ● As long as you give careful thought to how you want these to be used (how will pass in parameters) and how your algorithm will be set up to implement them, your class will be good.

10 Class Design in General ● Really, you should try to think of any class you create in a similar fashion. – What will it hold? – How will it be used? – What functions need to be made to make it useful?


Download ppt "Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known."

Similar presentations


Ads by Google