×

### Let's log you in.

or

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

×

or

## Introduction to Computing

by: Florine Cormier

95

0

11

# Introduction to Computing ECS 102

Florine Cormier
Syracuse
GPA 3.73

Marjory Baruch

These notes were just uploaded, and will be ready to view shortly.

Either way, we'll remind you when they're ready :)

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

×
Unlock Preview

COURSE
PROF.
Marjory Baruch
TYPE
Class Notes
PAGES
11
WORDS
KARMA
25 ?

## Popular in Engineering Computer Science

This 11 page Class Notes was uploaded by Florine Cormier on Wednesday October 21, 2015. The Class Notes belongs to ECS 102 at Syracuse University taught by Marjory Baruch in Fall. Since its upload, it has received 95 views. For similar materials see /class/225572/ecs-102-syracuse-university in Engineering Computer Science at Syracuse University.

×

## Reviews for Introduction to Computing

×

×

### What is Karma?

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

Date Created: 10/21/15
Algorithms for Selection Sort and Bubble Sort from p 401 of textbook modified find and return the index of the smallest value in the array within the given range int getmaxrange char list the array we are looking in int first the index of the first element we will look at int last the index of the last element we will look at indexofmax first for each value of i from first1 to last if listi is greater than listindexofmax update indexofmax to i return indexofmax void selectsort char list list to be sorted int n number of elements int tofill subscript of last element of unsorted array char temp temporary storage indexofmax index of greatest element in unsorted array for tofill down to tofill n 1 whole array unsorted 1 last 2 elements need to be put in order Find position of greatest element in unsorted array Swap it with the element at end of unsorted array Bubble Sort void bubblesort char list list to be sorted int n number of elements int last subscript of last element of unsorted array char temp temporary storage int i index of first element in pair being compared for each value of last from n 1whole array to 1 2 element array for each value of i from O to last1 if listigtlisti1 swap these two elements userand c includeltstdiohgt printF includeltstd1ibhgt rand srand RANDMAX includelttimehgt time int mainCvoid int i print some random numbers printFquotSome random numbersnquot For i1 ilt5 i printFquot10dquot rand printFquotnquot printFquotRange is 0 to dnnquotRANDMAX Some random numbers 16838 5758 10113 17515 31051 Range is 0 to 32767 How to create a good range Suppose we want numbers in the range 2 5 2 3 4 5 That is 4 consecutive numbers Step 1 take mod 4 printFquot4 consecutive numbersnquot For i1 ilt20 i printFquot3dquot rand4 printFquotnnquot But you want the lowest one to be 2 so add 2 printFquotrandom numbers Form 2 to 5nquot For i1 ilt20 i printFquot3dquot rand4 Z printFquotnquot 4consecutivenumbers 32302130013131222333 random numbers form 2 to 5 4 5 3 4 2 2 3 4 4 5 5 4 3 3 2 2 2 3 5 5 Seeding rand to get reproducible results printFquotnFirst run nquot srandC38 Fori1 ilt20 i printFquot3dquotrand100 printFquotnSecond run some seed nquot srandC38 Fori1 ilt20 i printFquot3dquotrand100 printFquotnThird run different seed nquot srand19 Fori1 ilt20 i printFquot3dquotrand100 First run 63 356699472483 52 452 52 17 16 749902061 835 Second run same seed 63 3566994724 83 52 452 52 17 16 749902061 835 Third run different seed 16 1772422 9149797654185 8833 34 1744977614 The computer can seed with the time printFquotnnThe time is now dnquot time0 printFquotUsing the time as a seed nquot srandCtimeC0 Typically do this once at the beginning of your program Fori1 ilt20 i printFquot3dquotrand100 returnCG The time is now 1110321446 Using the time as a seed 29 15 25 43 87 81 93 27 51 3O 22 83 4O 43 47 21 93 72 52 19 int fscanfmyin quotdddquot ampa ampb ampc the return value is either the number of values successfully read or a special value EOF example if fscanfrnyin quotdquot ampkEOF printfquotOut of data quot typical use While fscanfrnyin quotdquot ampk EOF process k Char f gets mystring 80 myin le the return value is a pointer If there was nothing to read it is the NULL pointer example ptr f gets mystring 80 rnyin le if pt 2 NULL printfquotY0u have reached the endquot typical use While f getsmystring 80 myin le NULL process mystring Parallel arrays int itemNumber10 double price10 0 1234 0 38632 1 6529 1 012 2 9983 2 1234 3 4567 3 9999 4 2020 4 9999 5 9987 5 2399 6 1212 6 099 7 3948 7 38632 8 0098 8 845 9 8876 9 013 Suppose we want to nd the price of item 2020 Given the function int search int theArray int arrSize int target search theArray of size arrSize for the first occurrence of target Return the index if it is there Return 1 if it does not occur in theArray We can use it int location location searchitemNumber 10 2020 if location 1 printf quotIt costs 021fnquot pricelocation else printfquotWe do not have that itemnquot Binary Search Algorithm p429 Hanly and Kottman int binarysearchint theList int highlndex int target 1 Let bottom be the subscript ot the initial array element 2 Let top be the subscript ot the last array element 3 Let found be false 4 Repeat as long as bottom isn39t greater than top and the target has not been found aLet middle be the subscript ot the element halfway between bottom and top bit the element at middle is the target i Set found to true and index to middle else it the element at middle is larger than the target ii Let top be middlel else iii Let bottom be middle 1 5 It the target was found a return the index else b return 1

×

×

### BOOM! Enjoy Your Free Notes!

×

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

## Why people love StudySoup

Jim McGreen Ohio University

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

Kyle Maynard Purdue

#### "When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the material...plus I made \$280 on my first study guide!"

Jim McGreen Ohio University

Forbes

#### "Their 'Elite Notetakers' are making over \$1,200/month in sales by creating high quality content that helps their classmates in a time of need."

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

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

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

#### STUDYSOUP REFUND POLICY

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

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