introduction to data structure
DESCRIPTION
introduction to data structureTRANSCRIPT
![Page 1: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/1.jpg)
DATA STRUCTURE AND
ALGORITHM ANALYSIS
![Page 2: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/2.jpg)
WHAT ARE DATA STRUCTURES
AND ALGORITHMS?
![Page 3: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/3.jpg)
DATA STRUCTURE It is a way of storing data in a computer
so that it can be used efficiently. Is a collection of data objects and a set
of legal operations to be performed on them.
method of organizing large amounts of data
Filing cabinets with alphabetized folders
The correct choice of data structure allows major improvements in program efficiency.
![Page 4: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/4.jpg)
ALGORITHM manipulate the data in these structures in
various ways, such as inserting anew data item, searching for a particular item, or sorting the items.
You can think of analgorithm as a recipe: a list of detailed instructions for carrying out an activity.
Step-by-step procedure used to solve a problem These steps should be capable of being
performed by a machine Must eventually stop and so produce an answer
![Page 5: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/5.jpg)
WHAT SORTS OF PROBLEMS CAN YOU SOLVE WITH A KNOWLEDGE OF THESE TOPICS?
they’re useful into three categories:
- Real-world data storage- Programmer’s tools- Modeling
![Page 6: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/6.jpg)
REAL-WORLD DATA STORAGE Some examples are a personnel record that
describes an actual human being, an inventory record that describes an existing car part or grocery item, and a financial transaction record.
A non-computer example of real-world data storage is a stack of index cards.(address book or home inventory)
![Page 7: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/7.jpg)
PROGRAMMER’S TOOLS
Not all data storage structures are used to store real-world data.
Typically, real-world data is accessed more or less directly by a program’s user.
However, some data storage structures are not meant to be accessed by the user, but by the program itself.
A programmer uses such structures as tools to facilitate some other operation.
Stacks, queues, and priority queues are often used in this way.
![Page 8: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/8.jpg)
REAL-WORLD MODELING
Some data structures directly model a real-world situation.
Stacks, queues, and priority queues are often used for this purpose.
A queue, for example, can model customers waiting in line at a bank, whereas a priority queue can model messages waiting to be transmitted over a local area network
![Page 9: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/9.jpg)
OVERVIEW OF DATA STRUCTURE
![Page 10: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/10.jpg)
OVERVIEW OF DATA STRUCTURE
![Page 11: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/11.jpg)
OVERVIEW OF ALGORITHM Many of the algorithms apply directly to
specific data structures. For most data structures, you must know how
to do the following:● Insert a new data item.● Search for a specified item.● Delete a specified item.● traverse through all the items in a data structure
●Sorting● Recursion
![Page 12: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/12.jpg)
ALGORITHM ANALYSIS
Analysis: How to predict an algorithm’s performance How well an algorithm scales up How to compare different algorithms for a problem
Data Structures How to efficiently store, access, manage data Data structures effect algorithm’s performance
![Page 13: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/13.jpg)
EXAMPLE ALGORITHMS Two algorithms for computing the Factorial Which one is better?
int factorial (int n) { if (n <= 1) return 1; else return n * factorial(n-1);}
int factorial (int n) { if (n<=1) return 1; else { fact = 1; for (k=2; k<=n; k++) fact *= k; return fact; }}
![Page 14: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/14.jpg)
EXAMPLES OF FAMOUS ALGORITHMS Constructions of Euclid Newton's root finding Fast Fourier Transform Compression (Huffman, Lempel-Ziv, GIF, MPEG) DES, RSA encryption Simplex algorithm for linear programming Shortest Path Algorithms (Dijkstra, Bellman-Ford) Error correcting codes (CDs, DVDs) TCP congestion control, IP routing Pattern matching (Genomics) Search Engines
![Page 15: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/15.jpg)
ROLE OF ALGORITHMS IN MODERN WORLD Enormous amount of data
E-commerce (Amazon, Ebay) Network traffic (telecom billing, monitoring) Database transactions (Sales, inventory) Scientific measurements (astrophysics, geology) Sensor networks. RFID tags Bioinformatics (genome, protein bank)
Amazon hired first Chief Algorithms Officer (Udi Manber)
![Page 16: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/16.jpg)
A REAL-WORLD PROBLEM Communication in the Internet Message (email, ftp) broken down into IP
packets. Sender/receiver identified by IP address. The packets are routed through the Internet
by special computers called Routers. Each packet is stamped with its destination
address, but not the route. Because the Internet topology and network
load is constantly changing, routers must discover routes dynamically.
What should the Routing Table look like?
![Page 17: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/17.jpg)
HOW TO MEASURE ALGORITHM PERFORMANCE What metric should be used to judge
algorithms? Length of the program (lines of code) Ease of programming (bugs, maintenance) Memory required Running time
Running time is the dominant standard. Quantifiable and easy to compare Often the critical bottleneck
![Page 18: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/18.jpg)
PRIMITIVE TYPESare data types provided by a
programming language as basic building blocks. Primitive types are also known as built-in types or basic types.
![Page 19: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/19.jpg)
PRIMITIVE TYPESCharacter IntegerStringDoubleFloatArray
![Page 20: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/20.jpg)
SPECIAL TYPES
![Page 21: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/21.jpg)
IntegerIs used to refer a data type which
represents some finite subset of mathematical integers.
Also known as integral data types.
Integral Types:UnsignedSigned
![Page 22: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/22.jpg)
Binary Coded DecimalIt is another representation of integer which is commonly used in mainframe financial applications and in database.
![Page 23: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/23.jpg)
StringIs an ordered sequence of
symbols.
Binary string
Byte string
Are used to suggest strings in which the stored data does not represent text.
![Page 24: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/24.jpg)
Double Double precision is a computer
numbering format that occupies two adjacent location in computer memory.
DoubleorDouble precision number
Defined to be an integer, fixed point, or floating point.
![Page 25: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/25.jpg)
Floatdescribes a system for numerical
representation in which a string of digits (or bits) represents a real number.
The term floating point refers to the fact that the radix point (decimal point, or, more commonly in computers, binary point) can "float": that is, it can be placed anywhere relative to the significant digits of the number
![Page 26: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/26.jpg)
ArrayIs a data structure consisting of a
group that are accessed by indexing.
Classification of ArrayFixed-sized arraysDynamic arrays
![Page 27: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/27.jpg)
DIFFERENT ALGORITHMS FOR SAME PROBLEM
Devise an algorithm to find the solution to a number raised to a positive powereg 45or 10 3 ie number power
1 set answer to 12 Loop 1 to power times
2.1 answer becomes answer * number3 report answer
Notice the layout and numbering
![Page 28: Introduction to Data Structure](https://reader035.vdocuments.us/reader035/viewer/2022062502/577cc6c11a28aba7119f136d/html5/thumbnails/28.jpg)
FIND THE RESULT OF NUMBER POWER
1 Set answer to 12 Loop for 1 to 5 times
2.1 answer becomes answer * 2
3 Report answer
AnswerLoop
1 12 24 38 416 532 ?
2 5 3 4
1 Set answer to 12 Loop for 1 to 4 times
2.1 answer becomes answer * 3
3 Report answerAnswer
Loop1 13 29 327 481 ?