d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Abstract Data Types
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 6 2012 02:03am
Professor kinda glosses over this. Did some reading tonight and it seems like a pretty important idea.

Could anyone briefly explain what these are/how they are important to someone like me relatively new?

I can't put the pieces together by myself it seems.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 6 2012 02:20am
dont let the terminology confuse you. they're just data structures where implementations can vary. Queues and stacks, for example, can be made via arrays or linked lists.

picking the right data structure is crucial for algorithms.

quick example of their importance: browser's back button. this is done via a stack. if some goof ball accidentally used a queue, how useful would it be?

This post was edited by carteblanche on Oct 6 2012 02:22am
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 6 2012 02:23am
Quote (carteblanche @ Oct 6 2012 03:20am)
dont let the terminology confuse you. they're just data structures where implementations can vary. Queues and stacks, for example, can be made via arrays or linked lists.

picking the right data structure is crucial for algorithms.


ahh. So the stuff we are learning right now (queues, stacks, soon to be trees templates etc) all come in handy for different things? And static VS dynamic as well.



Another question: Is a dynamic implementation of a list or stack etc ever WORSE than a static?

Aside from ease of use? (I guess?) I thought dynamic stacks/queues seemed pretty smart.

Though I am guessing that the memory allocated by them is not in a neat little bunch, contrasted with static.

This post was edited by Eep on Oct 6 2012 02:24am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 6 2012 02:30am
i dont know what you mean by dynamic vs static. what is dynamic? the size? if so, they come with overhead you want to avoid if you dont need it. for example if you know you need between 150-200 items in an arraylist, just pre-allocate the 200 slots as opposed to starting with 10 then growing it as you add more. then when you remove items, you could be dynamic and resize your array to be smaller. which of course means allocating a new array, spending time to copy over the data, then destroying the old array.

or by dynamic do you mean the type? eg using generics instead of hard coding a linked list of only ints? the generic method is preferable (depending on language restrictions/implementations)

or something else entirely?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 6 2012 02:35am
Quote (carteblanche @ Oct 6 2012 03:30am)
i dont know what you mean by dynamic vs static. what is dynamic? the size? if so, they come with overhead you want to avoid if you dont need it. for example if you know you need between 150-200 items in an arraylist, just pre-allocate the 200 slots as opposed to starting with 10 then growing it as you add more. then when you remove items, you could be dynamic and resize your array to be smaller. which of course means allocating a new array, spending time to copy over the data, then destroying the old array.

or by dynamic do you mean the type? eg using generics instead of hard coding a linked list of only ints? the generic method is preferable (depending on language restrictions/implementations)

or something else entirely?


I mean size wise. Like, why you would ever implement a stack as an array vs a stack as a linked list.

Is it about the overhead of linked lists? Or is it just preference?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 6 2012 02:51am
Quote (Eep @ Oct 6 2012 04:35am)
I mean size wise. Like, why you would ever implement a stack as an array vs a stack as a linked list.

Is it about the overhead of linked lists? Or is it just preference?


99% of the time the in-memory performance difference to an app developer is insignificant. it might take you a whole 10 milliseconds extra, whereas your database hit takes 5 seconds which greatly overshadows it

but if you're being nitpicky, then i already gave you examples of when to use one vs the other. if your requirements have a very specific number and it hovers there all the time, then you can use an array. another example, suppose i want to keep the 5 most recent of xyz. you can very easily track it via circular array faster than a linked list (which requires constant memory allocation and deallocation).

This post was edited by carteblanche on Oct 6 2012 02:52am
Member
Posts: 13,630
Joined: Dec 4 2009
Gold: 0.00
Oct 6 2012 03:07am
Quote (carteblanche @ Oct 6 2012 01:20am)
dont let the terminology confuse you. they're just data structures where implementations can vary. Queues and stacks, for example, can be made via arrays or linked lists.

picking the right data structure is crucial for algorithms.

quick example of their importance: browser's back button. this is done via a stack. if some goof ball accidentally used a queue, how useful would it be?


Completely unrelated:

I like pronouncing this word like "kway" with emphasis on the "ay" morpheme, even though I know it's pronounced like "cue".

I need sleeeeep
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 6 2012 03:39am
Quote (carteblanche @ Oct 6 2012 03:51am)
99% of the time the in-memory performance difference to an app developer is insignificant. it might take you a whole 10 milliseconds extra, whereas your database hit takes 5 seconds which greatly overshadows it

but if you're being nitpicky, then i already gave you examples of when to use one vs the other. if your requirements have a very specific number and it hovers there all the time, then you can use an array. another example, suppose i want to keep the 5 most recent of xyz. you can very easily track it via circular array faster than a linked list (which requires constant memory allocation and deallocation).


that is the answer I was looking for. thanks.

I am still a bit nervous of how 2261 will go (a java class) next semester....I hope the hurdle of learning new languages isn't too hard once you got some key concepts down.

It should also be my first semester of pure CS courses, I think. Should be fun.

This post was edited by Eep on Oct 6 2012 03:40am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll