3 Pages

34S-CS106X-Practice-Key

Course: CS 106X, Winter 2010
School: Stanford
Rating:
 
 
 
 
 

Word Count: 736

Document Preview

34S February CS106X Handout 25th, 2011 Winter 2011 CS106B Practice Solution Solution 1: Linked Lists a. Map<string> concatenateMaps(node *maplist) { Set<string> keys; for (node *curr = maplist; curr != NULL; curr = curr->next) { foreach (string key in curr->map) { keys.add(key); } } Map<string> concatenations; foreach (string key in keys) { string value;...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> Stanford >> CS 106X

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
34S February CS106X Handout 25th, 2011 Winter 2011 CS106B Practice Solution Solution 1: Linked Lists a. Map<string> concatenateMaps(node *maplist) { Set<string> keys; for (node *curr = maplist; curr != NULL; curr = curr->next) { foreach (string key in curr->map) { keys.add(key); } } Map<string> concatenations; foreach (string key in keys) { string value; for (node *curr = maplist; curr != NULL; curr = curr->next) { if (curr->map.containsKey(key)) { value += curr->map.get(key); } } concatenations.put(key, value); } return concatenations; } b. void stretchList(node *list) { int copyCount = 1; while (list != NULL) { for (int i = 0; i < copyCount; i++) { node *newNode = new node; newNode->value = list->value; newNode->next = list->next; list->next = newNode; list = newNode; } list = list->next; copyCount++; } } 2 c. void BuildSeriallzationArray(node *list, Vector<int>& values) { if (list == NULL) return; values.add(list->value); BuildSeriallzationArray(list->down, values); BuildSeriallzationArray(list->next, values); } node *ArrayToList(Vector<int>& values) { node *head = NULL; for (int i = values.size() 1; i >= 0; i--) { node *newNode = new node; newNode->value = values[i]; newNode->down = NULL; newNode->next = head; head = newNode; } return head; } node *flattenList(node *list) { Vector<int> values; BuildSeriallzationArray(list, values); return ArrayToList(values); } Solution 2: Planetarium Memory Trace 93.1 venus mars 3 Solution 3: Encoding General Trees struct genTreeNode { int value; Vector<genTreeNode *> children; }; struct binTreeNode { int value; binTreeNode *left; binTreeNode *right; }; binTreeNode *encode(Vector<genTreeNode *>& siblings, int start) { if (start == siblings.size()) return NULL; binTreeNode *root = new binTreeNode; root->value = siblings[start]->value; root->left = encode(siblings[start]->children, 0); root->right = encode(siblings, start + 1); return root; } binTreeNode *encode(genTreeNode *root) { Vector<genTreeNode *> rootAsVector; rootAsVector.add(root); return encode(rootAsVector, 0); } Solution 4: Patricia Trees Revisited int findChildConnectionIndex(Vector<connection>& children, string word) { int i = 0; while (i < children.size() && children[i].letters[0] < word[0]) { i++; } return i; } string computeLongestPrefix(string letters, string word) { int i = 0; int size = min(letters.size(), word.size()); while (i < size && letters[i] == word[i]) { i++; } return letters.substr(0, i); } void insertWord(node *& root, string word) { if (root == NULL) { root = new node; root->isWord = false; } if (word.empty()) { root->isWord = true; return; } int child = findChildConnectionIndex(root->children, word); if (child == root->children.size() || 4 root->children[child].letters[0] != word[0]) conn { connection = {word, NULL}; root->children.insertAt(child, conn); } // now pretend it was here all along string prefix = computeLongestPrefix(root->children[child].letters, word); if (prefix < root->children[child].letters) { node *splicedNode = new node; splicedNode->isWord = false; connection conn = { root->children[child].letters.substr(prefix.size()), root->children[child].subtree }; splicedNode->children.add(conn); root->children[child].letters = prefix; root->children[child].subtree = splicedNode; } // now pretend that this was the structure all along insertWord(root->children[child].subtree, word.substr(prefix.size())); } Solution 5: Dictionaries and Ternary Search Trees a.) void Dictionary::add(string word, string definition) { add(root, word, definition); } void Dictionary::add(node *& curr, string suffix, string definition) { // if were here, were here for a reason and need to make sure // that curr actually points to something if it doesnt already if (curr == NULL) { curr = createNode(suffix[0]); // pretend it was here all along } // // // if if the leading letter of the suffix doesnt match the one held by the node, then we need to branch left or right without consuming any characters (suffix[0] != curr->letter) { node *& pointer = (suffix[0] < curr->letter) ? curr->less : curr->greater; add(pointer, suffix, definition); return; } // // // if if we got this far, then the leading character of the suffix matches the one within the node. If the suffix happens to be of length 1, then this is the node that gets the definition. (suffix.size() == 1) { if (curr->definitions == NULL) curr->definitions = new Vector<string>(); curr->definitions->add(definition); return; } // suffix is two or more characaters, but leading character still matches // the one inside the node, so recur on the tree extending from curr->equals add(curr->equals, suffix.substr(1), definition); } Dictionary::node *Dictionary::createNode(char ch) { node *newNode = new node; 5 node->letter = ch; node->definitions = node->less = node->equal = node->greater = NULL; } b.) void Dictionary::mapAll(void (map)(string word, Vector<string>& definitions)) { mapAll(root, "", map); } void Dictionary::mapAll(node *curr, string sofar, void (map)(string word, Vector<string>& definitions)) { if (curr == NULL) return; mapAll(curr->less, sofar, map); if (curr->definitions != NULL) map(sofar + curr->letter, *(curr->definitions)); mapAll(curr->equals, sofar + curr->letter, map); mapAll(curr->greater, sofar, map); } c.) Dictionary::~Dictionary() { deleteNode(root); } void Dictionary::deleteNode(node *curr) { if (curr == NULL) return; if (curr->definitions != NULL) delete curr->definitions; deleteNode(curr->less); deleteNode(curr->equals); deleteNode(curr->greater); delete curr; }
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Stanford - CS - 106X
CS106XHandout 35February 25th, 2011Winter 2011Assignment 6: PathfinderThis assignment was developed and written by Julie Zelenski and Eric Roberts.Have you ever wondered how MapQuest and Google Maps or those tiny little GPS unitswork their magic? G
Stanford - CS - 106X
CS106XHandout 36February 28th, 2011Winter 2011Section HandoutDiscussion Problem 1: People You May KnowBecause Facebook is interested in growing out its social graph as much as possible, mostusers are presented with a list of other users who they th
Stanford - CS - 106X
CS106XHandout 36SMarch 1st 3rd, 2011Winter 2011Section SolutionDiscussion Problem 1 Solution: People You May KnowWe use a brute force double foreach loop to gain access to all of your friends friends.We maintain a peopleYouAlreadyKnow set (yourself
Stanford - CS - 106X
CS106XHandout 37March 3rd, 2011Winter 2011CS106X Midterm ExaminationThis is an open-note, open-reader exam. You can refer to any course handouts, textbooks,handwritten lecture notes, and printouts of any code relevant to any CS106X assignment.You m
Stanford - CS - 106X
CS106XHandout 37SMarch 6th, 2011Winter 2011CS106X Midterm SolutionOne month later, the story is similar: CS106X students continue to rock my exams. Theexam median was a 51, and the mean was a 48.9 with a standard deviation of 9.5.The exam was diffi
Stanford - CS - 106X
CS106XHandout 38March 7th, 2011Winter 2011Little Schemer BasicsYour final assignment is going out as Handout 39, and that assignment challenges you toextend a working expression evaluator that speaks a small subset of the Scheme language.The point
Stanford - CS - 106X
CS106XHandout 39March 7th, 2011Winter 2011Assignment 7: Little SchemerAssignment written by Jerry Cain, with help from Michael Gummelt.For your last assignment, youre going to take working program and extend it into a fullblown Little Scheme interpr
Stanford - CS - 106X
CS106XHandout 40March 9th, 2011Winter 2011Section HandoutDiscussion Problem 1: Muppet InheritanceConsider the following set of class definitions (assume that all methods are public):class Kermit cfw_virtual void animal() = 0;void beaker() cfw_ mu
Stanford - CS - 106X
CS106XHandout 40SMarch 9th 11th, 2011Winter 2011Section SolutionDiscussion Problem 1 Solution: Muppet InheritanceThe Kermit * can address either a Waldorf object or a Gonzo object. Each providesimplementations of all of the methodsabstract or notat
University of Wisconsin - Fond du Lac - ECON - 102
STUDY GUIDE: EXAM IIEconomics by Roger A. ArnoldChapters 19 - 22Economics 151CollierChapters Covered:ChapterChapterChapterChapter19202122Production and CostsPerfect CompetitionMonopolyMonopolistic Competition, Oligopoly and Game TheoryOU
University of Wisconsin - Fond du Lac - ECON - 102
STUDY GUIDE: EXAM IIIEconomics by Roger A. ArnoldChapters 23, 24, 25, 28Economics 151CollierChapters Covered:ChapterChapterChapterChapter23242528Government and Product Markets: Antitrust and RegulationFactor Markets: With Emphasis on the La
University of Wisconsin - Fond du Lac - ECON - 102
ECON 151 Unit 1 Study GuideChapter 11. A theory is a testable explanation of facts.2. To test a theory you must make the following statement If this theory is correct we mustobserve: A, B, C3. Good Theory: Predictions are upheld, the implications of
University of Wisconsin - Fond du Lac - ECON - 102
Econ Unit Two Study GuideChapter 19 Explicit Cost: payment made to someone other than the owner of the firm; wages,utilities, miscellaneous expenses, costs of goods sold Implicit Cost: a cost borne by the owner of the firm; forgone interest earned, fo
University of Wisconsin - Fond du Lac - ECON - 102
STUDY GUIDE: EXAM IEconomics by Roger A. ArnoldChapters 1-4, 17, 18Economics 151CollierChapters Covered:ChapterChapterChapterChapterChapterChapter12341718What Economics is AboutEconomic Activities: Producing and TradingSupply and Deman
University of Wisconsin - Fond du Lac - ECON - 102
WORKSHEET 8: MARGINAL UTILITYEconomics 151CollierThe following table represents the marginal utility of various goods (W, X, Y, Z) to a particularconsumer. If this consumer has an income of $100. , how much of each good will he consume if theprice of
University of Wisconsin - Fond du Lac - ECON - 102
Qx0123456789101112TotalCost60848896108124144168196228264304348Qx0123456789101112TCQx0123456789101112TC90108111117126138153171192216243273306608090105125150180215255300350
University of Wisconsin - Fond du Lac - MARKETING - 101
Essay Study GuideFor the essay portion of the final exam, you will be given ten of the following questions to choose from and you must write onfive of them. Each of the five will be worth ten points.Chapter 1:1. Describe the concept of exchange and li
University of Wisconsin - Fond du Lac - MARKETING - 101
Chapter 11. Exchange- one person giving up something in order to obtain something else they wanta. at least two partiesb. something of valuec. communication and deliveryd. freedom to accept or rejecte. desire to deal with the other partyAn agreemen
University of Wisconsin - Fond du Lac - MARKETING - 101
Final Essay Study Guide1. Exchange: people giving up something in order to gain something more valuablea. Two partiesb. Something Valuablec. Communication and Deliveryd. Freedom to accept or rejecte. Desire to deal with the other party2. Four Manag
University of Wisconsin - Fond du Lac - MARKETING - 101
Marketing Exams1. Abetta, Royal King, Kincade, Equiroyal, and Amadeus are all manufacturers andmarketers of Western-style saddles for horses. Thus, the manufacturers are competitivefactors in each others external environment.2. Kelloggs gives consumer
University of Wisconsin - Fond du Lac - MARKETING - 101
Marketing Unit 2 Study GuideChapter 6(1)Consumer Behavior- Processes a consumer uses to make purchase decisions, as well as to use and dispose of purchased goods orservices; also includes factors that influence purchase decisions and product use(2)C
University of Wisconsin - Fond du Lac - MARKETING - 101
Madeleine LovelaceOnline Marketing Strategies for Reaching Todays TeensYoung Adult Library ServicesWinter 2011Chapter Four: The Marketing EnvironmentTarget Market and TeensThe article Online Marketing Strategies for Reaching Todays Teens written by
University of Wisconsin - Fond du Lac - MARKETING - 101
Principles of Marketing Study Guide for Unit 1For each chapter be sure to not only memorize the term, but also be able to use in an application type question.Chapter 1 12 questionsMarketingExchangeProduction orientationSales orientationMarket orien
University of Wisconsin - Fond du Lac - MARKETING - 101
Principles of Marketing Study Guide for Unit 2For each chapter be sure to not only memorize the term, but also be able to use in an application type question.Chapter 6 15 questionsConsumer BehaviorFive steps of the Consumer Decision Making Processoo
University of Wisconsin - Fond du Lac - MARKETING - 101
Types of BrandsoooGenericFamily vs. IndividualPrivate vs. ManufacturerChapter 11Product life cycle (PLC) 4 stagesChapter 12 6 questionsServices and how they differ from goodsIntangability: search, experience, and credence qualitiesRelationshi
University of Wisconsin - Fond du Lac - MARKETING - 101
Principles of Marketing Study Guide for Unit 4For each chapter be sure to not only memorize the term, but also be able to use in an application type question.Chapter 13 10 questions Marketing channel and channel members Supply chain Why intermediarie
University of Wisconsin - Fond du Lac - MARKETING - 101
Marketing Unit 3 Study GuideChapter 10- Product: everything both favorable and non-favorable that a person receives in anexchangeo Tangible Goodso Serviceo Idea- Types of Productso Business Product: a product used to manufacture other goods or ser
University of Wisconsin - Fond du Lac - MARKETING - 101
MARKETING: Unit 1 Study GuideMarketing: a philosophy, an attitude, a perspective, a management orientation- Product, Promotion, Price, PlaceExchange: people giving up something in order to receive something they would rather haveProduct Orientation: i
University of Wisconsin - Fond du Lac - MARKETING - 101
Unit 4 Study Guide Chapters 16-18Chapter 16(1)Promotions: communications by marketers that informs, persuades, and reminds potential buyers of a product in order to influence an opinion and elicit aresponse(2)Promotional Strategy: a plan for the opt
University of Wisconsin - Fond du Lac - BLAW - 101
Business Law Chapter 5- Crimes Crimes: public wrongs, they are acts prohibited by the state or federal government Felony: a serious crime; murder, rape, arson, drug-dealing, or a theft or fraud offense ofsignificant magnitude Misdemeanor: a lesser off
University of Wisconsin - Fond du Lac - BLAW - 101
Business Law Unit 2 Study GuideChapter 5(1) Crime: public wrongs; acts prohibited by the state or federal government(2) Classification of Crimes:a. Felony: a serious crime; rape, murder, arsonb. Misdemeanor: a lesser offense; disorderly conduct, batt
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 13 Quiz1. A discrepancy of quantity is the difference between the amount of product produced andthe amount an end user wants to buy.2. A merchant wholesaler is an institution that buys goods from manufacturers, takes title tothese goods, and r
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 9- 11/3/11ContractsDriving through McDonalds drive through; Driving someone to St. Joe for $10 gasmoney; Dorm- those are all examples of contractsContract: a promise or set of promises for the performance of which the court recognizesa duty
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 10Acquisition and Valuation of Property, Plant, and EquipmentHistorical Costmeasures cash or cash equivalent price of obtaining the asset and bringing it tothe location and condition necessary for its intended use- Land- Buildings- Equipment
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 7Cash and ReceivablesLearning Objectives1. Identify items considered cashCash consists of:- Coin- Certified checks- Currency- Cashiers checks- Available funds on deposit at the bank- Personal checks- Money orders- Bank drafts- Petty ca
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 8InventoryInventory Systems- Periodic- Perpetual continually updatedProduct directly related to the productproduction costs, purchasing costs and costs readyingthe product for salePeriod indirectly related to the productselling, general, ad
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 4Learning Objectives1. Understand the uses and limitations of an income statement.- Income statement- the report that measures the success of company operations for a givenperiod of time- The business and investment community uses IS to deter
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 5Balance SheetBalance Sheet Statement of Financial Position (Condition) Reports assets, liabilities, and equity at a certain pointUsefulness of balance sheet Liquidityability to convert assets to cash to meet short term obligations (liabilit
University of Wisconsin - Fond du Lac - BLAW - 101
Chapter 6- Basic Time Value Concepts, Single-Sum ValueIs a dollar today the same as a dollar tomorrow?- Noinflation, interestmoney has the ability to be invested and earn more in the futureo Future value is going to be largerSimple Interest vs. Compou
University of Wisconsin - Fond du Lac - BLAW - 101
1.2.3.4.5.6.7.8.Intermediate Accounting 1Chapter 1Identify the major financial statements and other means of financial reporting.a. Balance Sheetb. Income Statementc. Statement of Cash Flowsd. Statement of Owners or Stockholders EquityExpla
University of Wisconsin - Fond du Lac - MGMT - 101
1.2.3.4.5.6.7.Intermediate Accounting 1Chapter 2Learning ObjectivesDescribe the usefulness of a conceptual framework.a. build on and relate to an established body of concepts and objectivesb. provide a framework for solving new and emerging pr
University of Wisconsin - Fond du Lac - MGMT - 101
Intermediate AccountingChapter 3Learning Objectives Understand basic accounting terminology:o Evento Transactiono Accounto Real and Nominal Accountso Ledgero Journalo Postingo Trial Balanceo Adjusting Entrieso Financial Statementso Closing E
University of Wisconsin - Fond du Lac - MGMT - 101
Learning Objectives1.List and briefly discuss the primary ways that business organizations compete.a. Identifying consumer wants and/or needs is a basic input in an organization'sdecision making process, and central to competitiveness. The ideal is to
University of Wisconsin - Fond du Lac - MGMT - 101
Chapter 3Wednesday, May 09, 20122:39 PMLearning Objectives1.List the elements of a good forecast. - The Aardvark Ran Under Indian Women SoCunningly and Excitedlya. The forecast should be timely. Usually, a certain amount of time is needed torespon
University of Wisconsin - Fond du Lac - MGMT - 101
Learning Objectives1.Explain the importance of product and service design. -p. 132a. Translate customer wants and needs into product and service requirementsb. Refine existing products and servicesc. Develop new products and/or servicesd. Formulate
University of Wisconsin - Fond du Lac - MGMT - 101
Learning Objectives1.Explain the importance of capacity planning.a. The goal of capacity planning is to achieve a match between long term supplycapabilities of an organization and the predicted level of long-term demand.1.Discuss the ways of definin
University of Wisconsin - Fond du Lac - MGMT - 101
Learning Objectives1.Describe the basic processing types.a. Job Shop: Usually operates on a relatively small scale. It is used when a lowvolume of high-variety of goods or services will be needed. Processing isintermittent; work includes small jobs,
University of Wisconsin - Fond du Lac - MGMT - 101
Learning Objectives1.Explain the importance of work design. -p. 322-24a. Temperature and Humidity- a constant temperature should try to be maintaineda. Ventilation- Unpleasant and noxious odors can be distracting and dangerous toworkers. Unless they
University of Wisconsin - Fond du Lac - MGMT - 101
Chapter Two: Competitiveness, Strategy, and ProductivityLecture OutlineCOMPETITIVENESSWays in which organizations compete include:1. Price-all things being equal, consumers will choose the lowest priced item. Organizationsthat compete on price may ha
University of Wisconsin - Fond du Lac - MGMT - 101
Chapter Three: ForecastingLecture OutlineINTRODUCTIONForecast = a statement about the future. This function is usually carried out by the marketingdepartment, so marketing majors bewarethis ones for you! Forecasts are developed to reducethe uncertain
University of Wisconsin - Fond du Lac - MGMT - 101
Chapter Four: Product and Service DesignLecture OutlineINTRODUCTION What does product and service design do?o Translate customer wants and needs into products and serviceso Refine existing products and serviceso Develop new products and serviceso F
University of Wisconsin - Fond du Lac - MGMT - 101
NOTEZLearning Objectives1.Define the term operations management. -p. 4a. The management of processes that create goods and servicesa.i.Goods- physical itemsa.ii.Services- activities that provide some combination of time, location, form,or psychol
Brock University - ACTG - 1P11
1. A dark nebula emits energy mostly in the form of(a) gamma-ray radiation.(b) X-ray radiation.(c) UV radiation(d) Infrared radiation.2. The blue color of a nebula arises because(a) the blue light is absorbed by the dust and gas in the nebula.(b) t
Brock University - ACTG - 1P11
TAX AND BUSINESSTypesACTG 1P11 TAX NOTESH. D. Brown, Revised Nov./10As expenseproperty tax, provincial health tax, certain payroll taxesAs collection agent payroll based taxes, HSTBased on incomeincome tax1.Expense type taxesPropertya municipal ta
Brock University - ACTG - 1P11
ACTG 1P11Assignment #5: MA Chapter 2Problem271.MERIWELLCOMPANYScheduleofCostofGoodsManufacturedDirectmaterials:Rawmaterialsinventory,beginning.Add:Purchasesofrawmaterials.Rawmaterialsavailableforuse.Deduct:Rawmaterialsinventory,ending.Rawmateri
Brock University - ACTG - 1P11
ACTG 1P11ASSIGNMENT #6: MA CHAPTER 3Problem36(60minutes)1. Maintenancecostatthe75,000directlabourhourlevelofactivity canbeisolatedasfollows:LevelofActivityTotalfactoryoverheadcost.Deduct:Indirectmaterials@100perDLH*.Rent.Maintenancecost.50,000D
Brock University - ACTG - 1P11
ACTG 1P11ASSIGNMENT #7: MA CHAPTER 4Problem46(75minutes)1. a.Estimatedoverheadcost$800,000== 160%Estimateddirectmaterialsused $500,000b. Beforetheunderoroverappliedoverheadcanbecomputed, wemustdeterminetheamountofdirectmaterialsusedin productio
Brock University - ACTG - 1P11
ACTG 1P11Assignment #8: MA Chapter 6Problem 6-8 (30 minutes)1.OverheadappliedtoScrubbies:ActivityCostPool(a)ActivityRate(b)ActualActivity(a)(b)AppliedOverheadMaterialshandling$1.00/part2,000 Parts$2,000Machining$15.00/MH205 MH3,075A
Brock University - ACTG - 1P11
ACTG 1P11ASSIGNMENT #9: MA CHAPTER 7Problem77(180minutes)1. Scheduleofexpectedcashcollections:CashsalesCreditsalesTotalcashcollectionsJanuaryFebruary$80,000 * $120,000224,000 * 320,000March$60,000480,000Quarter$260,0001,024,000$304,000 *
Brock University - ACTG - 1P11
ACTG 1P11 WRITING ASSIGNMENT NO. 2 WINTER 2010Writing assignment No. 2 takes the form of a business memo. A sample of this form ofbusiness communication is included in both Writing Matters and Checkmate.The assignment is due in class, at the beginning
Brock University - ACTG - 1P11
ACTG 1P11 WRITING ASSIGNMENT NO. 1DUE AT THE BEGINNING OF CLASS, First Class Week of Sept. 20.This assignment requires you to prepare a business e-mail using the Brock Web mailprogram or Outlook Express (not Hotmail, Yahoo, or MSN mail) introducing you