d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question Big O-notation
Add Reply New Topic New Poll
Member
Posts: 856
Joined: Oct 10 2018
Gold: 0.00
Aug 4 2019 02:28am
I need help with the following task:

a. How long do you need to remove the snow depending on the size of the
surface
b. How long to find a word in a sorted dictionary
c. How long to find a word in an unsorted dictionary

O(n) , O(n2) etc.

can any1 help me?

ty
Member
Posts: 12,080
Joined: May 3 2017
Gold: Locked
Trader: Scammer
Aug 4 2019 05:47am
Im learning atm so curious about this too if someone can quote me in on the answers
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Aug 4 2019 10:46am
With these questions you're basically trying to classify these algorithms by their complexity given a word problem.
First you need to determine what algorithm is going to be used to solve these problems.
Assuming you can clear 1 sqr feet of snow per minute. The only variable is the amount of snow. This depends on the size of the surface.
If your surface is 1 sqr feet it takes you 1 minute.
If your surface is 2 sqr feet it takes you 2 minutes.
If your surface is 500 sqr feet it takes you 500 minutes.
If your surface is n sqr feet it takes you n minutes.
and so on.

You can graph this with a line. (remember y = mx+b)
This is a linear function.
Use the table in the "Orders of common functions" section on the wiki page to get the big O for that if you don't already know it: https://en.wikipedia.org/wiki/Big_O_notation
It is O(n)

Now to answer question 2 you need determine if or how the retrieval time of objects in a dictionary changes depending on the size of the dictionary. To do this you need to figure out an algorithm to find the word. Then see if that takes a constant, log, linear, exponential or some other time. Then You will know if it is O(1), O(log n ), O(n), O(n^2) etc.

This helps, but will not teach you how to solve this on your own: https://www.bigocheatsheet.com/

I'll help more if u give this a stab. Someone else may just give you the 3 answers, but I figure you both need to learn this for a class?

edit: I was missing word.

This post was edited by waraholic on Aug 4 2019 10:54am
Member
Posts: 856
Joined: Oct 10 2018
Gold: 0.00
Aug 4 2019 11:31am
Quote (waraholic @ Aug 4 2019 06:46pm)
With these questions you're basically trying to classify these algorithms by their complexity given a word problem.
First you need to determine what algorithm is going to be used to solve these problems.
Assuming you can clear 1 sqr feet of snow per minute. The only variable is the amount of snow. This depends on the size of the surface.
If your surface is 1 sqr feet it takes you 1 minute.
If your surface is 2 sqr feet it takes you 2 minutes.
If your surface is 500 sqr feet it takes you 500 minutes.
If your surface is n sqr feet it takes you n minutes.
and so on.

You can graph this with a line. (remember y = mx+b)
This is a linear function.
Use the table in the "Orders of common functions" section on the wiki page to get the big O for that if you don't already know it: https://en.wikipedia.org/wiki/Big_O_notation
It is O(n)

Now to answer question 2 you need determine if or how the retrieval time of objects in a dictionary changes depending on the size of the dictionary. To do this you need to figure out an algorithm to find the word. Then see if that takes a constant, log, linear, exponential or some other time. Then You will know if it is O(1), O(log n ), O(n), O(n^2) etc.

This helps, but will not teach you how to solve this on your own: https://www.bigocheatsheet.com/

I'll help more if u give this a stab. Someone else may just give you the 3 answers, but I figure you both need to learn this for a class?

edit: I was missing word.


thanks dude, ill give it a try :)
Member
Posts: 75
Joined: Feb 10 2019
Gold: 0.00
Aug 8 2019 12:25am
Quote (05BB @ Aug 4 2019 01:28am)
I need help with the following task:

a. How long do you need to remove the snow depending on the size of the
surface
b. How long to find a word in a sorted dictionary
c. How long to find a word in an unsorted dictionary

O(n) , O(n2) etc.

can any1 help me?

ty


if area of snow is defined by n and m, n being length of rectangle of snow, and m being width, AND removing a 1x1 sq unit of snow is a O(1) operation then it's O(nm)

b and c both depend on the implementation. Dictionary might mean a hash / hashmap / hashtable. If that's the case finding a word regardless if it's sorted or unsorted should be a constant time O(1) operation due to hashing. You can get into pretty bad worst case depending on how bad the hash function is.
Member
Posts: 1,039
Joined: Jul 8 2008
Gold: 1,939.50
Aug 8 2019 04:51pm
Quote (drwl @ Aug 8 2019 02:25am)
if area of snow is defined by n and m, n being length of rectangle of snow, and m being width, AND removing a 1x1 sq unit of snow is a O(1) operation then it's O(nm)

b and c both depend on the implementation. Dictionary might mean a hash / hashmap / hashtable. If that's the case finding a word regardless if it's sorted or unsorted should be a constant time O(1) operation due to hashing. You can get into pretty bad worst case depending on how bad the hash function is.


There is no reason to over complicate things. The question states:

How long do you need to remove the snow depending on the size of the surface

The only variable that changes is the size of the surface. Simply define it in sqr feet. So define size of surface = n.
n is in sqr feet
O(n)

I'm pretty sure questions 2 and 3 reference a literal dictionary.

This post was edited by waraholic on Aug 8 2019 04:52pm
Member
Posts: 75
Joined: Feb 10 2019
Gold: 0.00
Aug 10 2019 12:25am
Quote (waraholic @ Aug 8 2019 03:51pm)
There is no reason to over complicate things. The question states:

How long do you need to remove the snow depending on the size of the surface

The only variable that changes is the size of the surface. Simply define it in sqr feet. So define size of surface = n.
n is in sqr feet
O(n)

I'm pretty sure questions 2 and 3 reference a literal dictionary.


oh i see, what a shit question for 2 and 3 haha
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll