The document discusses several common data structures used in programming:
1. Arrays can store data sequentially in memory and access elements using an index. This includes one-dimensional, two-dimensional, and multi-dimensional arrays.
2. Queues and stacks follow first-in first-out (FIFO) and last-in first-out (LIFO) access rules respectively. They use pointers to insert and remove elements.
3. Lists and trees provide flexible data structures that use pointers between elements to link them together non-sequentially. Lists use a single pointer between elements while trees can have multiple child pointers.
The document discusses several common data structures used in programming:
1. Arrays can store data sequentially in memory and access elements using an index. This includes one-dimensional, two-dimensional, and multi-dimensional arrays.
2. Queues and stacks follow first-in first-out (FIFO) and last-in first-out (LIFO) access rules respectively. They use pointers to insert and remove elements.
3. Lists and trees provide flexible data structures that use pointers between elements to link them together non-sequentially. Lists use a single pointer between elements while trees can have multiple child pointers.
The document discusses several common data structures used in programming:
1. Arrays can store data sequentially in memory and access elements using an index. This includes one-dimensional, two-dimensional, and multi-dimensional arrays.
2. Queues and stacks follow first-in first-out (FIFO) and last-in first-out (LIFO) access rules respectively. They use pointers to insert and remove elements.
3. Lists and trees provide flexible data structures that use pointers between elements to link them together non-sequentially. Lists use a single pointer between elements while trees can have multiple child pointers.
Programming in assembly language (ALP) vs High Level
Language
C Program Elements:- Macros and functions,
Use of Date Types, Structure, Pointers, Function Calls
Program Modeling Concepts – Program Models- DFG
Models – FSM Models – Modeling of Multiprocessor Systems Data Structures: Arrays
• Array: A structure with a series of data items
sequentially placed in memory • Each element accessible by an identifier name (which points to the array) and an index, ‘i’ (which define offset from the first element) • ‘I’ starts from 0 and is +ve integer One dimensional array (vector) Example 1: unsigned int salary [12]; salary [0] – 1st month salary salary [11] – 12th month salary Each integer is of 32-bit (4 bytes); salary assigned 48 bytes address space Two dimensional array • unsigned int salary [11, 9]; salary [3, 5]– 4th month 6th year salary salary [11, 4] – 12th month 5th year salary salary assigned 12*10*4 = 480 bytes address space Multi-dimensional array • char pixel [144,176, 24]; pixel [0, 2, 5] – 1st horizontal line index x, 3rd vertical line index y, 6th color c. pixel assigned 144*176*24 = 608256 bytes address space in a colored picture of resolution 144x 176 and 24 colors Queue • A structure with a series of data elements with the first element waiting for an operation. • Used when an element is not to be accessed by index with a pointer directly, as in an array, but only through FIFO (first in first out) mode through a queue-head pointer. • An element can be inserted only at the end (also called tail or back) in series of elements waiting for an operation and deleted from front (queue-head). • There are two pointers, one for deleting after the read operation from the head and other for inserting at the tail. Both increment after an operation. Circular Queue Priority Queue • When there is an urgent message to be placed in a queue, we can program such that a priority data element inserts at the head instead of at the tail. • That element retrieves as if there is last-in first out. Standard Functions used in a queue 1. QELInsert – Insert an element into the queue as pointed by *qtail and increment the qtail pointer address 2. QELReturn – Return an element into the queue as pointed by *qhead and the element deletes from queue on increment in the qhead pointer address─ return also means delete 3. isQNotEmpty– Return true or false after the check for the queue not empty. Data Structure - Stack • A structure with a series of data elements with last sent element waiting for a delete operation. • Used when an element is not to be accessible by the index with pointer directly, as in an array, but only through LIFO (Last in first out) mode through a stack-top pointer. Stack • Push and Pop onto a Push and Pop onto a STACK • A data-element can be pushed (inserted) only at the from front (stack-head) in the series of elements waiting for an operation and popped (deleted) also from front (stack-head). Standard Functions used in a Stack 1. SELInsert – Pushes a data-element into the stack as pointed by item and increment the item pointer address 2. SELReturn – Pop an element from the stack as pointed by *item and the element deletes from stack on decrement in the item pointer address 3. isSNotEmpty– Return true or false after the check for the stack not empty. Stack Pointer • SP (stack pointer): SP is pointer to a memory block dedicated to saving the context on context switch to another ISR or routine. List • list differs from an array; array memory allocation- as per the index assigned to an element. List • each element- Must include along with an item a pointer, LIST_NEXT. Each element is at the memory address to which the predecessor list-element points. • LIST_NEXT points to the next element in the list. LIST_NEXT points to NULL in element at end of the list. • The memory-size of an item of an element can also vary. The address of the list element at the top is a pointer, LIST_TOP. Only by using the LIST_TOP and traversing through all the LIST_NEXT values for the preceding elements can an element be deleted or replaced or inserted between the two elements • A list differs from a queue as follows: A queue is accessible and is readable as FIFO only. • An insertion of an element in the list can be done anywhere within it only by traversing through LIST_NEXT pointers at all the preceding elements. An insertion is always at the tail in queue. • Also, an element can be read and deleted from anywhere in the list only by traversing through the list. It is always from the head in the queue. Tree • When the list becomes long traversing through it, insertions, deletion, and search of an element in-between the list becomes lengthier process. Tree • Suppose a list element instead of just pointing to the next element through LIST_NEXT, it points to two elements using LIST_NEXT_LEFT and LIST_NEXT _RIGHT or to more than two elements by LIST_NEXT1, LIST_NEXT2, …. Then instead of List, we form a Tree. Tree 1) There is a root element. 2) Root has two or more branches each having a daughter element. 3) Each daughter element has two or more daughter elements. 4) Last one (leaf) does not have any daughter element and points to Null. Tree
5) Only the root element is identifiable and it is done by
the treetop pointer (Header). 6) Each element points to TNodeNextLeft and TNodeNextRIGHT in a binary tree and or to more than two elements by TNodeNext1, TNodeNext2, … , TNodeNextN in tree with N-branches (maximum) at a node. 7) Since no other element is identifiable directly, by traversing the root element, then proceeding continuously through all the succeeding daughters, a tree element can be read or read and deleted, or can be added to another daughter or replaced by another element. Tree 7) Last element in the node points to NULL like in a list. 8) A tree has data elements arranged as branches. The last daughter, called node has no further daughters. A binary tree is a tree with a maximum of two daughters (branches) in each element. Application Examples of a Tree 1. A directory - Number of file-folders, Each file- folder having a number of other file folders and so on and a file is at the least node (leaf). 2. USB Devices nodes connected to hubs and nodes, and finally to a host controller at root. 3. Network architecture in which a central server connects to multiple servers and clients Table • A two-dimensional array (matrix) and is an important data set that is allocated a memory block. • There is always a base pointer for a table. • Base pointer points to its first element at the first column first row. • There are two indices, one for a column and other for a row. Pointers in Table
• Three pointers, table base, column index and
destination index pointers can retrieve any element of the table Hash Table • A hash table is a two-dimensional array (matrix) with first column can be said to hold key and second column the values • An important data set. • Each row has key and from look at the key, the addressed data in second column is traced • Just as an index identifies an array element, a hash-key identifies a hash element Hash Table