Download presentation
Presentation is loading. Please wait.
Published byAndré Beauchemin Modified over 5 years ago
1
Introduction to Data Structures and Algorithms
Chien-Chung Shen CIS/UD
2
Data Structures A data structure is a way of organizing, storing, and performing operations on data Examples: array, list, stack, tree, heap, graph The choice of data structures used in a program (application) depends on both the type of data being stored and the operations the program may need to perform on that data e.g., array vs. (linked) list there are no bad (or good) data structures, but only “suitable” data structures
3
Algorithms An algorithm describes a sequence of steps to solve a computational problem or perform a calculation An algorithm can be described in English, pseudocode, a programming language, hardware (e.g., ASIC), etc. A computational problem specifies an input, a question about the input that can be answered using a computer, and the desired output Jeannette M. Wing, Computational Thinking, Communications of the ACM, Volume 49, Issue 3, pp , March 2006 A skill in addition to reading, writing, and arithmetic Video lecture 1 and video lecture 2
4
Efficient Algorithms and Hard Problems
Algorithm efficiency is most commonly measured by the algorithm runtime, and an efficient algorithm is one whose runtime increases no more than polynomially with respect to the input size There are problems where the existence of “efficient algorithms” are unknown NP-complete problems are a set of problems for which no known efficient algorithm exists Characteristics of NP-complete problems no efficient algorithm has been found to solve an NP-complete problem no one has proven that an efficient algorithm to solve an NP-complete problem is impossible if an efficient algorithm exists for one NP-complete problem, then all NP-complete problem can be solved efficiently
6
Efficient Algorithms and Hard Problems
By knowing a problem is NP-complete, instead of trying to find an efficient algorithm to solve the problem optimally, people focus on finding an algorithm to efficiently find a good, but non-optimal, solution
7
Clique Problem The clique problem is the computational problem of finding cliques (subsets of vertices, all adjacent to each other (termed complete subgraphs) in a graph 2-clique in 7-vertex graph 3-clique in 7-vertex graph 4-clique in 7-vertex graph
8
4-clique “brute force” algorithm C(7, 4) = ?
9
Relation between Data Structures and Algorithms
Program = Data Structures + Algorithms Data structures not only define how data is organized and stored, but also the operations performed on the data structure data structure chosen → algorithms developed e.g. array vs. list Some algorithms utilize data structures to store and organize data during the algorithm execution OS uses linked lists, tables (arrays), etc.
10
Abstract Data Types In computer science (esp. languages), the notion of type is very crucial e.g., “integer” type what does the type of a variable tell you? the (legal) operations you could work on it An abstract data type (ADT) is a data type described by predefined user operations without indicating how each operation is implemented
11
Abstract Data Types Can you think about that a “car” is an ADT?
What operations can you “operate” on a car? accelerate, break, turn, etc. Do you know how these operations work? probably not gas engine vs. electric Car tesla; tesla.break(); tesla.accelerate();
12
Is Keurig an ADT? Keurig k; k.open(); k.brew();
13
The Power of Abstraction
Barbara Liskov (ACM A.M. Turing Award lecture), 2007 For contributions to practical and theoretical foundations of programming language and system design, especially related to data abstraction, fault tolerance, and distributed computing
14
Abstraction vs. Optimization
There is no free lunch – “tradeoff” of ADT abstraction hides underlying implementation Using ADTs enables programmers or algorithm designers to focus on higher-level operations and algorithms, thus improving programmer efficiency However, knowledge of the underlying implementation is needed to analyze or improve the runtime efficiency We will be learning both in this class!
15
ADTs in Standard Libraries
C++ Standard template library (STL) vector, list, deque, queue, stack, set, map Python Python standard library list, set, dict, deque Java Java collections framework (JCF) Collection, Set, List, Map, Queue, Deque #include <iostream> #include <vector> using namespace std; int main( ) { vector<int> squares( 100 ); for( int i = 0; i < squares.size( ); ++i ) squares[ i ] = i * i; cout << i << " " << squares[ i ] << endl; return 0; }
16
Algorithm Efficiency Algorithm efficiency is typically measured by the algorithm's computational complexity Computational complexity is the amount of resources used by the algorithm The most common resources considered are the runtime (time) and memory usage (space) Runtime complexity is a function T(N) representing the number of constant time operations performed by an algorithm on an input of size N Space complexity is a function S(N) representing the number of fixed-size memory units used by an algorithm for an input of size N
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.