欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    《基本数据结构》PPT课件.ppt

    • 资源ID:5487091       资源大小:595KB        全文页数:30页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    《基本数据结构》PPT课件.ppt

    Elementary Data Structures,Stacks,Queues,&ListsAmortized analysisTrees,Elementary Data Structures,2,The Stack ADT(2.1.1),The Stack ADT stores arbitrary objectsInsertions and deletions follow the last-in first-out schemeThink of a spring-loaded plate dispenserMain stack operations:push(object):inserts an elementobject pop():removes and returns the last inserted element,Auxiliary stack operations:object top():returns the last inserted element without removing itinteger size():returns the number of elements storedboolean isEmpty():indicates whether no elements are stored,Elementary Data Structures,3,Applications of Stacks,Direct applicationsPage-visited history in a Web browserUndo sequence in a text editorChain of method calls in the Java Virtual Machine or C+runtime environmentIndirect applicationsAuxiliary data structure for algorithmsComponent of other data structures,Elementary Data Structures,4,Array-based Stack(2.1.1),A simple way of implementing the Stack ADT uses an arrayWe add elements from left to rightA variable t keeps track of the index of the top element(size is t+1),Algorithm pop():if isEmpty()thenthrow EmptyStackException else t t 1return St+1,Algorithm push(o)if t=S.length 1 thenthrow FullStackException else t t+1St o,Elementary Data Structures,5,Growable Array-based Stack(1.5),In a push operation,when the array is full,instead of throwing an exception,we can replace the array with a larger oneHow large should the new array be?incremental strategy:increase the size by a constant cdoubling strategy:double the size,Algorithm push(o)if t=S.length 1 thenA new array ofsize for i 0 to t do Ai Si S At t+1St o,Elementary Data Structures,6,Comparison of the Strategies,We compare the incremental strategy and the doubling strategy by analyzing the total time T(n)needed to perform a series of n push operationsWe assume that we start with an empty stack represented by an array of size 1We call amortized time of a push operation the average time taken by a push over the series of operations,i.e.,T(n)/n,Elementary Data Structures,7,Analysis of the Incremental Strategy,We replace the array k=n/c timesThe total time T(n)of a series of n push operations is proportional ton+c+2c+3c+4c+kc=n+c(1+2+3+k)=n+ck(k+1)/2Since c is a constant,T(n)is O(n+k2),i.e.,O(n2)The amortized time of a push operation is O(n),Elementary Data Structures,8,Direct Analysis of the Doubling Strategy,We replace the array k=log2 n timesThe total time T(n)of a series of n push operations is proportional ton+1+2+4+8+2k=n+2k+1-1=2n-1T(n)is O(n)The amortized time of a push operation is O(1),Elementary Data Structures,9,The accounting method determines the amortized running time with a system of credits and debitsWe view a computer as a coin-operated device requiring 1 cyber-dollar for a constant amount of computing.,Accounting Method Analysis of the Doubling Strategy,We set up a scheme for charging operations.This is known as an amortization scheme.The scheme must give us always enough money to pay for the actual cost of the operation.The total cost of the series of operations is no more than the total amount charged.(amortized time)(total$charged)/(#operations),Elementary Data Structures,10,Amortization Scheme for the Doubling Strategy,Consider again the k phases,where each phase consisting of twice as many pushes as the one before.At the end of a phase we must have saved enough to pay for the array-growing push of the next phase.At the end of phase i we want to have saved i cyber-dollars,to pay for the array growth for the beginning of the next phase.,We charge$3 for a push.The$2 saved for a regular push are“stored”in the second half of the array.Thus,we will have 2(i/2)=i cyber-dollars saved at then end of phase i.Therefore,each push runs in O(1)amortized time;n pushes run in O(n)time.,Elementary Data Structures,11,The Queue ADT(),The Queue ADT stores arbitrary objectsInsertions and deletions follow the first-in first-out schemeInsertions are at the rear of the queue and removals are at the front of the queueMain queue operations:enqueue(object):inserts an element at the end of the queueobject dequeue():removes and returns the element at the front of the queue,Auxiliary queue operations:object front():returns the element at the front without removing itinteger size():returns the number of elements storedboolean isEmpty():indicates whether no elements are storedExceptionsAttempting the execution of dequeue or front on an empty queue throws an EmptyQueueException,Elementary Data Structures,12,Applications of Queues,Direct applicationsWaiting linesAccess to shared resources(e.g.,printer)MultiprogrammingIndirect applicationsAuxiliary data structure for algorithmsComponent of other data structures,Elementary Data Structures,13,Singly Linked List,A singly linked list is a concrete data structure consisting of a sequence of nodesEach node storeselementlink to the next node,next,elem,node,A,B,C,D,Elementary Data Structures,14,Queue with a Singly Linked List,We can implement a queue with a singly linked listThe front element is stored at the first nodeThe rear element is stored at the last nodeThe space used is O(n)and each operation of the Queue ADT takes O(1)time,f,r,nodes,elements,Elementary Data Structures,15,List ADT(),The List ADT models a sequence of positions storing arbitrary objectsIt allows for insertion and removal in the“middle”Query methods:isFirst(p),isLast(p),Accessor methods:first(),last()before(p),after(p)Update methods:replaceElement(p,o),swapElements(p,q)insertBefore(p,o),insertAfter(p,o),insertFirst(o),insertLast(o)remove(p),Elementary Data Structures,16,Doubly Linked List,A doubly linked list provides a natural implementation of the List ADTNodes implement Position and store:elementlink to the previous nodelink to the next nodeSpecial trailer and header nodes,prev,next,elem,trailer,header,nodes/positions,elements,node,Elementary Data Structures,17,Trees(2.3),In computer science,a tree is an abstract model of a hierarchical structureA tree consists of nodes with a parent-child relationApplications:Organization chartsFile systemsProgramming environments,Elementary Data Structures,18,Tree ADT(),We use positions to abstract nodesGeneric methods:integer size()boolean isEmpty()objectIterator elements()positionIterator positions()Accessor methods:position root()position parent(p)positionIterator children(p),Query methods:boolean isInternal(p)boolean isExternal(p)boolean isRoot(p)Update methods:swapElements(p,q)object replaceElement(p,o)Additional update methods may be defined by data structures implementing the Tree ADT,Elementary Data Structures,19,Preorder Traversal(),A traversal visits the nodes of a tree in a systematic mannerIn a preorder traversal,a node is visited before its descendants Application:print a structured document,Make Money Fast!,1.Motivations,References,2.Methods,2.1 StockFraud,2.2 PonziScheme,1.1 Greed,1.2 Avidity,2.3 BankRobbery,1,2,3,5,4,6,7,8,9,Algorithm preOrder(v)visit(v)for each child w of vpreorder(w),Elementary Data Structures,20,Postorder Traversal(),In a postorder traversal,a node is visited after its descendantsApplication:compute space used by files in a directory and its subdirectories,Algorithm postOrder(v)for each child w of vpostOrder(w)visit(v),cs16/,homeworks/,todo.txt1K,programs/,DDR.java10K,Stocks.java25K,h1c.doc3K,h1nc.doc2K,Robot.java20K,9,3,1,7,2,4,5,6,8,Elementary Data Structures,21,Binary Trees(),A binary tree is a tree with the following properties:Each internal node has two childrenThe children of a node are an ordered pairWe call the children of an internal node left child and right childAlternative recursive definition:a binary tree is eithera tree consisting of a single node,ora tree whose root has an ordered pair of children,each of which is a binary tree,Applications:arithmetic expressionsdecision processessearching,A,B,C,F,G,D,E,H,I,Elementary Data Structures,22,Arithmetic Expression Tree,Binary tree associated with an arithmetic expressioninternal nodes:operatorsexternal nodes:operandsExample:arithmetic expression tree for the expression(2(a-1)+(3 b),Elementary Data Structures,23,Decision Tree,Binary tree associated with a decision processinternal nodes:questions with yes/no answerexternal nodes:decisionsExample:dining decision,Want a fast meal?,How about coffee?,On expense account?,Starbucks,In N Out,Antoines,Dennys,Yes,No,Yes,No,Yes,No,Elementary Data Structures,24,Properties of Binary Trees,Notationnnumber of nodesenumber of external nodesinumber of internal nodeshheight,Properties:e=i+1n=2e-1h ih(n-1)/2e 2hh log2 eh log2(n+1)-1,Elementary Data Structures,25,Inorder Traversal,In an inorder traversal a node is visited after its left subtree and before its right subtreeApplication:draw a binary treex(v)=inorder rank of vy(v)=depth of v,Algorithm inOrder(v)if isInternal(v)inOrder(leftChild(v)visit(v)if isInternal(v)inOrder(rightChild(v),3,1,2,5,6,7,9,8,4,Elementary Data Structures,26,Euler Tour Traversal,Generic traversal of a binary treeIncludes a special cases the preorder,postorder and inorder traversalsWalk around the tree and visit each node three times:on the left(preorder)from below(inorder)on the right(postorder),+,-,2,5,1,3,2,L,B,R,Elementary Data Structures,27,Printing Arithmetic Expressions,Specialization of an inorder traversalprint operand or operator when visiting nodeprint“(“before traversing left subtreeprint“)“after traversing right subtree,Algorithm printExpression(v)if isInternal(v)print(“()inOrder(leftChild(v)print(v.element()if isInternal(v)inOrder(rightChild(v)print(“),(2(a-1)+(3 b),Elementary Data Structures,28,Linked Data Structure for Representing Trees(),A node is represented by an object storingElementParent nodeSequence of children nodesNode objects implement the Position ADT,B,D,A,C,E,F,B,A,D,F,C,E,Elementary Data Structures,29,Linked Data Structure for Binary Trees,A node is represented by an object storingElementParent nodeLeft child nodeRight child nodeNode objects implement the Position ADT,B,D,A,C,E,Elementary Data Structures,30,Array-Based Representation of Binary Trees,nodes are stored in an array,let rank(node)be defined as follows:rank(root)=1if node is the left child of parent(node),rank(node)=2*rank(parent(node)if node is the right child of parent(node),rank(node)=2*rank(parent(node)+1,1,2,3,6,7,4,5,10,11,

    注意事项

    本文(《基本数据结构》PPT课件.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开