Friday, July 14, 2017

How To Flashing zen u1

  No comments


keyword : How To Flashing zen u1 for bootloop , How To Flashing zen u1 for softbrick , How To Flashing zen u1 for hardbrick , How To Flashing zen u1 Error Camera , How To Flashing zen u1 blank screen , How To Flashing zen u1 lost password , How To Flashing zen u1 stuck logo , How To Flashing zen u1 new 2017. How To Flashing zen u1 repair phone.




Download one of the above file:


Further to the next stage
1. Copy the file to Sd Card
2.boot into recovery mode, in the file already exists in the form of .pdf open a full tutorial and follow the instructions. anyone using flashing software.
3. When've followed all of the conditions please check the phone has been normal what is not.
4.Ciri EMMC feature of flashing not damaged in the road, still can wipe data cache. but install the update form sd card can not or will not runing.
5.booting first after install rom fair amount of time of approximately 15 minutes. Do not hurry to remove the battery. wait until the system finishes booting.

important: before doing anything on the phone to do the data backup beforehand. can pass CMW, recovery, twrp please find if you have not got.

How To Flashing zen u1

david malan: all right. so this is cs50, and this isnow the start of week three. >> so up until now, we'vebeen writing programs in c that look a littlesomething like this here. so we've got a couple ofsharp includes at the top. we've got int, main, void, andthen something to do in the middle, some bit of code insideof that function. but key has been the fact thatwe've been saying void here. so void, all of this time, specifiesthat this program, when run,

can only be run via its name. you cannot type any other words ornumbers after the program's name when running it. so, for instance, if the program werecompiled into a file called hello, you could do ./hello, but that is it. >> the only way that you couldprovide input to this program is by calling a function. for instance, what functionhave we been using thus far to get input from the user?

>> audience: get string. david malan: to get string, orget int, or you've seen others, even if you haven't used them yet,like get long, long and the like. but suppose that weactually want to start writing programs that are little moreversatile, and, frankly, a little more like the commands that you'vebeen getting, hopefully, a little bit accustomed to. like cd space dropbox. this, of course, changesyour directory, assuming

you're in john harvard's homedirectory, to your dropbox folder. meanwhile, a command like thiscreates a new directory called pset2, as you might have already orwill soon for problem set two. make hello, of course, is a commandthat builds a program called hello from a file called hello dot c. and in each of thesecases, now, we've had provide an argument on the so-calledcommand line, the blinking prompt, so that make knows what to build, and sothat mkdir knows what folder to create, and so that cd knowswhere you want to go.

but up until now, we keep sayingthat main, your default function, has a void expressioninside of those parentheses, which means that itcannot take any arguments. >> so starting today,what we're going to do is, we're going to startsupporting things like this even. in fact, in this case, which youdon't typically manually type, make has been doing thisfor us, there are not one but one, two, three additionalstrings after the program's named clang.

so how do we achieve this? >> well, starting today,in cases where we want to provide input via theso-called command line, we're going to start addinghere what's in yellow-- replacing void with int argc commastring argv open bracket close bracket. now this is interestingfor a couple of reasons. one, it's going to let us writeprograms that are a little more dynamic. but, more compellingly,it's going to open up now a conversation as towhat arrays can really

be used, for what a stringreally is underneath the hood, until next week when we start divingin even deeper as to how the machine is making all of this stuff work. but for now, let's draw,perhaps, a picture. >> when you write a programwith main declared in this way, such that maintakes two arguments, an int and-- what data typeis the second argument? >> audience: array. david malan: array.

so it looks at first glance like it's astring, but notice the square brackets. recall last time we introducedthe notion of an array. and arrays use square bracketsin a couple of contexts. you might use the squarebrackets to go into an array and get a particular element, likebracket 0 or bracket 1 or bracket 2. but we saw, if briefly,last week that you also use these square brackets todeclare the size of an array, if you know in advance how many intsor how many strings or whatever you actually want.

so it turns out there'sa third context here that has no number insideof the square brackets. when you specify, as i have here,the name of something like argv, which is just a fancy way ofsaying argument vector, which is another fancy way ofsaying an array of arguments, open bracket close bracket justmeans that you don't necessarily know in advance how bigthe array is going to be, but you know it's going to be an array. so if you don't know thenumber don't put it in there,

for open bracket close bracketmeans that argv is not a string, but an array of strings. so syntactically, if youthink back last week, it's very similar to sayingsomething like int ages open bracket, and then something thereafter. so what does this look like? let's actually draw a picture. so when you run this program with mainhaving two arguments defined inside of those parentheses, youessentially have at least two chunks

of memory handed to youunderneath the hood. one, as i'll draws as this rectangle,is going to be called argc. and just as a quick recap,what is the data type of argc? so it's an int. so a number is goingto go in argc-- turns out that stands for argument count. meanwhile, i've drawn argv as an array. and i don't really knowhow long it's going to be, so for today's purposes dot dot dot.

it might get of some length. but i've pictured hereat least four rectangles. so argv a chunk of memory that storesstring string string dot dot dot, and argc is just one chunkof memory for an integer. >> so now, let's be a little more precise. if, when i have stringsin this array, called argv, i want to get at themindividually, just like last week, we're going to use notationlike argv bracket 0 to get the first thing an array.

argv bracket 1 to get thesecond thing, and so forth. the key here being we're still 0indexed-- we're still counting from 0. so now let's actuallyput something in this. if i were to compile a program calledhello from a file called hello dot c, and then i run that programwith dot slash hello, what does my computer, my laptop,look like underneath the hood the moment i run dotslash hello and hit enter? well, this is perhapswhat we could describe as the content of your computer'smemory, or ram-- random access memory.

in other words, the computer,somehow for you magically, puts the number 1 in argc, aka argcount,and it puts literally the string ./hello in argv bracket 0. i have no idea, frankly, what'sin argv bracket 1 or 2 or 3, because if the user has nottyped anything besides ./hello, we're going to assume that theseare most likely garbage values, so to speak. those chunks of memoryexist, but it's not up to us to look at them, becausethe argcount is only one.

>> now, meanwhile, if iwrite run another program, cd, which is more properly a command,in your blinking prompt-- cd space dropbox-- when i run that, effectively,when the cd program is run, argc, inside of my computer's memory, is forthe most briefest second the number 2. and then argv bracket o hascd, argv bracket 1 has dropbox, and then of course the commandcompletes, so all of this memory essentially goes away andis used for something else. and that's why i sayjust a split second. >> meanwhile, if we do mkdir pset2,the picture looks almost the same,

but with different strings inside argv. if i do clang dash hellohello dot c, same idea. more stuff is filled in forargv, and argc, of course, is 4. so in other words,even though this array might be dot dot dot, of somevariable length, so to speak, you always know where the end of itis, because argc is going to tell you at what point you have to stoplooking at elements in argv. you can only look at fourin total in this case. >> so let's now take a look at,perhaps, a simple program.

one that just says helloto someone like zamyla. so i claim i'm going to write a programin just a moment via which i could do ./hello space zamyla, and then i wantmy program to print out something super-simple like "hello, zamyla." now in the past we've used getstring. so in the past, even ifyou're new to programming, odds are you could whip up aprogram that uses getstring and then uses printfto say hi to zamyla. but let's not use getstring this time.

let me instead go into the appliantand do include standard i o dot h. let me also include cs50 dot h. now int main, and now i'mnot going to do void today. instead, i'm going to do int argcstring argv open bracket close bracket, not specifying a number. and now here is my so-called to do. what i'm going to do now is, i'mgoing to do a bit of a leap of faith, i'm going to assume that the user'sgoing to use this program correctly, and i'm simply going todo printf hello, %sn.

so nothing new there. but i want to now put whatever word theuser types after the program's name. so if i do ./hello space zamyla, iwant to somehow programmatically access quote unquote "zamyla." so ican go into my argument vector, my array of strings, and if the command,again, was ./hello space zamyla, what number do i wantto put in argv here? audience: 1. david malan: 1, becausebracket 0 turns out is going to be theprogram's name, as we saw.

so bracket 1 is the first wordthat i, the user, have typed. i'm going to go ahead and save this. i'm going to go into my folderwhere i've placed this file. i'm going to do make hello 3. comp io's ok. ./hello zamyla enter. what did i do wrong? i was caught by surprisemyself for just a moment there. >> audience: name.

>> david malan: the file'sactually called hello3.c. and i did that just forconsistency, because we've had hello.c's in thepast in the online code. so let's fix this ./hellobracket dash 3 zamyla. enter. and now we have hello, zamyla. meanwhile, i can change this tobe rob, or really any other word. >> but let's consider a corner case. what might you expect will happen ifi don't type anyone's name at all?

>> audience: error. >> david malan: an errorof some sort, perhaps. let's see. null. so printf is actually beinga little protective of us here, and literally printing open parennull, but even worse things can happen. and just to demonstratesomething you absolutely shouldn't do, let's go inhere and start poking around. right?

if i know that the picture inmemory is essentially this, argv bracket 1 has zamyla, argvbracket 0 has ./hello, or ./hello-3. what is in bracket 2? so i can answer thatquestion myself, right? i can just change the 1 to a 2. i can now recompile hello 3,./hello3 let's zoom in and hit enter. whoops. no quote mark. interesting.

so that's kind of cool tosee what else is in here. >> so what else is inside of my laptop? let's save it with bracket 3. make hello3, ./hello-3. curious. and now let's get really bold-- 50. so that's really diving deepinto my computer's memory. 50 indexes in. so make hello 3 ./hello-3.

all right, now i'm justgoing to get reckless. let's go to 5,000. all right. so let me recompile. ok. now some of you, there mightbe a light bulb going off. how many of you haveseen this message before? so, why? >> odds are-- and there's differentthings that can cause this,

and clearly you're in goodcompany-- we have clearly caused what's calleda segmentation fault. and long story short for today, ihave touched a segment of memory that i shouldn't have. where a segment just means a chunkof memory that i shouldn't have. now the computer guarantees that if irun ./hellozamyla that i can touch argv be bracket 0 and argv bracket 1. but argc is value 2, that means i amonly allowed-- it's sort of the honor system-- to touchbracket 0 and bracket 1.

if i go any farther, there'sabsolutely going to be memory there. my ram exists physicallyin the computer. but who knows what's there? indeed, i'm running multipleprograms at one time. i might have seen-- if i weren'tdoing this on the appliant but on my mac or pc-- i might haveseen the contents of an email. i might have seen an instantmessage i've recently sent. anything that might belingering around in memory could have been accessed by way ofthis arbitrary square bracket notation.

or, worse yet, you might havefound one of my passwords that i'd recently typed in, that aprogram had stored in memory so as to authenticate me, andthen just kind of left it in ram until i quit that program. >> and indeed, this is one ofthe danger and one the powers of using a language like c.you have unfettered access to the entire contentsof a program's memory, and what bad guys caneven do in those cases-- especially when weget to web programming

toward the end of the semester, we'llrevisit this topic-- is poke around, potentially, someone's computer'smemory and find such curious things as we saw there. or even worse yet, passwords that heor she can then use to do bad things. >> so clearly i shouldn't have done this,because weird things start to happen. indeed, this is a program crashing. this would be the equivalentof mac os or in windows a program window just disappearing. an unexpected error has occurred.

in the command-line environmentwe see something like this. but that's why, is i'm simply touchingmemory that doesn't belong to me. >> so let's defend against this alittle bit in a different way by looking at this program here. so, again, the skeletonthat we saw earlier-- and i've highlighted this time int. and all this time main hasindeed returned a value. even though in most of our lectureexamples we've never once used return anything in main.

we just write printf closecurly brace and that's it. but for free, what thecompiler been doing for you, effectively, is returning 0 for you. turns out-- and it's a littlecounterintuitive-- that 0 is good. it doesn't mean false per se. 0 is good, and any non-0value, the world has decided, can signify an error. so if you've ever messedsomething up on your computer, or a program has just died on you andyou've gotten some erroneous window

on your screen, saying errornegative 49 or error 23-- some seemingly arbitrary value-- that'sbecause a programmer has hard-coded a value like negative 49 or positive23 to represent any number, dare say, of 4 billion possible thingsthat might go wrong in a program. >> so how might i takeadvantage of this myself? well, let me open up a programthat i wrote in advance, and poke around online called hello 4. and it's almost identical, except thatits got a little bit of error-checking. in this case, i've again declaredmain as taking two arguments,

but this time, on line 17, noticei'm doing a bit of a sanity check. i'm making sure thatargc equals equals 2. because if it is, thatmeans i can safely touch not only bracket 0, but bracket 1. and i go ahead and print out,in this case, zamyla or rob or whatever word i typed out. and now just to geta little more proper, i'm going to explicitly return0 to signify all is well. nothing bad happened.

>> but by convention, i'm going toreturn 1, or frankly any non-0 value, if something went wrong. now the user is not going toreally notice what's going on. indeed if i go into this directory,we zoom in and do make hello 4, ./hello-4 zamyla behaves as i expect. but if i instead don't typeanything, nothing seems to happen, but it doesn't crash. and if i instead do somethinglike rob is a proctor in thayer-- sharingarbitrary information.

but notice, argv 1, 2, 3, 4, and5 should now exist in memory. that, too, is not whatmy program expects, because i've checked whetherargc equals equals 2 or not. so i'm now defending against this. >> now, as an aside, we theprogrammer-- or rather we the users-- never see that 0 or 1 but using atool called debugger, or other tools, as we'll see beforelong, you the programmer can actually see what might begoing wrong inside of your program. >> so, any questions on argc?

yeah. >> audience: i've seen where theyhaven't had the character, [inaudible] just said string star d, likecharacter asterisk comma. are they equivalent here? >> david malan: they are. so the question is, you haveoccasionally seen programs like this that don'tsay string argv bracket but instead say somethinglike char star argv bracket. and there's even othervariants that you might see.

they are indeed equivalent. for now, we have thesesort of training wheels on in the form of string in the cs50library, but in just over a week or so we're going to remove thatobstruction altogether and actually look at what the char and the starare, and how those pertain to memory representation more generally. so we'll come back to that. >> other questions on our argv or argc? audience: why did it returnan error [inaudible]?

david malan: why did itreturn an error only-- oh! in the previous case, when wewere futzing around with memory, why did it only return an errorwhen i really typed a big number? short answer is, we just got lucky. generally speaking, a computerallocates memory in chunks, and it gave me a big enough chunk thati got away, without being noticed, of touching bracket 2, bracket 3,bracket 50, but as soon as i pushed my luck, i went beyond theboundaries of the chunk of memory the operating system had given me.

and that's when itclamped down and said, no. segmentation error. >> audience: how does the computerknow the value of argc? >> david malan: how does thecomputer know the value of argc? when you run a program, that program,by nature of the blinking prompt, is handed the array ofwords that were typed at the prompt, that wastyped at the prompt. and so it is your operatingsystem that essentially populates main's arguments for you.

so that's one of the servicesthat you get, sort of secretly underneath the hood ofan operating system. other questions? >> audience: what does core dump mean? david malan: what does core dump mean? so that's a good question. and let me go back intothis directory here. and you'll notice thati have a new file there. it's indeed called core, and it'sactually typically a decent-sized file.

that is essentially a snapshot ofthe contents of my program's memory or ram when it crashed. and this will be useful,potentially, diagnostically, once we talk in a future lectureand section about debugging, because you can actually do theequivalent of a digital autopsy on that file to help figure outwhat you did wrong in your program. >> audience: is argc a command initself, or can you name it anything? >> david malan: good question. is argc a command in itself,or can you name it anything?

it's definitely not a command. it's simply a variable'sname or an argument's name, and so absolutely wecould call this foo, we could call this bar, which tendto be the go-to words that a computer scientist goes to. but by convention, we use argc and argv. but that's just a humanconvention, nothing more. so turns out, i've beentelling a bit of a white lie-- and frankly, in the future, you'll seewe've been telling other white lies.

but for now, we're goingto peel back one of these. in this case here when i previouslyran a program like ./hello or ./hello-3 zamyla, we had the contents of mycomputer's memory looking roughly like this. but recall what a string is. what did we say a week ago what astring actually is underneath the hood? audience: array of chars. david malan: it's anarray of chars, right? so we might have an array ofstrings, but, in turn, a string

is an array of characters. so if i really want to beanal when i draw this picture, i should really be drawingit a little more like this, whereby in each of theseindexes of my argv array, there is itself a whole stringthat itself is in an array. and now the white liewe're telling today is that the picture doesn'tlook quite like this. in fact, the little squares aretypically outside of the big rectangles there.

but we'll come back to that before long. but this is ./hello backslash 0,that being the special character that demarcates the end of a string,and we've got another one after zamyla's name. so what does this mean? >> well, let me go ahead andopen up two other examples that are available online. one is called argv1.cand the other is argv2. it's a super-simple program thatis different from past programs

in that now i'm usingargc and argv up here. and now i'm integrating with a for loopin line 18, from i=0 on up to argc. and what am i going to dowith this line of code here? in english. this obviously demonstrates use of argc. but in english, what doesit do if i run this program? yeah? >> audience: it's going to print yourscreen as many times as you want. david malan: exactly.

so whatever words itype at the prompt, it's going to regurgitatethem at me one per line. so let's go ahead and do this. let me go into my directoryand do make argv1 ./argv1. and now, let's keep it simple. let's do nothing at first. it did print out one thing, andthat's indeed the name of the program, because that's in bracket 0. if i now say foo, it's going to dothose two, and if i say foo bar,

it's going to say those three things. now that's somewhat interesting, maybe. but recall that argvis an array of strings, but a string is an array of chars,so we can take things up a notch and apply that basiclogic and make code that looks a little more cryptic, admittedly. but by having a nestedloop, something akin to what you might recall from mario,for instance, if you did it this way. >> so now notice on line 19, i'magain iterating over my arguments,

from 0 on up to argc. and now in line 21-- i'mborrowing a trick from last week-- i am checking what is thelength of argv bracket i. i'm storing that answer in n. and then i'm integrating from j onup to n, where j is initialized to 0. so, convention for counting. once you've used i, if you have anested loop, you can't use i again, otherwise you'll clobber, potentially,the value outside of the inner loop. so i'm using j by convention.

we might use k. if you have more than k, you probablyhave too much nesting, typically. but now, notice my printfline is slightly different. i'm not printing %s, i'mprinting %c, which, of course, is a placeholder for a char. >> and now notice this syntax. new. we haven't seen it before. but logically, this just meansget the ith string in argv

and get the jth what? audience: character. david malan: character in that string. so by using square bracketsfollowed by square brackets, this is diving firstinto argv's strings, and then the secondsquare brackets with j is diving into the characters ofthat particular string in argv. and then, just for good measure,i'm printing a new line here. so now let me go ahead and openup a slightly bigger window

so we can see this in action. let me go into that folder. and now do make argv-2--whoops-- make argv-2, ./argv 2. and it's a little hardto read vertically, but that's indeed the name of theprogram, followed by a blank line. now let me go ahead and do foo. similarly hard to read, but it'sindeed printing one character per line. and if i do bar, it's nowprinting those line by line. so the takeaway here isn't so muchthat, wow, look at this neat new trick

where you can get at the contentsof an array's specific characters, but rather how we're taking these basicideas like indexing into an array, and then indexing into anarray that was in that array, and just applying the same ideas toslightly more sophisticated examples. but the basics really haven'tchanged, even since last week. >> now this is sort of timely,in that, recall, in week zero we played with a phone book like this. and even though this is obviouslyphysical pieces of paper, you can kind of think ofa phone book as an array.

certainly, if you were to reimplementthis pieces these pieces of paper in a computer, probablyyou would use something like an array to store all of thosenames and numbers from a all the way through z. so this is nice, becauseit allows us an opportunity, perhaps, to consider how you mightactually implement something like that. as with a series of doors here. so if i could-- we need onevolunteer to come on up. an unfamiliar face perhaps,unfamiliar face perhaps. how about in orange?

here. orange shirt, come on up. >> let's go ahead now and movethese doors over to the side, move these out of the way for a moment. what's your name? >> ajay: >> david malan: ajay. david. nice to meet you.

so we have behind these sixdoors digitally on the screen-- or, rather, seven doors on thescreen-- a whole bunch of numbers. and i've told you nothingin advance-- agreed? ajay: nothing in advance. david malan: all i want you to donow is to find for me, and for us, really, the number 50,one step at a time. >> ajay: number 50? >> david malan: the number 50. and you can reveal what'sbehind each of these doors

simply by touching it with a finger. damn it. [laughter] >> [applause] >> very well done. we have a lovely giftprize for you here. your pick of movies wediscussed last week. >> ajay: oh, man. oh, i've never seen spaceballs. >> david malan: spaceballs.

so hold on just one moment. how-- let's make thisa teachable moment-- how did you go aboutfinding the number 50? ajay: i chose randomly. david malan: so you choserandomly and got lucky. ajay: yes. david malan: ok. excellent. so now, had you notgotten lucky, what else

might have happened behind these doors? so if i go ahead andreveal these numbers here, they actually are in random order. and the best you could havedone, frankly, is by, ultimately, in the worst case, checking them all. so you got super-lucky, whichisn't what we'd call an algorithm. yes, congrats. but now let's-- humor me, if you could. let's go to this tab here.

and here are the numbers in clearlywhat seems to be a random order, and they were. but now if i instead claimthat behind these doors are numbers that are sorted. the goal now is to alsofind us the number 50. but do it algorithmically, andtell us how you're going about it. and if you find it, you keep the movie. you don't find it, you give it back. ajay: so i'm going to check the endsfirst, to determine if there's--

[laughter and applause] david malan: here you go. let's take a look at oneof ajay's predecessors, sean, who wasn't quite as lucky. ok, so your task here,sean, is the following. i have hidden behind thesedoors the number seven, but tucked away in some of these doorsas well are other non-negative numbers. and your goal is to think of thistop row of numbers as just an array. we're just a sequence of piecesof paper with numbers behind them.

and your goal is, only using the toparray here, find me the number seven. and we are then going to critiquehow you go about doing it. find us the number seven, please. no. 5, 19, 13. it's not a trick question. 1. at this point your score is not verygood, so you might as well keep going. 3.

go on. frankly, i can't help but wonderwhat you're even thinking about. >> sean: i can take from only the top row. david malan: only the top row. so you've got three left. so find me 7. >> [audience shouts suggestions] so both of those were amazingfor very different reasons. so this is where weleft off a moment ago,

and the key insight herewas these doors had numbers behind them that were sorted, the idealtakeaway for which is that you could do fundamentally better inthis second example-- and, indeed, that was sean'sfirst attempt with random numbers just as before-- but as soonas these numbers are sorted, much like the phone book,what can you obviously do? or how can you leverage that knowledge? >> audience: you go halfway [inaudible]. david malan: yeah.

exactly. so ajay's initial instinct wasto check the ends, as i recall, and then we sort of finishedthe example quickly. but if we started to do this moremethodically along those lines, but starting perhaps in themiddle, because they're sorted, as soon as we reveal thenumber 16, we therefore know-- and let's do exactly that-- wetherefore know that 50, in today's case, has got to be to the right. so just like in week zero whenwe tore the phone book in half

and threw half of theproblem away, same idea here. we can throw this halfof the problem away. and probably what youmight do algorithmically, once you know that 50 must beto the right, if it's anywhere, is try there, in the middleof the remaining doors. of course, 50 is higherthan 42, so we can throw this remainingquarter of the problem away, and, finally, identifysomething like 50. but just as with thephone book, these numbers

were given to us already insorted order, which leaves us with the question, how do youget things into sorted order? and, frankly, at what cost? it's one thing to behanded the phone book and then impress your friends by findinga phone number really quickly, right? tearing 32 pages out to find aperson out of 4 billion pages, we said was one extreme example. but how much time did it takeverizon to sort that phone book? how much time did it take usto sort these seven numbers?

that's a question that we'vethus far completely ignored. >> so let's answer this question now. and we're all out of movies now,but we do have some stress balls. if, say, eight volunteerswouldn't mind joining us up here? let's go ahead and do, how aboutthe four of you, three of you here? get some new faces. and the four of you there? and now-- let's not bias here-- andnumber eight over here on the end. come on up.

so what we have here foreach of you is a number. if you'd like to goahead, take this number. >> artie:artie. >> david malan: artie, okay. you're number 1. >> amin: amin. david malan: amin. you're number 2. and go ahead, as i handyou the sheets of paper,

line yourselves up in front of the musicstands in the same order as up there. >> andy: hi, andy. >> david malan: andy, it's nice to see you. number 3. >> jacob: jacob. >> david malan: jacob, number 4. welcome aboard. grant: grant. david malan: grant.

number 5. >> alanna: alanna. >> david malan: alanna, number 6. >> frances: frances. david malan: frances, number 7. and? >> rachel: rachel. >> david malan: rachel, number 8. go ahead and get yourself in this order.

let me put one remainingmusic stand in place. where do you need a stand? go ahead and just put your numberswhere the audience can see them on, the music stand facing outward. and hopefully, our firstsanity check here-- 4, 2, 6. oh-oh. wait a minute. we don't have an 8. i need to evict you fromthe example somehow.

no, that's ok. we can do this. stand by. there we go. correct. so, now we have 8, 1, 3 7, 5. >> so the question at hand is, atwhat cost, and via what method, can we actually sort these numbers hereso that we can kind of work backwards, ultimately, and decide-- is it reallyimpressive, is it really efficient,

that i can divide andconquer a phone book? is it really efficient thati can divide and conquer those digital piecesof paper on the board, if maybe it's going to cost us afortune in time or energy or cpu cycles to actually get our datainto some sorted order? so let's ask that question. >> so first off, these numbers arein pretty much random order, and i'm going to proposeone algorithm, or process by which we can sort these folks.

i'm going to approachthis pretty naively. and i'm going to recognizethat it's kind of a lot for me to wrap my mind around thewhole data set at once. but you know what? i'm going to make somevery simple marginal fixes. 4 and 2 are out of order, if thegoal is to go from 1 on up to 8. so you know what? i'm going to have youguys swap, if you switch physically positions andyour pieces of paper.

now 4 and 6, these are in order. i'm going to leave those be. 6 and 8, those are in order. going to leave them be. 8 and1, out of order. if you two wouldn't mind swapping. now 8 and 3, if you guys could swap. 8 and 7, if you guys could swap. and 8 and 5, if you guys could swap.

>> now, am i done? no, obviously not. but i have made thesituation better, right? what was your name again, number 8? david malan: so rachel haseffectively bubbled up pretty far, all the way to the end ofmy array of numbers here. and so that problem is kind of solved. now, clearly, 2 still needs tomove a bit, and 4 and 6 and 1. but i seem to have gotten alittle closer to the solution.

so let's apply this samenaive heuristic again. 2 and 4, ok. 4 and 6, ok. 6 and 1, mm-mm. let's swap. 6 and 3, mm-mm. 6 and 7 is ok. 7 and 5, nope. and now 7 and 8.

and what's your name again? frances: frances. david malan: frances. so now frances is in even a betterposition, because now 7 and 8 are correctly bubbled up to the top. so 2 and 4, ok. 4 and 1, let's swap. 4 and 3, let's swap. 4 and 6, you're ok.

6 and 5, let's swap. and now those guys are good. we're almost there. 2 and 1, out of order, so swap. and now let me do a sanity check. 2 and 3, 3 and 4, 4 and5, 5 and 6, 6 and 7, 8. ok, so we're done. >> but at what cost did isort these numbers here? well, how many steps did i potentiallytake when sorting these folks?

well, we'll come back to that question. but, frankly, if you gota little bored, that's kind of revealing in that this wasn'tmaybe the most efficient algorithm. and indeed, frankly, i'm sweatingall the more walking back and forth. that didn't feel particularly efficient. so let's try something else. if you guys could resetyourselves to these eight values. good job. >> let's take a look digitally, for justa moment before we try something else,

at what just happened. up here, you're about to see avisualization of these eight humans whereby blue and redbars represent numbers. the taller the bar,the bigger the number. the shorter the bar,the smaller the number. and what you're going to see is inrandom order more than eight of them. you're going to see these barsgetting sorted by that same algorithm, or set of instructions, whichwe'll call henceforth bubble sort. so notice, every second or so,two bars are lighting up in red,

are being compared by the computer. and then if the big bar and thelittle bar are out of order, they are being swapped for me. >> now this is incredibly tediousto watch this, certainly, for very long, but notice thetakeaway-- big bars moving to the right, little bars moving to the left. let's abort this processand speed this up to be much faster, so we canget a high-level sense of what, indeed, bubble sort is doing.

indeed, it's bubbling up to theright hand side of the list, or the array, the bigger bars. and conversely, the little bars arebubbling their way down to the left, albeit at a faster pacethan we previously did. so, harder to see with humans,but visually that's indeed what was happening. >> but let's try a fundamentallydifferent approach now. let's try a differentalgorithm whereby we have you guys start in these originalpositions, which was this order here.

and let's go ahead now. and i'm going to do somethingeven simpler, right? in retrospect, swapping pairwise againand again, almost a little clever. let's do things even more naively,where if i want to sort these folks, let me just keep lookingfor the smallest element. so right now, 4 is thesmallest number i've seen. i'm going to remember that. no, 2 is better, and remember that. 1 is even smaller.

3, 7, 5. one-- what's your name again? >> artie: artie. >> david malan: artie. so, artie, go ahead. i'm going to pull you out of the line. if you could come back here. and i need to make room for him. we have a decision point here.

how might we make room for artie hereat the beginning where number 1 belongs? >> audience: shift. >> david malan: ok, wecould shift everyone. but propose an optimization. that feels a little annoyingfor me to ask four people to move all the way down. what else could i do? >> audience: switch them. >> david malan: switch them.

david malan: jacob, move. much more efficient just to havejacob swap locations with artie, as opposed to forcingall four of these folks, thank you very much, totheir correct position. what's nice about artie now,he's in his correct position. let's do this again. 2, that's the smallest number i've seen. 2 is definitely the smallest. don't have to do any work.

let's do it again. 6. smallest? 8. nope. 4? ooh. let me remember 4. let me remember 3.

7, 5. smallest number i'veseen on this pass is 3. if you'd come on out. where are we going to put you? and what's your name? >> david malan: alanna, we'regoing to have to evict you. but that is more efficient,to just swap two people, than to have multiple peopleactually sidestep over. now let's do this again.

i'm going to select 4, so come on out. and who's going to move? number 8, of course. if i now find number 5, come on out. number 8's going to get evicted again. i'm now going to find number 6 in place. 7 in place. 8 in place. >> what we just did now issomething called selection sort,

and if we visualize this, it'sgoing to feel a little different. let's go ahead and from thismenu here, this visualization-- let's change this to-- come on, firefox. let's change this to selection sort. and let's speed it up as before,and start the visualization now. and this algorithm hasa different feel to it. on each iteration, frankly,it's even more straightforward. i'm just selecting the smallest element. now, frankly, i got a little lucky thattime, in that it sorted super-fast.

the elements were random. it's not, as we'll eventuallysee, fundamentally faster. but let's see a third and finalapproach here as to what's going on. so let's go ahead and reset you guysone final time to be in this order here. >> and now, i'm going tobe a little more clever, just to round out our algorithms. i'm going to do this. i'm going to not goback and forth so much. frankly, i'm tired ofall this traversing.

i'm just going to take what i'mgiven at the beginning of the list, and i'm going to sortthat then and there. so here we are. number 4. i'm going to insert number4 into a sorted list. done. i claim now, and just to make this moreclear, this part of my list is sorted. it's kind of a stupid claim, but indeed4 is sorted in a list of size one. now, i'm going to take on number 2.

number 2 i'm now going toinsert into the right place. so where does 2 belong? obviously, over here. so go ahead and move back, if you could. and why don't you guys just takeyour music stands with you this time. and let's forcibly insert youinto the beginning of the list. so a little more work. i had to move jacob around,and what's your name? >> david malan: amin.

but at least i didn't go back and forth. i'm just taking things as i go. i'm just inserting themin the right place. 6, this is actually pretty easy. let's insert you over there, if youjust wanted to move over slightly. number 8, also pretty easy. right over there. damn it. number 1 we can't justswap with amin here,

because that's goingto mess up the order. so we have to be a little more clever. so, artie, if you couldback up for a moment. let's go ahead and shift now,unlike our previous algorithms, to make room for artieright here at the beginning. so at the end of the day, i'm kind ofdoing what i wanted to avoid before. and so my algorithm is sortof reversed, intellectually, from what it originally was. i'm just doing the shiftingat a different point.

now i'm at 3. oh, damn. we have to do more work again. so let's push you out. let's move 8, 6, 4-- oh oh-- and3 is going to go right there. so at least slight savings this time. 7, not too much work to be done. so if you want to popback, let's insert you. and lastly, 5, if youwant to pop back, we

need to shift you, you,you, until five is in place. >> so now to see this at ahigh level graphically, let's do this algorithmvisualization one additional time. so this we shall call insertion sort. we'll run it just asfast, and start it here. and it, too, has a different feel. it's sort of getting better andbetter, but it's never perfect until i go in and smooth in those gaps. because, again, i'm only taking whati'm being given from left to right.

so i didn't get so luckythat everything was perfect. that's why we had these littlemispositions that we fixed over time. >> so all of these algorithms seem torun at slightly different paces. in fact, which would you say isthe best or the fastest so far? bubble sort, the first? selection sort, the second? insertion sort, the third? i hear some selection sorts. other thoughts?

>> so it turns out thatall of these algorithms are fundamentally just as efficient aseach other-- or, conversely, just as inefficient as each other,because we can do fundamentally better than all threeof these algorithms. and that's a bit of a white lie, too. when i say as efficientor as inefficient, that's at least forsuper-large values of n. when we have just eight people here,or maybe 50 or so bars on the screen, you'll absolutely notice differencesamong these three algorithms.

but as n, the number of people,or the number of numbers, or the number of people in the phonebook, or the number of web pages in google's databasegets bigger and bigger, we'll see that all three of thesealgorithms are actually pretty poor. and we can do fundamentallybetter than that. >> let's take a look, finally,at what these algorithms might sound like in thecontext of a few others as well by way of thisvisualization here that will introduce us toa number of algorithms.

let's go ahead and congratulateour participants here, all of whom sorted themselves very well. if you'd like to take a parting gift. you can keep your numbers as well. and what you'll see,or rather hear, now, is that as we put soundsto each of these bars and associate it with the software,different frequency of sound, you can wrap your mind more audiolyaround what each of these things look like.

the first of which is insertion sort >> [tones] >> this is bubble sort. >> selection sort. >> something called merge sort. >> gnome sort. >> that's it for cs50. we will see you on wednesday. >> narrator: and now, "deepthoughts," by daven farnham.

why is it a for loop? why not make it better? i'd make a five loop. >> [laughter]

No comments :

Post a Comment