×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

### Create a StudySoup account

#### Be part of our community, it's free to join!

or

##### By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

by: Shlomo Oved

51

0

4

# Study Guide for Data Structures and Algorithms CS UY 2134

Marketplace > New York University > CS UY 2134 > Study Guide for Data Structures and Algorithms
Shlomo Oved
NYU

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

### Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

Covers all the Test Topics: 1. Determine the big-Oh run time for a code snippet 2. Estimate the run time an algorithm will take on an input of size n, given the run time of the algorithm on an in...
COURSE
Data Structures & Algorithms
PROF.
Linda M Sellie
TYPE
Study Guide
PAGES
4
WORDS
KARMA
50 ?

## Popular in Department

This 4 page Study Guide was uploaded by Shlomo Oved on Monday September 26, 2016. The Study Guide belongs to CS UY 2134 at New York University taught by Linda M Sellie in Fall 2016. Since its upload, it has received 51 views.

×

## Reviews for Study Guide for Data Structures and Algorithms

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/26/16
Shlomi  Oved   Study  Guide  for  Midterm   09/26/16   Topics  on  Midterm:       • Determine  the  big-­‐Oh  run  time  for  a  code  snippet   Intro  to  Big-­‐Oh   • Consider  running  time  vs  input  size   • We’re  interested  in  general  behavior  not  exact  details   o Ignore  lower  order  terms   o Ignore  multiplicative  constant   • Example:  n(n+1)/2  is  O(n )   • Graph  has  “same  shape”     Formal  definition   T(n)  is  O(g(n))  is  there  are  positive  0  and  n  such  that  T(n)<=cg(n) 0when  n>=n   3n  is  O(n)   3n+  10n is  O(n )     Big-­‐Oh  notation   • C  g(n)  is  an  upper  bound  growth  rate,  for  some  constant  c   • Platform-­‐independent  (not  affected  by  choice  of  computer,  compiler,   operating  system,  etc.   • G(n)  is  written  as  simply  as  possible  where  constants  an  low  order  term  are   omitted     Some  Important  Big-­‐Oh’s   • O(1)-­‐  constant   • O(log  n)-­‐  logarithmic   • O(n)-­‐  linear   • O(n  log  n)-­‐  linearithmic   • O(n )-­‐  quadratic   • O(n )-­‐  cubic   n • O(2 )-­‐  exponential   • O(n!)-­‐  factorial     Big  Theta  is  more  precise  than  Big-­‐Oh     Examples  of  Running  Times   • Find  element  k  of  array  A:  O(1)   • Find  k  element  in  a  list:  O(n)   • Find  smallest  element  in  array:  O(n)   • Find  smallest  element  in  sorted  array:  O(1)   • Insertion  sort:  O(n )   • Merge  sort:  O(n  log  n)     • Use  a  vector  class  iterator   • Vector  class  has  a  Random  Access  Iterator.   Shlomi  Oved   Study  Guide  for  Midterm   09/26/16   • The  Random  class  Iterator  can  do  the  following  actions:   • Itr1<  itr2,  itr1  <=  itr2,  itr-­‐=c,  itr  +=c,  itr2-­‐itr1,  itr1+c,  itr1-­‐c,  itr[c],  itr1>=itr2,   itr1>itr2,  -­‐-­‐itr,  itr-­‐-­‐,  Itr++,  ++itr,  *itr,  itr1==itr2,  itr1  !=  itr2,  itr-­‐>m   • Example  of  a  function  using  Vector  iterator:   • template<class  Object,  class  Iterator>   • void  goThroughVector(const  vector<Object>&  objects){   • for(Iterator  itr=objects.begin();  itr!=objects.end();  itr++){   • cout  <<  *itr  <<  endl;   •          }   • }     • Write  a  functor   • Example  of  functors:   • class  isEven{   • public:   •                  bool  operator()(const  int&  evenNumber){return  evenNumber%2==0;}   • };   • template<class  Object,  class  Functor>   •                  bool  evenOrOdd(const  Object&  obj,  Functor  funct){   •                return  funct(obj);   • }   • class  strCompare{   • public:   •                  bool  operator()(const  string&  str1,  const  string&  str2){return  str1<str2;}   • };   • template<class  Object,  class  Functor>   •                bool  isShorter(Object  obj1,  Object  obj2,  Functor  funct){   •                return  funct(obj1,  obj2);   • }     • Write  a  generic  function  template  for  some  algorithm  where  the   parameters  to  the  function  are  iterators  and  functors   • Ex:   • template  <class  Itr,  class  UnaryPred>   • void  print_if(Itr  start,  Itr  end,  UnaryPred  pred){   •                      for  (Itr  itr=start;  itr!=end;  itr++){   •                                bool  result=pred(*itr);   •                              if  (result)  cout  <<  *itr  <<  endl;   •                }   • }     • Know  how  iterators  work  for  the  vector  and  list  class   • For  the  list  class  iterators  are  forward  directional  iterators  or  bi-­‐directional   iterators  depending  on  the  type  of  list.     Shlomi  Oved   Study  Guide  for  Midterm   09/26/16   • Possible  Operations  of  Iterators   • Forward  Iterators:   • Itr++,  ++itr,  *itr,  itr1==itr2,  itr1  !=  itr2,  itr-­‐>m   • Bi-­‐Directional  iterators:   • -­‐-­‐itr,  itr-­‐-­‐,  Itr++,  ++itr,  *itr,  itr1==itr2,  itr1  !=  itr2,  itr-­‐>m       • Vector  class  has  a  Random  Access  Iterator.   • The  Random  class  Iterator  can  do  the  following  actions:   • Itr1<  itr2,  itr1  <=  itr2,  itr-­‐=c,  itr  +=c,  itr2-­‐itr1,  itr1+c,  itr1-­‐c,  itr[c],  itr1>=itr2,   itr1>itr2,  -­‐-­‐itr,  itr-­‐-­‐,  Itr++,  ++itr,  *itr,  itr1==itr2,  itr1  !=  itr2,  itr-­‐>m     • Write  a  copy  constructor,  move  constructor,  move  assignment  operator,   copy  assignment  operator,  or  destructor  for  a  class   • Example:   • //Copy  Constructor    IntArray::IntArray(const  IntArray&  rhs)  {       •                            size  =  rhs.size;   •                            array  =  new  int[size];   •     for  (int  i  =  0;  i  <  size;  i++)  {     •     array[i]  =  rhs.array[i];       •                      }   •  }   •  //Move  Constructor   • IntArray::IntArray(IntArray&&  rhs)  {   •     size  =  rhs.size;   •     array  =  rhs.array;       •                          rhs.array  =  nullptr;       •                          rhs.size  =  0;     • }     • //Copy  Assignment  Operator   • IntArray&  IntArray::operator=(const  IntArray&  rhs)  {   •     //self  check   •     //copy  over         •                            if  (this  !=  &rhs)  {   •                  size  =  rhs.size;   •                                        array  =  new  int[size];   •                                        for  (int  i  =  0;  i  <  size;  i++)  {   •       array[i]  =  rhs.array[i];     •     }       •                                    }       •                                        //return       •                                      return  *this;     • }     • //Move  Assignment  Operator   • IntArray&  IntArray::operator=(IntArray&&  rhs)  {   Shlomi  Oved   Study  Guide  for  Midterm   09/26/16   •     if  (this  !=  &rhs)  {   •       size  =  rhs.size;   •       delete[]  array;     •     array  =  rhs.array;   •       rhs.size  =  0;   •       rhs.array  =  nullptr;   •     }       •                                    return  *this;     • }       • //Destructor   • IntArray::  ~IntArray(){       •                          size  =  0;   •                        delete[]  array;     • }

×

×

×

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Allison Fischer University of Alabama

#### "I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over \$600 per month. I LOVE StudySoup!"

Bentley McCaw University of Florida

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.