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

Size: px
Start display at page:

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

Transcription

1

2 Chapter 8 Strigs ad Vectors

3 Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3

4 8.1 A Array Type for Strigs

5 A Array Type for Strigs C-strigs ca be used to represet strigs of characters C-strigs are stored as arrays of characters C-strigs use the ull character '\0' to ed a strig The Null character is a sigle character To declare a C-strig variable, declare a array of characters: char s[11]; Slide 8-5

6 C-strig Details Declarig a C-strig as char s[10] creates space for oly ie characters The ull character termiator requires oe space A C-strig variable does ot eed a size variable The ull character immediately follows the last character of the strig Example: s[0] s[1] s[2] s[3] s[4] s[5] s[6] s[7] s[8] s[9] H i M o m! \0?? Slide 8-6

7 C-strig Declaratio To declare a C-strig variable, use the sytax: char Array_ame[ Maximum_C_Strig_Size + 1]; + 1 reserves the additioal character eeded by '\0' Slide 8-7

8 Iitializig a C-strig To iitialize a C-strig durig declaratio: char my_message[20] = "Hi there."; The ull character '\0' is added for you Aother alterative: char short_strig[ ] = "abc"; but ot this: char short_strig[ ] = {'a', 'b', 'c'}; Slide 8-8

9 C-strig error This attempt to iitialize a C-strig does ot cause the \0 to be iserted i the array char short_strig[ ] = {'a', 'b', 'c'}; Slide 8-9

10 Do't Chage '\0' Do ot to replace the ull character whe maipulatig idexed variables i a C-strig If the ull character is lost, the array caot act like a C-strig Example: it idex = 0; while (our_strig[idex]!= '\0') { our_strig[idex] = 'X'; idex++; } This code depeds o fidig the ull character! Slide 8-10

11 Safer Processig of C-strigs The loop o the previous slide depeded o fidig the '\0' character It would be wiser to use this versio i case the '\0' character had bee removed it idex = 0; while (our_strig[idex]!= '\0' && idex < SIZE) { our_strig[idex] = 'X'; idex++; } Slide 8-11

12 Assigmet With C-strigs This statemet is illegal: a_strig = "Hello"; This is a assigmet statemet, ot a iitializatio The assigmet operator does ot work with C-strigs Slide 8-12

13 Assigmet of C-strigs A commo method to assig a value to a C-strig variable is to use strcpy, defied i the cstrig library Example: #iclude <cstrig> char a_strig[ 11]; strcpy (a_strig, "Hello"); Places "Hello" followed by the ull character i a_strig Slide 8-13

14 A Problem With strcpy strcpy ca create problems if ot used carefully strcpy does ot check the declared legth of the first argumet It is possible for strcpy to write characters beyod the declared size of the array Slide 8-14

15 A Solutio for strcpy May versios of C++ have a safer versio of strcpy amed strcpy strcpy uses a third argumet represetig the maximum umber of characters to copy Example: char aother_strig[10]; strcpy(aother_strig, a_strig_variable, 9); This code copies up to 9 characters ito aother_strig, leavig oe space for '\0' Slide 8-15

16 == Alterative for C-strigs The == operator does ot work as expected with C-strigs The predefied fuctio strcmp is used to compare C- strig variables Example: #iclude <cstrig> if (strcmp(c_strig1, c_strig2)) cout << "Strigs are ot the same."; else cout << "Strig are the same."; Slide 8-16

17 strcmp's logic strcmp compares the umeric codes of elemets i the C-strigs a character at a time If the two C-strigs are the same, strcmp returs 0 0 is iterpreted as false As soo as the characters do ot match strcmp returs a egative value if the umeric code i the first parameter is less strcmp returs a positive value if the umeric code i the secod parameter is less No-zero values are iterpreted as true Slide 8-17

18 More C-strig Fuctios The cstrig library icludes other fuctios strle returs the umber of characters i a strig it x = strle( a_strig); strcat cocateates two C-strigs The secod argumet is added to the ed of the first The result is placed i the first argumet Example: char strig_var[20] = "The rai"; strcat(strig_var, "i Spai"); Now strig_var cotais "The raii Spai" Slide 8-18

19 The strcat Fuctio strcat is a safer versio of strcat A third parameter specifies a limit for the umber of characters to cocateate Example: char strig_var[20] = "The rai"; strcat(strig_var, "i Spai", 11); Display 8.1 (1) Display 8.1 (2) Slide 8-19

20 C-strigs as Argumets ad Parameters C-strig variables are arrays C-strig argumets ad parameters are used just like arrays If a fuctio chages the value of a C-strig parameter, it is best to iclude a parameter for the declared size of the C-strig If a fuctio does ot chage the value of a C-strig parameter, the ull character ca detect the ed of the strig ad o size argumet is eeded Slide 8-20

21 C-strig Output C-strigs ca be output with the isertio operator Example: char ews[ ] = "C-strigs"; cout << ews << " Wow." << edl; Slide 8-21

22 C-strig Iput The extractio operator >> ca fill a C-strig Whitespace eds readig of data Example: char a[80], b[80]; cout << "Eter iput: " << edl; ci >> a >> b; cout << a << b << "Ed of Output"; could produce: Eter iput: Do be do to you! DobeEd of Output Slide 8-22

23 Readig a Etire Lie Predefied member fuctio getlie ca read a etire lie, icludig spaces getlie is a member of all iput streams getlie has two argumets The first is a C-strig variable to receive iput The secod is a iteger, usually the size of the first argumet specifyig the maximum umber of elemets i the first argumet getlie is allowed to fill Slide 8-23

24 Usig getlie The followig code is used to read a etire lie icludig spaces ito a sigle C-strig variable char a[80]; cout << "Eter iput:\"; ci.getlie(a, 80); cout << a << Ed Of Output\"; ad could produce: Eter some iput: Do be do to you! Do be do to you!ed of Output Slide 8-24

25 getlie wrap up getlie stops readig whe the umber of characters, less oe, specified i the secod argumet have bee placed i the C-strig oe character is reserved for the ull character getlie stops eve if the ed of the lie has ot bee reached Slide 8-25

26 getlie ad Files C-strig iput ad output work the same way with file streams Replace ci with the ame of a iput-file stream i_stream >> c_strig; i_stream.getlie(c_strig, 80); Replace cout with the ame of a output-file stream out_stream << c_strig; Slide 8-26

27 getlie sytax Sytax for usig getlie is ci.getlie(strig_var, Max_Characters + 1); ci ca be replaced by ay iput stream Max_Characters + 1 reserves oe elemet for the ull character Slide 8-27

28 C-Strig to Numbers "1234" is a strig of characters 1234 is a umber Whe doig umeric iput, it is useful to read iput as a strig of characters, the covert the strig to a umber Readig moey may ivolve a dollar sig Readig percetages may ivolve a percet sig Slide 8-28

29 C-strigs to Itegers To read a iteger as characters Read iput as characters ito a C-strig, removig uwated characters Use the predefied fuctio atoi to covert the C-strig to a it value Example: atoi("1234") returs the iteger 1234 atoi("#123") returs 0 because # is ot a digit Slide 8-29

30 C-strig to log Larger itegers ca be coverted usig the predefied fuctio atol atol returs a value of type log Slide 8-30

31 C-strig to double C-strigs ca be coverted to type double usig the predefied fuctio atof atof returs a value of type double Example: atof("9.99") returs 9.99 atof("$9.99") returs 0.0 because the $ is ot a digit Slide 8-31

32 Library cstdlib The coversio fuctios atoi atol atof are foud i the library cstdlib To use the fuctios use the iclude directive #iclude <cstdlib> Slide 8-32

33 Numeric Iput We ow kow how to covert C-strigs to umbers How do we read the iput? Fuctio read_ad_clea, i Display 8.2 Reads a lie of iput Discards all characters other tha the digits '0' through '9' Uses atoi to covert the "cleaed-up" C-strig to it Display 8.2 (1) Display 8.2 (2) Slide 8-33

34 Cofirmig Iput Fuctio get_it, from Display 8.3 Uses read_ad_clea to read the user's iput Allows the user to reeter the iput util the user is satisfied with the umber computed from the iput strig Display 8.3 (1) Display 8.3 (2) Slide 8-34

35 Sectio 8.1 Coclusio Ca you Describe the beefits of readig umeric data as characters before covertig the characters to a umber? Write code to do iput ad output with C-strigs? Use the atoi, atol, ad atof fuctios? Idetify the character that eds a C-strig? Slide 8-35

36 8.2 The Stadard strig Class

37 The Stadard strig Class The strig class allows the programmer to treat strigs as a basic data type No eed to deal with the implemetatio as with C-strigs The strig class is defied i the strig library ad the ames are i the stadard amespace To use the strig class you eed these lies: #iclude <strig> usig amespace std; Slide 8-37

38 The Stadard strig Class Slide 1-38

39 Assigmet of Strigs Variables of type strig ca be assiged with the = operator Example: strig s1, s2, s3; s3 = s2; Quoted strigs are type cast to type strig Example: strig s1 = "Hello Mom!"; Slide 8-39

40 Usig + With strigs Variables of type strig ca be cocateated with the + operator Example: strig s1, s2, s3; s3 = s1 + s2; If s3 is ot large eough to cotai s1 + s2, more space is allocated Slide 8-40

41 strig Costructors The default strig costructor iitializes the strig to the empty strig Aother strig costructor takes a C-strig argumet Example: strig phrase; // empty strig strig ou("ats"); // a strig versio // of "ats" Slide 8-41

42 Mixig strigs ad C-strigs It is atural to work with strigs i the followig maer strig phrase = "I love" + adjective + " " + ou + "!"; It is ot so easy for C++! It must either covert the ull-termiated C-strigs, such as "I love", to strigs, or it must use a overloaded + operator that works with strigs ad C-strigs Display 8.4 Slide 8-42

43 I/O With Class strig The isertio operator << is used to output objects of type strig Example: strig s = "Hello Mom!"; cout << s; The extractio operator >> ca be used to iput data for objects of type strig Example: strig s1; ci >> s1; >> skips whitespace ad stops o ecouterig more whitespace Slide 8-43

44 getlie ad Type strig A getlie fuctio exists to read etire lies ito a strig variable This versio of getlie is ot a member of the istream class, it is a o-member fuctio Sytax for usig this getlie is differet tha that used with ci: ci.getlie( ) Sytax for usig getlie with strig objects: getlie(istream_object, Strig_Object); Slide 8-44

45 getlie Example This code demostrates the use of getlie with strig objects strig lie; cout "Eter a lie of iput:\"; getlie(ci, lie); cout << lie << "END OF OUTPUT\"; Output could be: Eter some iput: Do be do to you! Do be do to you!end OF OUTPUT Slide 8-45

46 Character Iput With strigs The extractio operator caot be used to read a blak character To read oe character at a time remember to use ci.get ci.get reads values of type char, ot type strig The use of getlie, ad ci.get for strig iput are demostrated i Display 8.5 (1) Display 8.5 (2) Slide 8-46

47 Aother Versio of getlie The versios of getlie we have see, stop readig at the ed of lie marker '\' getlie ca stop readig at a character specified i the argumet list This code stops readig whe a '?' is read strig lie; cout <<"Eter some iput: \"; getlie(ci, lie, '?'); Slide 8-47

48 getlie Returs a Referece getlie returs a referece to its first argumet This code will read i a lie of text ito s1 ad a strig of o-whitespace characters ito s2: strig s1, s2; getlie(ci, s1) >> s2; returs ci >> s2; Slide 8-48

49 getlie Declaratios These are the declaratios of the versios of getlie for strig objects we have see istream& getlie(istream& is, strig& str_var, char delimiter); istream& getlie(istream& is, strig& str_var); Slide 8-49

50 Mixig ci >> ad getlie Recall ci >> skips whitespace to fid what it is to read the stops readig whe whitespace is foud ci >> leaves the '\' character i the iput stream Example: it ; strig lie; ci >> ; getlie(ci, lie); leaves the '\' which immediately eds getlie's readig lie is set equal to the empty strig Slide 8-50

51 igore igore is a member of the istream class igore ca be used to read ad discard all the characters, icludig '\' that remai i a lie Igore takes two argumets First, the maximum umber of characters to discard Secod, the character that stops readig ad discardig Example: ci.igore(1000, '\'); reads up to 1000 characters or to '\' Slide 8-51

52 Strig Processig The strig class allows the same operatios we used with C-strigs ad more Characters i a strig object ca be accessed as if they are i a array last_ame[i] provides access to a sigle character as i a array Idex values are ot checked for validity! Display 8.6 Slide 8-52

53 Member Fuctio legth The strig class member fuctio legth returs the umber of characters i the strig object: Example: it = strig_var.legth( ); Slide 8-53

54 Member Fuctio at at is a alterative to usig [ ]'s to access characters i a strig. at checks for valid idex values Example: strig str("mary"); Equivalet cout << str[6] << edl; cout << str.at(6) << edl; Equivalet str[2] = 'X'; str.at(2) = 'X'; Other strig class fuctios are foud i Display 8.7 Slide 8-54

55 strig class to umbers C++11 has ew fuctios to covert a strig class object to a umber it i; double d; strig s; i = stoi("35"); // Coverts the strig "35" to a iteger 35 d = stod("2.5"); // Coverts the strig "2.5" to the double 2.5 C++11 has ew fuctios to covert a strig class object to a umber strig s = to_strig(1.2*2); // 2.4 stored i s Slide 1-55

56 Compariso of strigs Compariso operators work with strig objects Objects are compared usig lexicographic order (Alphabetical orderig usig the order of symbols i the ASCII character set.) == returs true if two strig objects cotai the same characters i the same order Remember strcmp for C-strigs? <, >, <=, >= ca be used to compare strig objects Slide 8-56

57 Program Example: Palidrome Testig A palidrome is a strig that reads the same from frot to back as it does from back to frot This program igores spaces ad puctuatio Upper ad lowercase versios of letters are cosidered the same letter Examples: Able was I 'ere I saw Elba. Madam, I'm Adam. A ma, a pla, a caal, Paama. Racecar Slide 8-57

58 Palidrome Testig: remove_puct remove_puct removes puctuatio from a strig remove_puct compares each character i the strig to the characters i a strig cotaiig all the puctuatio characters ad the space character. If a match is ot foud, the character is added to the strig o_puct o_puct, the origial strig less ay puctuatio or spaces, is retured Slide 8-58

59 Palidrome Testig: substr The substr member fuctio is used to locate a substrig withi a strig remove_puct uses substr to extract a sigle character at a time from the source strig. The character is stored i a_char. remove_puct the uses fuctio fid to see if the character i a_char is i the strig of puctuatio characters Slide 8-59

60 Palidrome Testig: The Program The etire palidrome testig program is foud i Display 8.8 (1) Display 8.8 (2) Display 8.8 (3) Display 8.8 (4) Slide 8-60

61 Display 8.8 (1/4) Back Next Slide 8-61

62 Display 8.8 (2/4) Back Next Slide 8-62

63 Display 8.8 (3/4) Back Next Slide 8-63

64 Display 8.8 (4/4) Back Next Slide 8-64

65 strig Objects to C-strigs Recall the automatic coversio from C-strig to strig: char a_c_strig[] = "C-strig"; strig_variable = a_c_strig; strigs are ot coverted to C-strigs Both of these statemets are illegal: a_c_strig = strig_variable; strcpy(a_c_strig, strig_variable); Slide 8-65

66 Covertig strigs to C-strigs The strig class member fuctio c_str returs the C-strig versio of a strig object Example: strcpy(a_c_strig, strig_variable.c_str( ) ); This lie is still illegal a_c_strig = strig_variable.c_str( ) ; Recall that operator = does ot work with C- strigs Slide 8-66

67 Sectio 8.2 Coclusio Ca you Show how a strig object ca be used like a C-strig? Write code to read a etire lie ito a strig object? Use the strig fuctio at to access idividual characters i a strig object? Write code to covert a strig to a C-strig? Slide 8-67

68 8.3 Vectors

69 Vectors Vectors are like arrays that ca chage size as your program rus Vectors, like arrays, have a base type To declare a empty vector with base type it: vector<it> v; <it> idetifies vector as a template class You ca use ay base type i a template class: vector<strig> v; Slide 8-69

70 Accessig vector Elemets Vectors elemets are idexed startig with 0 [ ]'s are used to read or chage the value of a item: v[i] = 42; cout << v[i]; [ ]'s caot be used to iitialize a vector elemet Slide 8-70

71 Vector i memory Slide 1-71

72 Iitializig vector Elemets Elemets are added to a vector usig the member fuctio push_back push_back adds a elemet i the ext available positio Example: vector<double> sample; sample.push_back(0.0); sample.push_back(1.1); sample.push_back(2.2); Slide 8-72

73 The size Of A vector The member fuctio size returs the umber of elemets i a vector Example: To prit each elemet of a vector give the previous vector iitializatio: for (it i= 0; i < sample.size( ); i++) cout << sample[i] << edl; Slide 8-73

74 The Type usiged it The vector class member fuctio size returs a usiged it Usiged it's are oegative itegers Some compilers will give a warig if the previous for-loop is ot chaged to: for (usiged it i= 0; i < sample.size( ); i++) cout << sample[i] << edl; Slide 8-74

75 Alterate vector Iitializatio A vector costructor exists that takes a iteger argumet ad iitializes that umber of elemets Example: vector<it> v(10); iitializes the first 10 elemets to 0 v.size( ) would retur 10 [ ]'s ca ow be used to assig elemets 0 through 9 push_back is used to assig elemets greater tha 9 Slide 8-75

76 Vector Iitializatio With Classes The vector costructor with a iteger argumet Iitializes elemets of umber types to zero Iitializes elemets of class types usig the default costructor for the class Slide 8-76

77 The vector Library To use the vector class Iclude the vector library #iclude <vector> Vector ames are placed i the stadard amespace so the usual usig directive is eeded: usig amespace std; Display 8.9 Slide 8-77

78 vector Issues Attemptig to use [ ] to set a value beyod the size of a vector may ot geerate a error The program will probably misbehave The assigmet operator with vectors does a elemet by elemet copy of the right had vector For class types, the assigmet operator must make idepedet copies Slide 8-78

79 vector Efficiecy A vector's capacity is the umber of elemets allocated i memory Accessible usig the capacity( ) member fuctio Size is the umber of elemets iitialized Whe a vector rus out of space, the capacity is automatically icreased A commo scheme is to double the size of a vector More efficiet tha allocatig smaller chuks of memory Slide 8-79

80 Cotrollig vector Capacity Whe efficiecy is a issue Member fuctio reserve ca icrease the capacity of a vector Example: v.reserve(32); // at least 32 elemets v.reserve(v.size( ) + 10); // at least 10 more resize ca be used to shrik a vector Example: v.resize(24); //elemets beyod 24 are lost Slide 8-80

81 Sectio 8.3 Coclusio Ca you Declare ad iitialize a vector of 10 doubles? Write code to icrease the size of a vector i at least two differet ways? Describe the differece betwee a vector's size ad its capacity? Slide 8-81

82 Chapter 8 -- Ed Slide 8-82

83 Display 8.1 (1/2) Back Next Slide 8-83

84 Display 8.1 (2/2) Back Next Slide 8-84

85 Display 8.2 (1/2) Back Next Slide 8-85

86 Display 8.2 (2/2) Back Next Slide 8-86

87 Display 8.3 (1/3) Back Next Slide 8-87

88 Display 8.3 (2/3) Back Next Slide 8-88

89 Display 8.3 (3/3) Back Next Slide 8-89

90 Display 8.4 Back Next Slide 8-90

91 Display 8.5 (1/2) Back Next Slide 8-91

92 Display 8.5 (2/2) Back Next Slide 8-92

93 Display 8.6 Back Next Slide 8-93

94 Display 8.7 Back Next Slide 8-94

95 Display 8.9 Back Next Slide 8-95

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

Copyright 2003 Pearson Education, Inc. Slide 1

Copyright 2003 Pearson Education, Inc. Slide 1 Copyright 2003 Pearson Education, Inc. Slide 1 Chapter 11 Strings and Vectors Created by David Mann, North Idaho College Copyright 2003 Pearson Education, Inc. Slide 2 Overview An Array Type for Strings

More information

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

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

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 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

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

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

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

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

In this chapter, you will learn about: An Array Type for Strings. The Standard string Class. Vectors. Introduction Computer Science 1 CS 23021

In this chapter, you will learn about: An Array Type for Strings. The Standard string Class. Vectors. Introduction Computer Science 1 CS 23021 Chapter 8 In this chapter, you will learn about: An Array Type for Strings The Standard string Class Vectors The C Language Representation of Strings (C-Strings) The C-String Variable: Array of Characters

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

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

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

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

. 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

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

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

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

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

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

! 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

n n B. How many subsets of C are there of cardinality n. We are selecting elements for such a

n n B. How many subsets of C are there of cardinality n. We are selecting elements for such a 4. [10] Usig a combiatorial argumet, prove that for 1: = 0 = Let A ad B be disjoit sets of cardiality each ad C = A B. How may subsets of C are there of cardiality. We are selectig elemets for such a subset

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

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

CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++

CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++ Brad Rippe CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++ String and Vectors Overview 8.1 An Array Type for Strings 8.2 The Standard string Class 8.3 Vectors An Array Type for Strings 8.1 An Array

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

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

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

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

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

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

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

Package RcppRoll. December 22, 2014

Package RcppRoll. December 22, 2014 Type Package Package RcppRoll December 22, 2014 Title Fast rollig fuctios through Rcpp ad RcppArmadillo Versio 0.1.0 Date 2013-01-10 Author Kevi Ushey Maitaier Kevi Ushey RcppRoll

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

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

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

Lecture 28: Data Link Layer

Lecture 28: Data Link Layer Automatic Repeat Request (ARQ) 2. Go ack N ARQ Although the Stop ad Wait ARQ is very simple, you ca easily show that it has very the low efficiecy. The low efficiecy comes from the fact that the trasmittig

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

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

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method A ew Morphological 3D Shape Decompositio: Grayscale Iterframe Iterpolatio Method D.. Vizireau Politehica Uiversity Bucharest, Romaia ae@comm.pub.ro R. M. Udrea Politehica Uiversity Bucharest, Romaia mihea@comm.pub.ro

More information

CSE 417: Algorithms and Computational Complexity

CSE 417: Algorithms and Computational Complexity Time CSE 47: Algorithms ad Computatioal Readig assigmet Read Chapter of The ALGORITHM Desig Maual Aalysis & Sortig Autum 00 Paul Beame aalysis Problem size Worst-case complexity: max # steps algorithm

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

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

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

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004

The Open University, Walton Hall, Milton Keynes, MK7 6AA First published 2004 8 Programs ad data This publicatio forms part of a Ope Uiversity course M150 Data, Computig ad Iformatio. Details of this ad other Ope Uiversity courses ca be obtaied from the Course Iformatio ad Advice

More information

Computational Geometry

Computational Geometry Computatioal Geometry Chapter 4 Liear programmig Duality Smallest eclosig disk O the Ageda Liear Programmig Slides courtesy of Craig Gotsma 4. 4. Liear Programmig - Example Defie: (amout amout cosumed

More information

Overview. Common tasks. Observation. Chapter 20 The STL (containers, iterators, and algorithms) 8/13/18. Bjarne Stroustrup

Overview. Common tasks. Observation. Chapter 20 The STL (containers, iterators, and algorithms) 8/13/18. Bjarne Stroustrup Overview Chapter 20 The STL (cotaiers, iterators, ad algorithms) Bjare Stroustrup www.stroustrup.com/programmig Commo tasks ad ideals Geeric programmig Cotaiers, algorithms, ad iterators The simplest algorithm:

More information

Graphs. Minimum Spanning Trees. Slides by Rose Hoberman (CMU)

Graphs. Minimum Spanning Trees. Slides by Rose Hoberman (CMU) Graphs Miimum Spaig Trees Slides by Rose Hoberma (CMU) Problem: Layig Telephoe Wire Cetral office 2 Wirig: Naïve Approach Cetral office Expesive! 3 Wirig: Better Approach Cetral office Miimize the total

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

Lecture 7 7 Refraction and Snell s Law Reading Assignment: Read Kipnis Chapter 4 Refraction of Light, Section III, IV

Lecture 7 7 Refraction and Snell s Law Reading Assignment: Read Kipnis Chapter 4 Refraction of Light, Section III, IV Lecture 7 7 Refractio ad Sell s Law Readig Assigmet: Read Kipis Chapter 4 Refractio of Light, Sectio III, IV 7. History I Eglish-speakig coutries, the law of refractio is kow as Sell s Law, after the Dutch

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

27 Refraction, Dispersion, Internal Reflection

27 Refraction, Dispersion, Internal Reflection Chapter 7 Refractio, Dispersio, Iteral Reflectio 7 Refractio, Dispersio, Iteral Reflectio Whe we talked about thi film iterferece, we said that whe light ecouters a smooth iterface betwee two trasparet

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

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

On (K t e)-saturated Graphs

On (K t e)-saturated Graphs Noame mauscript No. (will be iserted by the editor O (K t e-saturated Graphs Jessica Fuller Roald J. Gould the date of receipt ad acceptace should be iserted later Abstract Give a graph H, we say a graph

More information

ECE4050 Data Structures and Algorithms. Lecture 6: Searching

ECE4050 Data Structures and Algorithms. Lecture 6: Searching ECE4050 Data Structures ad Algorithms Lecture 6: Searchig 1 Search Give: Distict keys k 1, k 2,, k ad collectio L of records of the form (k 1, I 1 ), (k 2, I 2 ),, (k, I ) where I j is the iformatio associated

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 19 Query Optimizatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Query optimizatio Coducted by a query optimizer i a DBMS Goal:

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

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov

Sorting in Linear Time. Data Structures and Algorithms Andrei Bulatov Sortig i Liear Time Data Structures ad Algorithms Adrei Bulatov Algorithms Sortig i Liear Time 7-2 Compariso Sorts The oly test that all the algorithms we have cosidered so far is compariso The oly iformatio

More information

5.3 Recursive definitions and structural induction

5.3 Recursive definitions and structural induction /8/05 5.3 Recursive defiitios ad structural iductio CSE03 Discrete Computatioal Structures Lecture 6 A recursively defied picture Recursive defiitios e sequece of powers of is give by a = for =0,,, Ca

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

Getting Started. Getting Started - 1

Getting Started. Getting Started - 1 Gettig Started Gettig Started - 1 Issue 1 Overview of Gettig Started Overview of Gettig Started This sectio explais the basic operatios of the AUDIX system. It describes how to: Log i ad log out of the

More information

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns K-NET bus The K-Net bus is based o the SPI bus but it allows to addressig may differet turrets like the I 2 C bus. The K-Net is 6 a wires bus (4 for SPI wires ad 2 additioal wires for request ad ackowledge

More information

Data Structures and Algorithms Part 1.4

Data Structures and Algorithms Part 1.4 1 Data Structures ad Algorithms Part 1.4 Werer Nutt 2 DSA, Part 1: Itroductio, syllabus, orgaisatio Algorithms Recursio (priciple, trace, factorial, Fiboacci) Sortig (bubble, isertio, selectio) 3 Sortig

More information

CSE 111 Bio: Program Design I Class 11: loops

CSE 111 Bio: Program Design I Class 11: loops SE 111 Bio: Program Desig I lass 11: loops Radall Muroe, xkcd.com/1411/ Robert H. Sloa (S) & Rachel Poretsky (Bio) Uiversity of Illiois, hicago October 2, 2016 Pytho ets Loopy! he Pytho, Busch ardes Florida

More information

3. b. Present a combinatorial argument that for all positive integers n : : 2 n

3. b. Present a combinatorial argument that for all positive integers n : : 2 n . b. Preset a combiatorial argumet that for all positive itegers : : Cosider two distict sets A ad B each of size. Sice they are distict, the cardiality of A B is. The umber of ways of choosig a pair of

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

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

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

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016 CS 111: Program Desig I Lecture 15: Objects, Padas, Modules Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 13, 2016 OBJECTS AND DOT NOTATION Objects (Implicit i Chapter 2, Variables,

More information

Lecture 9: Exam I Review

Lecture 9: Exam I Review CS 111 (Law): Program Desig I Lecture 9: Exam I Review Robert H. Sloa & Richard Warer Uiversity of Illiois, Chicago September 22, 2016 This Class Discuss midterm topics Go over practice examples Aswer

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

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70 NOTE:. Attempt all seve questios. Major CSL 02 2. Write your ame ad etry o o every sheet of the aswer script. Time 2 Hrs Max Marks 70 Q No Q Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Total MM 6 2 4 0 8 4 6 70 Q. Write a

More information

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server:

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server: 3 Usig MySQL Programs This chapter provides a brief overview of the programs provided by MySQL AB ad discusses how to specify optios whe you ru these programs. Most programs have optios that are specific

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

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

why study sorting? Sorting is a classic subject in computer science. There are three reasons for studying sorting algorithms.

why study sorting? Sorting is a classic subject in computer science. There are three reasons for studying sorting algorithms. Chapter 5 Sortig IST311 - CIS65/506 Clevelad State Uiversity Prof. Victor Matos Adapted from: Itroductio to Java Programmig: Comprehesive Versio, Eighth Editio by Y. Daiel Liag why study sortig? Sortig

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

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

Heaps. 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, 201 Heaps 201 Goodrich ad Tamassia xkcd. http://xkcd.com/83/. Tree. Used with permissio uder

More information