0% found this document useful (0 votes)
3 views

Data Structure

The document is a lecture note on Data Structures, detailing their definition, importance, and various types. It explains how data structures organize, process, and store data efficiently, highlighting the significance of choosing the appropriate structure for specific tasks. The document also covers characteristics of data structures, their applications, and examples of different types such as arrays, stacks, queues, and trees.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Data Structure

The document is a lecture note on Data Structures, detailing their definition, importance, and various types. It explains how data structures organize, process, and store data efficiently, highlighting the significance of choosing the appropriate structure for specific tasks. The document also covers characteristics of data structures, their applications, and examples of different types such as arrays, stacks, queues, and trees.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1

2 TIMEON KAIROS POLYTECHNIC


3 326, Lagos- Abeokuta Expressway, Abule-Egba, Lagos.
4

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.

8 In computer science and computer programming, a data structure may be selected or


9 designed to store data for the purpose of using it with various algorithms. In some
0 cases, the algorithm's basic operations are tightly coupled to the data structure's
1 design. Each data structure contains information about the data values, relationships
2 between the data and -- in some cases -- functions that can be applied to the data.

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.

0 Why are data structures important?


1 Typical base data types, such as integers or floating-point values, that are available in
2 most computer programming languages are generally insufficient to capture the logical
3 intent for data processing and use. Yet applications that ingest, manipulate and produce
4 information must understand how data should be organized to simplify processing. Data
5 structures bring together the data elements in a logical way and facilitate the effective
6 use, persistence and sharing of data. They provide a formal model that describes the
7 way the data elements are organized.

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:

7 1. What kind of information will be stored?

8 2. How will that information be used?


3
9 3. Where should data persist, or be kept, after it is created?

0 4. What is the best way to organize the data?

1 5. What aspects of memory and storage reservation management should be


2 considered?
3 How are data structures used?
4 In general, data structures are used to implement the physical forms of abstract data
5 types. Data structures are a crucial part of designing efficient software. They also play a
6 critical role in algorithm design and how those algorithms are used within computer
7 programs.

8 Early programming languages -- such as Fortran, C and C++ -- enabled programmers to


9 define their own data structures. Today, many programming languages include an
0 extensive collection of built-in data structures to organize code and information. For
1 example, Python lists and dictionaries, and JavaScript arrays and objects are common
2 coding structures used for storing and retrieving information.

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.

6  Data exchange. Data structures define the organization of information shared


7 between applications, such as TCP/IP packets.

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.

7 2. Homogeneous or heterogeneous. This characteristic describes whether all data


8 items in a given repository are of the same type. One example is a collection of
9 elements in an array, or of various types, such as an abstract data type defined as a
0 structure in C or a class specification in Java.

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.

0  integer, which stores a range on mathematical integers -- or counting numbers.


1 Different sized integers hold a different range of values -- e.g., a signed 8-bit integer
2 holds values from -128 to 127, and an unsigned long 32-bit integer holds values from
3 0 to 4,294,967,295.

4  Floating-point numbers, which store a formulaic representation of real numbers.

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.

7  Character, which uses symbols from a defined mapping of integer values to


8 symbols.

9  Pointers, which are reference values that point to other values.

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.

2 The data structure


3 hierarchy shows how data types and data structures are related.
4 Types of data structures
5 The data structure type used in a particular situation is determined by the type of
6 operations that will be required or the kinds of algorithms that will be applied. The
7 various data structure types include the following:

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.

1 An array can hold a


2 collection of integers, floating-point numbers, stings or even other arrays.

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.

0 Linked list data structures


1 are a set of nodes that contain data and the address or a pointer to the next node.

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.

2 How to choose a data structure


3 When choosing a data structure for a program or application, developers should
4 consider the answers to the following three questions:

5 1. Supported operations. What functions and operations does the program need?

6 2. Computational complexity. What level of computational performance is tolerable?


7 For speed, a data structure whose operations execute in time linear to the number of
8 items managed -- using Big O notation: O(n) -- will be faster than a data structure
9 whose operations execute in time proportional to the square of the number of items
0 managed -- O(n^2).

1 3. Programming elegance. Are the organization of the data structure and its
2 functional interface easy to use?

3 Some real-world examples include:

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

You might also like