Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Size: px
Start display at page:

Download "Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved."

Transcription

1

2 Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved.

3 Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4 Classes ad Dyamic Arrays Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-3

4 11.1 Fried Fuctios Copyright 2014 Pearso Addiso-Wesley. All rights reserved.

5 Fried Fuctio Class operatios are typically implemeted as member fuctios Some operatios are better implemeted as ordiary (omember) fuctios Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-5

6 Program Example: A Equality Fuctio The DayOfYear class from Chapter 10 ca be ehaced to iclude a equality fuctio A equality fuctio tests two objects of type DayOfYear to see if their values represet the same date Two dates are equal if they represet the same day ad moth Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-6

7 Declaratio of The equality Fuctio We wat the equality fuctio to retur a value of type bool that is true if the dates are the same The equality fuctio requires a parameter for each of the two dates to compare The declaratio is bool equal(dayofyear date1, DayOfYear date2); Notice that equal is ot a member of the class DayOfYear Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-7

8 Defiig Fuctio equal The fuctio equal, is ot a member fuctio It must use public accessor fuctios to obtai the day ad moth from a DayOfYear object equal ca be defied i this way: bool equal(dayofyear date1, DayOfYear date2) { retur ( date1.get_moth( ) == date2.get_moth( ) && date1.get_day( ) == date2.get_day( ) ); } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-8

9 Usig The Fuctio equal The equal fuctio ca be used to compare dates i this maer if ( equal( today, bach_birthday) ) cout << "It's Bach's birthday!"; A complete program usig fuctio equal is foud i Display 11.1 (1) Display 11.1 (2) Display 11.1 (3) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-9

10 Is equal Efficiet? Fuctio equal could be made more efficiet Equal uses member fuctio calls to obtai the private data values Direct access of the member variables would be more efficiet (faster) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-10

11 A More Efficiet equal As defied here, equal is more efficiet, but ot legal bool equal(dayofyear date1, DayOfYear date2) { retur (date1.moth = = date2.moth && date1.day = = date2.day ); } The code is simpler ad more efficiet Direct access of private member variables is ot legal! Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-11

12 Fried Fuctios Fried fuctios are ot members of a class, but ca access private member variables of the class A fried fuctio is declared usig the keyword fried i the class defiitio A fried fuctio is ot a member fuctio A fried fuctio is a ordiary fuctio A fried fuctio has extraordiary access to data members of the class As a fried fuctio, the more efficiet versio of equal is legal Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-12

13 Declarig A Fried The fuctio equal is declared a fried i the abbreviated class defiitio here class DayOfYear { public: fried bool equal(dayofyear date1, DayOfYear date2); // The rest of the public members private: // the private members }; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-13

14 Usig A Fried Fuctio A fried fuctio is declared as a fried i the class defiitio A fried fuctio is defied as a omember fuctio without usig the "::" operator A fried fuctio is called without usig the '.' operator Display 11.2 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-14

15 Fried Declaratio Sytax The sytax for declarig fried fuctio is class class_ame { public: fried Declaratio_for_Fried_Fuctio_1 fried Declaratio_for_Fried_Fuctio_2 Member_Fuctio_Declaratios private: Private_Member_Declaratios }; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-15

16 Are Frieds Needed? Fried fuctios ca be writte as o-fried fuctios usig the ormal accessor ad mutator fuctios that should be part of the class The code of a fried fuctio is simpler ad it is more efficiet Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-16

17 Choosig Frieds How do you kow whe a fuctio should be a fried or a member fuctio? I geeral, use a member fuctio if the task performed by the fuctio ivolves oly oe object I geeral, use a omember fuctio if the task performed by the fuctio ivolves more tha oe object Choosig to make the omember fuctio a fried is a decisio of efficiecy ad persoal taste Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-17

18 Program Example: The Moey Class (versio 1) Display 11.3 demostrates a class called Moey U.S. currecy is represeted Value is implemeted as a iteger represetig the value as if coverted to peies A iteger allows exact represetatio of the value Type log is used to allow larger values Two fried fuctios, equal ad add, are used Display 11.3 (1 5) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-18

19 Characters to Itegers Notice how fuctio iput (Display 11.3) processes the dollar values etered First read the character that is a $ or a If it is the -, set the value of egative to true ad read the $ sig which should be ext Next read the dollar amout as a log Next read the decimal poit ad cets as three characters digit_to_it is the used to covert the cets characters to itegers Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-19

20 digit_to_it (optioal) digit_to_it is defied as it digit_to_it(char c) { retur ( it ( c ) it ( '0') ); } A digit, such as '3' is parameter c This is the character '3' ot the umber 3 The type cast it(c) returs the umber that implemets the character stored i c The type cast it('0') returs the umber that implemets the character '0' Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-20

21 it( c) it ('0')? The umbers implemetig the digits are i i order it('0') + 1 is equivalet to it('1') it('1') + 1 is equivalet to it('2') If c is '0' it( c ) - it('0') returs iteger 0 If c is '1' it( c ) it ('0') returs iteger 1 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-21

22 Leadig Zeros Some compilers iterpret a umber with a leadig zero as a base 8 umber Base 8 uses digits 0 7 Usig 09 to represet 9 cets could cause a error the digit 9 is ot allowed i a base 8 umber The ANSI C++ stadard is that iput should be iterpreted as base 10 regardless of a leadig zero Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-22

23 Parameter Passig Efficiecy A call-by-value parameter less efficiet tha a call-by-referece parameter The parameter is a local variable iitialized to the value of the argumet This results i two copies of the argumet A call-by-referece parameter is more efficiet The parameter is a placeholder replaced by the argumet There is oly oe copy of the argumet Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-23

24 Class Parameters It ca be much more efficiet to use call-by-referece parameters whe the parameter is of a class type Whe usig a call-by-referece parameter If the fuctio does ot chage the value of the parameter, mark the parameter so the compiler kows it should ot be chaged Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-24

25 cost Parameter Modifier To mark a call-by-referece parameter so it caot be chaged: Use the modifier cost before the parameter type The parameter becomes a costat parameter cost used i the fuctio declaratio ad defiitio Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-25

26 cost Parameter Example Example (from the Moey class of Display 11.3): A fuctio declaratio with costat parameters fried Moey add(cost Moey& amout1, cost Moey& amout2); A fuctio defiitio with costat parameters Moey add(cost Moey& amout1, cost Moey& amout2) { } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-26

27 cost Cosideratios Whe a fuctio has a costat parameter, the compiler will make certai the parameter caot be chaged by the fuctio What if the parameter calls a member fuctio? Moey add(cost Moey& amout1, cost Moey& amout2) { amout1.iput( ci ); } The call to iput will chage the value of amout1! Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-27

28 cost Ad Accessor Fuctios Will the compiler accept a accessor fuctio call from the costat parameter? Moey add(cost Moey& amout1, cost Moey& amout2) { amout1.output(cout); } The compiler will ot accept this code There is o guaratee that output will ot chage the value of the parameter Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-28

29 cost Modifies Fuctios If a costat parameter makes a member fuctio call The member fuctio called must be marked so the compiler kows it will ot chage the parameter cost is used to mark fuctios that will ot chage the value of a object cost is used i the fuctio declaratio ad the fuctio defiitio Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-29

30 Fuctio Declaratios With cost To declare a fuctio that will ot chage the value of ay member variables: Use cost after the parameter list ad just before the semicolo class Moey { public: void output (ostream& outs) cost ; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-30

31 Fuctio Defiitios With cost To defie a fuctio that will ot chage the value of ay member variables: Use cost i the same locatio as the fuctio declaratio void Moey::output(ostream& outs) cost { // output statemets } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-31

32 cost Problem Solved Now that output is declared ad defied usig the cost modifier, the compiler will accept this code Moey add(cost Moey& amout1, cost Moey& amout2) { amout1.output(cout); } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-32

33 cost Wrapup Usig cost to modify parameters of class types improves program efficiecy cost is typed i frot of the parameter's type Member fuctios called by costat parameters must also use cost to let the compiler kow they do ot chage the value of the parameter cost is typed followig the parameter list i the declaratio ad defiitio Display 11.4 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-33

34 Use cost Cosistetly Oce a parameter is modified by usig cost to make it a costat parameter Ay member fuctios that are called by the parameter must also be modified usig cost to tell the compiler they will ot chage the parameter It is a good idea to modify, with cost, every member fuctio that does ot chage a member variable Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-34

35 Sectio 11.1 Coclusio Ca you Describe the promise that you make to the compiler whe you modify a parameter with cost? Explai why this declaratio is probably ot correct? class Moey { public: void iput(istream& is) cost; }; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-35

36 11.2 Overloadig Operators Copyright 2014 Pearso Addiso-Wesley. All rights reserved.

37 Overloadig Operators I the Moey class, fuctio add was used to add two objects of type Moey I this sectio we see how to use the '+' operator to make this code legal: Moey total, cost, tax; total = cost + tax; // istead of total = add(cost, tax); Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-37

38 Operators As Fuctios A operator is a fuctio used differetly tha a ordiary fuctio A ordiary fuctio call eclosed its argumets i parethesis add(cost, tax) With a biary operator, the argumets are o either side of the operator cost + tax Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-38

39 Operator Overloadig Operators ca be overloaded The defiitio of operator + for the Moey class is early the same as member fuctio add To overload the + operator for the Moey class Use the ame + i place of the ame add Use keyword operator i frot of the + Example: fried Moey operator + (cost Moey& amout1 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-39

40 Operator Overloadig Rules At least oe argumet of a overloaded operator must be of a class type A overloaded operator ca be a fried of a class New operators caot be created The umber of argumets for a operator caot be chaged The precedece of a operator caot be chaged., ::, *, ad? caot be overloaded Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-40

41 Program Example: Overloadig Operators The Moey class with overloaded operators + ad == is demostrated i Display 11.5 (1) Display 11.5 (2) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-41

42 Display 11.5 (1/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-42

43 Display 11.5 (2/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-43

44 Automatic Type Coversio With the right costructors, the system ca do type coversios for your classes This code (from Display 11.5) actually works Moey base_amout(100, 60), full_amout; full_amout = base_amout + 25; The iteger 25 is coverted to type Moey so it ca be added to base_amout! How does that happe? Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-44

45 Type Coversio Evet 1 Whe the compiler sees base_amout + 25, it first looks for a overloaded + operator to perform Moey_object + iteger If it exists, it might look like this fried Moey operator +(cost Moey& amout1, cost it& amout2); Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-45

46 Type Coversio Evet 2 Whe the appropriate versio of + is ot foud, the compiler looks for a costructor that takes a sigle iteger The Moey costructor that takes a sigle parameter of type log will work The costructor Moey(log dollars) coverts 25 to a Moey object so the two values ca be added! Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-46

47 Type Coversio Agai Although the compiler was able to fid a way to add base_amout + 25 this additio will cause a error base_amout There is o costructor i the Moey class that takes a sigle argumet of type double Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-47

48 A Costructor For double To permit base_amout , the followig costructor should be declared ad defied class Moey { public: Moey(double amout); // Iitialize object so its value is $amout Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-48

49 Overloadig Uary Operators Uary operators take a sigle argumet The uary operator is used to egate a value x = -y ++ ad - - are also uary operators Uary operators ca be overloaded The Moey class of Display 11.6 ca icludes A biary operator A uary operator Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-49

50 Overloadig - Overloadig the operator with two parameters allows us to subtract Moey objects as i Moey amout1, amout2, amout2; amout3 = amout1 amout2; Overloadig the operator with oe parameter allows us to egate a moey value like this amout3 = -amout1; Display 11.6 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-50

51 Display 11.6 Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-51

52 Overloadig << ad >> The isertio operator << is a biary operator The first operad is the output stream The secod operad is the value followig << cout << "Hello out there.\"; Operad 1 Operad 2 Operator Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-52

53 Replacig Fuctio output Overloadig the << operator allows us to use << istead of Moey's output fuctio Give the declaratio: Moey amout(100); amout.output( cout ); ca become cout << amout; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-53

54 What Does << Retur? Because << is a biary operator cout << "I have " << amout << " i my purse."; seems as if it could be grouped as ( (cout << "I have" ) << amout) << "i my purse."; To provide cout as a argumet for << amout, (cout << "I have") must retur cout Display 11.7 Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-54

55 Display 11.7 Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-55

56 Overloaded << Declaratio Based o the previous example, << should retur its first argumet, the output stream This leads to a declaratio of the overloaded << operator for the Moey class: class Moey { public: fried ostream& operator << (ostream& outs, cost Moey& amout); Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-56

57 Overloaded << Defiitio The followig defies the << operator ostream& operator <<(ostream& outs, cost Moey& amout) { <Same as the body of Moey::output i Display 11.3 (except all_cets is replaced with amout.all_cets) > } retur outs; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-57

58 Retur ostream&? The & meas a referece is retured So far all our fuctios have retured values The value of a stream object is ot so simple to retur The value of a stream might be a etire file, the keyboard, or the scree! We wat to retur the stream itself, ot the value of the stream The & meas that we wat to retur the stream, ot its value Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-58

59 Overloadig >> Overloadig the >> operator for iput is very similar to overloadig the << for output >> could be defied this way for the Moey class istream& operator >>(istream& is, Moey& amout); { } <This part is the same as the body of Moey::iput i Display 11.3 (except that all_cets is replaced with amout.all_cets)> retur is; Display 11.8 (1-4) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-59

60 Display 11.8 (1/4) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-60

61 Display 11.8(2/4) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-61

62 Display 11.8 (3/4) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-62

63 Display 11.8 (4/4) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-63

64 Sectio 11.2 Coclusio Ca you Describe the purpose of a makig a fuctio a fried? Describe the use of costat parameters? Idetify the retur type of the overloaded operators << ad >>? Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-64

65 11.3 Arrays ad Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved.

66 Arrays ad Classes Arrays ca use structures or classes as their base types Example: struct WidIfo { double velocity; char directio; } WidIfo data_poit[10]; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-66

67 Accessig Members Whe a array's base type is a structure or a class Use the dot operator to access the members of aidexed variable Example: for (i = 0; i < 10; i++) { cout << "Eter velocity: "; ci >> data_poit[i].velocity; } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-67

68 A Array of Moey The Moey class of Chapter 11 ca be the base type for a array Whe a array of classes is declared The default costructor is called to iitialize the idexed variables A array of class Moey is demostrated i Display 11.9 (1-3) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-68

69 Arrays as Structure Members A structure ca cotai a array as a member Example: struct Data { double time[10]; it distace; } Data my_best; my_best cotais a array of type double Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-69

70 Accessig Array Elemets To access the array elemets withi a structure Use the dot operator to idetify the array withi the structure Use the [ ]'s to idetify the idexed variable desired Example: my_best.time[i] refereces the ith idexed variable of the variable time i the structure my_best Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-70

71 Arrays as Class Members Class TemperatureList icludes a array The array, amed list, cotais temperatures Member variable size is the umber of items stored class TemperatureList { public: TemperatureList( ); //Member fuctios private: double list [MAX_LIST_SIZE]; it size; } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-71

72 Overview of TemperatureList To create a object of type TemperatureList: TemperatureList my_data; To add a temperature to the list: My_data.add_temperature(77); A check is made to see if the array is full << is overloaded so output of the list is cout << my_data; Display (1-2) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-72

73 Sectio 11.3 Coclusio Ca you Declare a array as a member of a class? Declare a array of objects of a class? Write code to call a member fuctio of a elemet i a array of objects of a class? Write code to access a elemet of a array of itegers that is a member of a class? Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-73

74 11.4 Classes ad Dyamic Arrays Copyright 2014 Pearso Addiso-Wesley. All rights reserved.

75 Classes ad Dyamic Arrays A dyamic array ca have a class as its base type A class ca have a member variable that is a dyamic array I this sectio you will see a class usig a dyamic array as a member variable. Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-75

76 Program Example: A Strig Variable Class We will defie the class StrigVar StrigVar objects will be strig variables StrigVar objects use dyamic arrays whose size is determied whe the program is ruig The StrigVar class is similar to the strig class discussed earlier Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-76

77 The StrigVar Costructors The default StrigVar costructor creates a object with a maximum strig legth of 100 Aother StrigVar costructor takes a argumet of type it which determies the maximum strig legth of the object A third StrigVar costructor takes a C-strig argumet ad sets maximum legth to the legth of the C-strig copies the C-strig ito the object's strig value Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-77

78 The StrigVar Iterface I additio to costructors, the StrigVar iterface icludes: Member fuctios it legth( ); void iput_lie(istream& is); fried ostream& operator << (ostream& outs, cost StrigVar& the_strig); Copy Costructor discussed later Destructor discussed later Display (1) Display (2) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-78

79 A StrigVar Sample Program Usig the StrigVar iterface of Display 11.11, we ca write a program usig the StrigVar class The program uses fuctio coversatio to Create two StrigVar objects, your_ame ad our_ame your_ame ca cotai ay strig max_ame_size or shorter i legth our_ame is iitialized to "Borg" ad ca have ay strig of 4 or less characters Display (3) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-79

80 The StrigVar Implemetatio StrigVar uses a dyamic array to store its strig StrigVar costructors call ew to create the dyamic array for member variable value '\0' is used to termiate the strig The size of the array is ot determied util the array is declared Costructor argumets determie the size Display (1) Display (2) Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-80

81 Dyamic Variables Dyamic variables do ot "go away" uless delete is called Eve if a local poiter variable goes away at the ed of a fuctio, the dyamic variable it poited to remais uless delete is called A user of the SrigVar class could ot kow that a dyamic array is a member of the class, so could ot be expected to call delete whe fiished with a StrigVar object Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-81

82 Destructors A destructor is a member fuctio that is called automatically whe a object of the class goes out of scope The destructor cotais code to delete all dyamic variables created by the object A class has oly oe destructor with o argumets The ame of the destructor is distiguished from the default costructor by the tilde symbol ~ Example: ~StrigVar( ); Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-82

83 ~StrigVar The destructor i the StrigVar class must call delete [ ] to retur the memory of ay dyamic variables to the freestore Example: StrigVar::~StrigVar( ) { delete [ ] value; } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-83

84 Poiters as Call-by-Value Parameters Usig poiters as call-by-value parameters yields results you might ot expect Remember that parameters are local variables No chage to the parameter should cause a chage to the argumet The value of the parameter is set to the value of the argumet (a address is stored i a poiter variable) The argumet ad the parameter hold the same address If the parameter is used to chage the value poited to, this is the same value poited to by the argumet! Display Display Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-84

85 Copy Costructors The problem with usig call-by-value parameters with poiter variables is solved by the copy costructor. A copy costructor is a costructor with oe parameter of the same type as the class The parameter is a call-by-referece parameter The parameter is usually a costat parameter The costructor creates a complete, idepedet copy of its argumet Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-85

86 StrigVar Copy Costructor This code for the StrigVar copy costructor Creates a ew dyamic array for a copy of the argumet Makig a ew copy, protects the origial from chages StrigVar::StrigVar(cost StrigVar& strig_object) : max_legth(strig_object.legth()) { value = ew char[max_legth+ 1]; strcpy(value, strig_object.value); } Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-86

87 Callig a Copy Costructor A copy costructor ca be called as ay other costructor whe declarig a object The copy costructor is called automatically Whe a class object is defied ad iitialized by a object of the same class Whe a fuctio returs a value of the class type Whe a argumet of the class type is plugged i for a call-by-value parameter Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-87

88 The Need For a Copy Costructor This code (assumig o copy costructor) illustrates the eed for a copy costructor void show_strig(strigvar the_strig) { } StrigVar greetig("hello"); show_strig(greetig); cout << greetig << edl; Whe fuctio show_strig is called, greetig is copied ito the_strig the_strig.value is set equal to greetig.value Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-88

89 The Need For a Copy Costructor (cot.) Sice greetig.value ad the_strig.value are poiters, they ow poit to the same dyamic array "Hello" greetig.value the_strig.value Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-89

90 The Need For a Copy Costructor (cot.) Whe show_strig eds, the destructor for the_strig executes, returig the dyamic array poited to by the_strig.value to the freestore Udefied greetig.value the_strig.value greetig.value ow poits to memory that has bee give back to the freestore! Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-90

91 The Need For a Copy Costructor (cot.) Two problems ow exist for object greetig Attemptig to output greetig.value is likely to produce a error I some istaces all could go OK Whe greetig goes out of scope, its destructor will be called Callig a destructor for the same locatio twice is likely to produce a system crashig error Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-91

92 Copy Costructor Demostratio Usig the same example, but with a copy costructor defied greetig.value ad the_strig.value poit to differet locatios i memory "Hello" "Hello" greetig.value the_strig.value Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-92

93 Copy Costructor Demostratio (cot.) Whe the_strig goes out of scope, the destructor is called, returig the_strig.value to the freestore "Hello" udefied greetig.value the_strig.value greetig.value still exists ad ca be accessed or deleted without problems Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-93

94 Whe To Iclude a Copy Costructor Whe a class defiitio ivolves poiters ad dyamically allocated memory usig "ew", iclude a copy costructor Classes that do ot ivolve poiters ad dyamically allocated memory do ot eed copy costructors Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-94

95 The Big Three The big three iclude The copy costructor The assigmet operator The destructor If you eed to defie oe, you eed to defie all Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-95

96 The Assigmet Operator Give these declaratios: StrigVar strig(10), strig2(20); the statemet strig1 = strig2; is legal But, sice StrigVar's member value is a poiter, we have strig1.value ad strig2.value poitig to the same memory locatio Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-96

97 Overloadig = The solutio is to overload the assigmet operator = so it works for StrigVar operator = is overloaded as a member fuctio Example: operator = declaratio void operator=(cost StrigVar& right_side); Right_side is the argumet from the right side of the = operator Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-97

98 Defiitio of = The defiitio of = for StrigVar could be: void StrigVar::operator= (cost StrigVar& right_side) { it ew_legth = strle(right_side.value); if (( ew_legth) > max_legth) ew_legth = max_legth; for(it i = 0; i < ew_legth; i++) value[i] = right_side.value[i]; } value[ew_legth] = '\0'; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-98

99 = Details This versio of = for StrigVar Compares the legths of the two StrigVar's Uses oly as may characters as fit i the left had StrigVar object Makes a idepedet copy of the right had object i the left had object Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide 11-99

100 Problems with = The defiitio of operator = has a problem Usually we wat a copy of the right had argumet regardless of its size To do this, we eed to delete the dyamic array i the left had argumet ad allocate a ew array large eough for the right had side's dyamic array The ext slide shows this (buggy) attempt at overloadig the assigmet operator Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

101 Aother Attempt at = void StrigVar::operator= (cost StrigVar& right_side) { delete [ ] value; it ew_legth = strle(right_side.value); max_legth = ew_legth; value = ew char[max_legth + 1]; for(it i = 0; i < ew_legth; i++) value[i] = right_side.value[i]; } value[ew_legth] = '\0'; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

102 A New Problem With = The ew defiitio of operator = has a problem What happes if we happe to have the same object o each side of the assigmet operator? my_strig = my_strig; This versio of operator = first deletes the dyamic array i the left had argumet. Sice the objects are the same object, there is o loger a array to copy from the right had side! Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

103 A Better = Operator void StrigVar::operator = (cost StrigVar& right_side) { it ew_legth = strle(right_side.value); if (ew_legth > max_legth) //delete value oly { // if more space delete [ ] value; // is eeded max_legth = ew_legth; value = ew char[max_legth + 1]; } } for (it I = 0; i< ew_legth; i++) value[i] = right_side.value[i]; value[ew_legth] = '\0'; Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

104 Sectio 11.4 Coclusio Ca you Explai why a overloaded assigmet operator is ot eeded whe the oly data cosist of built-i types? Explai what a destructor does? Explai whe a copy costructor is called? Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

105 Chapter Ed Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

106 Display 11.1 (1/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

107 Display 11.1 (2/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

108 Display 11.1 (3/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

109 Display 11.2 Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

110 Display 11.3 (1/5) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

111 Display 11.3 (2/5) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

112 Display 11.3 (3/5) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

113 Display 11.3 (4/5) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

114 Display 11.3 (5/5) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

115 Display 11.4 Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

116 Display 11.9 (1/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

117 Display 11.9 (2/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

118 Display 11.9 (3/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

119 Display (1/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

120 Display (2/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

121 Display (1/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

122 Display (2/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

123 Display (3/3) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

124 Display (1/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

125 Display (2/2) Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

126 Display Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

127 Display Back Next Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Slide

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then UCLA PIC 10 B Problem Solvig usig C++ Programmig Ivo Diov, Asst. Prof. i Mathematics, Neurology, Statistics Istructor: Teachig Assistat: Suzae Nezzar, Mathematics Chapter 13 Templates for More Abstractio

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 3 More Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 3.1 Usig Boolea Expressios 3.2 Multiway Braches 3.3 More about C++ Loop Statemets 3.4 Desigig Loops Copyright

More information

The Magma Database file formats

The Magma Database file formats The Magma Database file formats Adrew Gaylard, Bret Pikey, ad Mart-Mari Breedt Johaesburg, South Africa 15th May 2006 1 Summary Magma is a ope-source object database created by Chris Muller, of Kasas City,

More information

! Given the following Structure: ! We can define a pointer to a structure. ! Now studentptr points to the s1 structure.

! Given the following Structure: ! We can define a pointer to a structure. ! Now studentptr points to the s1 structure. Liked Lists Uit 5 Sectios 11.9 & 18.1-2 CS 2308 Fall 2018 Jill Seama 11.9: Poiters to Structures! Give the followig Structure: struct Studet { strig ame; // Studet s ame it idnum; // Studet ID umber it

More information

Examples and Applications of Binary Search

Examples and Applications of Binary Search Toy Gog ITEE Uiersity of Queeslad I the secod lecture last week we studied the biary search algorithm that soles the problem of determiig if a particular alue appears i a sorted list of iteger or ot. We

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle: Recursio Recursio Jordi Cortadella Departmet of Computer Sciece Priciple: Reduce a complex problem ito a simpler istace of the same problem Recursio Itroductio to Programmig Dept. CS, UPC 2 Mathematical

More information

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as a Itroductio to Objects ad Classes Overview 6.1 Streams ad Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams ad Basic File I/O I/O Streams I/O refers

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions: CS 604 Data Structures Midterm Sprig, 00 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Istructios: Prit your ame i the space provided below. This examiatio is closed book ad closed

More information

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming Lecture Notes 6 Itroductio to algorithm aalysis CSS 501 Data Structures ad Object-Orieted Programmig Readig for this lecture: Carrao, Chapter 10 To be covered i this lecture: Itroductio to algorithm aalysis

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

11.2. Overloading Operators

11.2. Overloading Operators 11.2 Overloading Operators Overloading Operators In the Money class, function add was used to add two objects of type Money In this section we see how to use the '+' operator to make the following code

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide CS11 Fall 003 Prelim Solutios ad Gradig Guide Problem 1: (a) obj = obj1; ILLEGAL because type of referece must always be a supertype of type of object (b) obj3 = obj1; ILLEGAL because type of referece

More information

6.854J / J Advanced Algorithms Fall 2008

6.854J / J Advanced Algorithms Fall 2008 MIT OpeCourseWare http://ocw.mit.edu 6.854J / 18.415J Advaced Algorithms Fall 2008 For iformatio about citig these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.415/6.854 Advaced Algorithms

More information

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows:

WORKED EXAMPLE 7.1. Producing a Mass Mailing. We want to automate the process of producing mass mailings. A typical letter might look as follows: Worked Example 7.1 Producig a Mass Mailig 1 WORKED EXAMPLE 7.1 Producig a Mass Mailig We wat to automate the process of producig mass mailigs. A typical letter might look as follows: To: Ms. Sally Smith

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig

More information

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types Aoucemets HW9 due today HW10 comig up, will post after class Team assigmet Data abstractio (types) ad cotrol abstractio (parameter passig) Due o Tuesday, November 27 th Last Class Types Type systems Type

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Ruig Time of a algorithm Ruig Time Upper Bouds Lower Bouds Examples Mathematical facts Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite

More information

Algorithm. Counting Sort Analysis of Algorithms

Algorithm. Counting Sort Analysis of Algorithms Algorithm Coutig Sort Aalysis of Algorithms Assumptios: records Coutig sort Each record cotais keys ad data All keys are i the rage of 1 to k Space The usorted list is stored i A, the sorted list will

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Cocurrecy Threads ad Cocurrecy i Java: Part 1 What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Threads ad Cocurrecy i Java: Part 1 1 Cocurrecy What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs What are we goig to lear? CSC316-003 Data Structures Aalysis of Algorithms Computer Sciece North Carolia State Uiversity Need to say that some algorithms are better tha others Criteria for evaluatio Structure

More information

Lecture 5. Counting Sort / Radix Sort

Lecture 5. Counting Sort / Radix Sort Lecture 5. Coutig Sort / Radix Sort T. H. Corme, C. E. Leiserso ad R. L. Rivest Itroductio to Algorithms, 3rd Editio, MIT Press, 2009 Sugkyukwa Uiversity Hyuseug Choo choo@skku.edu Copyright 2000-2018

More information

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions U.C. Berkeley CS170 : Algorithms Midterm 1 Solutios Lecturers: Sajam Garg ad Prasad Raghavedra Feb 1, 017 Midterm 1 Solutios 1. (4 poits) For the directed graph below, fid all the strogly coected compoets

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

The isoperimetric problem on the hypercube

The isoperimetric problem on the hypercube The isoperimetric problem o the hypercube Prepared by: Steve Butler November 2, 2005 1 The isoperimetric problem We will cosider the -dimesioal hypercube Q Recall that the hypercube Q is a graph whose

More information

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS APPLICATION NOTE PACE175AE BUILT-IN UNCTIONS About This Note This applicatio brief is iteded to explai ad demostrate the use of the special fuctios that are built ito the PACE175AE processor. These powerful

More information

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria.

Computer Science Foundation Exam. August 12, Computer Science. Section 1A. No Calculators! KEY. Solutions and Grading Criteria. Computer Sciece Foudatio Exam August, 005 Computer Sciece Sectio A No Calculators! Name: SSN: KEY Solutios ad Gradig Criteria Score: 50 I this sectio of the exam, there are four (4) problems. You must

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

EE123 Digital Signal Processing

EE123 Digital Signal Processing Last Time EE Digital Sigal Processig Lecture 7 Block Covolutio, Overlap ad Add, FFT Discrete Fourier Trasform Properties of the Liear covolutio through circular Today Liear covolutio with Overlap ad add

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway. Bjare Stroustrup www.stroustrup.com/programmig Chapter 5 Errors Abstract Whe we program, we have to deal with errors. Our most basic aim is correctess, but we must deal with icomplete problem specificatios,

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

Pattern Recognition Systems Lab 1 Least Mean Squares

Pattern Recognition Systems Lab 1 Least Mean Squares Patter Recogitio Systems Lab 1 Least Mea Squares 1. Objectives This laboratory work itroduces the OpeCV-based framework used throughout the course. I this assigmet a lie is fitted to a set of poits usig

More information

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8 The Implemetatio of Data Structures i Versio 5 of Ico* Ralph E. Gr is wo Id TR 85-8 April 1, 1985 Departmet of Computer Sciece The Uiversity of Arizoa Tucso. Arizoa 85721 This work was supported by the

More information

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer

DATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Data structures. Appetizer. Appetizer Data structures DATA STRUCTURES Static problems. Give a iput, produce a output. Ex. Sortig, FFT, edit distace, shortest paths, MST, max-flow,... amortized aalysis biomial heaps Fiboacci heaps uio-fid Dyamic

More information

Exercise 6 (Week 42) For the foreign students only.

Exercise 6 (Week 42) For the foreign students only. These are the last exercises of the course. Please, remember that to pass exercises, the sum of the poits gathered by solvig the questios ad attedig the exercise groups must be at least 4% ( poits) of

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes Prelimiaries Liked Lists public class StrageObject { Strig ame; StrageObject other; Arrays are ot always the optimal data structure: A array has fixed size eeds to be copied to expad its capacity Addig

More information

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS) CSC165H1, Witer 018 Learig Objectives By the ed of this worksheet, you will: Aalyse the ruig time of fuctios cotaiig ested loops. 1. Nested loop variatios. Each of the followig fuctios takes as iput a

More information

Guide to Applying Online

Guide to Applying Online Guide to Applyig Olie Itroductio Respodig to requests for additioal iformatio Reportig: submittig your moitorig or ed of grat Pledges: submittig your Itroductio This guide is to help charities submit their

More information

Homework 1 Solutions MA 522 Fall 2017

Homework 1 Solutions MA 522 Fall 2017 Homework 1 Solutios MA 5 Fall 017 1. Cosider the searchig problem: Iput A sequece of umbers A = [a 1,..., a ] ad a value v. Output A idex i such that v = A[i] or the special value NIL if v does ot appear

More information

Analysis of Algorithms

Analysis of Algorithms Presetatio for use with the textbook, Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Aalysis of Algorithms Iput 2015 Goodrich ad Tamassia Algorithm Aalysis of Algorithms

More information

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5 Morga Kaufma Publishers 26 February, 28 COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Chapter 5 Set-Associative Cache Architecture Performace Summary Whe CPU performace icreases:

More information

IMP: Superposer Integrated Morphometrics Package Superposition Tool

IMP: Superposer Integrated Morphometrics Package Superposition Tool IMP: Superposer Itegrated Morphometrics Package Superpositio Tool Programmig by: David Lieber ( 03) Caisius College 200 Mai St. Buffalo, NY 4208 Cocept by: H. David Sheets, Dept. of Physics, Caisius College

More information

UNIT 4C Iteration: Scalability & Big O. Efficiency

UNIT 4C Iteration: Scalability & Big O. Efficiency UNIT 4C Iteratio: Scalability & Big O 1 Efficiecy A computer program should be totally correct, but it should also execute as quickly as possible (time-efficiecy) use memory wisely (storage-efficiecy)

More information

CIS 121. Introduction to Trees

CIS 121. Introduction to Trees CIS 121 Itroductio to Trees 1 Tree ADT Tree defiitio q A tree is a set of odes which may be empty q If ot empty, the there is a distiguished ode r, called root ad zero or more o-empty subtrees T 1, T 2,

More information

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

More information

Term Project Report. This component works to detect gesture from the patient as a sign of emergency message and send it to the emergency manager.

Term Project Report. This component works to detect gesture from the patient as a sign of emergency message and send it to the emergency manager. CS2310 Fial Project Loghao Li Term Project Report Itroductio I this project, I worked o expadig exercise 4. What I focused o is makig the real gesture recogizig sesor ad desig proper gestures ad recogizig

More information

Message Integrity and Hash Functions. TELE3119: Week4

Message Integrity and Hash Functions. TELE3119: Week4 Message Itegrity ad Hash Fuctios TELE3119: Week4 Outlie Message Itegrity Hash fuctios ad applicatios Hash Structure Popular Hash fuctios 4-2 Message Itegrity Goal: itegrity (ot secrecy) Allows commuicatig

More information

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 3: ISA ad Itroductio to Microarchitecture Prof. Yajig Li Uiversity of Chicago Lecture Outlie ISA uarch (hardware implemetatio of a ISA) Logic desig basics Sigle-cycle

More information

One advantage that SONAR has over any other music-sequencing product I ve worked

One advantage that SONAR has over any other music-sequencing product I ve worked *gajedra* D:/Thomso_Learig_Projects/Garrigus_163132/z_productio/z_3B2_3D_files/Garrigus_163132_ch17.3d, 14/11/08/16:26:39, 16:26, page: 647 17 CAL 101 Oe advatage that SONAR has over ay other music-sequecig

More information

implement language system

implement language system Outlie Priciples of programmig laguages Lecture 3 http://few.vu.l/~silvis/ppl/2007 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia e-mail: silvis@few.vu.l

More information

Sorting 9/15/2009. Sorting Problem. Insertion Sort: Soundness. Insertion Sort. Insertion Sort: Running Time. Insertion Sort: Soundness

Sorting 9/15/2009. Sorting Problem. Insertion Sort: Soundness. Insertion Sort. Insertion Sort: Running Time. Insertion Sort: Soundness 9/5/009 Algorithms Sortig 3- Sortig Sortig Problem The Sortig Problem Istace: A sequece of umbers Objective: A permutatio (reorderig) such that a ' K a' a, K,a a ', K, a' of the iput sequece The umbers

More information

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering EE 4363 1 Uiversity of Miesota Midterm Exam #1 Prof. Matthew O'Keefe TA: Eric Seppae Departmet of Electrical ad Computer Egieerig Uiversity of Miesota Twi Cities Campus EE 4363 Itroductio to Microprocessors

More information

Parabolic Path to a Best Best-Fit Line:

Parabolic Path to a Best Best-Fit Line: Studet Activity : Fidig the Least Squares Regressio Lie By Explorig the Relatioship betwee Slope ad Residuals Objective: How does oe determie a best best-fit lie for a set of data? Eyeballig it may be

More information

ENGI 4421 Probability and Statistics Faculty of Engineering and Applied Science Problem Set 1 Descriptive Statistics

ENGI 4421 Probability and Statistics Faculty of Engineering and Applied Science Problem Set 1 Descriptive Statistics ENGI 44 Probability ad Statistics Faculty of Egieerig ad Applied Sciece Problem Set Descriptive Statistics. If, i the set of values {,, 3, 4, 5, 6, 7 } a error causes the value 5 to be replaced by 50,

More information

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

The number n of subintervals times the length h of subintervals gives length of interval (b-a). Simulator with MadMath Kit: Riema Sums (Teacher s pages) I your kit: 1. GeoGebra file: Ready-to-use projector sized simulator: RiemaSumMM.ggb 2. RiemaSumMM.pdf (this file) ad RiemaSumMMEd.pdf (educator's

More information

Oracle Server. What s New in this Release? Release Notes

Oracle  Server. What s New in this Release? Release Notes Oracle email Server Release Notes Release 5.2 for Widows NT May 2001 Part No. A90426-01 These release otes accompay Oracle email Server Release 5.2 for Widows NT. They cotai the followig topics: What s

More information

Module 8-7: Pascal s Triangle and the Binomial Theorem

Module 8-7: Pascal s Triangle and the Binomial Theorem Module 8-7: Pascal s Triagle ad the Biomial Theorem Gregory V. Bard April 5, 017 A Note about Notatio Just to recall, all of the followig mea the same thig: ( 7 7C 4 C4 7 7C4 5 4 ad they are (all proouced

More information

Behavioral Modeling in Verilog

Behavioral Modeling in Verilog Behavioral Modelig i Verilog COE 202 Digital Logic Desig Dr. Muhamed Mudawar Kig Fahd Uiversity of Petroleum ad Mierals Presetatio Outlie Itroductio to Dataflow ad Behavioral Modelig Verilog Operators

More information

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1

CS200: Hash Tables. Prichard Ch CS200 - Hash Tables 1 CS200: Hash Tables Prichard Ch. 13.2 CS200 - Hash Tables 1 Table Implemetatios: average cases Search Add Remove Sorted array-based Usorted array-based Balaced Search Trees O(log ) O() O() O() O(1) O()

More information

Sub-Exponential Algorithms for 0/1 Knapsack and Bin Packing

Sub-Exponential Algorithms for 0/1 Knapsack and Bin Packing Sub-Expoetial Algorithms for 0/1 Kapsack ad Bi Packig Thomas E. O Neil Computer Sciece Departmet Uiversity of North Dakota Grad Forks, ND, USA 58202-9015 Abstract - This paper presets simple algorithms

More information