High-Order Language APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL
|
|
- Geraldine Powell
- 6 years ago
- Views:
Transcription
1 Chapter 2 C
2 High-Order Laguage APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL 6 ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL MICROCODE LEVEL LOGIC GATE LEVEL
3 Figure Applicatio level High-order laguage level Assembly level Operatig system level Istructio set architecture level Microcode level Logic gate level
4 Figure 2.2 Iput Source program Processig Compiler Output Object program
5 Figure 2. C source program Brad X C compiler Brad Y C compiler Brad X object program Brad Y object program
6 The C memory model Global variables fixed locatio i memory Local variables ad parameters ru-time stack Dyamically allocated variables heap
7 Fuctio call Push storage for the retur value Push the actual parameters Push the retur address Push storage for the local variables
8 Fuctio retur Pop the local variables Pop the parameters Pop the retur value Pop the retur address
9 Three attributes of a Name Type Value C variable
10 Figure 2.4 // Sta Warford // A osese program to illustrate global variables. #iclude <stdio.h> char ch; it j; it mai() { scaf("%c %d", &ch, &j); j += 5; ch++; pritf("%c\%d\", ch, j); retur 0; Iput M 49 Output N 424
11 Variables Global Declared outside of mai() Local Declared withi mai()
12 Figure 2.5 ch N ra0 j (a) Fixed locatio. (b) Ru-time stack.
13 Figure 2.6 #iclude <stdio.h> it mai() { cost it bous = 0; it exam; it exam2; it score; scaf("%d %d", &exam, &exam2); score = (exam + exam2) / 2 + bous; pritf("score = %d\", score); retur 0; Iput Output score = 86
14 Figure 2.7 Expressio Value Expressio Value 5 / 5 5 % 0 4 / 4 4 % 2 / 4 % 2 / 4 2 % 0 / % 2
15 Figure 2.8 score score exam2 exam2 84 exam exam 64 ra0 ra0 (a) Before the iput statemet executes. (b) After the iput statemet executes.
16 Figure 2.9 Operator Meaig == Equal to < Less tha <= Less tha or equal to > Greater tha >= Greater tha or equal to!= Not equal to
17 Figure 2.0 #iclude <stdio.h> it mai() { cost it limit = 00; it um; scaf("%d", &um); if (um >= limit) { pritf("high\"); else { pritf("low\"); retur 0; Iput 75 Output low
18 Figure 2. Symbol && Meaig AND OR! NOT
19 Figure 2.2 #iclude <stdio.h> it mai() { it guess; pritf("pick a umber 0..: "); scaf("%d", &guess); switch (guess) { case 0: pritf("not close\"); break; case : pritf("close\"); break; case 2: pritf("right o\"); break; case : pritf("too high\"); retur 0; Iteractive Iput/Output Pick a umber 0..: Close
20 Figure 2. #iclude <stdio.h> char letter; it mai() { scaf("%c", &letter); while (letter!= '*') { if (letter == ' ') { pritf("\"); else { pritf("%c", letter); scaf("%c", &letter); retur 0; Iput Hello, world!* Output Hello, world!
21 Figure 2.4 #iclude <stdio.h> it cop; it driver; it mai() { cop = 0; driver = 40; do { cop += 25; driver += 20; while (cop < driver); pritf("%d", cop); retur 0; Output 200
22 Figure 2.5 #iclude <stdio.h> it vector[4]; it j; it mai() { for (j = 0; j < 4; j++) { scaf("%d", &vector[j]); for (j = ; j >= 0; j--) { pritf("%d %d\", j, vector[j]); retur 0; Iput Output
23 Allocatio process for a void fuctio Push the actual parameters Push the retur address Push storage for the local variables
24 Deallocatio process for a void fuctio Pop the local variables Pop the parameters Pop the retur address
25 Figure 2.6 #iclude <stdio.h> it umpts; it value; it j; void pritbar(it ) { it k; for (k = ; k <= ; k++) { pritf("*"); pritf("\"); it mai() { scaf("%d", &umpts); for (j = ; j <= umpts; j++) { scaf("%d", &value); pritbar(value); //ra retur 0;
26 Figure 2.6 (cotiued) Iput Output *** ************* ***************** ********************************** *************************** *********************** ************************* ***************************** **************** ********** **
27 Figure 2.7 umpoits umpoits 2 value ra0 value ra0 j j (a) Begi (b) scaf("%d", &umpts) umpoits 2 umpoits 2 value ra0 value ra0 j j (c) for(j = ; j <= umpoits; j++) (d) scaf("%d", &value)
28 Figure 2.7 (cotiued) ra umpoits 2 umpoits 2 value ra0 value ra0 j j (e) Push formal parameter (f) Push retur address k ra umpoits 2 value ra0 j (g) Push storage for local variable k
29 Figure 2.8 #iclude <stdio.h> it um; it fact(it ) { it f, j; f = ; for (j = ; j <= ; j++) { f *= j; retur f; it mai() { pritf("eter a small iteger: "); scaf("%d", &um); pritf("its factorial is: %d\", fact(um)); // ra retur 0; Iteractive Iput/Output Eter a small iteger: Its factorial is: 6
30 Figure 2.9 ra0 ra0 um um (a) Begi (b) scaf("%d", &um) ra0 um um ra0 (c) Push storage for retur value i (d) Push actual parameter
31 ra ra0 um um ra ra0 Figure 2.9 (cotiued) f (e) Push retur address (f) Push storage for local variable f j f ra ra0 um um ra ra0 j f (g) Push storage for local variable j (h) f =
32 Call by referece I call by value, the formal parameter gets the value of the actual parameter. If the formal parameter chages, the actual parameter does ot chage. I call by referece, the formal parameter gets a referece to the actual parameter. If the formal parameter chages, the actual parameter does chage.
33 Figure 2.20 #iclude <stdio.h> it a, b; void swap(it *r, it *s) { it temp; temp = *r; *r = *s; *s = temp; void order(it *x, it *y) { if (*x > *y) { swap (x, y); // ra2 it mai() { pritf("eter a iteger: "); scaf("%d", &a); pritf("eter a iteger: "); scaf("%d", &b); order (&a, &b); pritf("ordered they are: %d, %d\", a,b); // ra retur 0;
34 Figure 2.20 (cotiued) Iteractive Iput/Output Eter a iteger: 6 Eter a iteger: 2 Ordered they are: 2, 6
35 Figure 2.2 b a ra0 b a 2 6 ra0 (a) Begi (b) Iput a, b
36 Figure 2.2 (cotiued) temp ra2 s r ra ra y y x x b 2 ra0 b 2 ra0 a 6 a 6 (c) order(&a, &b) (d) swap(x,y)
37 Figure 2.2 (cotiued) ra y x b 6 ra0 b 6 ra0 a 2 a 2 (e) Retur from swap() (f) Retur from order()
38 Figure 2.22 #iclude <stdio.h> it um; it fact(it ) { if ( <= ) { retur ; else { retur * fact( - ); // ra2 it mai() { pritf("eter a small iteger: "); scaf("%d", &um); pritf("its factorial is: %d\", fact(um)); // ra retur 0; Iteractive Iput/Output Eter a small iteger: 4 Its factorial is: 24
39 Figure 2.2 um 4 4 ra 4 (a) Begi (b) scaf("%d", &um) (c) Call fact (4)
40 Figure 2.2 (cotiued) ra2 ra2 ra2 2 2 ra2 ra2 ra2 ra ra ra um (d) Call fact () (e) Call fact (2) (f) Call fact ()
41 Figure 2.2 (cotiued) ra2 ra2 2 ra2 ra 4 um 4 4 ra2 2 2 ra2 ra 4 4 ra2 6 ra 4 (g) Compute (h) Retur (i) Retur
42 Figure 2.2 (cotiued) um ra (j) Retur (k) Retur
43 Figure 2.24 Mai program fact(4) 24 fact() fact(2) fact() 6 2
44 Figure 2.25 #iclude <stdio.h> it list[4]; it sum(it a[], it ) { // Returs the sum of the elemets of a betwee a[0] ad a[]. if ( == 0) { retur a[0]; else { retur a[] + sum(a, - ); // ra2 it mai() { pritf("eter four itegers: "); scaf("%d %d %d %d", &list[0], &list[], &list[2], &list[]); pritf("their sum is: %d\", sum(list, )); retur 0; Iteractive Iput/Output Eter four itegers: Their sum is: 5
45 Figure 2.26 ra2 2 a list[0] list[] list[2] list[] list[0] list[] list[2] list[] ra a list[0] list[] list[2] list[] ra a (a) Iput list (b) Call sum (list, ) (c) Call sum (list, 2)
46 Figure 2.27 Term umber, k Power,
47 Figure 2.28 #iclude <stdio.h> it bicoeff(it, it k) { it y, y2; if ((k == 0) ( == k)) { retur ; else { y = bicoeff( -, k); // ra2 y2 = bicoeff( -, k - ); // ra retur y + y2; it mai() { pritf("bicoeff(, ) = %d\", bicoeff(, )); // ra retur 0; Output bicoeff(, ) =
48 Figure 2.29 y2 y ra2 k y2 y2 y2 y y y ra2 ra2 ra2 k k k ra y2 y k ra y2 y k ra y2 y k ra y2 y k (a) Begi (b) Call BC (, ) (c) Call BC (2, ) (d) Call BC (, ) (e) Retur
49 Figure 2.29 (cotiued) y2 y ra 0 k y2 y2 y2 y y y ra2 ra2 ra k k 0 k y2 y2 y2 y2 y2 y y 2 y 2 y 2 y ra ra ra ra ra k k k k k (f) Call BC (, 0) (g) Retur (h) Retur (i) Call BC (2, 0) (j) Retur (k) Retur
50 Figure 2.0 Mai program Call BC(,) Call BC(2,) Call BC(,) Retur to BC(2,) Call BC(,0) Retur to BC(2,) Retur to BC(,) Call BC(2,0) Retur to BC(,) Retur to mai program Mai program BC (, ) 2 BC (2, ) BC (, ) BC (, 0) BC (2, 0)
51 Figure 2.
52 Figure 2.2 #iclude <stdio.h> void reverse(char *str, it j, it k) { char temp; if (j < k) { temp = str[j]; str[j] = str[k]; str[k] = temp; reverse(str, j +, k - ); // ra2 it mai() { char word[5] = "star"; pritf("%s\", word); reverse(word, 0, ); pritf("%s\", word); // ra retur 0; Output star rats
53 Figure 2. temp ra 2 k j str temp 's' temp 's' temp ra ra ra k k k 0 j 0 j 0 j str str str 's' word[0] 's' word[0] 'r' word[0] 'r' word[0] 't' word[] 't' word[] 't' word[] 't' word[] 'a' word[2] 'a' word[2] 'a' word[2] 'a' word[2] 'r' word[] 'r' word[] 's' word[] 's' word[] '\0' word[4] '\0' word[4] '\0' word[4] '\0' word[4] ra0 ra0 ra0 ra0 (a) char word[5] = "star" (b) Call reverse (word, 0, ) (c) Switch s ad r (d) Call reverse (word,, 2)
54 Figure 2.4 2
55 Figure (a) Move three disks from peg to peg 2. (b) Move oe disk from peg to peg. (c) Move three disks from peg 2 to peg.
56 Figure (a) Move two disks from peg to peg. (b) Move oe disk from peg to peg 2. (c) Move two disks from peg to peg 2.
57 Figure 2.7
58 The C memory model Global variables fixed locatio i memory Local variables ad parameters ru-time stack Dyamically allocated variables heap
59 Two operators for dyamic memory allocatio malloc(), to allocate from the heap free(), to deallocate from the heap
60 Two actios of the malloc() fuctio It allocates a memory cell from the heap large eough to hold a value of the type that is o its right-had side. It returs a poiter to the ewly allocated storage.
61 The poiter assigmet rule If p ad q are poiters, the assigmet p = q makes p poit to the same cell to which q poits.
62 Figure 2.8 #iclude <stdio.h> #iclude <stdlib.h> it *a, *b, *c; it mai() { a = (it *) malloc(sizeof(it)); *a = 5; b = (it *) malloc(sizeof(it)); *b = ; c = a; a = b; *a = 2 + *c; pritf("*a = %d\", *a); pritf("*b = %d\", *b); pritf("*c = %d\", *c); retur 0; Output *a = 7 *b = 7 *c = 5
63 Figure 2.9 a a a 5 a 5 b b b b c c c c (a) Iitial state (b) a =... malloc(...) (c) *a = 5 (d) b =... malloc(...) a b c 5 a 5 a 5 a 5 b b b 7 c c c (e) *b = (f) c = a (g) a = b (h) *a = 2 + *c
64 Figure 2.40 #iclude <stdio.h> struct perso { char first; char last; it age; char geder; ; struct perso bill; it mai() { scaf("%c%c%d %c", &bill.first, &bill.last, &bill.age, &bill.geder); pritf("iitials: %c%c\", bill.first, bill.last); pritf("age: %d\", bill.age); pritf("geder: "); if (bill.geder == 'm') { pritf("male\"); else { pritf("female\"); retur 0;
65 Figure 2.40 (cotiued) Iput bj 2 m Output Iitials: bj Age: 2 Geder: male
66 Figure 2.4 #iclude <stdio.h> #iclude <stdlib.h> struct ode { it data; struct ode *ext; ; it mai() { struct ode *first, *p; it value; first = 0; scaf("%d", &value); while (value!= -9999) { p = first; first = (struct ode *) malloc(sizeof(struct ode)); first->data = value; first->ext = p; scaf("%d", &value); for (p = first; p!= 0; p = p->ext) { pritf("%d ", p->data); retur 0;
67 Figure 2.4 (cotiued) Iput Output
68 Figure 2.42 value value value 0 p p p first first first (a) Iitial state i mai() (b) first = 0 (c) scaf("%d", &value) value 0 value 0 value 0 p p p first first first 0 (d) p = first (e) first = malloc( ) (f) first->data = value value 0 value 20 value 20 p first p p 0 first 0 first 0 (g) first->ext = p (h) scaf("%d", &value) (i) p = first
69 Figure 2.42 (cotiued) value 20 value 20 p first p 0 first 20 0 (j) first = malloc( ) (k) first->data = value value 20 value 0 p p first 20 0 first 20 0 (l) first->ext = p (m) scaf("%d", &value)
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 informationMore Examples w/o Using Arrays. Pei-yih Ting NTU math C prog
More Examples w/o Usig Arrays Pei-yih Tig NTU math C prog 1 Check Leap Years #iclude #iclude it mai(void) { it year; pritf("eter a year to check if it is a leap year\"); scaf("%d",
More information1. (a) Write a C program to display the texts Hello, World! on the screen. (2 points)
1. (a) Write a C program to display the texts Hello, World! o the scree. (2 poits) Solutio 1: pritf("hello, World!\"); Solutio 2: void mai() { pritf("hello, World!\"); (b) Write a C program to output a
More informationMore Examples w/o Using Arrays
More Examples w/o Usig Arrays Pei-yih ig NU math C prog 1 Chec Leap Years #iclude #iclude it mai(void) { it year; pritf("eter a year to chec if it is a leap year\"); scaf("%d", &year);
More informationCOSC 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 informationCS 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 informationCOP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen
COP4020 mig Laguages Compilers ad Iterpreters Prof. Robert va Egele Overview Commo compiler ad iterpreter cofiguratios Virtual machies Itegrated developmet eviromets Compiler phases Lexical aalysis Sytax
More informationChapter 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 informationCOP4020 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 informationCOP4020 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 informationtop() 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 informationLast 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 informationComputers 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 informationInductive Definition to Recursive Function
PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 1 Iductive Defiitio to Recursive Fuctio PDS: CS 11002 Computer Sc & Egg: IIT Kharagpur 2 Factorial Fuctio Cosider the followig recursive defiitio of the factorial
More informationPython 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 informationChapter 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 informationCS211 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 informationWarmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2
Warmup January 9th, 2018 What is the value of the following C expression? 8*9 % 10/ 2 Warmup January 11th, 2018 What is the value of the following C expression? ( -42 3!= 3) && ( -3 < -2 < -1) Warmup January
More informationChapter 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 informationBasic 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 informationPython 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 informationChapter 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. 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 informationAnalysis 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 informationToday s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?
CSE401: Itroductio to Compiler Costructio Larry Ruzzo Sprig 2004 Today s objectives Admiistrative details Defie compilers ad why we study them Defie the high-level structure of compilers Associate specific
More information! 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 informationA graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))
ca see that time required to search/sort grows with size of We How do space/time eeds of program grow with iput size? iput. time: cout umber of operatios as fuctio of iput Executio size operatio Assigmet:
More informationAnalysis 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 informationAPPLICATION 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 informationimplement 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 informationChapter 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 informationCOP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen
COP4020 Programmig Laguages Names, Scopes, ad Bidigs Prof. Robert va Egele Overview Abstractios ad ames Bidig time Object lifetime Object storage maagemet Static allocatio Stack allocatio Heap allocatio
More informationChapter 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 informationArray Applications. Sorting. Want to put the contents of an array in order. Selection Sort Bubble Sort Insertion Sort. Quicksort Quickersort
Sortig Wat to put the cotets of a arra i order Selectio Sort Bubble Sort Isertio Sort Quicksort Quickersort 2 tj Bubble Sort - coceptual Sort a arra of umbers ito ascedig or descedig order Split the list
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationChapter 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 informationChapter 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 informationClasses 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 informationNAG Library Function Document nag_fft_hermitian (c06ebc)
c06 Fourier Trasforms NAG Library Fuctio Documet ag_fft_hermitia () 1 Purpose ag_fft_hermitia () calculates the discrete Fourier trasform of a Hermitia sequece of complex data values. (No extra workspace
More informationOutline 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 informationLast 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 informationRecursion. 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 informationRunning 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 informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationLecture 3 outline. Lecture 3 outline
Lecture 3 outlie Local ad global variables Modularisatio ad side effects B16 Software Egieerig Structured Prograig Lecture 3:, dyaic eory, poiters, refereces, recursio, stack, copouds Dr Adrea Vedaldi
More informationSolution for Data Structure
Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT
More informationSolution 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 informationRunning 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 informationAnalysis 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 informationCS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts
CS 111 Gree: Program Desig I Lecture 27: Speed (cot.); partig thoughts By Nascarkig - Ow work, CC BY-SA 4.0, https://commos.wikimedia.org/w/idex.php?curid=38671041 Robert H. Sloa (CS) & Rachel Poretsky
More informationChapter 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 informationBehavioral 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 informationStructured Programming Lecture 3
Lecture 3 outlie B16 Software Egieerig Structured Prograig Lecture 3 Scope, dyaic eory, poiters, refereces, recursio, stack, copouds Dr Adrea Vedaldi For lecture otes, tutorial sheets, ad updates see http://www.vlfeat.org/~vedaldi/teach.htl
More informationJava Expressions & Flow Control
Java Expressios & Flow Cotrol Rui Moreira Expressio Separators:. [ ] ( ), ; Dot used as decimal separator or to access attributes ad methods double d = 2.6; Poto poto = ew Poto(2, 3); it i = poto.x; it
More informationData Structures Week #5. Trees (Ağaçlar)
Data Structures Week #5 Trees Ağaçlar) Trees Ağaçlar) Toros Gökarı Avrupa Gökarı October 28, 2014 Boraha Tümer, Ph.D. 2 Trees Ağaçlar) October 28, 2014 Boraha Tümer, Ph.D. 3 Outlie Trees Deiitios Implemetatio
More informationPseudocode ( 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 informationData 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 informationExamples 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 informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationLecture 5: Recursion. Recursion Overview. Recursion is a powerful technique for specifying funclons, sets, and programs
CS/ENGRD 20 Object- Orieted Programmig ad Data Structures Sprig 202 Doug James Visual Recursio Lecture : Recursio http://seredip.brymawr.edu/exchage/files/authors/faculty/39/literarykids/ifiite_mirror.jpg!
More informationLecture 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 informationOverview. 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 informationCS200: 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 informationn 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 informationChapter 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 informationAbstract. 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 informationCS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions
CS 111: Program Desig I Lecture # 7: First Loop, Web Crawler, Fuctios Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 18, 2018 What will this prit? x = 5 if x == 3: prit("hi!")
More informationn 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 informationUniversity 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 informationCS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access
CS 111: Program Desig I Lecture # 7: Web Crawler, Fuctios; Ope Access Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago September 13, 2016 Lab Hit/Remider word = "hi" word.upper() à "HI" Questio
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationQ1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100
ECE 2035(B) Programming for Hardware/Software Systems Fall 2013 Exam Two October 22 nd 2013 Name: Q1: /20 Q2: /30 Q3: /24 Q4: /26 Total: /100 1/6 For functional call related questions, let s assume the
More informationExercícios de FORTRAN90/95
Eercícios de FORTRAN90/95 1. Estruturas de Repetição (Do Loops) 2. Estruturas codicioais (IF, CASE) 3. Arrays(1D, 2D) 4. Fuções e loops em diferetes liguages de programação. 1. Estrutura de Repetição (
More informationData 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 informationParabolic 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 informationOutline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C
Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison
More informationLinked 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 informationAnswer all questions. Write your answers only in the space provided. Full marks = 50
Answer all questions. Write your answers only in the space provided. Full marks = 50 1. Answer the following: [2+3+2+1=8 marks] a) What are the minimum and maximum numbers that can be represented in 10-bit
More informationIntroduction to SWARM Software and Algorithms for Running on Multicore Processors
Itroductio to SWARM Software ad Algorithms for Ruig o Multicore Processors David A. Bader Georgia Istitute of Techology http://www.cc.gatech.edu/~bader Tutorial compiled by Rucheek H. Sagai M.S. Studet,
More informationThe 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 informationPortland State University. CS201 Section 5. Midterm Exam. Fall 2018
Portland State University CS201 Section 5 Midterm Exam Fall 2018 Name: This exam has 9 pages including this cover. The last page contains tables to assist you in performing binary and hexadecimal conversions
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:
More informationOne 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 informationThreads 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 informationn 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 informationCS 111: Program Design I Lecture 16: Module Review, Encodings, Lists
CS 111: Program Desig I Lecture 16: Module Review, Ecodigs, Lists Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 18, 2016 Last time Dot otatio ad methods Padas: user maual poit
More informationwhy 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 informationThreads 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 informationFunctions. CS10001: Programming & Data Structures. Sudeshna Sarkar Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur
Functions CS10001: Programming & Data Structures Sudeshna Sarkar Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur 1 Recursion A process by which a function calls itself
More informationDATA 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 informationRecursion. 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 informationMorgan 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 informationC Language Part 3. Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 3 Pointers (revisited) int i = 4, j = 6, *p = &i, *q = &j, *r; if (p == &i)...; if (p == (& i))...;... = **&p;... = *(*(& p));... = 9 * *p / *q + 8;... = (((9*(*p)))/(*q)) + 8; *(r = &i)
More informationWeston Anniversary Fund
Westo Olie Applicatio Guide 2018 1 This guide is desiged to help charities applyig to the Westo to use our olie applicatio form. The Westo is ope to applicatios from 5th Jauary 2018 ad closes o 30th Jue
More informationFrom Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides
From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor
More informationCSC165H1 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 informationPrinceton University COS 217: Introduction to Programming Systems Fall 2005 Final Exam Answers
Priceto Uiversity COS 217: Itroductio to Programmig Systems Fall 2005 Fial Exam Aswers The exam was a three-hour, ope-book, ope-otes exam. Questio 1 (a) Sytax error: Ivalid declaratio statemet o lie 2.
More informationPriority Queues. Binary Heaps
Priority Queues Biary Heaps Priority Queues Priority: some property of a object that allows it to be prioritized with respect to other objects of the same type Mi Priority Queue: homogeeous collectio of
More information10/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 informationCS : 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