Lesson Data Structures in AI - Artificial Intelligence - ثالث ثانوي

Lesson 2 Data Structures in AI

The Importance of Data Structures in AI

Lesson 2 Data Structures in AI

Primitive Data Structures

Non-Primitive Data Structures

Different types of data

Linear Data Structures

Stack

Last In First Out (LIFO) rule

Lesson 2 Data Structures in AI

Operations on the stack

Push Operation

Pop Operation

Lesson 2 Data Structures in AI

Stack in Python

The push operation of the stack is

Lesson 2 Data Structures in AI

Jupyter Notebook

Lesson 2 Data Structures in AI

To create a new Jupyter Notebook:

Lesson 2 Data Structures in AI

To create a program in Jupyter Notebook:

Lesson 2 Data Structures in AI

Let's see the example of figure 1.15 in Jupyter.

Lesson 2 Data Structures in AI

In the following program, you will create a stack

Lesson 2 Data Structures in AI

Execute the previous program as follows:

Lesson 2 Data Structures in AI

Queue

Operations on the Queue:

First In First Out (FIFO) rule

The difference between the stack

Pointer

Index

Figure 1.22: Operations on the Queue

Lesson 2 Data Structures in AI

Enqueue Operation

Dequeue Operation

Lesson 2 Data Structures in AI

Queue in Python

Table 1.4: listName.pop() vs listName.pop(0) method

Lesson 2 Data Structures in AI

To program the above steps in Python,

Lesson 2 Data Structures in AI

Queue Applications

Stack and Queue Using Queue Module

Lesson 2 Data Structures in AI

Create a queue in which five values are entered by the user during program execution,

Lesson 2 Data Structures in AI

As mentioned before, the Queue module includes

Lesson 2 Data Structures in AI

You can use the following algorithm:

Lesson 2 Data Structures in AI

You can use the following algorithm:2

Lesson 2 Data Structures in AI

You can use the following algorithm:3

Lesson 2 Data Structures in AI

Static and Dynamic Data Structures

Static Data Structure

Dynamic Data Structure

Memory Allocation

Lesson 2 Data Structures in AI

Linked List

Linked List

Node

Figure 1.28: Graphical representation of node

Lesson 2 Data Structures in AI

Figure 1.30: Access the third node of the linked list

Table 1.8: Differences between list and linked list

Lesson 2 Data Structures in AI

Linked List in Python

Class

You will first create a node using Class.

Lesson 2 Data Structures in AI

Now add more nodes to your linked list.

Add a Node to a Linked List The actions required to add the new node

Lesson 2 Data Structures in AI

# single node

Delete a Node from a Linked List

Lesson 2 Data Structures in AI

If you want to delete the first node of a linked list, you must move the head to the second node of the list.

Lesson 2 Data Structures in AI

Read the sentences and tick True or False.

State the differences between static and dynamic data structures.

Write two examples of uses for linked lists.

Lesson 2 Data Structures in AI

You have a stack with six empty spaces.

• What is the process used to add the above elements into the queue?

• Complete the queue after adding the elements.

• What is the process used to remove elements from the queue?

How many times should the above operation be performed to remove the element with value 5?

Write Python code to create the previous queue.

Lesson 2 Data Structures in AI

Given the following nodes, draw the linked list and then write the values in the list in the correct order.

Draw the nodes of the linked list.

Describe the process of adding the number 7 after the number 45.

Draw the new list.

Describe the process required to delete the second node of the list.

• Draw the final linked list.