CS3334 Lecture 3

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

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

时间: 2024-11-02 13:29:51

CS3334 Lecture 3的相关文章

CS3334 Lecture 1

Lecture 1: Complexity Analysis How to measure Running time: Use a function to model the running time of a program or procedure. Assume an abstract machine and count the number of "steps" executed by an algorithm Function: In mathematics, a funct

codeforces 499B.Lecture 解题报告

题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 professor's lecture 的 n 个单词.问记下来的笔记是什么.对于professor's lecture 的某个单词,如果在单词表中找到,word1, word2 都有可能.如果 word1 的长度  <= word2 的长度,就输出word1,否则word2 考了map<string, st

Learning OpenCV Lecture 4 (Transforming Images with Morphological Operations)

In this chapter, we will cover: Eroding and dilating images using morphological filters Opening and closing images using morphological filters Detecting edges and corners using morphological filters Segmenting images using watersheds 分水岭算法 Extracting

Learning OpenCV Lecture 5 (Filtering the Images)

In this chapter, we will cover: Filtering images using low-pass filters Filtering images using a median filter Applying directional filters to detect edges Computing the Laplacian of an image 图像各有不同因为他们有不一样的灰度级分布.如天空的灰度级不怎么变化,但是在一个对象非常多的图像里面,灰度级变化非常剧

C++基本要点复习--------coursera程序设计实习(PKU)的lecture notes

因为一些特性复杂,很多时候也用不到一些特性,所以忘记了,算是随笔,也当作一个临时查找的手册.没有什么顺序,很杂. 1.构造函数通过函数重载的机制可以有多个(不同的构造函数,参数个数,或者参数类型不同.),但是析构函数只能有一个.当没有在代码中写明构造或析构函数时,编译器会自动生成缺省的构造或析构函数.构造函数和析构函数都无返回值.另外,析构函数必须无参数.没写复制(拷贝)构造函数,编译器也会自动生成缺省的复制构造函数.复制构造函数会生成一个临时隐藏的对象,在调用一个以类对象作为参数的函数和调用一

Codefources 519E. A and B and Lecture Rooms LCA

简单LCA: 求树上距离给定两个点a,b距离相等的点有多少个 先预处理出每个节点的孩子个数sum[x],求出a,b的LCA,根据深度就可以知道两个点的距离,距离为偶数的有解.... 根据lca在a,b之间的位置不同分情况讨论: 设a与lca距离为 ha , b与lca距离为 hb 1:lca在a,b正中间既a,b分别属于lca的两个子树中, 结果为: n-sum[ a往上距离lca ha-1 的点] - sum[ b往上距离lca hb-1 的点] 2:a,b两个点相对lca一上一下. c:a,

Learning OpenCV Lecture 6 (Extracting Lines,Contours, and Components)

In this chapter, we will cover: Detecting image contours with the Canny operator Detecting lines in images with the Hough transform Fitting a line to a set of points Extracting the components' contours Computing components' shape descriptors Detectin

Learning OpenCV Lecture 3 (Counting the Pixels with Histograms)

In this chapter, we will cover: Computing the image histogram Applying look-up tables to modify image appearance Equalizing the image histogram Backprojecting a histogram to detect specific image content Using the mean shift algorithm to find an obje

Learning OpenCV Lecture 2 (Using the Strategy pattern in algorithm design)

ColorDetector.h: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> class ColorDetector { public: // empty constructor ColorDetector() : minDist(100) { // default parameter initialization here target[0] = target[1] = targe