Data Structure
Data Structure
9 LECTURE NOTE ON
0
4 DATA STRUCTURES
5 COURSE CODE: CTE 115
6
0 Mr Tajudeen A.A
1
1
5 Introduction to Data Structures
6 Data Structure is a way of collecting and organising data in such a way that we can
7 perform operations on these data in an effective way. Data Structures is about
8 rendering data elements in terms of some relationship, for better organization and
9 storage. For example, we have some data which has, player's name "Virat" and age 26.
0 Here "Virat" is of String data type and 26 is of integer data type.
1 We can organize this data as a record like Player record, which will have both player's
2 name and age in it. Now we can collect and store player's records in a file or database
3 as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
4 If you are aware of Object Oriented programming concepts, then a class also does the
5 same thing, it collects different type of data under one single entity. The only difference
6 being, data structures provides for techniques to access and manipulate data efficiently.
7 In simple language, Data Structures are structures programmed to store ordered data,
8 so that various operations can be performed on it easily. It represents the knowledge of
9 data to be organized in memory. It should be designed and implemented in such a way
0 that it reduces the complexity and increases the efficiency.
1 Data structures
2 A data structure is a specialized format for organizing, processing, retrieving and storing
3 data. There are several basic and advanced types of data structures, all designed to
4 arrange data to suit a specific purpose. Data structures make it easy for users to access
5 and work with the data they need in appropriate ways. Most importantly, data structures
6 frame the organization of information so that machines and humans can better
7 understand it.
3 For instance, in an object-oriented programming language, the data structure and its
4 associated methods are bound together as part of a class definition. In non-object-
5 oriented languages, there may be functions defined to work with the data structure, but
6 they are not technically part of the data structure.
2
7 . A data item is a single unit of values. It is a raw fact which becomes information after processing. Data items
8 for example, date are called group items if they can be divided into subsystems. The date for instance is
9 represented by the day, the month and umber is called an elementary item, because it cannot be sub-divided
0 into sub-items. It is indeed treated as a single item. An entity is used to describe anything that has certain
1 attributes or properties, which may be assigned values. For example, the following are possible attributes and
2 their corresponding values for an entity known as STUDENT.
ATTRIBUTES NAME AGE SEX MATRIC NO
VALUES Paul 21 Male 800654
63
4 Entities with similar attributes for example, all the 200 level Computer science & Statistics students form an
5 entity set.
6 Main functions of data Structures:
7 Seek to identify and develop entities, operations and appropriate classes of problems to use them.
8 Determine representations for abstract entities to implement abstract operations on concrete
9 representations.
8 Data structures are the building blocks for more sophisticated applications. They are
9 designed by composing data elements into a logical unit representing an abstract data
0 type that has relevance to the algorithm or application. An example of an abstract data
1 type is a "customer name" that is composed of the character strings for "first name,"
2 "middle name" and "last name."
3 It is not only important to use data structures, but it is also important to choose the
4 proper data structure for each task. Choosing an ill-suited data structure could result in
5 slow runtimes or unresponsive code. Five factors to consider when picking a data
6 structure include the following:
3 Software engineers use algorithms that are tightly coupled with the data structures --
4 such as lists, queues and mappings from one set of values to another. This approach
5 can be fused in a variety of applications, including managing collections of records in
6 a relational database and creating an index of those records using a data structure
7 called a binary tree.
8 Some examples of how data structures are used include the following:
9 Storing data. Data structures are used for efficient data persistence, such as
0 specifying the collection of attributes and corresponding structures used to store
1 records in a database management system.
2 Managing resources and services. Core operating system (OS) resources and
3 services are enabled through the use of data structures such as linked lists for
4 memory allocation, file directory management and file structure trees, as well as
5 process scheduling queues.
4
8 Ordering and sorting. Data structures such as binary search trees -- also known as
9 an ordered or sorted binary tree -- provide efficient methods of sorting objects, such
0 as character strings used as tags. With data structures such as priority queues,
1 programmers can manage items organized according to a specific priority.
2 Indexing. Even more sophisticated data structures such as B-trees are used to index
3 objects, such as those stored in a database.
4 Searching. Indexes created using binary search trees, B-trees or hash tables speed
5 the ability to find a specific sought-after item.
6 Scalability. Big data applications use data structures for allocating and managing
7 data storage across distributed storage locations, ensuring scalability and
8 performance. Certain big data programming environments -- such as Apache Spark --
9 provide data structures that mirror the underlying structure of database records to
0 simplify querying.
1 Characteristics of data structures
2 Data structures are often classified by their characteristics. The following three
3 characteristics are examples:
4 1. Linear or non-linear. This characteristic describes whether the data items are
5 arranged in sequential order, such as with an array, or in an unordered sequence,
6 such as with a graph.
1 3. Static or dynamic. This characteristic describes how the data structures are
2 compiled. Static data structures have fixed sizes, structures and memory locations at
3 compile time. Dynamic data structures have sizes, structures and memory locations
4 that can shrink or expand, depending on the use.
5 Data types
6 If data structures are the building blocks of algorithms and computer programs, the
7 primitive -- or base -- data types are the building blocks of data structures. The typical
8 base data types include the following:
5
9 Boolean, which stores logical values that are either true or false.
5 Fixed-point numbers, which are used in some programming languages and hold
6 real values but are managed as digits to the left and the right of the decimal point.
0 String, which is an array of characters followed by a stop code -- usually a "0" value
1 -- or is managed using a length field that is an integer value.
6
8 Array. An array stores a collection of items at adjoining memory locations. Items
9 that are the same type are stored together so the position of each element can be
0 calculated or retrieved easily by an index. Arrays can be fixed or flexible in length.
3 Stack. A stack stores a collection of items in the linear order that operations are
4 applied. This order could be last in, first out (LIFO) or first in, first out (FIFO).
5 Queue. A queue stores a collection of items like a stack; however, the operation
6 order can only be first in, first out.
7 Linked list. A linked list stores a collection of items in a linear order. Each element,
8 or node, in a linked list contains a data item, as well as a reference, or link, to the
9 next item in the list.
2 Tree. A tree stores a collection of items in an abstract, hierarchical way. Each node is
3 associated with a key value, with parent nodes linked to child nodes -- or subnodes.
4 There is one root node that is the ancestor of all the nodes in the tree.
7
5
6 A binary search tree is a set of nodes where each has a value and can point to two child nodes.
7 Heap. A heap is a tree-based structure in which each parent node's associated key
8 value is greater than or equal to the key values of any of its children's key values.
9 Graph. A graph stores a collection of items in a nonlinear fashion. Graphs are made
0 up of a finite set of nodes, also known as vertices, and lines that connect them, also
1 known as edges. These are useful for representing real-world systems such as
2 computer networks.
3 Trie. A trie, also known as a keyword tree, is a data structure that stores strings as
4 data items that can be organized in a visual graph.
5 Hash table. A hash table -- also known as a hash map -- stores a collection of items
6 in an associative array that plots keys to values. A hash table uses a hash function to
7 convert an index into an array of buckets that contain the desired data item.
8
8 Hashing is a data structure
9 technique where key values are converted into indexes of an array where the data is stored.
0 These are considered complex data structures as they can store large amounts of
1 interconnected data.
5 1. Supported operations. What functions and operations does the program need?
1 3. Programming elegance. Are the organization of the data structure and its
2 functional interface easy to use?
4 Linked lists are best if a program is managing a collection of items that don't need
5 to be ordered, constant time is required for adding or removing an item from the
6 collection and increased search time is OK.
7 Stacks are best if the program is managing a collection that needs to support a LIFO
8 order.
9
9 Queues should be used if the program is mana ging a collection that needs to
0 support a FIFO order.
1 Binary trees are good for managing a collection of items with a parent-child
2 relationship, such as a family tree.
3 Binary search trees are appropriate for managing a sorted collection where the
4 goal is to optimize the time it takes to find specific items in the collection.
5 Graphs work best if the application will analyze connectivity and relationships
6 among a collection of individuals in a social media network.
7 The following are the units for identifying data character, fields, sub fields , records, files.
8 A file is a collection of logically related records; e.g students file, stock file.
9 A record is a collection of logically related data fields; e. g Data relating to students in students file. In a
0 database table records are usually in rows. Therefore, the table below has three (3) records. While a field is
1 consecutive storage position of values. It is a unit of data within a record e. g student's number, Name, Age.
2 In a database concept fields are usually in columns of a given table.
3 Data items for example , date are called group items if they can be divided into subsystems. The date for
4 instance is represented by the day, the month andumber is called an elementary item, because it can not be
5 sub-divided into sud-items otherwise known as sub fields called . It is indeed treated as a single item.
6 Character is the smallest unit of information. It includes letters, digits and special symbols such as + (Plus
7 sign), _(minus sign), \, /, $,a,b,z, A,B,Z etc. Every character requires one byte of memory unit for storage in
8 computer system.
9
10
6
11
3
12