Data Structures & Algorithms – I, Essays (high school) of Computer science

The fundamentals of data structures and algorithms, which are essential topics in computer science and engineering. It introduces common data structures such as arrays, lists, stacks, queues, graphs, and trees, and discusses how to analyze their efficiency in terms of space and time complexity. The document also provides examples of algorithms in programming, including adding two numbers and finding the largest among three numbers. It explains the concept of abstract data types and the differences between scalar, linear, and nonlinear data structures. Additionally, the document covers pointers, their usage, and how they can be used as function parameters. This comprehensive overview of data structures and algorithms would be valuable for university students studying computer science, computer engineering, or related fields, as it provides a solid foundation for understanding and applying these fundamental concepts in problem-solving and software development.

Typology: Essays (high school)

2019/2020

Uploaded on 06/24/2024

realanad-renad
realanad-renad 🇱🇾

1 document

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Da
t
a S
tru
c
tur
e
s
&
A
l
g
orithms
I
EC
352
I
nstr
.
Sa
rr
a E
lr
ab
i
e
i
Fa
ll
2023/2024
U
niv
e
rsity
o
f T
ripoli
Fac
ulty
o
f E
n
g
in
ee
rin
g
-
C
omput
e
r
E
n
g
in
ee
rin
g De
p
a
m
e
nt
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Data Structures & Algorithms – I and more Essays (high school) Computer science in PDF only on Docsity!

Data Structures & Algorithms – I

EC 352 

 Instr. Sarra Elrabiei  Fall 2023/

University of Tripoli

Faculty of Engineering- Computer Engineering Depament 

Data structure: A container class that provides storage for data items and capabilities for storing and retrieving data items.

Common data structures—Arrays, lists, stacks, queues, graphs, and trees.

Set Stack^ Tree

Data Structures (DS)

Why Study 

Data Structures &

Algorithms?

  • • – – – – – – Basics of Algorithms and data structures are ve impoant in computer science and engineering.

Examples of real world applications

Arrays, Stacks, Tables, Trees …etc (Data Structures) Soing data ( Varies algorithms such as Selection, Bubble & Merge) Routing communication algorithms (Find shoest path) Database indices rely on search Tree & Tables data structures Search engines Such as Google use algorithms; such as PageRank algorithm , to rank impoance of websites Graphics needs geometric algorithms to compute primitives shapes

Algorithms

Algorithms Analysis: Space: amount of memo required to complete an algorithm Time: Algorithm running time

Algorithms can be expressed in many kinds of notation such as pseudocode and owchas.

An algorithm to nd the largest among three dierent numbers entered by user.

Step 1: Sta Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop

Example (2):

What will you learn?

What are some of the common data structures?

What are some ways to implement them?

How to analyze their eciency?

How to use them to solve practical problems?

Example (cont’d)

  • What to do?

Sol. 1 Sequential matching: 1 sec. x 600,000 words = 166 hours Sol. 2 Bina searching:

  • order the words
  • search only half at a time

Ex. Search 25 in 5 8 12 15 15 17 23 25 27 25? 15 15 17 23 25 27 25? 23 23 25 27 25? 25 How many steps?

Abstract data type

A data type can be considered abstract when it is de f in e d by a s e t o f v a lu e a n d a s e t o f operations.

An Abstract Data Type (ADT) is: a set of values a set of operations, which can be applied uniformly to all these values The def inition of ADT only mentions what operations are to be per formed but not how these operations will be implemented. It does not specify how data will be organized in memo a n d w h a t a l g o r i t h m s w i l l b e u s e d f o r implementing the operations.

  • • • • • • • • Scalar data structure: A container that hold one value at a time. Examples:
  • Integer - Float - Double - Character

Linear data structure : A container that holds one or more values at a time Elements are adjacent to each other (2 neighbours). Examples,

  • Arrays - List - Queue - Stack

Nonlinear data structure : A container that holds one or more values at a time. One element can be connected to more than two adjacent element.

Data Structures (DS)

13

Pointers

    – –  A Pointer is an address Pointers simplify the transfer of information from one location to another. When two functions operate on the same set of data, passing along the address is more ef ficient than a copy of the data itself. That is  improve speed Save space Also pointers allow the function to change more than one variable.

Pointer Fundamentals

When a variable is def ined the compiler (linker/loader actually) allocates a real memo address for the variable. int x;

It will allocate 4 bytes in the main memor y, which will be used to store an integer value.

When a value is assigned to a variable, the value is actually placed to the memo that was allocated. x=3; It will store integer 3 in the 4 bytes of memo.

00000000 00000000 00000000 00000011

x

Pointers

To declare a pointer variable

type * pointername;

Example:

int *p;

P

Memo

 (^) The variable p is pointer to an integer.

int *a;

int b = 17;

a=&b;

Example

int main() { int n=44; cout << "n = " << n << ", &n = " << &n << endl; int* pn=&n; // pn holds the address of n cout << " pn = " << pn << endl; cout << "&pn = " << &pn << endl; }

This program denes the int variable n and the int*

variable pn: