码迷,mamicode.com
首页 > 其他好文 > 详细

CS3334 Lecture 3

时间:2018-02-04 15:40:52      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:post   for   one   base   height   sort   storage   bsp   min   

Arrays, Linked Lists, Stacks & Queues 

Introduction

Efficiency is important

Focus on main memory data storage; data storage in secondary storage (e.g., hard disks and databases) is usually called indexing structures 

 


Array

Array is a data structure that arranges items at equally spaced addresses in computer memory 

int foo[7]

Unsorted Arrays

Pros:

  • Array elements can be accessed by specifying the array name followed by the index in square brackets. Eg foo[2] is 8
  • Efficient for insertion by appending a new element.

Cons:

  • Have to scan through the whole array to determine for sure if an item is not there 

Sorted Arrays

Pros:

  • Efficient for searching

Cons:

  • Have to move all items behind the point of insertion to make room for the new one 

 


Linked Lists

 

A linked list is a data structure that allows both efficient searching and insertion/deletion.

A collection of items linked in a sequence: 

技术分享图片

Pros:

  • Easy to insert/delete items in the middle, provided we know where to insert/delete (a sorted linked list can easily be maintained.) 

Cons:

  • Difficult to access the i-th item, given an arbitrary i

 

 


Stacks

A stack is a sequence of elements in which update can only happen at one end of the sequence, called the top.

Operations supported:

– push(x): add an element x to the top

– pop(x): remove the top element and return it in x, i.e., first-in-last-out (FILO) 

技术分享图片

 

 

 

 

 


Queues

 

 

 

 

 

 

 

 

 

 

 

CS3334 Lecture 3

标签:post   for   one   base   height   sort   storage   bsp   min   

原文地址:https://www.cnblogs.com/charon922/p/8413176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!