This document provides an introduction to C++'s IOStream library for formatting input and output. It discusses stream manipulators that modify stream properties, such as endl, boolalpha, setw, and hex. It covers checking for and clearing error states in streams using functions like good(), fail(), and clear(). The document also introduces getline for reading entire lines of input as strings and stringstreams for building strings from mixed data types. It recommends exploring random access, read/write functions, and the CS106 Lexicon class for additional IOStream capabilities. Practice questions are provided to try using the library.
This document provides an introduction to C++'s IOStream library for formatting input and output. It discusses stream manipulators that modify stream properties, such as endl, boolalpha, setw, and hex. It covers checking for and clearing error states in streams using functions like good(), fail(), and clear(). The document also introduces getline for reading entire lines of input as strings and stringstreams for building strings from mixed data types. It recommends exploring random access, read/write functions, and the CS106 Lexicon class for additional IOStream capabilities. Practice questions are provided to try using the library.
Este documento describe cómo investigadores han adaptado algoritmos y teoremas de robótica para simular de forma más rápida y económica los movimientos de proteínas. Las proteínas se mueven de forma similar a los robots y simular sus complejos movimientos con cientos de articulaciones tomaba días o meses. Los nuevos métodos basados en la robótica permiten analizar cómo las proteínas se mueven al cumplir sus funciones y alcanzar su estructura tridimensional en menos tiempo.
Este documento describe cómo investigadores han adaptado algoritmos y teoremas de robótica para simular de forma más rápida y económica los movimientos de proteínas. Las proteínas se mueven de forma similar a los robots y simular sus complejos movimientos con cientos de articulaciones tomaba días o meses. Los nuevos métodos basados en la robótica permiten analizar cómo las proteínas se mueven al cumplir sus funciones y alcanzar su estructura tridimensional en menos tiempo.
1. The document describes a menu-driven program with 5 options: input N and M, display a rectangle with numbers based on N and M, calculate the total of prime numbers in the rectangle, calculate the total of numbers in the last column, and exit.
2. It provides details on how each option should be coded as a separate function, including any arguments passed and return values.
3. It also includes a separate question to write a program that accepts N strings, stores them in an array, and displays the strings, number of even length strings, and list of even strings.
This document provides instructions for an assignment in elementary C programming. It outlines 3 questions to code as separate C files saved in a specific folder structure. Question 1 checks if a number is a perfect square. Question 2 creates a menu-driven program to input and manipulate an array, performing operations like finding max odd number. Question 3 prints a pattern of asterisks in N rows based on an odd number N input by the user.
2. Tìm kiếm
• Tìm kiếm tuần tự
• Thời gian tồi nhất là n
• Chúng tôi có Độ phức tạp O(n)
• Ứng dụng cho mảng (không sắp xếp) và danh
sách liên kết
• Tìm kiếm nhị phân
• Ứng dụng cho dãy đã sắp xếp
• Thời gian thực hiện thuật toán log2 n
• Độ phức tạp tính toán O(log n)
3. Tìm kiếm – Tìm kiếm nhị phân
• Tạo ra một dãy đã sắp xếp
• Bổ xung vào danh sách liên kết
(AddToCollection)
• Bổ xung giá trị vào các vị trí đúng
• Tìm vị trí c1 log2 n
• Duyệt xuống c2 n
• Tổng quát c1 log2 n + c2 n
Hoặc c2 n
• Mỗi hoạt động gắn với dãy đã sắp xếp O(n)
? Chúng tôi có thể duy trì một dãy đã sắp
xếp với các hoạt động chèn dẻ hơn?
Dominant
term
4. Cây
• Cây nhị phân
• Bao gồm
• Node
• Các cây con trái và cây con phải
• Cả hai cây con đều là cây nhị phân
5. Cây
• Cây nhị phân
• Bao gồm
• Node
• Các cây con trái và con phải
• Cả hai đều là cây nhị phân
Chú ý
Định nghĩa
đệ qui!
Mỗi cây con
Là một cây
Nhị phân
7. Cây – Thủ tục
• Tìm (Find )
extern int KeyCmp( void *a, void *b );
/* Returns -1, 0, 1 for a < b, a == b, a > b */
void *FindInTree( Node t, void *key ) {
if ( t == (Node)0 ) return NULL;
switch( KeyCmp( key, ItemKey(t->item) ) ) {
case -1 : return FindInTree( t->left, key );
case 0: return t->item;
case +1 : return FindInTree( t->right, key );
}
}
void *FindInCollection( collection c, void *key ) {
return FindInTree( c->root, key );
}
Less,
search
left
Greater,
search right
8. Cây – Thủ tục
• Find
• key = 22;
if ( FindInCollection( c , &key ) ) ….
n = c->root;
FindInTree( n, &key );
FindInTree(n->right,&key );
FindInTree(n->left,&key );
return n->item;
9. Cây – hoạt động
• Find
• Cây hoàn toàn
• Chiều cao, h
• Các node di truyển trên một con đường từ gốc đến
một lá
• Số các node, h
• n = 1 + 21 + 22 + … + 2h = 2h+1 - 1
• h = floor( log2 n )
10. Cây – Hoạt động
• Find
• Cây hoàn toàn
• Vì chúng tôi cần nhiều nhât h+1 phép so sánh,
độ phức tạp O(h+1) hoặc O(log n)
• Giống như tìm kiếm nhị phân
11. Tổng kết
Arrays
Đơn giản, nhanh
Không mềm dẻo
O(1)
O(n) inc sort
O(n)
O(n)
O(logn)
Tìm kiếm nhị phân
Add
Delete
Find
Linked List
Đơn giản
Mềm dẻo
O(1)
sort -> no adv
O(1) - any
O(n) - specific
O(n)
(không tìm kiếm
nhị phân)
Trees
Vẫn đơn giản
Mềm dẻo
O(log n)
12. Cây – Bổ xung (Addition)
• Cộng 21 vào cây
• Chúng tôi cần tối đa h+1 phép so sánh
• Tạo một node mới (thời gian là hằng số)
add lấy c1(h+1)+c2 hoặc c log n
• Vì thế việc bổ xung vào một cây cũng chiếm
thời gian là log n
Ignoring
low order
terms
13. Cây - Addition – thủ tục
static void AddToTree( Node *t, Node new ) {
Node base = *t;
/* If it's a null tree, just add it here */
if ( base == NULL ) {
*t = new; return; }
else
if( KeyLess(ItemKey(new->item),ItemKey(base->item)) )
AddToTree( &(base->left), new );
else
AddToTree( &(base->right), new );
}
void AddToCollection( collection c, void *item ) {
Node new, node_p;
new = (Node)malloc(sizeof(struct t_node));
/* Attach the item to the node */
new->item = item;
new->left = new->right = (Node)0;
AddToTree( &(c->node), new );
}
14. Cây – Bổ xung (Addition)
• Find c log n
• Add c log n
• Delete c log n
• Hiệu quả rất đáng kể!
• Tuy nhiên vẫn bắt gặp một số trường hợp
………..
15. Cây – Bổ xung (Addition)
• Lấy danh sách ký tự này và hình thành một
cây
A B C D E F
• ??
16. Trees - Addition
• Nhận danh sách ký tự này và hình thành
một cây A B C D E F
• Trong trường hợp này:
? Find
? Add
? Delete